SlideShare a Scribd company logo
Reversing malware analysis training part3 windows pefile formatbasics
Disclaimer
The Content, Demonstration, Source Code and Programs presented here
is "AS IS" without any warranty or conditions of any kind. Also the
views/ideas/knowledge expressed here are solely of the trainer’s only and
nothing to do with the company or the organization in which the trainer is
currently working.
However in no circumstances neither the trainer nor Cysinfo is
responsible for any damage or loss caused due to use or misuse of the
information presented here.
Acknowledgement
 Special thanks to null & Garage4Hackers community for their extended
support and cooperation.
 Thanks to all the trainers who have devoted their precious time and
countless hours to make it happen.
Reversing & Malware Analysis Training
This presentation is part of our Reverse Engineering & Malware
Analysis Training program. Currently it is delivered only during our local
meet for FREE of cost.
Who am I #1
Amit Malik (sometimes DouBle_Zer0,DZZ)
 Member SecurityXploded & Garage4Hackers
 Security Researcher
 RE, Exploit Analysis/Development, Malware Analysis
 Email: m.amit30@gmail.com
Who am I #2
Swapnil Pathak
 Member SecurityXploded
 Security Researcher
 RE, Malware Analysis, Network Security
 Email: swapnilpathak101@gmail.com
 PE – Portable Executable
 PE is the native Win32 file format.
 32-bit DLL, COM, OCX, Control Panel Applets(.CPL), .NET, NT
kernel mode drivers are all PE File Format.
 How windows loader loads the executable in memory.
 How loader build the import and export table for a module in memory
 From where to start the execution or Address of entry point
 Answer of the question “how binary compiled on a version of windows
works on another version of windows?”
 Where should attacker attack 
 Also today’s malwares are generally encrypted, packed. In order to rebuild
the original binary we need to know how the binary is structured.
Reversing malware analysis training part3 windows pefile formatbasics
 Most common sections found in executable are
◦ Executable Code section (.text , CODE)
◦ Data Sections (.data, .rdata, .bss, DATA)
◦ Resources section (.rsrc)
◦ Export Section (.edata)
◦ Import Section (.idata)
◦ Debug Information Section (.debug)
 All PE files start with DOS header
 First 64 bytes of the file.
 Run program in DOS.
 Runs the DOS stub
 Usually the string
“This program must be run under Microsoft Windows”
 e_lfanew is the pointer to PE or NT header
 Structure defined in windows.inc or winnt.h
e_magic = 4D, 5A (MZ)
e_lfanew is a DWORD which contains the offset of the PE header
 Begins with signature (DWORD) 50h, 45h, 00h, 00h
 Letters “PE” followed by two terminating zeros
 File Header- 20 Bytes – contains info about physical layout and
properties of the file
 Optional Header- 224 Bytes – contains info about the logical layout
of the PE file – size given by member of File header
 Machine
 NumberOfSections
 SizeOfOptionalHeader
 Characteristics
Reversing malware analysis training part3 windows pefile formatbasics
 AddressOfEntryPoint
 ImageBase
 SectionAlignment
 FileAlignment
 SizeOfImage
 SizeOfHeaders
 Subsystem
 DataDirectory
 Last 128 bytes of OptionalHeader
 Array of 16 Image_Data_Directory structures
 Each relating to an important data structure like the Import Table
 Members
 Virtual Address : RVA of the data structure
 iSize : size in bytes of the data structure
Reversing malware analysis training part3 windows pefile formatbasics
 IMAGE_DIRECTORY_ENTRY_EXPORT
 IMAGE_DIRECTORY_ENTRY_IMPORT
 IMAGE_DIRECTORY_ENTRY_RESOURCE
 IMAGE_DIRECTORY_ENTRY_TLS
 IMAGE_DIRECTORY_ENTRY_IAT
 Array of IMAGE_SECTION_HEADER
 Equal to the numberofsections – FileHeader member.
 Each structure size = 40 bytes
 Name – Virtually can be anything in text
 VirtualSize – Size of section in memory
 VirtualAddress – section entry offset in memory (RVA)
 SizeOfRawData – Size of section on disk
 PointerToRawData – section entry offset on disk
 Characteristics – Type of section (execuatble, data etc.)
 Section Alignment and File Alignment are two important
