【发布时间】:2019-01-28 19:28:45
【问题描述】:
我正在尝试使用缓冲区溢出来覆盖两个局部变量,以便可以调用隐藏函数。这是 C 代码。
#include <stdio.h>
#include <stdlib.h>
static void hidden_function(void)
{
puts("I laugh in the face of danger. Ha ha ha ha!");
}
static void visible_function(void)
{
puts("Knock, knock! Who's there? Recursion. Recursion who? Knock, knock!");
}
static void helper_function(void)
{
void (*f_ptr)(void) = visible_function;
unsigned int dumb_number = 0x12345678;
char buffer[32];
printf("Provide buffer input: ");
fgets(buffer, 64, stdin);
printf("Dumb number value is 0x%08x.\n", dumb_number);
printf("Buffer is %s\n", buffer);
f_ptr();
}
int main(void)
{
helper_function();
return 0;
}
这是我使用的 Makefile。
CC = gcc
CFLAGS = -m32 -Wall -Wextra -Wno-unused-function -g -O0 -fno-stack-protector -no-pie
LDFLAGS = -m32
.PHONY: all clean
all: overflow_ptr
overflow_ptr: overflow_ptr.o
$(CC) $(CFLAGS) -o $@ $<
overflow_ptr.o: overflow_ptr.c
clean:
-rm -f overflow_ptr.o overflow_ptr
-rm -f *~
运行 nm overflow_ptr 显示隐藏函数的地址如下:
080484a6 t hidden_function
所以我创建了以下有效负载:
python3 -c 'print(32*"A" + "\x21\x43\x65\x87" + "\xa6\x84\x04\x08")'
这应该使 dump_number = 0x87654321 和 f_ptr = 0x080484a6。但是,当我运行这个程序时,输出是:
Provide buffer input: Dumb number value is 0xc2654321.
这让我想知道为什么要插入 c2?我假设这是某种保护措施。如果是这样,有什么办法可以防止它? 我在 Ubuntu 上使用 64 位虚拟机。
【问题讨论】:
-
运行
python3 -c 'print(32*"A" + "\x21\x43\x65\x87" + "\xa6\x84\x04\x08")' | od -x时,值不对应。但这似乎是一个python问题。也许您可以尝试修复它或添加python标签。 -
您在某处进行了 utf8 转换。
标签: python c assembly x86 buffer-overflow