The Life of Binaries

Welcome    Why?    Training    Games    ChangeBlog    External Resources    Submit Content

 

Creator:     Xeno Kovah


License:   Creative Commons: Attribution, Share-Alike

(http://creativecommons.org/licenses/by-sa/3.0/)


Lab Requirements: Requires a Windows system with Visual C++ Express Edition, Windows DDK or WDK kernel module compilation environment, and WinDbg. Requires a Windows guest OS running in VMWare Player or VMWare Server in order to do kernel debugging with WinDbg from the host OS.


Class Textbook: None


Class Prereqs: Recommended, but not required, to have taken Introduction to x86.


Recommended Class Duration: 3 days (class previously taught in 2 days which was too little)


Creator Available to Teach In-Person Classes: Yes


Author Comments:


Topics include but are not limited to:

•Scanning and tokenizing source code.

•Parsing a grammar.

•Different targets for x86 assembly object files generation. (E.g. relocatable vs. position independent code).

•Linking object files together to create a well-formed binary.

•Detailed descriptions of the high level similarities and low level differences between the Windows PE and Linux ELF binary formats. (NOTE: we didn't get to this in the class where the video was recorded, but the materials are in the slides)

•How an OS loads a binary into memory and links it on the fly before executing it.


Along the way we discuss the relevance of security at different stages of a binary’s life, from the tricks that can be played by a malicious compiler, to how viruses really work, to the way which malware “packers” duplicate OS process execution functionality, to the benefit of a security-enhanced OS loader which implements address space layout randomization (ASLR).


Lab work includes:

•Manipulating compiler options to change the type of assembly which is output

•Manipulating linker options to change the structure of binary formats

•Reading and understanding PE files with PEView

•Reading and understanding ELF files with Readelf (NOTE: we didn't get to this in the class where the video was recorded, but the materials are in the slides)

•Using WinDbg and/or GDB to watch the loader dynamically link an executable

•Using Thread Local Storage (TLS) to obfuscate control flow and serve as a basic anti-debug mechanism

•Creating a simple example virus for PE

•Analyze the changes made to the binary format when a file is packed with UPX

•Using the rootkit technique of Import Address Table (IAT) hooking to subvert the integrity of a program’s calls to external libraries, allowing files to be hidden.


Knowledge of this material is recommended, but not required, for future classes such as Rootkits, but is required for reverse engineering.


A student Q&A forum has been set up at http://www.reddit.com/r/OST_LifeOfBinaries.


To submit any suggestions, corrections, or explanations of things I didn’t know the reasons for, please email me at the address included in the slides.



This is why it’s good to have a guide ;)


Author Biography: Xeno has a BS in CS from UMN, and an MS in security from CMU, which he attended through the National Science Foundation Scholarship for Service (aka CyberCorps) program. He has been attending security conferences since 1999 and working full time on security research since 2007. He learned about binary formats by working on a project where he had to make a new packer from scratch. He also ported this packer to Solaris/SPARC, for which no over public packers seemed to be available at the time.



Class Materials


2012_LoB_all.zip (.zip of ppt/pdf/odp(431 slides), pdf(PE/ELF specs), visual studio(code) files) - 111MB


2011_LoB_all_materials.zip (.zip of ppt/odp/pdf(373 slides), pdf(PE/ELF specs), visual studio(code) files) - 73MB


Slides Part 1 (Compiler background, 79 slides)
Slides Part 2 (Windows PE binary format, 106 slides)
Slides Part 2.5 (Windows PE binary format continued, 101 slides)
Slides Part 3 (ELF binary format, 96 slides)
Slides Part 4 (Packer & Virus labs, 49 slides)


Visual Studio Express 2010 code for labs & snapshot of the BinaryScavengerHunt python program that is used to reinforce class concepts.



Full quality downloadable QuickTime, h.264, and Ogg videos at Archive.org:

Day 1 Part 1 (1:05:28, 587 MB)

Day 1 Part 2 (1:16:42, 632 MB)

Day 1 Part 3 (48:46, 463 MB)

Day 1 Part 4 (46:56, 432 MB)

Day 1 Part 5 (1:08:26, 801 MB)

Day 1 Part 6 (1:07:34, 803 MB)

Day 2 Part 1 (59:17, 690 MB)

Day 2 Part 2 (52:49, 651 MB)

Day 2 Part 3 (1:20:23, 834 MB)

Day 2 Part 4 (1:03:02, 731 MB)

Day 2 Part 5 (56:12, 743 MB)

Day 2 Part 6 (1:12:28, 859 MB)

(12:38:03 total, sans lab time)


The videos are useful for students, but also more useful for potential instructors who would like to teach this material. By watching the video, you will better understand the intent of some slides which do not stand on their own. You are recommended to watch the largest size video so that the most possible text is visible without having to follow along in the slides.



Revision History:


03-17-2013 - Updated class slides for the version taught in fall 2012 which was updated to cover both 64 bit PE and ELF. The PE slides were split into two decks as PE is now more than 200 slides alone. Also the class was taught as a 2 day again but with skipping the compilers information, to make enough time to cover ELF. Also made the fine-grain class map more prominent. (It needs to be updated to include ELF though. This will be removed when that is done.)

04-14-2012 - Videos uploaded to Youtube

09-06-2011 - Videos uploaded to Archive.org

02-16-2011 - Initial class content upload


If you have used and modified this material, we would appreciate it if you submit your modified version for publishing here, so that all versions can benefit from your changes.