SlideShare a Scribd company logo
Reverse Engineering for exploit writers Jonathan Brossard, iViZ Research Team Clubhack 2008 Pune, India
Who Am I ? (and why am I writing this ??) We are recruting ! Send me your CVs at : [email_address]
Roadmap A (short) reminder of the ELF file format Introducing the problem How (not) to work with proprietary binaries anyway ? What to rebuild ? Refactoring the binary Refactoring in practice ©iViZ Techno Solutions Pvt Ltd.
A (short) reminder of the ELF format A (short) reminder of the ELF format ©iViZ Techno Solutions Pvt Ltd.
A (short) reminder of the ELF format The ELF header : (mandatory) typedef struct { unsigned char  e_ident[EI_NIDENT]; Elf32_Half  e_type; Elf32_Half  e_machine; Elf32_Word  e_version; Elf32_Addr  e_entry; Elf32_Off  e_phoff; // offset to Program  Header Table Elf32_Off  e_shoff; // offset to Section  Header Table Elf32_Word  e_flags; Elf32_Half  e_ehsize; Elf32_Half  e_phentsize; Elf32_Half  e_phnum; Elf32_Half  e_shentsize; // size of a section header Elf32_Half  e_shnum; // number of section headers Elf32_Half  e_shtrndx; // offset of associated string table } Elf32_Ehdr; ©iViZ Techno Solutions Pvt Ltd.
A (short) reminder of the ELF format Program Headers : (mandatory, one per segment) typedef struct { Elf32_Word  p_type; // Segment type (Alocate ? Null ? Dynamic ? …) Elf32_Off  p_offset; // offset in file Elf32_Addr  p_vaddr; Elf32_Addr  p_paddr; Elf32_Word  p_filesz; // length in file Elf32_Word  p_memsz; Elf32_Word  p_flags; Elf32_Word  p_align; } Elf32_Phdr; ©iViZ Techno Solutions Pvt Ltd.
A (short) reminder of the ELF format Section Headers : (optional, one per section) typedef struct { Elf32_Word sh_name; // index in string table Elf32_Word sh_type; // type of section Elf32_Word sh_flags; Elf32_Addr   sh_addr; Elf32_Off sh_offset; Elf32_Word sh_size; Elf32_Word sh_link; Elf32_Word sh_info; Elf32_Word sh_addralign; Elf32_Word sh_entsize; } Elf32_Shdr; ©iViZ Techno Solutions Pvt Ltd.
A (short) reminder of the ELF format Symbols : (the Symbol table is an array of Elf32_sym) typedef struct { Elf32_Word st_name; // Symbol name (string tbl index)  Elf32_Addr st_value; // Symbol value  Elf32_Word st_size; // Symbol size  unsigned char st_info; // Symbol type and binding  unsigned char st_other; // Symbol visibility  Elf32_Section st_shndx; // Section index  } Elf32_Sym; ©iViZ Techno Solutions Pvt Ltd.
Introducing the problem Proprietary binaries are commonly modified to make the job of security analysts difficult: - Sometimes packed (out of topic) - Usually don’t have a symbol table (stripped) - More and more have a missing/corrupted Section Header Table (sstripped, a la sstrip from elfkickers…)‏ and/or zeroed Section Headers. ©iViZ Techno Solutions Pvt Ltd.
- We know where the Segments are - We know where the Sections are located - The application has a symbol table ©iViZ Techno Solutions Pvt Ltd. Introducing the problem Before :
After : ©iViZ Techno Solutions Pvt Ltd. Introducing the problem - We know where the Segments are : the loader/dynamic linker can still do their jobs - We don’t know where the Sections start/end - The application has no symbol table
Introducing the problem Tools based on libbfd need to read the Section Headers to analyse it. Therefore, the handy GNU binutils utilities won't manage to analyze the target (readelf, objdump, objcopy, nm...)‏ Debugging with gdb will be really uneasy : - no symbols, so no breakpoints on symbol names. :( - the application doesn't even have a “main”. How to get a prompt once the shared libraries are loaded ? ©iViZ Techno Solutions Pvt Ltd.
Introducing the problem DEMO ©iViZ Techno Solutions Pvt Ltd.
How (not) to work with proprietary binaries anyway ? Use tools that aren't based on libbfd ? - Fenris (M Zalewski) : rebuilds a symbol table for dynamically linked binaries (moderately interresting for us) http://lcamtuf.coredump.cx/fenris/ - Elfsh from the Eresi project (attempts to rebuild the missing ELF section header and a symbol table) plus its debugger, tracer…‏ http://www.eresi-project.org/ ©iViZ Techno Solutions Pvt Ltd.
The problem with existing tools... DEMO Hrm... so we will code our own ;) How (not) to work with proprietary binaries anyway ? ©iViZ Techno Solutions Pvt Ltd.
What to rebuild ? Instead of rewriting ELF parsers and debuggers, the idea is to refactor the binary as little as possible (do not modify the .data or .text for instance) to make it usable by the standard tools we may need (libbfd based tools like the ones of binutils, GDB, etc). We need a Section Header Table and Section Headers (and infos on the sections to populate them !) for all the relevant sections. We need a symbol table with labels for every function/control structure ©iViZ Techno Solutions Pvt Ltd.
Increase the size of the binary to contain a new Section Header Table Modify the ELF Header to point to our new Section Header Table (via e_shoff) ©iViZ Techno Solutions Pvt Ltd. Refactoring the binary :
Refactoring the binary retrieve information about the sections start/end (make a wild guess or use heuristics when possible) ©iViZ Techno Solutions Pvt Ltd.
Refactoring the binary Example of heuristics on Sections : Entry point points to .text Segment types and Flags give indications on their content Some sections are in a predictable order if the compiler is known Patterns of bytes can be found for some sections starts/ends (eg: .interp) NOTE: We don’t care if 100% of the info is not correct ! ©iViZ Techno Solutions Pvt Ltd.
Allocate (append) and update Section Headers accordingly (don’t forget to e_shnum++ in ELF Header). ©iViZ Techno Solutions Pvt Ltd. Refactoring the binary
We can now use the binary with our usual disassemblers using libbfd. Disassemble the .text, and give names to the destination offsets of (un)conditional jumps and calls Update this list with labels corresponding to predictable offsets (eg: main()) and the content of the .dynamic section Add all those label/offset tuples to a symbol table (new section SHT_SYMTAB) at the end of the binary ©iViZ Techno Solutions Pvt Ltd. Refactoring the binary
Refactoring the binary Examples of heuristics : 1) Finding main() objdump -d -j .text ./binary \ 2>/dev/null|tac|grep \ "__libc_start_main@plt" -A 1|grep push|grep \ "0x[0-9a-fA-F]*" -o|awk '{print $0 " main"}' ©iViZ Techno Solutions Pvt Ltd.
Refactoring the binary Examples of heuristics : 2) Finding constructors objdump -d -j .text ./ binary 2>/dev/null \ |tac|grep \ "bb [0-9a-fA-F][0-9a-fA-F] [0-9a-fA-F][0-9a \ -fA-F] 0[0-9a-fA-F] 08" -A 4|grep -w 55|grep \ "[0-9a-fA-F][0-9a-fA-F]*" -o|head -n 1|sed \ s#"^0"##gi|awk '{print "0x" $0 “ \ __do_global_ctors_aux"}' ©iViZ Techno Solutions Pvt Ltd.
Refactoring the binary Examples of heuristics : 3) Finding destructors objdump -d -j .text ./binary \ 2>/dev/null|tac|grep "80 3d [0-9a-fA-F][0-9a \ -fA-F] [0-9a-fA-F][0-9a-fA-F] 0[0-9a-fA-F] 08 \ 00" -A 10|grep -w 55|grep "[0-9a-fA-F][0-9a \ -fA-F]*" -o|head -n 1|sed s#"^0"##gi|awk \ '{print "0x" $0 " __do_global_dtors_aux"}' ©iViZ Techno Solutions Pvt Ltd.
Refactoring the binary It is worth noticing that the modifications we did on the binary affect non loadable parts of the binary only. In other words, the process actually loaded in memory is not changed : addresses in .text, stack or heap won’t be modified (luckily from an exploit writer POV). We add information relevant to the auditor and its tools only : we don’t really care if all information is not accurate (as long as it helps…) ©iViZ Techno Solutions Pvt Ltd.
Refactoring in practice DEMO ©iViZ Techno Solutions Pvt Ltd.
Conclusion It is possible to unstrip (rebuild a symbol table) and even unsstrip (rebuild Section Headers) a binary. From a defensive point of view, it is not possible to remove more information from the binary without affecting its execution (eg: a binary without ELF header won’t be loaded properly). Go for packers… or opensource :p We can now write exploits using our usual tools without caring about those “protective” alterations. ©iViZ Techno Solutions Pvt Ltd.
Greetings Abhisek and Nibin from the iViZ Research Team irc.pulltheplug.org #social, in particular Silvio Cesare and Mayhem for their ideas/tools/knowledge irc.blacksecurity.org The Clubhack staff for making the event happen You for coming to this talk ;) ©iViZ Techno Solutions Pvt Ltd.
Questions ? ©iViZ Techno Solutions Pvt Ltd.
Thank You! ©iViZ Techno Solutions Pvt Ltd.

