SlideShare a Scribd company logo
A Dive Into
ELF Binaries
Null Mumbai
12rd
Jan 2019
By Bhashit Pandya
Who am I
● Information Security Consultant
● Scriptologist
● Not a bug hunter!!
● Explorer
Today we will:
● ask, why to understand them?
● know about executable files.
● peep into the internals.
● see, how to read and analyse it.
● check out some tools.
Its a Saturday morning!!!
I knew..
Motivation
● What if you encounter a linux bin?
● What if you are given a file to reverse and
patch the file?
● What if you have a software to crack?
● What if you know that this file is vulnerable
which can grant you a root access?
What are executables?
● Not a simple text files.
● Complied and linked against the syscall or
WinAPI.
● Has relocatable tables.
● Number of sections to define itself.
What are some binary file formats?
ELF Binary
● Initially developed by Unix System
Laboratories for ABI support for unix os.
● Named as System V Release 4 (SVR4)
● Quickly adopted by different vendors of unix
systems because of its support for
endiannesses and address size.
● Independent of CPU and instruction sets.
● In 1999, it was chosen as a standard binary
file format
ELF Binary Format
● It is just one of the binary format.
● Short abbrevation for Executable and Linkable
Format.
● Mostly linux executables are in ELF Format.
How to detect them? Will See..
ELF Structure
ELF Header
Section Headers
Program Headers
Symbol Table*
readelf -a <file>
About
Linking and
relocation
mmap()
Debuging purpose
It Worked!!
Volunteers Required
1.Candidate
2.Security Guard
3.Hiring Manager
ELF Parsing
1. Examine ELF Header {load_elf_binary()}
2. Loops into Program Header entries to check
for an interpreter and executable stack.
3. Initialize Program headers attributes to a
new program.
4. {flush_old_exec()} It clears up state in the
kernel that refers to prev program.
5. Location of the executable file for the
program is updated at /proc/pid/exe
6. Thread name is created using
{_set_task_comm()}
7. Kernel Memory tracking structure is
created.
ELF Parsing (Cont..)
1. Code loops through PT_LOAD seg and
maps to process addr space.
2.Additional pages are also being loaded such
as virtual dynamic shared object (vDSO) and
empty page for backward compatibility
reasons.
3.Security attributes are being added.
4.Final preparation for running is to setup the
rest of the stack {create_elf_tables()}
Loading ELF
● Check format information of ELF Header.
● Read the ELF Program Header.
● Map all the values of PT_LOAD segment into
new program memory.
● Leave space for interpreter BSS segment
(object or statically allocated var).
Basically Loading ELF
● Base Address
● It helps the code to load into memory.
● When ESP values are assigned to base
address, the execution of the program starts.
● The code segment of the ELF File is loaded
into the memory to execute.
Patching The Imported
Calls!
1. Most programs are dynamically linked.
(shared libs are to be located and linked in
run-time.)
2. The ELF Handler write ELF Interpreter
filename to a new space.
3. Loads the ELF program into memory.
4. ELF Interpreter take care of the linkage
program from the user space and resolves
the program undefined symbols.
5. The interpreter starts the execution of the
new program itself. (AT_ENTRY which holds
the entry point of text seg. which was set
during preparation)
Patching the calls
● Execution begins with ELF interpreter.
● Finds the linkage requirements.
● Loads those shared libs.
● Resolves the undefined symbols.
● Starts the execution of the new program.
Resources
Reversing and Exploiting Resources
● Infecting the Procedure Linkage Table.
● http://phrack.org/issues/56/7.html
● More about ELF
● https://smshaker.files.wordpress.com/2008/0
1/reveng-02.pdf
Thank you!

More Related Content

What's hot

An Introduction to Python Programming
An Introduction to Python ProgrammingAn Introduction to Python Programming
An Introduction to Python Programming
Morteza Zakeri
 
C# Common Type System & Common Language Specification
C# Common Type System & Common Language Specification C# Common Type System & Common Language Specification
C# Common Type System & Common Language Specification
Prem Kumar Badri
 
OPEN SOURCE SOFTWARE
OPEN SOURCE SOFTWAREOPEN SOURCE SOFTWARE
OPEN SOURCE SOFTWAREritajindal2
 
Analysis of malicious pdf
Analysis of malicious pdfAnalysis of malicious pdf
Analysis of malicious pdf
Raghunath G
 
Introduction to python
 Introduction to python Introduction to python
Introduction to python
Learnbay Datascience
 
Schizophrenic files v2
Schizophrenic files v2Schizophrenic files v2
Schizophrenic files v2
Ange Albertini
 
Introduction to phython programming
Introduction to phython programmingIntroduction to phython programming
Introduction to phython programming
ASIT Education
 
TechTalk#3: REST
TechTalk#3: RESTTechTalk#3: REST
TechTalk#3: REST
DA-14
 
Introduction to .NET Programming
Introduction to .NET ProgrammingIntroduction to .NET Programming
Introduction to .NET Programming
Karthikeyan Mkr
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
Sofian Hadiwijaya
 