values from optional header that control the entry point of
next section.
 The structure of PE file on disk is exactly the same as when it is
loaded into memory.
 The windows loader maps the required sections in memory.
 When sections are loaded into memory they are aligned to fit 4KB
memory pages (Section Alignment), each section starting on a new
page.
 Executable code
 Data
 Resources
 Export section
 Import section
 Thread Local Storage (TLS)
 Base Relocations (reloc.)
 Relevant to DLLs
 Export functions in two ways
- By name
- By ordinal only
 Ordinal – 16 bit value that uniquely defines a function in particular
DLL
nName
nBase
NumberOfFunctions
NumberOfNames
AddressOfFunctions
AddressOfNames
AddressOfNameOrdinals
Export by Ordinal only
Export Forwarding
 Contains information about all functions imported by executable
from DLLs
 Loader maps all the DLLs used by the application into its address
space
 Finds the addresses of all the imported functions and makes them
available to the executable being loaded.
 20 byte structure IMAGE_IMPORT_DESCRIPTOR
 Number of structures = Number of DLLs imported
 Last structure filed with zeros
 OriginalFirstThunk
 Name1
 FirstThunk
Hint
Name1
 Each IMAGE_THUNK_DATA str corresponds to one imported
function from the dll.
 Arrays pointed by OriginalFirstThunk and FirstThunk run parallelly.
 OriginalFirstThunk – Import Name Table – Never modified
 FirstThunk – Import Address Table – Contain actual function
addresses
Functions exported by ordinal only
- No IMAGE_IMPORT_BY_NAME structure
-IMAGE_THUNK_DATA contains the ordinal of the function
-MSB used to identify the same
- MSB is set, rest 31 bits are treated as an ordinal value.
-Bound Imports
Reversing malware analysis training part3 windows pefile formatbasics
 Write a program in “C” or “ASM” that will modify the Address of
Entry point of an Executable (.exe) file with any random address.
 Write a program in “C” or “ASM” that will add a new section into an
executable (.exe)
◦ For hints shoot us an email 
Thank You !

More Related Content

What's hot (20)

PPTX
Reversing malware analysis trainingpart9 advanced malware analysis
Cysinfo Cyber Security Community
 
PPTX
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
securityxploded
 
PPTX
Reversing & malware analysis training part 3 windows pe file format basics
securityxploded
 
PPTX
Reversing & malware analysis training part 2 introduction to windows internals
securityxploded
 
PPTX
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
securityxploded
 
PPTX
Advanced Malware Analysis Training Session 5 - Reversing Automation
securityxploded
 
PPTX
Primer on password security
securityxploded
 
PPTX
Advanced Malware Analysis Training Session 1 - Detection and Removal of Malwares
securityxploded
 
PPTX
Anti-Virus Evasion Techniques and Countermeasures
n|u - The Open Security Community
 
PPTX
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
securityxploded
 
PPTX
Reversing and Decrypting the Communications of APT Malware (Etumbot)
securityxploded
 
PPTX
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
securityxploded
 
PPTX
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
securityxploded
 
PPTX
Defeating public exploit protections (EMET v5.2 and more)
securityxploded
 
PPTX
Advanced malware analysis training session3 botnet analysis part2
Cysinfo Cyber Security Community
 
PPTX
Anatomy of Exploit Kits
securityxploded
 
PDF
Ida python intro
小静 安
 
PDF
Dynamic Binary Instrumentation
Cysinfo Cyber Security Community
 
PDF
Introduction to ida python
geeksec80
 
Reversing malware analysis trainingpart9 advanced malware analysis
Cysinfo Cyber Security Community
 
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
securityxploded
 
Reversing & malware analysis training part 3 windows pe file format basics
securityxploded
 
Reversing & malware analysis training part 2 introduction to windows internals
securityxploded
 
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
securityxploded
 
Advanced Malware Analysis Training Session 5 - Reversing Automation
securityxploded
 
Primer on password security
securityxploded
 
