Intro To Reverse Engineering: Intropy
Intro To Reverse Engineering: Intropy
~ intropy ~
Intro
Why do we reverse engineer?
• Closed source software
– Vulnerability Research
– Product verification
• Proprietary formats
– Interoperability
• SMB on UNIX
• Word compatible editors
• Virus research
Why should you give a fuck?
• Basis of computing
– Reverse engineering teaches the inner workings
of any processor
– Learning how the processor handles data helps in
understanding many other aspects of computer
security
.bss - This section holds uninitialized data that contributes to the program's
memory image. By definition, the system initializes the data with zeros
when the program begins to run.
.comment - This section holds version control information.
.ctors - This section holds initialized pointers to the C++ constructor functions.
.data - This section holds initialized data that contribute to the program's
memory image.
.data1 - This section holds initialized data that contribute to the program's
memory image.
.debug - This section holds information for symbolic debugging. The contents are
unspecified.
.dtors - This section holds initialized pointers to the C++ destructor functions.
.dynamic - This section holds dynamic linking information.
ELF Sections Cont…
.dynstr - This section holds strings needed for dynamic linking, most commonly the
strings that represent the names associated with symbol table entries.
.dynsym - This section holds the dynamic linking symbol table.
.fini - This section holds executable instructions that contribute to the process
termination code. When a program exits normally the system arranges to
execute the code in this section.
.got - This section holds the global offset table.
.hash - This section holds a symbol hash table.
.init - This section holds executable instructions that contribute to the process
initialization code. When a program starts to run the system arranges to
execute the code in this section before calling the main program entry
point.
.interp - This section holds the pathname of a program interpreter. If the file has a
loadable segment that includes the section, the section's attributes will
include the SHF_ALLOC bit. Otherwise, that bit will be off.
.line - This section holds line number information for symbolic debugging, which
describes the correspondence between the program source and the
machine code. The contents are unspecified.
ELF Sections Cont…
.note - This section holds information in the ``Note Section'' format described
below.
.plt - This section holds the procedure linkage table.
.relNAME - This section holds relocation information. By convention, ``NAME'' is
supplied by the section to which the relocations apply. Thus a relocation
section for .text normally would have the name .rel.text
.rodata - This section holds read-only data that typically contributes to a non-
writable segment in the process image.
.rodata1 - This section holds read-only data that typically contributes to a non-
writable segment in the process image.
.shstrtab - This section holds section names.
.strtab - This section holds strings, most commonly the strings that represent the
names associated with symbol table entries.
.symtab - This section holds a symbol table. If the file has a loadable segment that
includes the symbol table, the section's attributes will include the
SHF_ALLOC bit. Otherwise the bit will be off.
.text - This section holds the ``text'' or executable instructions, of a program.
Executable Formats Cont…
• PE – Portable Executable
– History
Microsoft migrated to the PE format with the introduction of the Windows NT 3.1
operating system. It is based of a modified form of the UNIX COFF format
– What uses PE
• Windows NT
• Window 2000
• Windows XP
• Windows 2003
• Windows CE
– Dissection
• DOS Stub
– The DOS stub contains a message that the executable will not run in DOS mode
• Optional Header (Not optional]
• RVA
– Relative virtual addressing
• Sections
Optional Header
• The optional header in a PE executable contains various information regarding the
executable contents needed for the OS loader
SizeOfCode - Size of the code (text) section, or the sum of all code sections
if there are multiple sections.
AddressOfEntryPoint – Address of the entry function to start execution from
BaseOfCode - RVA of the start of the code relative to the base address
BaseOfData – RVA of the start of the data relative to the base address
SectionAlignment – Alignment of sections when loaded into memory
FileAlignment – Alignment of section on disk
SizeOfImage - Size, in bytes, of image, including all headers; must be a
multiple of Section Alignment
SizeOfHeaders - Combined size of MS-DOS stub, PE Header, and section
headers rounded up to a multiple of FileAlignment.
NumberOfRvaAndSizes - Number of data-dictionary entries in the remainder of the
Optional Header. Each describes a location and size.
Sections
• The sections in a PE file contain various pieces of the
executable needed to run including various RVA’s and offsets
• cdecl
– Most common calling convention
– Dynamic parameters
– Caller unwinds stack
• pop ebp
• ret
• fastcall
– Higher performance
– First two parameters are passed over registers
• stdcall
– Common in Windows
– Parameters are received in reverse order
– Function unwinds stack
• ret 0x16
Example
Thanks fend3r!
Conclusion
• Reverse engineering is a vast and complex
world
• With a lot of practice though it becomes much
easier
• A good reverser knows their tools inside and
out
• Workflow and organization are the keys to
reversing
Shirt Quiz
• Name the IA-32 registers
• What does .Net assemble into
• In OllyDbg how do you list the Names
• What is the IA-32 instruction to Compare two
integers
• How does the IA-32 processor handle signedness
• What does the IDC scripting language resemble
• How many processors does IDA support (roughly)
• In IDA how do you quickly follow a CALL
References
• Reversing - http://www.wiley.com/WileyCDA/WileyTitle/productCd-
0764574817.html
• ELF File format - http://www.skyfree.org/linux/references/ELF_Format.pdf
• PE File Format -
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndebug/html
/msdn_peeringpe.asp
• http://lsd-pl.net/references.html
• OllyDbg - http://ollydbg.de/
• OllyDbg Plugins - http://ollydbg.win32asmcommunity.net/stuph/
• IDA Pro - http://www.datarescue.com/
• IDC - http://www.datarescue.com/idadoc/707.htm
• IDA Plugins - http://home.arcor.de/idapalace/
• Reflector - http://www.aisto.com/roeder/dotnet/
• JODE - http://jode.sourceforge.net/
• Boomerang - http://boomerang.sourceforge.net/
• Crackmes.de - http://www.crackmes.de/
Fucking done.
Questions?