神盾加密解密教程(一)PHP变量可用字符_PHP
先来说说php变量的命名规则,百度下一抓一大把:
(1) PHP的变量名区分大小写;
(2) 变量名必须以美元符号$开始;
(3) 变量名开头可以以下划线开始;
(4) 变量名不能以数字字符开头.
其实所有编程都类似的命名规范就是:
1. 变量第一个字符最好是 字母或_,不能以数字开头
2. 第二个字符开始允许 数字,字母,_
好了,差不多就是这样了,但是这不是我们要说的重点。
今天我们说说 PHP 变量的可用字符,不仅仅是 数字,字母,_ 哦。
前几天QQ上一朋友发我一个shell,是加密过的,通篇乱码,不过上面有注释,叫做 “神盾加密” 好霸气的样子。
里面用了一些比较生僻的知识点,其中最明显的就是变量名,所以今天我们先从变量开始讲。
当然网上我也没找到权威的质料强有力的说明PHP的变量名可用字符的信息,所以我只能自己测试了。(英文不好,没办法谷歌到有利的证据)
先来看下我所用的方法,(如果你有更好的方法,希望分享下。)
复制代码 代码如下:
if ($_POST) {
$chr = chr($_POST['chr']);
eval('$'.$chr."=1;");
echo 'ok';
exit;
}
?>
<script><BR> for(var i = 0x00; i <= 0xFF; i++) { // 0x00 - 0xFF 255个字符<BR> $.ajaxSettings.async = false; // 同步模式, 为了按顺序返回数据<BR> $.post( "?", {chr: i}, (function (data) { // post i 给 php 解析<BR> data === 'ok' && console.log( "\\x"+(i).toString(16) ); // 如果只返回 ok 说明能正常执行,否则会抛出异常<BR> });<BR> }<BR> </script>
代码还算比较简单,PHP 部分只负责解析每一个字符当作变量名的执行结果是否会抛出溢出。
比如 字符 a 那么会解析 eval('$a=1;'); 这样的结果肯定没问题,所以不会抛出异常,返回结果就是 ok 字符。
如果 字符 - 那么会解析 eval('$-=1;'); 这明显是不对的,所以会抛出 PHP Parse error: syntax error, unexpected '-', expecting T_VARIABLE or '$' 和 ok 字符。
而下面的 ajax 部分者正是利用返回结果是否为 'ok' 而判断是否是有效的变量名。
看看执行后的结果是什么吧:
复制代码 代码如下:
"\x41, \x42, \x43, \x44, \x45, \x46, \x47, \x48, \x49, \x4a, \x4b, \x4c, \x4d, \x4e, \x4f, \x50, \x51, \x52, \x53, \x54, \x55, \x56, \x57, \x58, \x59, \x5a, \x5f, \x61, \x62, \x63, \x64, \x65, \x66, \x67, \x68, \x69, \x6a, \x6b, \x6c, \x6d, \x6e, \x6f, \x70, \x71, \x72, \x73, \x74, \x75, \x76, \x77, \x78, \x79, \x7a, \x7f, \x80, \x81, \x82, \x83, \x84, \x85, \x86, \x87, \x88, \x89, \x8a, \x8b, \x8c, \x8d, \x8e, \x8f, \x90, \x91, \x92, \x93, \x94, \x95, \x96, \x97, \x98, \x99, \x9a, \x9b, \x9c, \x9d, \x9e, \x9f, \xa0, \xa1, \xa2, \xa3, \xa4, \xa5, \xa6, \xa7, \xa8, \xa9, \xaa, \xab, \xac, \xad, \xae, \xaf, \xb0, \xb1, \xb2, \xb3, \xb4, \xb5, \xb6, \xb7, \xb8, \xb9, \xba, \xbb, \xbc, \xbd, \xbe, \xbf, \xc0, \xc1, \xc2, \xc3, \xc4, \xc5, \xc6, \xc7, \xc8, \xc9, \xca, \xcb, \xcc, \xcd, \xce, \xcf, \xd0, \xd1, \xd2, \xd3, \xd4, \xd5, \xd6, \xd7, \xd8, \xd9, \xda, \xdb, \xdc, \xdd, \xde, \xdf, \xe0, \xe1, \xe2, \xe3, \xe4, \xe5, \xe6, \xe7, \xe8, \xe9, \xea, \xeb, \xec, \xed, \xee, \xef, \xf0, \xf1, \xf2, \xf3, \xf4, \xf5, \xf6, \xf7, \xf8, \xf9, \xfa, \xfb, \xfc, \xfd, \xfe, \xff"
整理后发现是这样的16进制数据,当然看不懂没关系,看下转义后的结果:
复制代码 代码如下:
"A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, _, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, , ¡, ¢, £, ¤, ¥, ¦, §, ¨, ©, ª, «, ¬, , ®, ¯, °, ±, ², ³, ´, µ, ¶, ·, ¸, ¹, º, », ¼, ½, ¾, ¿, À, Á, Â, Ã, Ä, Å, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ð, Ñ, Ò, Ó, Ô, Õ, Ö, ×, Ø, Ù, Ú, Û, Ü, Ý, Þ, ß, à, á, â, ã, ä, å, æ, ç, è, é, ê, ë, ì, í, î, ï, ð, ñ, ò, ó, ô, õ, ö, ÷, ø, ù, ú, û, ü, ý, þ, ÿ"
除了前面的 A-Z_a-z 是我们熟悉的,后面的那些乱七八糟的东西竟然也能当作正常的变量名,简直不可思议。
其实只是PHP拓展了变量名的字符范围,在 A-Z_a-z 之上,将变量可用字符范围拓展到了 \x7f-\xff。
所以,第一个字符范围应该是 [a-zA-Z_\x7f-\xff]
那么第二个字符是否也是这样能,我们继续测试下。
将上面 php 代码里的 eval('$'.$chr."=1;"); 改成 eval('$a'.$chr."=1;"); 保存测试、
复制代码 代码如下:
"\x9, \xa, \xd, \x20, \x30, \x31, \x32, \x33, \x34, \x35, \x36, \x37, \x38, \x39, \x41, \x42, \x43, \x44, \x45, \x46, \x47, \x48, \x49, \x4a, \x4b, \x4c, \x4d, \x4e, \x4f, \x50, \x51, \x52, \x53, \x54, \x55, \x56, \x57, \x58, \x59, \x5a, \x5f, \x61, \x62, \x63, \x64, \x65, \x66, \x67, \x68, \x69, \x6a, \x6b, \x6c, \x6d, \x6e, \x6f, \x70, \x71, \x72, \x73, \x74, \x75, \x76, \x77, \x78, \x79, \x7a, \x7f, \x80, \x81, \x82, \x83, \x84, \x85, \x86, \x87, \x88, \x89, \x8a, \x8b, \x8c, \x8d, \x8e, \x8f, \x90, \x91, \x92, \x93, \x94, \x95, \x96, \x97, \x98, \x99, \x9a, \x9b, \x9c, \x9d, \x9e, \x9f, \xa0, \xa1, \xa2, \xa3, \xa4, \xa5, \xa6, \xa7, \xa8, \xa9, \xaa, \xab, \xac, \xad, \xae, \xaf, \xb0, \xb1, \xb2, \xb3, \xb4, \xb5, \xb6, \xb7, \xb8, \xb9, \xba, \xbb, \xbc, \xbd, \xbe, \xbf, \xc0, \xc1, \xc2, \xc3, \xc4, \xc5, \xc6, \xc7, \xc8, \xc9, \xca, \xcb, \xcc, \xcd, \xce, \xcf, \xd0, \xd1, \xd2, \xd3, \xd4, \xd5, \xd6, \xd7, \xd8, \xd9, \xda, \xdb, \xdc, \xdd, \xde, \xdf, \xe0, \xe1, \xe2, \xe3, \xe4, \xe5, \xe6, \xe7, \xe8, \xe9, \xea, \xeb, \xec, \xed, \xee, \xef, \xf0, \xf1, \xf2, \xf3, \xf4, \xf5, \xf6, \xf7, \xf8, \xf9, \xfa, \xfb, \xfc, \xfd, \xfe, \xff"
发现结果多了好多字符,其实有一部分我们是要去掉的,比如 \x20 其实就是 空格,相当于 eval('$a =1;'); 而已,当然是能正常执行的。
除了空格,还有 \t\r\n 都去掉因为这些也是PHP语法说允许的 \t=\x9,\n=\xa,\r=\xd,所以我们要去掉结果中的前4个数据\x9, \xa, \xd, \x20,
最终得到的结果其实只是多了 \x30, \x31, \x32, \x33, \x34, \x35, \x36, \x37, \x38, \x39 熟悉 ascii 的人也许一眼就看出来了,这就是数字 0-9
所以第一个字符范围应该是 [\w\x7f-\xff] 对正则不熟的也许会觉得怎么不是 [0-9a-zA-Z_\x7f-\xff],其实 \w 就是 0-9a-zA-Z_
也许有人会说 $$a; ${$a}; 这样的变量呢?
我觉得这个已脱离了变量命名的范围了,不是么。
好了,关于 php 变量可用字符的知识点分享完毕了,如果有哪说的不对的,请留言,我会及时改正以免误导大家。
我的猜测: ascii 范围 0-127(\x00-\x7f), latin1 范围 0-255(\x00-\xff),也许PHP就是将范围扩充到 latin1 字符集了,当然我没看过PHP源码,只能说是个猜想而已。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