Advanced Malware Analysis Training Session 1 - Detection and Removal of Malwares
securityxploded
 
Anti-Virus Evasion Techniques and Countermeasures
n|u - The Open Security Community
 
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
securityxploded
 
Reversing and Decrypting the Communications of APT Malware (Etumbot)
securityxploded
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
securityxploded
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
securityxploded
 
Defeating public exploit protections (EMET v5.2 and more)
securityxploded
 
Advanced malware analysis training session3 botnet analysis part2
Cysinfo Cyber Security Community
 
Anatomy of Exploit Kits
securityxploded
 
Ida python intro
小静 安
 
Dynamic Binary Instrumentation
Cysinfo Cyber Security Community
 
Introduction to ida python
geeksec80
 

Viewers also liked (20)

PDF
Neuigkeiten von DEPAROM & Co
Arne Krueger
 
PDF
Chicago AWS user group meetup - May 2014 at Cohesive
AWS Chicago
 
PPTX
MyHeritage backend group - build to scale
Ran Levy
 
PDF
Catálogo 15 16 elksport
Elk Sport
 
PDF
Streaming architecture with HDP & ELK
Alain Douangpraseuth
 
PPTX
#speakgeek - Open Source Software Infrastructure at iconnect360
Derek Chan
 
PDF
IM World presentation from Chris Swan: Application centric – how the cloud ha...
Cohesive Networks
 
PDF
Advanced Microservices - Greach 2015
Steve Pember
 
PPTX
Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...
Nagios
 
PPTX
Item analysis
Bimel Kottarathil
 
PDF
AWS + Puppet = Dynamic Scale
Shiva Narayanaswamy
 
PPTX
Monitoring & Analysis 101 - N00b to Ninja in 60 Minutes at ISSW on April 9, 2016
grecsl
 
PPTX
You know, for search
Peter van der Weerd
 
PPTX
Security For Humans
conjur_inc
 
PPT
Een Gezond Gebit2
guest031320
 
PPTX
Risk management
hussnain ali
 
PPTX
Persistence in the cloud with bosh
m_richardson
 
PDF
Evolution of OPNFV CI System: What already exists and what can be introduced
OPNFV
 
PDF
Sunbrella Ottomans by Outdoor Elegance
OutdoorEleganceAus
 
Neuigkeiten von DEPAROM & Co
Arne Krueger
 
Chicago AWS user group meetup - May 2014 at Cohesive
AWS Chicago
 
MyHeritage backend group - build to scale
Ran Levy
 
Catálogo 15 16 elksport
Elk Sport
 
Streaming architecture with HDP & ELK
Alain Douangpraseuth
 
#speakgeek - Open Source Software Infrastructure at iconnect360
Derek Chan
 
IM World presentation from Chris Swan: Application centric – how the cloud ha...
Cohesive Networks
 
Advanced Microservices - Greach 2015
Steve Pember
 
Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...
Nagios
 
Item analysis
Bimel Kottarathil
 
AWS + Puppet = Dynamic Scale
Shiva Narayanaswamy
 
Monitoring & Analysis 101 - N00b to Ninja in 60 Minutes at ISSW on April 9, 2016
grecsl
 
You know, for search
Peter van der Weerd
 
Security For Humans
conjur_inc
 
Een Gezond Gebit2
guest031320
 
Risk management
hussnain ali
 
Persistence in the cloud with bosh
m_richardson
 
Evolution of OPNFV CI System: What already exists and what can be introduced
OPNFV
 
Sunbrella Ottomans by Outdoor Elegance
OutdoorEleganceAus
 
Ad

Similar to Reversing malware analysis training part3 windows pefile formatbasics (20)

PDF
Reversing & malware analysis training part 3 windows pe file format basics
Abdulrahman Bassam
 
PDF
Binary art - Byte-ing the PE that fails you (extended offline version)
Ange Albertini
 
PPT
Intro reverse engineering
Nitin kumar Gupta
 
PPTX
OS Internals and Portable Executable File Format
Aitezaz Mohsin
 
PPTX
Revers engineering
AbdusSalam ALJBRI
 