More Related Content

PDF
Introduction to C programming
PPTX
C programming language
PPTX
Programming in C Basics
PDF
Advanced C Language for Engineering
PPTX
Introduction to c
PDF
C programming
ODP
Basic C Programming language
PPTX
COM1407: Introduction to C Programming
Introduction to C programming
C programming language
Programming in C Basics
Advanced C Language for Engineering
Introduction to c
C programming
Basic C Programming language
COM1407: Introduction to C Programming

What's hot (19)

PPT
C PROGRAMMING
PPT
Unit 4 Foc
PPT
Brief introduction to the c programming language
PPT
Introduction to C Programming
PPT
C language introduction
PPTX
PPT
C language programming
PDF
Embedded C programming based on 8051 microcontroller
PPT
Embedded c programming22 for fdp
PDF
C programming part1
PPTX
C programming tutorial for beginners
PPTX
Introduction to C Unit 1
PPTX
Discussing Fundamentals of C
DOCX
Features of c language 1
PPTX
A brief introduction to C Language
PPTX
PPTX
C programming interview questions
PPT
Introduction to c programming
PPT
Introduction to programming with c,
C PROGRAMMING
Unit 4 Foc
Brief introduction to the c programming language
Introduction to C Programming
C language introduction
C language programming
Embedded C programming based on 8051 microcontroller
Embedded c programming22 for fdp
C programming part1
C programming tutorial for beginners
Introduction to C Unit 1
Discussing Fundamentals of C
Features of c language 1
A brief introduction to C Language
C programming interview questions
Introduction to c programming
Introduction to programming with c,

