ctfshow web入门——爆破

文章目录

web21

题目描述:

跟着题目提示的那篇文章来弄就可以得到flag
tomcat 认证爆破之custom iterator使用

web23

题目描述:

php 复制代码
<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-03 11:43:51
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-03 11:56:11
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/
error_reporting(0);

include('flag.php');
if(isset($_GET['token'])){
    $token = md5($_GET['token']);
    if(substr($token, 1,1)===substr($token, 14,1) && substr($token, 14,1) ===substr($token, 17,1)){
        if((intval(substr($token, 1,1))+intval(substr($token, 14,1))+substr($token, 17,1))/substr($token, 1,1)===intval(substr($token, 31,1))){
            echo $flag;
        }
    }
}else{
    highlight_file(__FILE__);

}
?>

题目分析:


php中函数知识导入:

php 复制代码
substr($token, 14, 1):

$token:要截取的字符串(32位的MD5哈希值)
14:起始位置(第二个参数)
1:要截取的长度(第三个参数)

intval 函数用于将变量转换为整数

php 复制代码
intval(mixed $value, int $base = 10): int
eg:
1. 纯数字字符串
echo intval("123");      // 输出: 123
echo intval("045");      // 输出: 45(去掉前导0)
echo intval("3.14");     // 输出: 3(截断小数部分)

2. 数字开头的字符串
echo intval("42abc");    // 输出: 42(取前面的数字部分)
echo intval("10px");     // 输出: 10
echo intval("3.2em");    // 输出: 3

3. 非数字开头的字符串
echo intval("abc123");   // 输出: 0(不是数字开头)
echo intval("hello");    // 输出: 0
echo intval("");         // 输出: 0
echo intval(" ");        // 输出: 0

代码逻辑:

需要满足:

token[1] = token[14] = token[17] 同时我们可以肯定它们的值在1-9之间,且 token[31] = 3

接下来我们写代码爆破即可:

python 复制代码
import hashlib
import itertools
import string


def find_token():
    # 尝试各种可能的输入
    chars = string.ascii_letters + string.digits
    for length in range(1, 6):  # 尝试1-5位长度
        for combo in itertools.product(chars, repeat=length):
            input_str = ''.join(combo)
            md5_hash = hashlib.md5(input_str.encode()).hexdigest()

            # 检查条件1:三个位置字符相同
            if md5_hash[1] == md5_hash[14] == md5_hash[17]:
                x = md5_hash[1]

                # 检查字符必须是 '1'-'9'
                if x not in '123456789':
                    continue

                # 检查 token[31] 必须是 '3'
                if md5_hash[31] != '3':
                    continue

                # 验证数学条件(虽然前面条件已保证成立)
                try:
                    n = int(x)
                    result = (n + n + n) / n
                    if result == 3:
                        print(f"找到有效输入: {input_str}")
                        print(f"MD5哈希: {md5_hash}")
                        print(f"访问: ?token={input_str}")
                        return input_str
                except:
                    continue

    print("未找到符合条件的输入")
    return None


# 运行爆破
find_token()

运行得到:

复制代码
找到有效输入: ZE
MD5哈希: 597d92b2ff4fa691b9970c4cbb872503
访问: ?token=ZE

接下来输入进行即可得到flag:

这里我们来解释一下:

$_GET 是什么?

复制代码
$_GET 是 PHP 的超全局变量
它自动收集 URL 中 ? 后面的所有参数
是 PHP 内置的,不需要你手动创建

题目中

url:

复制代码
https://靶机地址/?token=ZE

PHP 代码收到:

php 复制代码
$_GET['token'] = "ZE"

之后代码执行通过我们即可得到flag

web24

题目描述:

php 复制代码
error_reporting(0);
include("flag.php");
if(isset($_GET['r'])){
    $r = $_GET['r'];
    mt_srand(372619038);
    if(intval($r)===intval(mt_rand())){
        echo $flag;
    }
}else{
    highlight_file(__FILE__);
    echo system('cat /proc/version');
}

?>

题目分析:

mt_srand(372619038),随机数设置随机种子,种子设定好了相当于后面生成的随机数我们都清楚了,所以我们只要写串代码得到后面一个随机数即可:

php 复制代码
<?php 
mt_srand(372619038);
echo intval(mt_rand())
?>
// 1155388967

得到flag:

web26

题目描述:

题目分析:

进去得到:

我们试一下直接什么也不填提交,得到:

我们再试一下提示内容进行提交,得到:

有点猫腻

接着在源码里面发现:

我们访问,并把参数传进去,得到:

web27

传送门

web28

题目描述:

题目分析:

打开,发现没啥思路,后面搜索别人的解法,得到:

我们进行抓包和爆破:




总结

  • bp爆破
  • get
  • post
  • php---intval()函数