PDF
Anatomy of A Shell Code, Reverse engineering
Abhineet Ayan
 
PPT
PE Packers Used in Malicious Software - Part 2
amiable_indian
 
PPTX
Creating user-mode debuggers for Windows
Mithun Shanbhag
 
PPT
CHAPTER 2 BASIC ANALYSIS.ppt
ManjuAppukuttan2
 
PPTX
Code Injection in Windows
n|u - The Open Security Community
 
PDF
CHAPTER 2 BASIC ANALYSIS.pdf
ManjuAppukuttan2
 
PPTX
Introduction to Malware Analysis
Andrew McNicol
 
PPT
assem.ppt
SonaliAjankar
 
PDF
PE102 - a Windows executable format overview (booklet V1)
Ange Albertini
 
PDF
Bypassing anti virus scanners
martacax
 
PDF
Bypassing anti virus scanners
martacax
 
PPTX
Malware Analysis Techniques &Incident Response.pptx
Gol D Roger
 
PPTX
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Sam Bowne
 
PPTX
Ch0 1
TylerDerdun
 
Reversing & malware analysis training part 3 windows pe file format basics
Abdulrahman Bassam
 
Binary art - Byte-ing the PE that fails you (extended offline version)
Ange Albertini
 
Intro reverse engineering
Nitin kumar Gupta
 
OS Internals and Portable Executable File Format
Aitezaz Mohsin
 
Revers engineering
AbdusSalam ALJBRI
 
Anatomy of A Shell Code, Reverse engineering
Abhineet Ayan
 
PE Packers Used in Malicious Software - Part 2
amiable_indian
 
Creating user-mode debuggers for Windows
Mithun Shanbhag
 
CHAPTER 2 BASIC ANALYSIS.ppt
ManjuAppukuttan2
 
Code Injection in Windows
n|u - The Open Security Community
 
CHAPTER 2 BASIC ANALYSIS.pdf
ManjuAppukuttan2
 
Introduction to Malware Analysis
Andrew McNicol
 
assem.ppt
SonaliAjankar
 
PE102 - a Windows executable format overview (booklet V1)
Ange Albertini
 
Bypassing anti virus scanners
martacax
 
Bypassing anti virus scanners
martacax
 
Malware Analysis Techniques &Incident Response.pptx
Gol D Roger
 
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
Sam Bowne
 
Ad

More from Cysinfo Cyber Security Community (20)

PDF
Understanding Malware Persistence Techniques by Monnappa K A
Cysinfo Cyber Security Community
 
PDF
Understanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
Cysinfo Cyber Security Community
 
PDF
Getting started with cybersecurity through CTFs by Shruti Dixit & Geethna TK
Cysinfo Cyber Security Community
 
PPTX
Emerging Trends in Cybersecurity by Amar Prusty
Cysinfo Cyber Security Community
 
PDF
A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
Cysinfo Cyber Security Community
 
PDF
Closer look at PHP Unserialization by Ashwin Shenoi
Cysinfo Cyber Security Community
 
PDF
Unicorn: The Ultimate CPU Emulator by Akshay Ajayan
Cysinfo Cyber Security Community
 
PDF
The Art of Executing JavaScript by Akhil Mahendra
Cysinfo Cyber Security Community
 
PDF
Reversing and Decrypting Malware Communications by Monnappa
Cysinfo Cyber Security Community
 
PPTX
DeViL - Detect Virtual Machine in Linux by Sreelakshmi
Cysinfo Cyber Security Community
 
PPTX
Analysis of android apk using adhrit by Abhishek J.M
Cysinfo Cyber Security Community
 
PDF
Understanding evasive hollow process injection techniques monnappa k a
Cysinfo Cyber Security Community
 
PPTX
Security challenges in d2d communication by ajithkumar vyasarao
Cysinfo Cyber Security Community
 
PPTX
S2 e (selective symbolic execution) -shivkrishna a
Cysinfo Cyber Security Community
 
PPTX
Dynamic binary analysis using angr siddharth muralee
Cysinfo Cyber Security Community
 
PPTX
Bit flipping attack on aes cbc - ashutosh ahelleya
Cysinfo Cyber Security Community
 
