我正在测试缓冲区溢出利用,但是当我编译代码时,gcc使用内存对齐,编译器添加的额外字节迫使我处理这个填充.
有没有办法用gcc编译代码而没有填充?
这是使用填充实现的溢出,但我想要一个没有编译器垃圾的清晰视图:
(gdb) x/60x 0xbffff450
0xbffff450: 0xbffff460 0x00000001 0x00000000 0x00000001
0xbffff460: *0x41414141 0x41414141 0x41414141 0x41414141[buffer begins]
0xbffff470: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff480: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff490: 0x41414141 0x41414141 0x41414141 0x41414141*[buffer ends]
0xbffff4a0: 0x41414141 0x41414141 0x41414141 [0x0804851c][Return Address]
Run Code Online (Sandbox Code Playgroud)
问候
编辑:
这是我正在编译的代码:
#include <stdio.h>
char *secret = "pepito";
void go_shell(){
char *shell = "/bin/sh";
char *cmd[] = { "/bin/sh", 0 };
printf("¿Quieres jugar a un juego?...\n");
setreuid(0);
execve(shell,cmd,0);
}
int authorize(){
char password[64];
printf("Escriba la contraseña: ");
gets(password);
if (!strcmp(password,secret))
return 1;
else
return 0;
}
int main(){
if (authorize()){
printf("Acceso permitido\n");
go_shell();
} else{
printf("Acceso denegado\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
是的,您需要调整gcc如何分配堆栈空间.默认情况下,它会尝试使堆栈在16字节边界上保持对齐,因为某些指令(SSE*)需要它.如果-mpreferred-stack-boundary=2在编译时在命令行上指定,gcc将使堆栈保持对齐为2 ^ 2 = 4,这是您使用32位环境时所期望的.
| 归档时间: |
|
| 查看次数: |
1020 次 |
| 最近记录: |