Skip to main content

TamuCTF 2019 pwn challenge 4&5 write up (ง'̀-'́)ง (day 29)

Image result for pwning meme

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

Popular posts from this blog

Having fun analyzing nginx log to find malicious attacker in the net (ง'̀-'́)ง (day 37)

  What makes you sleepless at night? is it because of a ghost or scary stories? is it because you have an important meeting tomorrow? or is it because you have an exam? For me, what keeps me up all night is that I keep thinking about what happens to a website that I just created, is it safe from an attacker (certainly not) or did I missing some security adjustments that lead to vulnerability? well I'm not the best secure programmer in the world, I'm still learning and there is a big possibility that I can make a mistake but for me, a mistake can be a valuable investment to myself or yourself to be better so from this idea, I want to know more about what attackers casually do when attacking a website. Here in this post, I'm going to show you how I analyzed attack to the website that I have permission to design and also some interesting findings that I could get from the analysis Background: All of this analysis comes from the traffic that is targeted to th...

Utilize Pwntools for crafting ROP chain :') (day 69)

who doesn't like pwntools? it is a very versatile tool and can be customized according to our need using the python script but did you need to know that pwntools itself can help us to automatically craft a rop chain for us? so in this post, I will show you how to make rop chain less painful and make pwntools do all the heavy lifting. To demonstrate this I will use the binary challenge callme 64 bit from ropemporium link: https://ropemporium.com/challenge/callme.html Crashing the app: Like any other exploitation process, we need to crash the program by generating a long string pattern to determine the offset. based on the information from the above figure we can see that we required to provide 40 bytes of offset Fun stuff: now this where the fun stuff began write the following python script: as in the guideline of the challenged said we need to chain the function call by first to call the callme_one function, callme_two function and then callme_three funct...

Easy Web Application Security Machine: CSharp VulnJSON ಠ_ಠ (day 101)

Hi everyone! Welcome back to another vulnhub machine walkthrough. In this post, we will try to solve the the Csharp VulnJSON machine, this particular machine are focus on introducing some key concept of known web application attacks. We will go through each of the vulnerability and we will see how we can elevate this into a working exploit. Background: Setting up this machine is easy, the author provide us with .ova file and all we have to do is just import the file then we good to go.     Information Gathering: first, we need to find out what is the machine ip address, to do this I used nmap to do ping sweep on my local network. from the result above we can see that the target machine is with 192.168.1.7. Now that we have our target IP address, let's proceed with scanning the open port on the machine. cool! so the machine only open port 80 and this will make it much more simple. If we go to the web server, we are welcomed with two forms: first is used for create a user and th...