PDF
Security Analytics using ELK stack
Cysinfo Cyber Security Community
 
PDF
Linux Malware Analysis
Cysinfo Cyber Security Community
 
ODP
Introduction to Binary Exploitation
Cysinfo Cyber Security Community
 
PDF
ATM Malware: Understanding the threat
Cysinfo Cyber Security Community
 
Understanding Malware Persistence Techniques by Monnappa K A
Cysinfo Cyber Security Community
 
Understanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
Cysinfo Cyber Security Community
 
Getting started with cybersecurity through CTFs by Shruti Dixit & Geethna TK
Cysinfo Cyber Security Community
 
Emerging Trends in Cybersecurity by Amar Prusty
Cysinfo Cyber Security Community
 
A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
Cysinfo Cyber Security Community
 
Closer look at PHP Unserialization by Ashwin Shenoi
Cysinfo Cyber Security Community
 
Unicorn: The Ultimate CPU Emulator by Akshay Ajayan
Cysinfo Cyber Security Community
 
The Art of Executing JavaScript by Akhil Mahendra
Cysinfo Cyber Security Community
 
Reversing and Decrypting Malware Communications by Monnappa
Cysinfo Cyber Security Community
 
DeViL - Detect Virtual Machine in Linux by Sreelakshmi
Cysinfo Cyber Security Community
 
Analysis of android apk using adhrit by Abhishek J.M
Cysinfo Cyber Security Community
 
Understanding evasive hollow process injection techniques monnappa k a
Cysinfo Cyber Security Community
 
Security challenges in d2d communication by ajithkumar vyasarao
Cysinfo Cyber Security Community
 
S2 e (selective symbolic execution) -shivkrishna a
Cysinfo Cyber Security Community
 
Dynamic binary analysis using angr siddharth muralee
Cysinfo Cyber Security Community
 
Bit flipping attack on aes cbc - ashutosh ahelleya
Cysinfo Cyber Security Community
 
Security Analytics using ELK stack
Cysinfo Cyber Security Community
 
Linux Malware Analysis
Cysinfo Cyber Security Community
 
Introduction to Binary Exploitation
Cysinfo Cyber Security Community
 
ATM Malware: Understanding the threat
Cysinfo Cyber Security Community
 

Recently uploaded (20)

DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
July Patch Tuesday
Ivanti
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
July Patch Tuesday
Ivanti
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 