ODT to Daisy (AEGIS project)
ODT to Daisy (AEGIS project)ODT to Daisy (AEGIS project)
ODT to Daisy (AEGIS project)
AEGIS-ACCESSIBLE Projects
 
Cimbalino Toolkit and Multilingual App Toolkit
Cimbalino Toolkit and Multilingual App ToolkitCimbalino Toolkit and Multilingual App Toolkit
Cimbalino Toolkit and Multilingual App Toolkit
Josué Yeray Julián Ferreiro
 
11 scripting languages
11 scripting languages11 scripting languages
11 scripting languagescherrybear2014
 
Vuls & VulsRepo: A Highly Flexible Vulnerability Scanner and Visualizer
Vuls & VulsRepo: A Highly Flexible Vulnerability Scanner and VisualizerVuls & VulsRepo: A Highly Flexible Vulnerability Scanner and Visualizer
Vuls & VulsRepo: A Highly Flexible Vulnerability Scanner and Visualizer
APNIC
 
Python part1
Python part1Python part1
Python part1
Vishal Dutt
 
14 file handling
14 file handling14 file handling
14 file handlingAPU
 
Dll hijacking
Dll hijackingDll hijacking
Dll hijacking
antitree
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52myrajendra
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47myrajendra
 

What's hot (20)

An Introduction to Python Programming
An Introduction to Python ProgrammingAn Introduction to Python Programming
An Introduction to Python Programming
 
C# Common Type System & Common Language Specification
C# Common Type System & Common Language Specification C# Common Type System & Common Language Specification
C# Common Type System & Common Language Specification
 
OPEN SOURCE SOFTWARE
OPEN SOURCE SOFTWAREOPEN SOURCE SOFTWARE
OPEN SOURCE SOFTWARE
 
Analysis of malicious pdf
Analysis of malicious pdfAnalysis of malicious pdf
Analysis of malicious pdf
 
Introduction to python
 Introduction to python Introduction to python
Introduction to python
 
Schizophrenic files v2
Schizophrenic files v2Schizophrenic files v2
Schizophrenic files v2
 
Introduction to phython programming
Introduction to phython programmingIntroduction to phython programming
Introduction to phython programming
 
TechTalk#3: REST
TechTalk#3: RESTTechTalk#3: REST
TechTalk#3: REST
 
Introduction to .NET Programming
Introduction to .NET ProgrammingIntroduction to .NET Programming
Introduction to .NET Programming
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
ODT to Daisy (AEGIS project)
ODT to Daisy (AEGIS project)ODT to Daisy (AEGIS project)
ODT to Daisy (AEGIS project)
 
Cimbalino Toolkit and Multilingual App Toolkit
Cimbalino Toolkit and Multilingual App ToolkitCimbalino Toolkit and Multilingual App Toolkit
Cimbalino Toolkit and Multilingual App Toolkit
 
11 scripting languages
11 scripting languages11 scripting languages
11 scripting languages
 
Vuls & VulsRepo: A Highly Flexible Vulnerability Scanner and Visualizer
Vuls & VulsRepo: A Highly Flexible Vulnerability Scanner and VisualizerVuls & VulsRepo: A Highly Flexible Vulnerability Scanner and Visualizer
Vuls & VulsRepo: A Highly Flexible Vulnerability Scanner and Visualizer
 
Python part1
Python part1Python part1
Python part1
 
14 file handling
14 file handling14 file handling
14 file handling
 
Module 02 ftk imager
Module 02 ftk imagerModule 02 ftk imager
Module 02 ftk imager
 
Dll hijacking
Dll hijackingDll hijacking
Dll hijacking
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 

Similar to Null

DEF CON 23 - Ryan o'neil - advances in linux forensics with ecfs
DEF CON 23 - Ryan o'neil - advances in linux forensics with ecfsDEF CON 23 - Ryan o'neil - advances in linux forensics with ecfs
DEF CON 23 - Ryan o'neil - advances in linux forensics with ecfs
Felipe Prado
 
2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf
cifoxo
 
Linux multiplexing
Linux multiplexingLinux multiplexing
Linux multiplexingMark Veltzer
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
guestd9065
 
Ppt project process migration
Ppt project process migrationPpt project process migration
Ppt project process migration
jaya380
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Ahmed El-Arabawy
 
Java and its features
Java and its featuresJava and its features
Java and its features
Pydi Nikhil
 
Interoperable PHP
Interoperable PHPInteroperable PHP
Interoperable PHP
weltling
 
Anatomy of PHP Shells
Anatomy of PHP ShellsAnatomy of PHP Shells
Anatomy of PHP Shells
Vedran Krivokuca
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Ahmed El-Arabawy
 
Getting Started with Python
Getting Started with PythonGetting Started with Python
Getting Started with Python
Sankhya_Analytics
 
Inferno
InfernoInferno
Inferno
Nagarajan
 
Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging Techniques
YourHelper1
 
