SlideShare a Scribd company logo
Defcamp 0x7DB - Ionut “Nytro” Popescu - Formatul Portable Executable  ...................................................... http://www.rstcenter.com/forum/
Formatul Portable Executable
 
 
 
 
 
 
 
 
 
 
 
 
DLL Injection - Registry - SetWindowHookEx - CreateRemoteThread
Registry
HHOOK SetWindowsHookEx (  int  idHook , HOOKPROC  lpfn , HINSTANCE  hMod , DWORD  dwThreadId  ); WH_CALLWNDPROC Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more information, see the CallWndProc hook procedure. WH_CBT Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application. For more information, see the CBTProc hook procedure. WH_KEYBOARD Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure. SetWindowsHookEx
CreateRemoteThread HANDLE WINAPI CreateRemoteThread( __in HANDLE  hProcess ,  __in LPSECURITY_ATTRIBUTES  lpThreadAttributes ,  __in SIZE_T  dwStackSize , __in LPTHREAD_START_ROUTINE  lpStartAddress ,  __in LPVOID  lpParameter ,  __in DWORD  dwCreationFlags ,  __out LPDWORD  lpThreadId  );
API Hooking - Proxy DLL - SSDT (Service Symbol Dispatch Table) - Inline Hooking - IAT Patching
Exemplu API
Load PE File CopyMemory idh, abExeFile(0), Len(idh) If idh.e_magic <> IMAGE_DOS_SIGNATURE Then MsgBox &quot;MZ signature not found!&quot;, vbCritical, &quot;File load error&quot; Exit Sub End If CopyMemory inh, abExeFile(idh.e_lfanew), Len(inh) If inh.Signature <> IMAGE_NT_SIGNATURE Then MsgBox &quot;PE signature not found!&quot;, vbCritical, &quot;File load error&quot; Exit Sub End If si.cb = Len(si) If CreateProcess(vbNullString, fisier, 0, 0, False, CREATE_SUSPENDED, 0, 0, si, pi) = 0 Then Exit Sub context.ContextFlags = CONTEXT86_INTEGER If GetThreadContext(pi.hThread, context) = 0 Then GoTo ClearProcess Call ReadProcessMemory(pi.hProcess, ByVal context.Ebx + 8, addr, 4, 0) If addr = 0 Then GoTo ClearProcess If ZwUnmapViewOfSection(pi.hProcess, addr) Then GoTo ClearProcess ImageBase = VirtualAllocEx(pi.hProcess, ByVal inh.OptionalHeader.ImageBase, inh.OptionalHeader.SizeOfImage, MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE) If ImageBase = 0 Then GoTo ClearProcess Call WriteProcessMemory(pi.hProcess, ByVal ImageBase, abExeFile(0), inh.OptionalHeader.SizeOfHeaders, ret) lOffset = idh.e_lfanew + Len(inh) For i = 0 To inh.FileHeader.NumberOfSections - 1 CopyMemory ish, abExeFile(lOffset + i * Len(ish)), Len(ish) Call WriteProcessMemory(pi.hProcess, ByVal ImageBase + ish.VirtualAddress, abExeFile(ish.PointerToRawData), ish.SizeOfRawData, ret) Call VirtualProtectEx(pi.hProcess, ByVal ImageBase + ish.VirtualAddress, ish.VirtualSize, Protect(ish.characteristics), addr) Next i Call WriteProcessMemory(pi.hProcess, ByVal context.Ebx + 8, ImageBase, 4, ret) context.Eax = ImageBase + inh.OptionalHeader.AddressOfEntryPoint Call SetThreadContext(pi.hThread, context) Call ResumeThread(pi.hThread) Exit Sub

More Related Content

PDF
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
PDF
NYU hacknight, april 6, 2016
PDF
Sniffing Mach Messages
PPT
Unix Programming with Perl
PDF
Art of Web Backdoor - Pichaya Morimoto
PPTX
Using the Power to Prove
PDF
iOS Automation Primitives
PDF
Book
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
NYU hacknight, april 6, 2016
Sniffing Mach Messages
Unix Programming with Perl
Art of Web Backdoor - Pichaya Morimoto
Using the Power to Prove
iOS Automation Primitives
Book

What's hot (20)