Viewers also liked (20)

PDF
M. golański program operacyjny polska cyfrowa 2014 2020
PPTX
Bantuan perniagaan KHB
DOCX
CALCULO DEL POTENCIAL A PARTIR DEL CAMPO
DOCX
Hoyos Advocacia em Santarém/PA - BRA
DOCX
Hongos oportunistas.
PPTX
Mi experiencia en la gastronomia
PPT
Mokocrm
PDF
Inversion publika
PDF
Key social o-net'54
PPT
Ariana torres mapa
PDF
SOBRE PERMISO CON GOCE POR EL DIA DEL MAESTRO - SUTE LIMA
PDF
Devens Annual Report 2003
PDF
Vad är Internet och hur fungerar det? Barn om Internet
PDF
march award
PDF
UFMG Provas Antigas 1994 aberta - Conteúdo vinculado ao blog http://fisi...
PPT
Резервируйте
PDF
UFMG Provas Antigas 1995 fechada 2 - Conteúdo vinculado ao blog http://f...
PDF
Aviso de pago
PPTX
Сандерс: Історія енергоефективності в Каліфорнії
M. golański program operacyjny polska cyfrowa 2014 2020
Bantuan perniagaan KHB
CALCULO DEL POTENCIAL A PARTIR DEL CAMPO
Hoyos Advocacia em Santarém/PA - BRA
Hongos oportunistas.
Mi experiencia en la gastronomia
Mokocrm
Inversion publika
Key social o-net'54
Ariana torres mapa
SOBRE PERMISO CON GOCE POR EL DIA DEL MAESTRO - SUTE LIMA
Devens Annual Report 2003
Vad är Internet och hur fungerar det? Barn om Internet
march award
UFMG Provas Antigas 1994 aberta - Conteúdo vinculado ao blog http://fisi...
Резервируйте
UFMG Provas Antigas 1995 fechada 2 - Conteúdo vinculado ao blog http://f...
Aviso de pago
Сандерс: Історія енергоефективності в Каліфорнії

Similar to Jonathan - Reverse Engineering for exploit writers - ClubHack2008 (20)

