Ida Pro Tutorial
Ida Pro Tutorial
Ida Pro Tutorial
Applied Security
Executive Summary
The Interactive Disassembler (IDA) is a tool used in reversing the internal functionality of an executable binary file. This tutorial describes basic functionality and usage of IDA Free 5.0.
This work is licensed under a Creative Commons Attribution 4.0 International License.
Contents
1
Introduction
Related News
Objectives
Background
Tutorial
6.1 Capture
6.2 Capture
6.3 Capture
6.4 Capture
6.5 Capture
6.6 Capture
The
The
The
The
The
The
Flag
Flag
Flag
Flag
Flag
Flag
1
2
3
4
5
6
.
.
.
.
.
.
Conclusion
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6
7
8
9
10
11
12
13
14
9 Revisions
15
1 Introduction
<>
The basic idea of reversing a binary is not overly complicated. Given a binary, it should be a fairly simple
thing to decode bit streams into sequences of instructions. The complications in this process come mainly
from the many different instruction sets in use for different processors and the different formats available for
binary files.
The different versions of IDA available will all disassemble binaries into a database and automatically
determine things like the file format, the processor the binary was compiled for, control flow, and many basic
data types. The information from the binary is pushed into a database file and the original binary is no
longer needed for reverse engineering. This feature is often brought up in reference to reversing malware as
a very useful feature.
It is important to distinguish between disassembly and decompilation. IDAs default functionality is disassembly. For which it provides a complex Graphical User Interface (GUI) that provides powerful visualizations
of the assembly code and many useful functions to run on the disassembled instructions. Decompilation is
a feature that is not available for free or as a demo and would allow decompilation of the assembly code
into higher-level code that would represent the code structures usually compiled into assembly matching a
certain fingerprint.
The basic method for using IDA involves dumping a binary into IDA for initial treatment. This will
result in the instructions, variable initializers, and basic call/jump structure being recognized and saved for
easier viewing later. All of this data will be presented in a myriad of windows in the somewhat overcrowded
default interface. These windows will show the original bytes, the sequential instructions, a graph view
showing code blocks and control flow, and many other bits of data that could be discovered through luck
or guidance. From here, a dedicated user can comment, correct, rename, debug, modify, recompile, and in
general reverse the functionality of the original binary. If given enough time.
[1] [2]
1
2 Related News
<>
BMW
Researchers were able to reverse engineer some of the software
Dropbox
Researchers found a way to reverse engineer Dropbox
Traffic Lights
Researchers could have reverse-engineered the protocol
Lenovo
Researchers managed to extract the private key for the Superfish certificate authority (CA) by reverse engineering the application
BMW Research
Allowed hackers to remotely unlock vehicles. [3]
DropBox Research
Allowed hackers to bypass authentication. [4]
Traffic Light Research
Allowed hackers full control of stoplights. [5]
Lenovos Superfish Research
Allowed hackers access to the private key for the Superfish Certificate Authority (CA) [6]
3 Objectives
<>
4 Background
<>
There are many different executable file formats in use today, and there have been many more in the past.
The two formats of interest during this lab are the Portable Executable (PE) format, and the Executable and
Linkable Format (ELF). These are the formats used in Windows and Unix based systems, and the format
of the binaries we will be reversing in this tutorial. [7]
In addition to the file format, there are many different assembly language variants, called instruction sets,
in use. These languages all share a base set of features like math operations, control flow, data storage, and
data retrieval. The different instruction sets are used to write binaries specific to processors and processor
families. The instruction set we will be viewing in this tutorial is the x86 instruction set. The binaries were
cross compiled on a 64-bit platform using the 32-bit instructions set. [8]
Another set of options that greatly affects the reversing process is the use of compiler optimizations.
Compilers tend to have signature ways of doing things that aids in the reversing process. For this reason,
IDA will often let you know its guess as to which compiler sourced the binary it is displaying. Compiler
options such as including debugging information, stripping data, and including/removing security features
all have an influence on the binary that is very noticeable while reversing. [9]
4
<>
Open VMs
Ubuntu
Username: radicl
Password: radicl
Windows
Username: radicl
Password: Windows1
Open IDA free 5.0
Open binary named example in IDA
6 Tutorial
<>
The basic goal of each round is to gain the character string representing a flag. This character string is
returned from each binary upon entry of the correct password. There are multiple ways one could go about
reversing the flags and passwords of each binary. Brute-force password cracking would work on all of these
binaries, but some have rather long password which would make it take too long.
Each of the binaries is an example of poor security. Some binaries contain the passwords and flags in
them as plain text. Other binaries do some obfuscating of the character strings, but not enough to cause
anyone much of a problem once they viewed the binary in a program like IDA. The goal of this tutorial is
not to show you bad coding practices, or to be an exercise in triviality. The reversals in this tutorial are
intentionally simple at first to enable a new user a chance to become familiar with the process, the interface,
and most importantly to hopefully have motivation and an interesting goal while learning.
Some things to consider for each binary
How does the binary respond to. . .
No password
Extremely long passwords
special characters
How are passwords being checked?
Are there potentially key portions of the application you might want to look at first?
<>
Try to determine not only where a string in the binary is referenced, but how many times. Is it used
repeatedly? What functions is it used in? Try renaming code blocks as you determine their use or irrelevance.
Notice that most strings have an XREF from the initialization to the data used to initialize them and
an XREF from the initialization portion back to the data, but some have additional XREFs. Where do the
extra XREFs point? Can you determine where the password prompt is being printed to the console? Where
else are strings being printed to the console?
Basic steps for solution
1. Find ImAP4$$word in the Strings window, double click it
2. Follow the XREF to the main routine
3. Right click the text and switch to data view if necessary
4. Scroll down through functions identifying any C system calls
5. Use printf calls to locate the flag
<>
Q1: Why are the password and flag strings so easy to find
and how could this be avoided?
The code for CTF1 and CTF2 is nearly identical. The only real differences are in the string initializers. The
main reason the binaries look so different is all of the memory protection and rights management code that
is inserted by default into binaries compiled in visual studio.
To find the flag in this binary follow the same steps as in CTF1. Find a string that you think is significant.
Trace the XREF to the code were the string is used. Follow the code in text and/or graph views until you
find where the flag is being printed to the console.
The strings in this binary and in CTF1 are initialized directly as in const char *str = "hello
world";. Because of this, the compiler places this data directly into the binary as a null-terminated array
of bytes.
Basic steps for solution
1. Find up with flags in the Strings window, double click it
2. Follow the XREF to the main routine
3. Right click the text and switch to data view if necessary
4. Use the connecting arrows to navigate through calls by double clicking them
5. Use printf calls to locate the flag
6. Determine which variable is being printed to console
7. Backtrack to determine what the variable was assigned
<>
What strings are there? Follow the XREFs. Rename things to make it easier to tell where you have
been. Dont waste time on rabbit trails, go back to main routine if you find yourself off in the weeds tracking
down system calls.
This binary uses some trickery to make things slightly less simple. A simple mathematical operation was
applied to the string of characters in order to keep them from displaying as ASCII in the binary.
Basic steps for solution
1. Find Unobtanium9000 in the Strings window, double click it
2. Follow the XREFs to the main routine
3. Right click the text and switch to data view if necessary
4. Use the connecting arrows to navigate through calls by double clicking them
5. Use printf calls to locate the flag
6. Determine which variable is being printed to console
7. Backtrack to determine what the variable was assigned
8. This one is slightly more tricky, check the value of the variable carefully
<>
What would you try if you could step through the code in debug mode? What strings are in the file?
Where are they used? Can you use anything gleaned from reversing while actually running the executable?
If this were a Windows binary, then IDA for windows could run it in debug mode.
Basic steps for solution
1. Find password1 in the Strings window, double click it
2. Follow the XREFs to the main routine
3. Right click the text and switch to data view if necessary
4. Use the connecting arrows to navigate through calls by double clicking them
5. Use printf calls to locate the flag
6. Determine which variable is being printed to console
7. Backtrack to determine what the variable was assigned
8. If figuring out what the flag is directly proves complex, try figuring out the password that is used in
strcmp()
9. Try the password in the running executable
10
<>
Follow the XREFs. Try debugging the binary in IDA. Can we cheat? Is there some way to force the jz
to jump to the password accepted location even when the zero flag is not set?
Basic steps for solution
1. Find football in the Strings window, double click it
2. Follow the XREFs to the main routine
3. Right click the text and switch to data view if necessary
4. Use the connecting arrows to navigate through calls by double clicking them
5. Use printf calls to locate the flag & password
6. Determine which variable is being printed to console
7. Backtrack to determine what the variable was assigned
8. Try running the executable in debug mode and setting the zero flag to the correct value to make the
input vs. password comparison jump to the printf(flag) code
9. Just ignore and hit continue for any exceptions IDA spits out during debugging
11
<>
This round is the closest we will come to what actual reversing courses examples look like. We will need
to run the binary, potentially multiple times, while reversing to test out different theories. Different lengths
of input will result in different behaviors for this binary because of an unchecked string length that allows
a buffer overflow. The thing that gives this away is the mystery character that sometimes shows up in the
Password x was incorrect string. The goal of this round is to determine how to take advantage of a fairly
straightforward buffer overflow vulnerability.
Basic steps for solution
1. Find Please enter the password in the Strings window, double click it
2. Follow the XREFs to the main routine
3. Right click the text and switch to data view if necessary
4. Use the connecting arrows to navigate through calls by double clicking them
5. Use printf calls to locate the flag & password
6. Determine which variable is being printed to console
7. Backtrack to determine what the variable was assigned
8. Determine what the logic is for a valid password
9. Take a guess at the buffer size for the password
10. Try to overflow the buffer in such a way that the code execution changes
12
7 Conclusion
<>
13
Registers
eax
al
ah
ax
rax
ebx
ecx
edx
accumulator register
base register
computer register
data register
Memory
mov
lea
push
pop
Arithmetic
add
sub
mul
div
inc
dec
cmp
test
Control Flow
call
call label
ret
ret
jmp
jmp location / location
j
j location
n, z, p
e, g, l
14
Revisions
Revision #
1.0
Comments
Joe F.
15
References
[1] Hex-Rays, Hex-rays home, 2015, [Online; accessed 2-March-2015]. [Online]. Available:
//www.hex-rays.com/index.shtml
https:
[2] D. Lukan, The basics of ida pro, 2012, [Online; accessed 2-March-2015]. [Online]. Available:
http://resources.infosecinstitute.com/basics-of-ida-pro-2/
[3] R. K. Singh, Bmw fixes security flaw in software that made 2.2 million vehicles vulnerable to
hijack, 2015, [Online; accessed 2-March-2015]. [Online]. Available: http://www.techworm.net/2015/
02/bmw-fixes-security-flaw-software-made-2-2-million-vehicles-vulnerable-hijack.html
[4] S. Colaner, Researchers reverse engineer and hack dropbox, heavily obfuscated python
app, 2015, [Online; accessed 2-March-2015]. [Online]. Available: http://hothardware.com/news/
Researchers-Reverse-Engineer-and-Hack-Dropbox-Heavily-Obfuscated-Python-App
[5] L. Hutchinson, Researchers find its terrifyingly easy to hack traffic lights, 2015, [Online;
accessed 2-March-2015]. [Online]. Available:
http://arstechnica.com/security/2014/08/
researchers-find-its-terrifyingly-easy-to-hack-traffic-lights/
[6] P. Croke, Lenovo caught spying, 2015, [Online; accessed 2-March-2015]. [Online]. Available:
http://lapostexaminer.com/lenovo-caught-spying/2015/02/25
[7] Wikipedia, Comparison of executable file formats wikipedia, the free encyclopedia, 2014,
[Online; accessed 2-March-2015]. [Online]. Available: http://en.wikipedia.org/w/index.php?title=
Comparison of executable file formats&oldid=639706438
[8] , List of instruction sets wikipedia, the free encyclopedia, 2015, [Online; accessed 2-March2015]. [Online]. Available: http://en.wikipedia.org/w/index.php?title=List of instruction sets&oldid=
644815110
[9] , Optimizing compiler wikipedia, the free encyclopedia, 2015, [Online; accessed 2-March-2015].
[Online]. Available: http://en.wikipedia.org/w/index.php?title=Optimizing compiler&oldid=645581075
16