Skip to main content

TUCTF RE write up 2019 ˙ ͜ʟ˙ (day 46)

The TUCTF 2019 event is finished. This time I was able to finish all of the RE challenges and I'm so happy to get my first wiped up



I learn so much from this competition since I try a lot of new things to solve the RE challenges and this actually opens my eyes to try harder since there are so many things that I don't know which is good.



For pwn, I only managed to finished 4 from 10 challenges I was stuck with one of the challenges but that's okay I will try it again to finish this leftover challenge and create the write-up ASAP. There are a lot of interesting challenge that I can't wait to solve

The write-up for pwn challenge will be posted in the next post

Faker:

I think you guys already know the purpose of this challenge judging from the name of the binary ^___^. When you run the program it will give you a bunch of fake flag


let's take a look at the source code using ghidra:


The code itself is not too hard to interpret, it only takes the input range from 1-4 and based on the input it will call the predefined functions.

But when we look at each of the function code it always ends up with the same behavior.



it takes this weird string and passed it to the printFlag functions that contain some sort of form of the decoding process.

ok so I think it is pretty clear here what we need to do next, we only need to get the weird string that contains the real flag and passed it to the printFlag in runtime.

let's try to list all of the strings in the program


the first string seems to be interesting it may contain the real flag. Run the binary inside gdb and put a breakpoint before the function called the printFlag functions, you can choose any functions at this time I choose the A function


After setting the breakpoint just run the binary and you will get to the breakpoint all you have to do is just assign the new value to rax register. As you can see the rax value is move to rdi register before calling the printFlag function this is one of the behavior in system call in 64 bit instead using PUSH it will use the register as the placing for the parameter.


hit continue and you will get the flag :)

Object:

this challenge is kinda unique instead giving us another executable file but they gave us an object file. In linux object file only containing code and data of the program without the neccessary library.



(This is what happen when you run object file in gdb)


so how do you make the object executable you can use gcc to compile it


Notice that every input we enter will be passed to the checkPassword function and will go under some sort of weird checksum


while ((int)local_10 < passlen) {
      if ((byte)(~(param_1[(int)local_10] << 1) ^ 0xaaU) != password[(int)local_10]) {


you only need to pay attention at this two codes, as you can see each of the input characters will be shifted left by one byte, negate it and at the end, it will be XORed with value 0xaa

all we need to do here is just reverse this process to get the flag and to automate all the tasks I used r2pipe library in python.

Don't forget that when the function checkpassword is called our input length is check and need to be length of 44 => 2c characters



with that knowledge, we can create .rr2 file for the input


then we can create this following script:


the reverse function is used to decode the characters by xored the character by 0xaa and you flipped the bit again and last, you need to shift the bit to the right

inside the loop for, there are two section

the first section is to gather the flag and decode it I use "pxj" command to get the value of the register


and then the second section is to just bypass the comparison so we able to get the next characters

run the script and you will get the flag :)



CORE:

so in this challenge, we got two files first is the source code and core file. The core file is just a file that generated by the file if segmentation fault occur

I try to run the core file and try to trace the execution but unfortunately, I don't get any clue about the flag. So I try to list all of the strings inside the program if there is any interesting content.


so after a quick glance, I found this interesting string and as I mentioned I get the source code


If we take a look at the source code we can see that the flag is XORed with 1 so all we have to do is just create a script to do the job.


cool we got the flag :)


Comments

  1. hi, i don't know how to dump file core elf ?, please respond to me soon, thank you !!!

    ReplyDelete
    Replies
    1. hi the dump file is include along the challenge

      Delete
  2. and my gmail: none.execuable123@gmail.com

    ReplyDelete

Post a Comment

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...

Bypassing stack canaries protection :') (day 51)

In my previous blogs, I show you guys how to bypass some common protection usually used in Linux binary such as NX and ASLR but this time we are going to take it to the next level we are going to talk about protection employ in the modern Linux OS which is "The Canaries" and how to bypass it. note: this post was not originally mined it was inspired by the following resources https://ctf-wiki.github.io/ctf-wiki/pwn/linux/mitigation/canary/ (Credit goes to the author) we are going to start this post about what is stack canaries and types of different implementation of it then move to the implementation about how to bypass this protection. We are going to focus on "leak canaries" technique What is stack canary: In layman terms, canaries are just another protection mechanism to prevent stack overflow implemented by appending 4/8 bytes value (depend on the architecture) into the stack when a function is entered. When the function is at the end of its exec...