Intro To Reverse Engineering and Debugging With Radare2
Intro To Reverse Engineering and Debugging With Radare2
By Chris James
0x00: Who am I?
● Minimum:
○ Interested in Computer Security
○ Can write programs in a programming language
■ Programming I/II (exposure to C/C++)
● Ideally:
○ Experience with C/C++ and some Assembly
○ Have taken some CS courses:
■ Computer Organization
■ Digital Logic
● Even Better:
○ Operating Systems
0x02: What I'm gonna cover
Review
● What is a binary file?
● How does a CPU execute
binary?
From source to CPU
registers
0x11: Compiling source
and Registers
● What is physical
Memory?
● Process Image Segments
● On 64-bit systems, 2 ^ 64
bytes of addressable memory:
○ 18,446,744,073,709,551,616 Bytes
(16 Exbibytes) (approx. 16
Exabytes)
○ 0x0000000000000000 -
0xffffffffffffffff
● Every process granted full
address space.
○ How? (Virtual Memory to Physical
Memory)
○ But: processes rarely use anywhere
near the total Virtual Memory
space.
0x22: Process memory layout
● .text (0x400000)
○ Section with executable
code
● .(ro)data
○ Sections with initialized
variables
● heap
○ malloc scratchpad
● Shared libraries
○ C std lib
● Stack (0x7fffffff)
○ Local function scratchpads
0x22: Process memory layout
$ cat ./<programName>.rr2
#!/usr/bin/env rarun2
program=<programName>
arg0=”./<programName>”
stdio=/dev/pts/<##>
0x42: Debugging in radare2
● Yellow == Current
Seek address
● Green == Stack view
● Blue == Registers
● Red == Disassembly
0x45: First binary walkthrough: hello
● Slides 0x42 and 0x43 provide useful ● If you need to back out of any menus
commands for both command and visual from visual mode use `q` to quit out
modes of them.
● Use `?` or `??` after a command for ● If you’re new to all this, start at
help! `re1` and open up `walkthrough.txt`
● Split your terminal window with using `less` or `nano` or `vim`:
<ctrl+shift+O> and <ctrl+shift+E>! ○ $ less walkthrough.txt
● If you accidently end up in ● If you have any questions about
no-man’s-land, using `:ood <args>` anything, please ask me or any of
will re-open the binary in radare2 the SIT officers and we’ll be glad
with any optional arguments you’d to help!
like (unless you used the .rr2 ● I encourage you to work in groups
rarun2 profile) since the complexity of this stuff
● Refer to this site for assembly is high and teamwork can help!
instruction reference. ● `:dcr` will continue until return!
0x47: External resources
0x11: Compiling source
Working with Hexadecimal: https://learn.sparkfun.com/tutorials/hexadecimal
High-level article on compilers: https://en.wikipedia.org/wiki/Compiler
0x21: Memory
Virtual-Physical memory mapping learned in OS
High-level overview of Linux Memory Management: http://www.thegeekstuff.com/2012/02/linux-memory-management/
0x23 Registers:
Learned about memory timings and CPU caching in Comp Org
Register reference: https://wiki.cdot.senecacollege.ca/wiki/X86_64_Register_and_Instruction_Quick_Start
Syscall table: http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
0x47: External resources
0x31: Assembly Instructions
High-level overview of Assembly: http://ian.seyler.me/easy_x86-64/
x86 Instruction reference: https://www.aldeid.com/wiki/X86-assembly#Pages_in_this_category
Video tutorial of basic assembly: https://www.youtube.com/watch?v=busHtSyx2-w
0x40: Radare2
Official radare2 repo (with install instructions): https://github.com/radare/radare2
My custom radare2 Cheat Sheet:
https://docs.google.com/document/d/1our_fcFcufIJ13QsZoDuGOEBqftF6o0zEkDsqzAy43U/edit?usp=sharing
Unofficial radare2 Cheat Sheet (a little outdated):
https://github.com/pwntester/cheatsheets/blob/master/radare2.md