Pwhub-另一份文件-Writeup

v大佬实战经验出的一个题目,思路真的强。

题目介绍
http://54.223.145.113:88/
文件到底在哪里?我的文件又去了哪?
------------
12.6 21.30 发放hint,自行寻找
------------
12.7 08.08 Flag是个文件,不需要shell,并且听说放文件的神秘人拥有服务器最高权限

其中hint是:

@move_uploaded_file($_FILES['file']['tmp_name'], $dir.$name);
echo "上传成功!\n\n文件内容:\n\n";
echo file_get_contents($dir.$name);
$files = glob($dir . '*'); 
@unlink($files[0]);

题外话:后面v大佬给了上传验证代码。

$type = array("txt","");
$fileext = strtolower(fileext(@$_FILES['file']['name']));
if(in_array($fileext, $type)){
    ....
}

从一开始的fuzz来看,能上传.结尾以及.txt结尾的文件,这个验证真的很好奇,感觉有啥新姿势,于是一直在fuzz文件名,看能不能getshell。=。=,fuzz都跑烂了。


本地测试:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
    <input type="file" value="" name="uploaded">
    <input type="text" value="1" name="Upload">
    <input type="submit" value="submit" name="submit">
</form>
</body>
</html>
<?php
$html = "";
if( isset( $_POST[ 'Upload' ] ) ) {
    $target_path  = "upload/";
    $target_path .= $_FILES[ 'uploaded' ][ 'name' ];
    if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
        $html .= '<pre>Your image was not uploaded.</pre>';
    }
    else {
        $html .= "<pre>succesfully uploaded!</pre>";
        echo file_get_contents($target_path);
        $dir = "upload/";
        $files = glob($dir . '*');
        var_dump($files);
        @unlink($files[0]);
        var_dump($_FILES);
    }
}
?>

设置upload目录下面的flag文件不可删除:

chattr +i w333lc0met00pwnhu66

此题关键点是这个:

$files = glob($dir . '*'); 
@unlink($files[0]);

glob获取文件信息是按顺序排列的,如果目录中有一个文件存在的话,可以通过类似布尔盲注的思维来猜测。

也就是当上传x的时候,$files[1] = xw333lc0met00pwnhu66被设置不可更动文件,是删除不了的,所以x文件也就被保留下来了。这样就可以推测我们要找的文件的第一位是w

写脚本跑一跑就出来了。


后面问v大佬当时的实战是什么情况以及后续,通过这个思路得到一个敏感的文件,这个文件也被管理员设置不能删除。Orz

posted @ 2016-12-08 01:53  l3m0n  阅读(842)  评论(1编辑  收藏  举报