Home >Backend Development >PHP Tutorial >Aegis encryption and decryption tutorial (1) Characters available for PHP variables_PHP tutorial
Let’s talk about the naming rules of PHP variables first. Baidu will catch up with them:
(1) PHP variable names are case-sensitive;
(2) Variable names must start with the dollar sign $;
(3) The variable name can start with an underscore;
(4) The variable name cannot start with a numeric character.
In fact, the naming convention that is similar to all programming is:
1. The first character of a variable is preferably a letter or _, and cannot start with a number
2. The second character allows numbers, letters, and _
Okay, that’s pretty much it, but that’s not the point.
Today we talk about the available characters of PHP variables, not just numbers, letters, _ oh.
A few days ago, a friend on QQ sent me a shell. It was encrypted and garbled throughout. However, there was a comment on it called "Aegis Encryption". It looked so domineering.
It uses some relatively unfamiliar knowledge points, the most obvious of which is variable names, so today we will start with variables.
Of course, I didn’t find any authoritative material on the Internet that strongly explains the characters available in PHP variable names, so I could only test it myself. (My English is not good, so I can’t Google to find any favorable evidence)
Let’s first look at the method I used. (If you have a better method, please share it.)
For example, the character a will be parsed eval('$a=1;'); This result is definitely no problem, so no exception will be thrown, and the returned result is the ok character.
If the character - then it will be parsed eval('$-=1;'); This is obviously wrong, so it will throw PHP Parse error: syntax error, unexpected '-', expecting T_VARIABLE or '$' and ok character.
The following ajax part uses whether the return result is 'ok' to determine whether it is a valid variable name.
Let’s see what the result is after execution:
In addition to the familiar A-Z_a-z in the front, the messy things in the back can also be used as normal variable names, which is incredible.
In fact, it is just PHP that expands the character range of variable names. On top of A-Z_a-z, it expands the available character range of variables to x7f-xff.
So, the first character range should be [a-zA-Z_x7f-xff]
Then let’s continue to test whether the second character can be the same.
Change eval('$'.$chr."=1;"); in the above php code to eval('$a'.$chr."=1;"); Save the test,
I found that there are a lot more characters in the result. In fact, some of them we need to remove. For example, x20 is actually a space, which is equivalent to eval('$a =1;');. Of course, it can be executed normally.
In addition to spaces, trn are all removed because these are also allowed by PHP syntax: t=x9, n=xa, r=xd, so we have to remove the first 4 data x9, xa, xd, x20 in the result.
The final result is actually just more x30, x31, x32, x33, x34, x35, x36, x37, x38, x39. People who are familiar with ascii may see it at a glance. These are the numbers 0-9
So the first character range should be [wx7f-xff] Those who are not familiar with regular expressions may wonder why it is not [0-9a-zA-Z_x7f-xff]. In fact, w is 0-9a-zA-Z_
Maybe someone will say $$a; ${$a}; What about variables like this?
I think this is out of the scope of variable naming, isn't it?
Okay, I have finished sharing the knowledge about the characters available in PHP variables. If there is anything wrong, please leave a message and I will correct it in time to avoid misleading everyone.
My guess: ascii range 0-127 (x00-x7f), latin1 range 0-255 (x00-xff), maybe PHP has expanded the range to latin1 character set, of course I have not seen the PHP source code, only It can be said to be just a conjecture.