PDF
Synack Shakacon OSX Malware Persistence
PDF
Codetainer: a Docker-based browser code 'sandbox'
PPT
Unix Programming with Perl 2
ODP
Mach-O Internals
PDF
DEF CON 23: 'DLL Hijacking' on OS X? #@%& Yeah!
PDF
PHP Secure Programming
PDF
PSR-7 and PSR-15, why can't you ignore them
PDF
Debugging: Rules & Tools
TXT
C99[2]
PDF
Node.js - iJS 2019
TXT
Simple php backdoor_by_dk
PDF
[2014 CodeEngn Conference 11] 정든품바 - 웹성코드
PDF
Django - Know Your Namespace: Middleware
KEY
Node.js - Best practices
PPTX
Introduction to puppet - Hands on Session at HPI Potsdam
PDF
LibreSSL
PDF
DLL Hijacking on OS X
PDF
ZeroNights: Automating iOS blackbox security scanning
PDF
Getting started with TDD - Confoo 2014
PPTX
Angular js security
Synack Shakacon OSX Malware Persistence
Codetainer: a Docker-based browser code 'sandbox'
Unix Programming with Perl 2
Mach-O Internals
DEF CON 23: 'DLL Hijacking' on OS X? #@%& Yeah!
PHP Secure Programming
PSR-7 and PSR-15, why can't you ignore them
Debugging: Rules & Tools
C99[2]
Node.js - iJS 2019
Simple php backdoor_by_dk
[2014 CodeEngn Conference 11] 정든품바 - 웹성코드
Django - Know Your Namespace: Middleware
Node.js - Best practices
Introduction to puppet - Hands on Session at HPI Potsdam
LibreSSL
DLL Hijacking on OS X
ZeroNights: Automating iOS blackbox security scanning
Getting started with TDD - Confoo 2014
Angular js security
Ad

Viewers also liked (7)

PPTX
Quick & Dirty Tips for x64 hooks
PDF
Userland Hooking in Windows
PPT
2006 03 15_pe & api hook
PDF
제12회 IT4U 강연회 - 악성코드 분석 잘하고 싶어요
PDF
악성코드 분석 도구
PDF
2.악성코드와 분석 방안
PDF
제12회 IT4U 강연회 - 화이트햇 해커들의 웹 해킹
Quick & Dirty Tips for x64 hooks
Userland Hooking in Windows
2006 03 15_pe & api hook
제12회 IT4U 강연회 - 악성코드 분석 잘하고 싶어요
악성코드 분석 도구
2.악성코드와 분석 방안
제12회 IT4U 강연회 - 화이트햇 해커들의 웹 해킹
Ad

Similar to Formatul Portable Executable (20)

PPTX
Code Injection in Windows
PDF
Arduino、Web 到 IoT
KEY
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
PDF
Sandboxie process isolation with kernel hooks
ODP
6. processes and threads
PDF
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
PDF
Ransomware for fun and non-profit
PPT
Backdoor coding
PPTX
44CON London 2015 - How to drive a malware analyst crazy
PPTX
How to drive a malware analyst crazy
PPT
Web application security
PDF
DEF CON 24 - Patrick Wardle - 99 problems little snitch
PDF
[DefCon 2016] I got 99 Problems, but 
Little Snitch ain’t one!
PPTX
Random numbers
PDF
Reutov, yunusov, nagibin random numbers take ii
PDF
Strategies to design FUD malware
ODP
Virtually Pwned
PDF
6.Web Servers
PPT
PHPUG Presentation
Code Injection in Windows
Arduino、Web 到 IoT
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Sandboxie process isolation with kernel hooks
6. processes and threads
"Revenge of The Script Kiddies: Current Day Uses of Automated Scripts by Top ...
Ransomware for fun and non-profit
Backdoor coding
44CON London 2015 - How to drive a malware analyst crazy
How to drive a malware analyst crazy
Web application security
DEF CON 24 - Patrick Wardle - 99 problems little snitch
[DefCon 2016] I got 99 Problems, but 
Little Snitch ain’t one!
Random numbers
Reutov, yunusov, nagibin random numbers take ii
Strategies to design FUD malware
Virtually Pwned
6.Web Servers
PHPUG Presentation

More from DefCamp (20)

PDF
Remote Yacht Hacking
PDF
Mobile, IoT, Clouds… It’s time to hire your own risk manager!
PPTX
The Charter of Trust
PPTX
Internet Balkanization: Why Are We Raising Borders Online?
PPTX
Bridging the gap between CyberSecurity R&D and UX
PPTX
Secure and privacy-preserving data transmission and processing using homomorp...
PPTX
Drupalgeddon 2 – Yet Another Weapon for the Attacker
PPTX
Economical Denial of Sustainability in the Cloud (EDOS)
PPTX
Trust, but verify – Bypassing MFA
PPTX
Threat Hunting: From Platitudes to Practical Application
PPTX
Building application security with 0 money down
PPTX
Implementation of information security techniques on modern android based Kio...
PPTX
Lattice based Merkle for post-quantum epoch
PPTX
The challenge of building a secure and safe digital environment in healthcare
PPTX
Timing attacks against web applications: Are they still practical?
PPTX
Tor .onions: The Good, The Rotten and The Misconfigured
PPTX
Needles, Haystacks and Algorithms: Using Machine Learning to detect complex t...
PPTX
We will charge you. How to [b]reach vendor’s network using EV charging station.
PPTX
Connect & Inspire Cyber Security
PPTX
The lions and the watering hole
Remote Yacht Hacking
Mobile, IoT, Clouds… It’s time to hire your own risk manager!
The Charter of Trust
Internet Balkanization: Why Are We Raising Borders Online?
Bridging the gap between CyberSecurity R&D and UX
Secure and privacy-preserving data transmission and processing using homomorp...
Drupalgeddon 2 – Yet Another Weapon for the Attacker
Economical Denial of Sustainability in the Cloud (EDOS)
Trust, but verify – Bypassing MFA
Threat Hunting: From Platitudes to Practical Application
Building application security with 0 money down
Implementation of information security techniques on modern android based Kio...
Lattice based Merkle for post-quantum epoch
The challenge of building a secure and safe digital environment in healthcare
Timing attacks against web applications: Are they still practical?
Tor .onions: The Good, The Rotten and The Misconfigured
Needles, Haystacks and Algorithms: Using Machine Learning to detect complex t...
We will charge you. How to [b]reach vendor’s network using EV charging station.
Connect & Inspire Cyber Security
The lions and the watering hole

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Spectroscopy.pptx food analysis technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectroscopy.pptx food analysis technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25 Week I
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
sap open course for s4hana steps from ECC to s4
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf

