当我在 GDB 中单步执行缓冲区溢出时,为什么我的 CC INT3 指令没有执行任何操作?

Why is my CC INT3 instruction not doing anything when I single-step my buffer overflow in GDB?

我正在做 protostar 漏洞利用练习 # 5。

基本上这是代码,目标是将代码执行重定向到您的 shellcode。我的问题只是关于为什么我的指令没有执行。

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

int main(int argc, char **argv)
{
  char buffer[64];

  gets(buffer);
}

这是一道缓冲区溢出题。我已经成功地将 return 地址重定向到我的 nop sled 的开头,然后是停止程序执行的 int3 "\xcc" shellcode(只是为了检查它是否会执行)

"\x90\x90\x90\x90\xcc\xcc\xcc\xcc"

基本上当我穿过我的 nop 雪橇时它只是说

0xbffff7a2 in ?? ()
(gdb)
0xbffff7a3 in ?? ()
(gdb)
0xbffff7a4 in ?? ()
(gdb)

请记住,我已成功将代码执行重定向到这些地址,并且我检查这些地址是“\x90"s and "\xcc"s respectively. But nothing happens. The program didn't even receive an interrupt from the "\xcc”的地址。

我可能没有提供足够的信息,但本质上它应该执行这些指令,但似乎不是。

我想可能是指令需要字节对齐?但这有关系吗?

我只想知道即使您正指向该地址,指令也可能无法执行的一些原因。

This is x86 Architecture machine. 

gdb 在内部使用 int3,这就是您看不到任何效果的原因。 您应该告诉它忽略 SIGTRAP 信号并将其传递给进程。

(gdb) handle SIGTRAP nostop noprint pass
SIGTRAP is used by the debugger.
Are you sure you want to change it? (y or n) y

Signal        Stop      Print   Pass to program Description
SIGTRAP       No        No      Yes             Trace/breakpoint trap

(gdb) si

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.

由于您试图仅将此用于检测用户模式下的代码执行,请考虑使用其他一些会导致错误的指令,例如 HLT。这不会干扰调试器操作,因此您无需更改信号处理。