PDF
Compilation and Execution
PPTX
In the lands of corrupted elves - Breaking ELF software with Melkor fuzzer
ODP
The forgotten art of assembly
PPTX
ELF(executable and linkable format)
PPT
Intro reverse engineering
PDF
The true story_of_hello_world
ODP
A Dive Into ELF Binaries
PDF
The Internals of "Hello World" Program
PPTX
Ben Agre - Adding Another Level of Hell to Reverse Engineering
PDF
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
PDF
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
PDF
Exploitation Crash Course
PDF
Appsec obfuscator reloaded
PDF
The walking 0xDEAD
PDF
printf tricks
PPTX
C from hello world to 010101
PDF
r2con 2017 r2cLEMENCy
PPTX
embedded C.pptx
Compilation and Execution
In the lands of corrupted elves - Breaking ELF software with Melkor fuzzer
The forgotten art of assembly
ELF(executable and linkable format)
Intro reverse engineering
The true story_of_hello_world
A Dive Into ELF Binaries
The Internals of "Hello World" Program
Ben Agre - Adding Another Level of Hell to Reverse Engineering
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Exploitation Crash Course
Appsec obfuscator reloaded
The walking 0xDEAD
printf tricks
C from hello world to 010101
r2con 2017 r2cLEMENCy
embedded C.pptx

More from ClubHack (20)