Operating system
Operating systemOperating system
Operating system
covapretic
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
Emertxe Information Technologies Pvt Ltd
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device drivers
Alexandre Moreno
 

Similar to Null (20)

DEF CON 23 - Ryan o'neil - advances in linux forensics with ecfs
DEF CON 23 - Ryan o'neil - advances in linux forensics with ecfsDEF CON 23 - Ryan o'neil - advances in linux forensics with ecfs
DEF CON 23 - Ryan o'neil - advances in linux forensics with ecfs
 
2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf
 
Linux multiplexing
Linux multiplexingLinux multiplexing
Linux multiplexing
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Ppt project process migration
Ppt project process migrationPpt project process migration
Ppt project process migration
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
ELF
ELFELF
ELF
 
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
 
Java and its features
Java and its featuresJava and its features
Java and its features
 
Interoperable PHP
Interoperable PHPInteroperable PHP
Interoperable PHP
 
Intro reverse engineering
Intro reverse engineeringIntro reverse engineering
Intro reverse engineering
 
Anatomy of PHP Shells
Anatomy of PHP ShellsAnatomy of PHP Shells
Anatomy of PHP Shells
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
Getting Started with Python
Getting Started with PythonGetting Started with Python
Getting Started with Python
 
Inferno
InfernoInferno
Inferno
 
Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging Techniques
 
Operating system
Operating systemOperating system
Operating system
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device drivers
 

Recently uploaded

power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 

Recently uploaded (20)

power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 

Null

  • 1. A Dive Into ELF Binaries Null Mumbai 12rd Jan 2019 By Bhashit Pandya
  • 2. Who am I ● Information Security Consultant ● Scriptologist ● Not a bug hunter!! ● Explorer
  • 3. Today we will: ● ask, why to understand them? ● know about executable files. ● peep into the internals. ● see, how to read and analyse it. ● check out some tools.
  • 4. Its a Saturday morning!!!
  • 6. Motivation ● What if you encounter a linux bin? ● What if you are given a file to reverse and patch the file? ● What if you have a software to crack? ● What if you know that this file is vulnerable which can grant you a root access?
  • 7. What are executables? ● Not a simple text files. ● Complied and linked against the syscall or WinAPI. ● Has relocatable tables. ● Number of sections to define itself. What are some binary file formats?
  • 8. ELF Binary ● Initially developed by Unix System Laboratories for ABI support for unix os. ● Named as System V Release 4 (SVR4) ● Quickly adopted by different vendors of unix systems because of its support for endiannesses and address size. ● Independent of CPU and instruction sets. ● In 1999, it was chosen as a standard binary file format
  • 9. ELF Binary Format ● It is just one of the binary format. ● Short abbrevation for Executable and Linkable Format. ● Mostly linux executables are in ELF Format. How to detect them? Will See..
  • 10. ELF Structure ELF Header Section Headers Program Headers Symbol Table* readelf -a <file> About Linking and relocation mmap() Debuging purpose
  • 11.
  • 14. ELF Parsing 1. Examine ELF Header {load_elf_binary()} 2. Loops into Program Header entries to check for an interpreter and executable stack. 3. Initialize Program headers attributes to a new program. 4. {flush_old_exec()} It clears up state in the kernel that refers to prev program. 5. Location of the executable file for the program is updated at /proc/pid/exe 6. Thread name is created using {_set_task_comm()} 7. Kernel Memory tracking structure is created.
  • 15. ELF Parsing (Cont..) 1. Code loops through PT_LOAD seg and maps to process addr space. 2.Additional pages are also being loaded such as virtual dynamic shared object (vDSO) and empty page for backward compatibility reasons. 3.Security attributes are being added. 4.Final preparation for running is to setup the rest of the stack {create_elf_tables()}
  • 16. Loading ELF ● Check format information of ELF Header. ● Read the ELF Program Header. ● Map all the values of PT_LOAD segment into new program memory. ● Leave space for interpreter BSS segment (object or statically allocated var).
  • 17. Basically Loading ELF ● Base Address ● It helps the code to load into memory. ● When ESP values are assigned to base address, the execution of the program starts. ● The code segment of the ELF File is loaded into the memory to execute.
  • 18. Patching The Imported Calls! 1. Most programs are dynamically linked. (shared libs are to be located and linked in run-time.) 2. The ELF Handler write ELF Interpreter filename to a new space. 3. Loads the ELF program into memory. 4. ELF Interpreter take care of the linkage program from the user space and resolves the program undefined symbols. 5. The interpreter starts the execution of the new program itself. (AT_ENTRY which holds the entry point of text seg. which was set during preparation)
  • 19. Patching the calls ● Execution begins with ELF interpreter. ● Finds the linkage requirements. ● Loads those shared libs. ● Resolves the undefined symbols. ● Starts the execution of the new program.
  • 20. Resources Reversing and Exploiting Resources ● Infecting the Procedure Linkage Table. ● http://phrack.org/issues/56/7.html ● More about ELF ● https://smshaker.files.wordpress.com/2008/0 1/reveng-02.pdf