
Now, move on to challenge 4 and 5
solving challenge 4 and challenge 5 doesn't require much analysis since you can do code injection directly.
Challenge 4:
Let's run the binary first:I try to put some file name inside the prompt, it doesn't give you anything and when I try to enter a file that not exist, it says no such file directory.
list all the functions and we can see that there are three functions inside the program that caught my eyes (main, laas, run_cmd)
dump the main function:
char *strchr(const char *str, int ch)
str – The string in which the character is searched.
ch – The character that is searched in the string str.
it just basically call the laas function, dump the laas function
we can see that there is a conditional check using strchr before a jump to run_cmd function
strchr basically just check if certain character is contained in the string and print the next character
char *strchr(const char *str, int ch)
str – The string in which the character is searched.
ch – The character that is searched in the string str.
#include <stdio.h>
#include <string.h>
int main () {
const char str[] = "This is just a String";
const char ch = 'u';
char *p;
p = strchr(str, ch);
printf("String starting from %c is: %s", ch, p);
return 0;
}
String starting from u is: ust a String
source: https://beginnersbook.com/2017/11/c-strchr-function/
and it looks like the function looking for value "0x2f" => which is the ASCII equivalent of "/"
so as long as you don't put "/" inside the string the program happily processes your string. I think this is to prevent anyone to read outside of the directory
and after that our input will be passed to run_cmd() functions
dump the run_cmd functions
let's try to put a breakpoint before the call system so we know what happens to our input
damn! it looks like the binary open some thread inside the binary so we cannot debug the binary
Don't worry tho if you notice we already figure out the vulnerability since our input is pass to the snprintf without sanitation we can append other bash command using ";"
Note:
The snprintf() function formats and stores a series of characters and values in the array buffer
int main()
{
char buffer[50];
char* s = "geeksforgeeks";
// Counting the character and storing
// in buffer using snprintf
int j = snprintf(buffer, 6, "%s\n", s);
// Print the string stored in buffer and
// character count
printf("string:\n%s\ncharacter count = %d\n",
buffer, j);
return 0;
}
source: https://www.geeksforgeeks.org/snprintf-c-library/
yea we got a shell so this is what happens when you don't sanitize your user input
Challenge 5:
Basically, the binary has the same vulnerability, the only difference is in how many buffers you can store in the buffer, challenge 4 allow us to input 0x1b (27) bytes whereas this challenge only allow us to put 7 bytes.yeay we pop a shell again
Hope you enjoy this blog :)
Comments
Post a Comment