PDF
India legal 31 october 2014
PPTX
Cyberlaw by Mr. Pavan Duggal at ClubHack Infosec KeyNote @ Bangalore
PPT
Cyber Insurance
PPTX
Summarising Snowden and Snowden as internal threat
PPTX
Fatcat Automatic Web SQL Injector by Sandeep Kamble
PDF
The Difference Between the Reality and Feeling of Security by Thomas Kurian
PDF
Stand Close to Me & You're pwned! Owning Smart Phones using NFC by Aditya Gup...
PPTX
Smart Grid Security by Falgun Rathod
PPTX
Legal Nuances to the Cloud by Ritambhara Agrawal
PPT
Infrastructure Security by Sivamurthy Hiremath
PDF
Hybrid Analyzer for Web Application Security (HAWAS) by Lavakumar Kuppan
PPTX
Hacking and Securing iOS Applications by Satish Bomisstty
PPTX
Critical Infrastructure Security by Subodh Belgi
PPTX
Content Type Attack Dark Hole in the Secure Environment by Raman Gupta
PDF
XSS Shell by Vandan Joshi
PDF
Clubhack Magazine Issue February 2012
PDF
ClubHack Magazine issue 26 March 2012
PDF
ClubHack Magazine issue April 2012
PDF
ClubHack Magazine Issue May 2012
PDF
ClubHack Magazine – December 2011
India legal 31 october 2014
Cyberlaw by Mr. Pavan Duggal at ClubHack Infosec KeyNote @ Bangalore
Cyber Insurance
Summarising Snowden and Snowden as internal threat
Fatcat Automatic Web SQL Injector by Sandeep Kamble
The Difference Between the Reality and Feeling of Security by Thomas Kurian
Stand Close to Me & You're pwned! Owning Smart Phones using NFC by Aditya Gup...
Smart Grid Security by Falgun Rathod
Legal Nuances to the Cloud by Ritambhara Agrawal
Infrastructure Security by Sivamurthy Hiremath
Hybrid Analyzer for Web Application Security (HAWAS) by Lavakumar Kuppan
Hacking and Securing iOS Applications by Satish Bomisstty
Critical Infrastructure Security by Subodh Belgi
Content Type Attack Dark Hole in the Secure Environment by Raman Gupta
XSS Shell by Vandan Joshi
Clubhack Magazine Issue February 2012
ClubHack Magazine issue 26 March 2012
ClubHack Magazine issue April 2012
ClubHack Magazine Issue May 2012
ClubHack Magazine – December 2011

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Empathic Computing: Creating Shared Understanding
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation theory and applications.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Modernizing your data center with Dell and AMD
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Empathic Computing: Creating Shared Understanding
The AUB Centre for AI in Media Proposal.docx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Weekly Chronicles - August'25 Week I
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Modernizing your data center with Dell and AMD
Machine learning based COVID-19 study performance prediction
Understanding_Digital_Forensics_Presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Jonathan - Reverse Engineering for exploit writers - ClubHack2008

  • 1. Reverse Engineering for exploit writers Jonathan Brossard, iViZ Research Team Clubhack 2008 Pune, India
  • 2. Who Am I ? (and why am I writing this ??) We are recruting ! Send me your CVs at : [email_address]
  • 3. Roadmap A (short) reminder of the ELF file format Introducing the problem How (not) to work with proprietary binaries anyway ? What to rebuild ? Refactoring the binary Refactoring in practice ©iViZ Techno Solutions Pvt Ltd.
  • 4. A (short) reminder of the ELF format A (short) reminder of the ELF format ©iViZ Techno Solutions Pvt Ltd.
  • 5. A (short) reminder of the ELF format The ELF header : (mandatory) typedef struct { unsigned char e_ident[EI_NIDENT]; Elf32_Half e_type; Elf32_Half e_machine; Elf32_Word e_version; Elf32_Addr e_entry; Elf32_Off e_phoff; // offset to Program Header Table Elf32_Off e_shoff; // offset to Section Header Table Elf32_Word e_flags; Elf32_Half e_ehsize; Elf32_Half e_phentsize; Elf32_Half e_phnum; Elf32_Half e_shentsize; // size of a section header Elf32_Half e_shnum; // number of section headers Elf32_Half e_shtrndx; // offset of associated string table } Elf32_Ehdr; ©iViZ Techno Solutions Pvt Ltd.
  • 6. A (short) reminder of the ELF format Program Headers : (mandatory, one per segment) typedef struct { Elf32_Word p_type; // Segment type (Alocate ? Null ? Dynamic ? …) Elf32_Off p_offset; // offset in file Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; // length in file Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align; } Elf32_Phdr; ©iViZ Techno Solutions Pvt Ltd.
  • 7. A (short) reminder of the ELF format Section Headers : (optional, one per section) typedef struct { Elf32_Word sh_name; // index in string table Elf32_Word sh_type; // type of section Elf32_Word sh_flags; Elf32_Addr sh_addr; Elf32_Off sh_offset; Elf32_Word sh_size; Elf32_Word sh_link; Elf32_Word sh_info; Elf32_Word sh_addralign; Elf32_Word sh_entsize; } Elf32_Shdr; ©iViZ Techno Solutions Pvt Ltd.
  • 8. A (short) reminder of the ELF format Symbols : (the Symbol table is an array of Elf32_sym) typedef struct { Elf32_Word st_name; // Symbol name (string tbl index) Elf32_Addr st_value; // Symbol value Elf32_Word st_size; // Symbol size unsigned char st_info; // Symbol type and binding unsigned char st_other; // Symbol visibility Elf32_Section st_shndx; // Section index } Elf32_Sym; ©iViZ Techno Solutions Pvt Ltd.
  • 9. Introducing the problem Proprietary binaries are commonly modified to make the job of security analysts difficult: - Sometimes packed (out of topic) - Usually don’t have a symbol table (stripped) - More and more have a missing/corrupted Section Header Table (sstripped, a la sstrip from elfkickers…)‏ and/or zeroed Section Headers. ©iViZ Techno Solutions Pvt Ltd.
  • 10. - We know where the Segments are - We know where the Sections are located - The application has a symbol table ©iViZ Techno Solutions Pvt Ltd. Introducing the problem Before :
  • 11. After : ©iViZ Techno Solutions Pvt Ltd. Introducing the problem - We know where the Segments are : the loader/dynamic linker can still do their jobs - We don’t know where the Sections start/end - The application has no symbol table
  • 12. Introducing the problem Tools based on libbfd need to read the Section Headers to analyse it. Therefore, the handy GNU binutils utilities won't manage to analyze the target (readelf, objdump, objcopy, nm...)‏ Debugging with gdb will be really uneasy : - no symbols, so no breakpoints on symbol names. :( - the application doesn't even have a “main”. How to get a prompt once the shared libraries are loaded ? ©iViZ Techno Solutions Pvt Ltd.
  • 13. Introducing the problem DEMO ©iViZ Techno Solutions Pvt Ltd.
  • 14. How (not) to work with proprietary binaries anyway ? Use tools that aren't based on libbfd ? - Fenris (M Zalewski) : rebuilds a symbol table for dynamically linked binaries (moderately interresting for us) http://lcamtuf.coredump.cx/fenris/ - Elfsh from the Eresi project (attempts to rebuild the missing ELF section header and a symbol table) plus its debugger, tracer…‏ http://www.eresi-project.org/ ©iViZ Techno Solutions Pvt Ltd.
  • 15. The problem with existing tools... DEMO Hrm... so we will code our own ;) How (not) to work with proprietary binaries anyway ? ©iViZ Techno Solutions Pvt Ltd.
  • 16. What to rebuild ? Instead of rewriting ELF parsers and debuggers, the idea is to refactor the binary as little as possible (do not modify the .data or .text for instance) to make it usable by the standard tools we may need (libbfd based tools like the ones of binutils, GDB, etc). We need a Section Header Table and Section Headers (and infos on the sections to populate them !) for all the relevant sections. We need a symbol table with labels for every function/control structure ©iViZ Techno Solutions Pvt Ltd.
  • 17. Increase the size of the binary to contain a new Section Header Table Modify the ELF Header to point to our new Section Header Table (via e_shoff) ©iViZ Techno Solutions Pvt Ltd. Refactoring the binary :
  • 18. Refactoring the binary retrieve information about the sections start/end (make a wild guess or use heuristics when possible) ©iViZ Techno Solutions Pvt Ltd.
  • 19. Refactoring the binary Example of heuristics on Sections : Entry point points to .text Segment types and Flags give indications on their content Some sections are in a predictable order if the compiler is known Patterns of bytes can be found for some sections starts/ends (eg: .interp) NOTE: We don’t care if 100% of the info is not correct ! ©iViZ Techno Solutions Pvt Ltd.
  • 20. Allocate (append) and update Section Headers accordingly (don’t forget to e_shnum++ in ELF Header). ©iViZ Techno Solutions Pvt Ltd. Refactoring the binary
  • 21. We can now use the binary with our usual disassemblers using libbfd. Disassemble the .text, and give names to the destination offsets of (un)conditional jumps and calls Update this list with labels corresponding to predictable offsets (eg: main()) and the content of the .dynamic section Add all those label/offset tuples to a symbol table (new section SHT_SYMTAB) at the end of the binary ©iViZ Techno Solutions Pvt Ltd. Refactoring the binary
  • 22. Refactoring the binary Examples of heuristics : 1) Finding main() objdump -d -j .text ./binary \ 2>/dev/null|tac|grep \ "__libc_start_main@plt" -A 1|grep push|grep \ "0x[0-9a-fA-F]*" -o|awk '{print $0 " main"}' ©iViZ Techno Solutions Pvt Ltd.
  • 23. Refactoring the binary Examples of heuristics : 2) Finding constructors objdump -d -j .text ./ binary 2>/dev/null \ |tac|grep \ "bb [0-9a-fA-F][0-9a-fA-F] [0-9a-fA-F][0-9a \ -fA-F] 0[0-9a-fA-F] 08" -A 4|grep -w 55|grep \ "[0-9a-fA-F][0-9a-fA-F]*" -o|head -n 1|sed \ s#"^0"##gi|awk '{print "0x" $0 “ \ __do_global_ctors_aux"}' ©iViZ Techno Solutions Pvt Ltd.
  • 24. Refactoring the binary Examples of heuristics : 3) Finding destructors objdump -d -j .text ./binary \ 2>/dev/null|tac|grep "80 3d [0-9a-fA-F][0-9a \ -fA-F] [0-9a-fA-F][0-9a-fA-F] 0[0-9a-fA-F] 08 \ 00" -A 10|grep -w 55|grep "[0-9a-fA-F][0-9a \ -fA-F]*" -o|head -n 1|sed s#"^0"##gi|awk \ '{print "0x" $0 " __do_global_dtors_aux"}' ©iViZ Techno Solutions Pvt Ltd.
  • 25. Refactoring the binary It is worth noticing that the modifications we did on the binary affect non loadable parts of the binary only. In other words, the process actually loaded in memory is not changed : addresses in .text, stack or heap won’t be modified (luckily from an exploit writer POV). We add information relevant to the auditor and its tools only : we don’t really care if all information is not accurate (as long as it helps…) ©iViZ Techno Solutions Pvt Ltd.
  • 26. Refactoring in practice DEMO ©iViZ Techno Solutions Pvt Ltd.
  • 27. Conclusion It is possible to unstrip (rebuild a symbol table) and even unsstrip (rebuild Section Headers) a binary. From a defensive point of view, it is not possible to remove more information from the binary without affecting its execution (eg: a binary without ELF header won’t be loaded properly). Go for packers… or opensource :p We can now write exploits using our usual tools without caring about those “protective” alterations. ©iViZ Techno Solutions Pvt Ltd.
  • 28. Greetings Abhisek and Nibin from the iViZ Research Team irc.pulltheplug.org #social, in particular Silvio Cesare and Mayhem for their ideas/tools/knowledge irc.blacksecurity.org The Clubhack staff for making the event happen You for coming to this talk ;) ©iViZ Techno Solutions Pvt Ltd.
  • 29. Questions ? ©iViZ Techno Solutions Pvt Ltd.
  • 30. Thank You! ©iViZ Techno Solutions Pvt Ltd.