Formatul Portable Executable

  • 1. Defcamp 0x7DB - Ionut “Nytro” Popescu - Formatul Portable Executable ...................................................... http://www.rstcenter.com/forum/
  • 3.  
  • 4.  
  • 5.  
  • 6.  
  • 7.  
  • 8.  
  • 9.  
  • 10.  
  • 11.  
  • 12.  
  • 13.  
  • 14.  
  • 15. DLL Injection - Registry - SetWindowHookEx - CreateRemoteThread
  • 17. HHOOK SetWindowsHookEx ( int idHook , HOOKPROC lpfn , HINSTANCE hMod , DWORD dwThreadId ); WH_CALLWNDPROC Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more information, see the CallWndProc hook procedure. WH_CBT Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application. For more information, see the CBTProc hook procedure. WH_KEYBOARD Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure. SetWindowsHookEx
  • 18. CreateRemoteThread HANDLE WINAPI CreateRemoteThread( __in HANDLE hProcess , __in LPSECURITY_ATTRIBUTES lpThreadAttributes , __in SIZE_T dwStackSize , __in LPTHREAD_START_ROUTINE lpStartAddress , __in LPVOID lpParameter , __in DWORD dwCreationFlags , __out LPDWORD lpThreadId );
  • 19. API Hooking - Proxy DLL - SSDT (Service Symbol Dispatch Table) - Inline Hooking - IAT Patching
  • 21. Load PE File CopyMemory idh, abExeFile(0), Len(idh) If idh.e_magic <> IMAGE_DOS_SIGNATURE Then MsgBox &quot;MZ signature not found!&quot;, vbCritical, &quot;File load error&quot; Exit Sub End If CopyMemory inh, abExeFile(idh.e_lfanew), Len(inh) If inh.Signature <> IMAGE_NT_SIGNATURE Then MsgBox &quot;PE signature not found!&quot;, vbCritical, &quot;File load error&quot; Exit Sub End If si.cb = Len(si) If CreateProcess(vbNullString, fisier, 0, 0, False, CREATE_SUSPENDED, 0, 0, si, pi) = 0 Then Exit Sub context.ContextFlags = CONTEXT86_INTEGER If GetThreadContext(pi.hThread, context) = 0 Then GoTo ClearProcess Call ReadProcessMemory(pi.hProcess, ByVal context.Ebx + 8, addr, 4, 0) If addr = 0 Then GoTo ClearProcess If ZwUnmapViewOfSection(pi.hProcess, addr) Then GoTo ClearProcess ImageBase = VirtualAllocEx(pi.hProcess, ByVal inh.OptionalHeader.ImageBase, inh.OptionalHeader.SizeOfImage, MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE) If ImageBase = 0 Then GoTo ClearProcess Call WriteProcessMemory(pi.hProcess, ByVal ImageBase, abExeFile(0), inh.OptionalHeader.SizeOfHeaders, ret) lOffset = idh.e_lfanew + Len(inh) For i = 0 To inh.FileHeader.NumberOfSections - 1 CopyMemory ish, abExeFile(lOffset + i * Len(ish)), Len(ish) Call WriteProcessMemory(pi.hProcess, ByVal ImageBase + ish.VirtualAddress, abExeFile(ish.PointerToRawData), ish.SizeOfRawData, ret) Call VirtualProtectEx(pi.hProcess, ByVal ImageBase + ish.VirtualAddress, ish.VirtualSize, Protect(ish.characteristics), addr) Next i Call WriteProcessMemory(pi.hProcess, ByVal context.Ebx + 8, ImageBase, 4, ret) context.Eax = ImageBase + inh.OptionalHeader.AddressOfEntryPoint Call SetThreadContext(pi.hThread, context) Call ResumeThread(pi.hThread) Exit Sub