实验吧_拐弯抹角(url伪静态)&Forms

拐弯抹角

先贴代码

 1  <?php
 2 // code by SEC@USTC
 3 
 4 echo '<html><head><meta http-equiv="charset" content="gbk"></head><body>';
 5 
 6 $URL = $_SERVER['REQUEST_URI'];
 7 //echo 'URL: '.$URL.'<br/>';
 8 $flag = "CTF{???}";
 9 
10 $code = str_replace($flag, 'CTF{???}', file_get_contents('./index.php'));
11 $stop = 0;
12 
13 //这道题目本身也有教学的目的
14 //第一,我们可以构造 /indirection/a/../ /indirection/./ 等等这一类的
15 //所以,第一个要求就是不得出现 ./
16 if($flag && strpos($URL, './') !== FALSE){
17     $flag = "";
18     $stop = 1;        //Pass
19 }
20 
21 //第二,我们可以构造 \ 来代替被过滤的 /
22 //所以,第二个要求就是不得出现 ../
23 if($flag && strpos($URL, '\\') !== FALSE){
24     $flag = "";
25     $stop = 2;        //Pass
26 }
27 
28 //第三,有的系统大小写通用,例如 indirectioN/
29 //你也可以用?和#等等的字符绕过,这需要统一解决
30 //所以,第三个要求对可以用的字符做了限制,a-z / 和 .
31 $matches = array();
32 preg_match('/^([0-9a-z\/.]+)$/', $URL, $matches);
33 if($flag && empty($matches) || $matches[1] != $URL){
34     $flag = "";
35     $stop = 3;        //Pass
36 }
37 
38 //第四,多个 / 也是可以的
39 //所以,第四个要求是不得出现 //
40 if($flag && strpos($URL, '//') !== FALSE){
41     $flag = "";
42     $stop = 4;        //Pass
43 }
44 
45 //第五,显然加上index.php或者减去index.php都是可以的
46 //所以我们下一个要求就是必须包含/index.php,并且以此结尾
47 if($flag && substr($URL, -10) !== '/index.php'){
48     $flag = "";
49     $stop = 5;        //Not Pass
50 }
51 
52 //第六,我们知道在index.php后面加.也是可以的
53 //所以我们禁止p后面出现.这个符号
54 if($flag && strpos($URL, 'p.') !== FALSE){
55     $flag = "";
56     $stop = 6;        //Not Pass
57 }
58 
59 //第七,现在是最关键的时刻
60 //你的$URL必须与/indirection/index.php有所不同
61 if($flag && $URL == '/indirection/index.php'){
62     $flag = "";
63     $stop = 7;        //Not Pass
64 }
65 if(!$stop) $stop = 8;
66 
67 echo 'Flag: '.$flag;
68 echo '<hr />';
69 for($i = 1; $i < $stop; $i++)
70     $code = str_replace('//Pass '.$i, '//Pass', $code);
71 for(; $i < 8; $i++)
72     $code = str_replace('//Pass '.$i, '//Not Pass', $code);
73 
74 
75 echo highlight_string($code, TRUE);
76 
77 echo '</body></html>'; 

上面的代码就是一系列思路讲解,可以好好地看一下

又来学习新姿势了:这题的关键在于伪静态,比如url中含有xxxx.php/xx/x,那么.php后的xx就会被当成参数名,x会被当成参数

所以这里的payload可以这么构造:http://ctf5.shiyanbar.com/indirection/index.php/x/index.php

 

 

 

 

Forms

看看源码没啥提示,那就直接抓包看看

把showsource的值改成1,得到了我们想要的东西

1 $a = $_POST["PIN"];
2 if ($a == -19827747736161128312837161661727773716166727272616149001823847) {
3     echo "Congratulations! The flag is $flag";
4 } else {
5     echo "User with provided PIN not found."; 
6 }

这不是送分题么,直接把这一大段post给pin就完事了

 

posted @ 2018-03-28 20:58  Ragd0ll  阅读(828)  评论(0编辑  收藏  举报