Reversing malware analysis training part3 windows pefile formatbasics

  • 2. Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions of any kind. Also the views/ideas/knowledge expressed here are solely of the trainer’s only and nothing to do with the company or the organization in which the trainer is currently working. However in no circumstances neither the trainer nor Cysinfo is responsible for any damage or loss caused due to use or misuse of the information presented here.
  • 3. Acknowledgement  Special thanks to null & Garage4Hackers community for their extended support and cooperation.  Thanks to all the trainers who have devoted their precious time and countless hours to make it happen.
  • 4. Reversing & Malware Analysis Training This presentation is part of our Reverse Engineering & Malware Analysis Training program. Currently it is delivered only during our local meet for FREE of cost.
  • 5. Who am I #1 Amit Malik (sometimes DouBle_Zer0,DZZ)  Member SecurityXploded & Garage4Hackers  Security Researcher  RE, Exploit Analysis/Development, Malware Analysis  Email: [email protected]
  • 6. Who am I #2 Swapnil Pathak  Member SecurityXploded  Security Researcher  RE, Malware Analysis, Network Security  Email: [email protected]
  • 7.  PE – Portable Executable  PE is the native Win32 file format.  32-bit DLL, COM, OCX, Control Panel Applets(.CPL), .NET, NT kernel mode drivers are all PE File Format.
  • 8.  How windows loader loads the executable in memory.  How loader build the import and export table for a module in memory  From where to start the execution or Address of entry point  Answer of the question “how binary compiled on a version of windows works on another version of windows?”  Where should attacker attack   Also today’s malwares are generally encrypted, packed. In order to rebuild the original binary we need to know how the binary is structured.
  • 10.  Most common sections found in executable are ◦ Executable Code section (.text , CODE) ◦ Data Sections (.data, .rdata, .bss, DATA) ◦ Resources section (.rsrc) ◦ Export Section (.edata) ◦ Import Section (.idata) ◦ Debug Information Section (.debug)
  • 11.  All PE files start with DOS header  First 64 bytes of the file.  Run program in DOS.  Runs the DOS stub  Usually the string “This program must be run under Microsoft Windows”  e_lfanew is the pointer to PE or NT header  Structure defined in windows.inc or winnt.h
  • 12. e_magic = 4D, 5A (MZ) e_lfanew is a DWORD which contains the offset of the PE header
  • 13.  Begins with signature (DWORD) 50h, 45h, 00h, 00h  Letters “PE” followed by two terminating zeros  File Header- 20 Bytes – contains info about physical layout and properties of the file  Optional Header- 224 Bytes – contains info about the logical layout of the PE file – size given by member of File header
  • 14.  Machine  NumberOfSections  SizeOfOptionalHeader  Characteristics
  • 16.  AddressOfEntryPoint  ImageBase  SectionAlignment  FileAlignment  SizeOfImage  SizeOfHeaders  Subsystem  DataDirectory
  • 17.  Last 128 bytes of OptionalHeader  Array of 16 Image_Data_Directory structures  Each relating to an important data structure like the Import Table  Members  Virtual Address : RVA of the data structure  iSize : size in bytes of the data structure
  • 19.  IMAGE_DIRECTORY_ENTRY_EXPORT  IMAGE_DIRECTORY_ENTRY_IMPORT  IMAGE_DIRECTORY_ENTRY_RESOURCE  IMAGE_DIRECTORY_ENTRY_TLS  IMAGE_DIRECTORY_ENTRY_IAT
  • 20.  Array of IMAGE_SECTION_HEADER  Equal to the numberofsections – FileHeader member.  Each structure size = 40 bytes
  • 21.  Name – Virtually can be anything in text  VirtualSize – Size of section in memory  VirtualAddress – section entry offset in memory (RVA)  SizeOfRawData – Size of section on disk  PointerToRawData – section entry offset on disk  Characteristics – Type of section (execuatble, data etc.)  Section Alignment and File Alignment are two important values from optional header that control the entry point of next section.
  • 22.  The structure of PE file on disk is exactly the same as when it is loaded into memory.  The windows loader maps the required sections in memory.  When sections are loaded into memory they are aligned to fit 4KB memory pages (Section Alignment), each section starting on a new page.
  • 23.  Executable code  Data  Resources  Export section  Import section  Thread Local Storage (TLS)  Base Relocations (reloc.)
  • 24.  Relevant to DLLs  Export functions in two ways - By name - By ordinal only  Ordinal – 16 bit value that uniquely defines a function in particular DLL
  • 26. Export by Ordinal only Export Forwarding
  • 27.  Contains information about all functions imported by executable from DLLs  Loader maps all the DLLs used by the application into its address space  Finds the addresses of all the imported functions and makes them available to the executable being loaded.
  • 28.  20 byte structure IMAGE_IMPORT_DESCRIPTOR  Number of structures = Number of DLLs imported  Last structure filed with zeros
  • 29.  OriginalFirstThunk  Name1  FirstThunk Hint Name1
  • 30.  Each IMAGE_THUNK_DATA str corresponds to one imported function from the dll.  Arrays pointed by OriginalFirstThunk and FirstThunk run parallelly.  OriginalFirstThunk – Import Name Table – Never modified  FirstThunk – Import Address Table – Contain actual function addresses
  • 31. Functions exported by ordinal only - No IMAGE_IMPORT_BY_NAME structure -IMAGE_THUNK_DATA contains the ordinal of the function -MSB used to identify the same - MSB is set, rest 31 bits are treated as an ordinal value. -Bound Imports
  • 33.  Write a program in “C” or “ASM” that will modify the Address of Entry point of an Executable (.exe) file with any random address.  Write a program in “C” or “ASM” that will add a new section into an executable (.exe) ◦ For hints shoot us an email 