1. 程式人生 > >實驗吧:拐彎抹角

實驗吧:拐彎抹角

先貼程式碼,可也學習下。
<?php

// code by [email protected]

echo '<html><head><meta http-equiv="charset" content="gbk"></head><body>';

$URL = $_SERVER['REQUEST_URI'];

//echo 'URL: '.$URL.'<br/>';

$flag = "CTF{???}";

$code = str_replace($flag, 'CTF{???}', file_get_contents('./index.php'));

$stop = 0;

//這道題目本身也有教學的目的

//第一,我們可以構造 /indirection/a/../ /indirection/./ 等等這一類的

//所以,第一個要求就是不得出現 ./

if($flag && strpos($URL, './') !== FALSE){

$flag = "";

$stop = 1;        //Pass

}

//第二,我們可以構造 \ 來代替被過濾的 /

//所以,第二個要求就是不得出現 ../

if($flag && strpos($URL, '\\') !== FALSE){

$flag = "";

$stop = 2;        //Pass

}

//第三,有的系統大小寫通用,例如 indirectioN/

//你也可以用?和#等等的字元繞過,這需要統一解決

//所以,第三個要求對可以用的字元做了限制,a-z / 和 .

$matches = array();

preg_match('/^([0-9a-z\/.]+)$/', $URL, $matches);

if($flag && empty($matches) || $matches[1] != $URL){

$flag = "";

$stop = 3;        //Pass

}

//第四,多個 / 也是可以的

//所以,第四個要求是不得出現 //

if($flag && strpos($URL, '//') !== FALSE){

$flag = "";

$stop = 4;        //Pass

}

//第五,顯然加上index.php或者減去index.php都是可以的

//所以我們下一個要求就是必須包含/index.php,並且以此結尾

if($flag && substr($URL, -10) !== '/index.php'){

$flag = "";

$stop = 5;        //Not Pass

}

//第六,我們知道在index.php後面加.也是可以的

//所以我們禁止p後面出現.這個符號

if($flag && strpos($URL, 'p.') !== FALSE){

$flag = "";

$stop = 6;        //Not Pass

}

//第七,現在是最關鍵的時刻

//你的$URL必須與/indirection/index.php有所不同

if($flag && $URL == '/indirection/index.php'){

$flag = "";

$stop = 7;        //Not Pass

}

if(!$stop) $stop = 8;

echo 'Flag: '.$flag;

echo '<hr />';

for($i = 1; $i < $stop; $i++)

$code = str_replace('//Pass '.$i, '//Pass', $code);

for(; $i < 8; $i++)

$code = str_replace('//Pass '.$i, '//Not Pass', $code);

echo highlight_string($code, TRUE);

echo '</body></html>';

 

url偽靜態的知識,學到了。

簡單來說,比如http://ctf5.shiyanbar.com/indirection/index.php/user/index.php,雖然在index.php後面還加上了一些東西,但是這個user會被解析成引數名,而index.php則會被解析成user的值。