Skip to main content

Memory Manipulation using radare2 ( ͠° ͟ʖ ͡°) (day 23)

Image result for manipulation meme

In this post, I will show you how to do some tinkering inside of memory in Linux binary. Before i start i just want to remind you this material is based on:



we are going to use the second binary name "xor". Now, once you clone the repository and inside the "tut2-memory" you need to build the executable using

~# make

after that, the executable will be available inside the directory. Try to run it and as you can see the executable requires a password, we are going to find out what is the password.

to examine the executable we need to open the binary using "debugging mode" in radare2. Debugging mode enables us to place a breakpoint and read/write memory, this is very effective when we want to dig deep in on how the executable is behaved.


List all the function and we got two functions that really interesting "main" and "sym.check". Let's open the main function to get to know the big picture of the executable.


Ok wow! there is a lot of assigning byte there lol. So as you guess this might be the secret string but unfortunately this is encrypted and we found out by scrolling down it is show that the secret string and our input are pass to the "sym.check" function.


push eax=> pass encrypted string as parameter to "check" function
push esi => pass our string as parameter to "check" function
call sym.check => call the function

before you can examine the memory you must put a breakpoint inside the executable so we can start dissecting the register, type:

~# dcu main => it means debuggingcontinueuntil main (this will stop at the beginning of main function)

next

~# dcu check =>  it means debuggingcontinueuntil check (this will stop at the beginning of check function)

now we can examine the memory register by typing:

~# ps @ eax (this will print the content inside eax register which is the encrypted string)

and

~# ps @ esi (this will print the content inside esi register which is our input)



you can play with how much length of byte you want to print by appending "!"

for example

ps @ eax ! 2 => means that print the first 2 byte of the eax register
ps @ eax ! 32 => means that print the first 32 byte of the eax register

let's try to examine the "check" function:






now from the result we can see that there is a xor operation, notice the command:

~# xor byte[edx],al

this means that register edx that contain our input will be xor by register al (8-bit value of eax that means 42 => *) and the value of eax will be a loop and incremented by 3 until it reaches 0x8a (138)

by understanding the logic of the execution, we just reveal how to make the key. all we need to do is to generate char from 42 until 138 (increment by 3)

you have two choices, create python script or use radare2:

for python

1. you need to obtain the hex of the encrypted string, use the previous command that I just you show to examine the register


2. create a python script



for radare2:

1. there is a command that called "woe" that able to generate a pattern of key that we desired:



~# woe 42 3 @ esi ! 32

this command will generate char from 42 to 138 and will replace the register esi contain our value since it is rubbish. Don't forget to append "! 32" This is very crucial since it is told the radare to stop at the byte 32 or it will rewrite everything

2. now that we have the key all you have to do is just to xor the binary to the register eax (contain encrypted string) using "wox"


~# wox `p8 32 @ esi` @ eax ! 32

"`" this symbol helps us to nest command inside a command inside radare.

That's all thank you, folks :)



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

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