SlideShare a Scribd company logo
 www.harmonysecurity.com
 info@harmonysecurity.com




                             Reflective DLL Injection
                                                      v1.0




                                     By Stephen Fewer
                                          31st October 2008
Contents

Disclaimer......................................................................................................................................2
Introduction...................................................................................................................................3
Overview........................................................................................................................................4
Implementation.............................................................................................................................5
Detection........................................................................................................................................6
References.....................................................................................................................................7




Disclaimer
The information in this paper is believed to be accurate at the time of publishing based on
currently available information. Use of the information constitutes acceptance for use in
an AS IS condition. There are no warranties, implied or express, with regard to this
information. In no event shall the author be liable for any direct or indirect damages
whatsoever arising out of or in connection with the use or spread of this information. Any
use of this information is at the reader's own risk.
Introduction
Under the Windows platform, library injection techniques both local and remote have
been around for many years. Remote library injection as an exploitation technique was
introduced in 2004 by Skape and JT[1]. Their technique employs shellcode to patch the
host processes ntdll library at run time and forces the native Windows loader to load a
Dynamic Link Library (DLL) image from memory. As an alternative to this technique I
present Reflective DLL Injection.

Reflective DLL injection is a library injection technique in which the concept of
reflective programming is employed to perform the loading of a library from memory
into a host process. As such the library is responsible for loading itself by implementing a
minimal Portable Executable (PE) file loader. It can then govern, with minimal
interaction with the host system and process, how it will load and interact with the host.
Previous work in the security field of building PE file loaders include the bo2k server by
DilDog[2].

The main advantage of the library loading itself is that it is not registered in any way with
the host system and as a result is largely undetectable at both a system and process level.
When employed as an exploitation technique, Reflective DLL Injection requires a
minimal amount of shellcode, further reducing its detection footprint against host and
network based intrusion detection and prevention systems.
Overview
The process of remotely injecting a library into a process is two fold. Firstly, the library
you wish to inject must be written into the address space of the target process (Herein
referred to as the host process). Secondly the library must be loaded into that host process
in such a way that the library's run time expectations are met, such as resolving its
imports or relocating it to a suitable location in memory. For any of these steps to occur
you should have some form of code execution in the host process, presumably obtained
through exploitation of a remote code execution vulnerability.

Assuming we have code execution in the host process and the library we wish to inject
has been written into an arbitrary location of memory in the host process, (for example
via a first stage shellcode), Reflective DLL Injection works as follows.

   ●   Execution is passed, via a tiny bootstrap shellcode, to the library's
       ReflectiveLoader function which is an exported function found in the library's
       export table.

   ●   As the library's image will currently exists in an arbitrary location in memory the
       ReflectiveLoader will first calculate its own image's current location in memory
       so as to be able to parse its own headers for use later on.

   ●   The ReflectiveLoader will then parse the host processes kernels export table in
       order to calculate the addresses of three functions required by the loader, namely
       LoadLibraryA, GetProcAddress and VirtualAlloc.

   ●   The ReflectiveLoader will now allocate a continuous region of memory into
       which it will proceed to load its own image. The location is not important as the
       loader will correctly relocate the image later on.

   ●   The library's headers and sections are loaded into their new locations in memory.

   ●   The ReflectiveLoader will then process the newly loaded copy of its image's
       import table, loading any additional library's and resolving their respective
       imported function addresses.

   ●   The ReflectiveLoader will then process the newly loaded copy of its image's
       relocation table.

   ●   The ReflectiveLoader will then call its newly loaded image's entry point function,
       DllMain with DLL_PROCESS_ATTACH. The library has now been successfully
       loaded into memory.

   ●   Finally the ReflectiveLoader will return execution to the initial bootstrap
       shellcode which called it.
Implementation
A skeleton Reflective DLL project for building library's for use with Reflective DLL
Injection is available under the three clause BSD license[7]. Support for Reflective DLL
Injection has also been added to Metasploit[6] in the form of a payload stage and a
modified VNC DLL.

The ReflectiveLoader itself is implemented in position independent C code with a
minimal amount of inlined assembler. The ReflectiveLoader code has been heavily
commented and for a thorough understanding you should read through this code. A good
understanding of the PE file format[3] is recommended when reading through the source
code. Matt Pietrek has written a number of good articles detailing the PE file format[4]
[5] which are also recommended reading.

Under Metasploit, the Ruby module Payload::Windows::ReflectiveDllInject implements
a new stage for injecting a DLL which contains a ReflectiveLoader. This stage will
calculate the offset to the library's exported ReflectiveLoader function and proceed to
generate a small bootstrap shellcode, as show below in Listing 1, which is patched into
the DLL images MZ header. This allows execution to be passed to the ReflectiveLoader
after the Metasploit intermediate stager loads the entire library into the host process.

     dec ebp             ; M
     pop edx             ; Z
     call 0              ; call next instruction
     pop ebx             ; get our location (+7)
     push edx            ; push edx back
     inc ebp             ; restore ebp
     push ebp            ; save ebp
     mov ebp, esp        ; setup fresh stack frame
     add ebx, 0x???????? ; add offset to ReflectiveLoader
     call ebx            ; call ReflectiveLoader
     mov ebx, eax        ; save DllMain for second call
     push edi            ; our socket
     push 0x4            ; signal we have attached
     push eax            ; some value for hinstance
     call eax            ; call DllMain( somevalue,
     DLL_METASPLOIT_ATTACH, socket )
     push 0x????????     ; our EXITFUNC placeholder
     push 0x5            ; signal we have detached
     push eax            ; some value for hinstance
     call ebx            ; call DllMain( somevalue,
     DLL_METASPLOIT_DETACH, exitfunk )
                         ; we only return if we don't set a valid
     EXITFUNC
     Listing 1: Bootstrap Shellcode.

The bootstrap shellcode also lets us attach Metasploit by passing in the payloads socket
and finally the payloads exit function via calls to DllMain for compatibility with the
Metasploit payload system.
Detection
Successfully detecting a DLL that has been loaded into a host process through Reflective
DLL Injection will be difficult. Previous methods of detecting injected libraries will be
largely obsolete, such as inspecting a process's currently loaded library's for irregularities
or detecting hooked library functions.

As a reflectively loaded library will not be registered in the host processes list of loaded
modules, specifically the list held in the Process Environment Block (PEB) which is
modified during API calls such as kernel32's LoadLibrary and LoadLibraryEx, any
attempt to enumerate the host processes modules will not yield the injected library. This
is because the injected library's ReflectiveLoader does not register itself with its host
process at any stage.

Similarly, detecting hooked library functions is redundant as no library functions are
required to be hooked for the ReflectiveLoader to work.

At a process level the only indicators that the library exists is that their will be a chunk of
allocated memory present, via VirtualAlloc, where the loaded library resides. This
memory will be marked as readable, writable and executable. Their will also be a thread
of execution which will be, periodically at least, executing code from this memory chunk.

By periodically scanning all threads of execution and cross referencing the legitimately
loaded libraries in the process with a call trace of each thread it may be possible to
identify unusual locations of code. This will inevitably lead to many false positives as
there are many reasons to execute code in a location of memory other then a library's
code sections. Examples of this are packed or protected executables and languages that
use techniques like just in time (JIT) compilation, such as Java or .NET.

At a system level when using Reflective DLL Injection in remote exploitation, the library
should be undetectable by file scanners, such as Anti Virus, as it never touches disk. This
leaves the main detection surface being the network, although many IDS evasion
techniques are available[8] to aid circumventing detection such as polymorphic
shellcode.
References

[1] Skape and JT, Remote Library Injection
http://www.nologin.org/Downloads/Papers/remote-library-injection.pdf

[2] DilDog, Back Orifice 2000
http://sourceforge.net/projects/bo2k/

[3] Microsoft, Microsoft Portable Executable and Common Object File Format
Specification
http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx

[4] Matt Pietrek, An In-Depth Look into the Win32 Portable Executable File Format
http://msdn.microsoft.com/en-gb/magazine/cc301805.aspx

[5] Matt Pietrek, Peering Inside the PE: A Tour of the Win32 Portable Executable File
Format
http://msdn.microsoft.com/en-gb/magazine/ms809762.aspx

[6] Metasploit LLC, Metasploit
http://www.metasploit.com

[7] Stephen Fewer, Reflective Dll Injection
http://www.harmonysecurity.com/ReflectiveDllInjection.html

[8] Kevin Tim, IDS Evasion Techniques and Tactics
http://www.securityfocus.com/infocus/1577




                                         Harmony Security provides computer and network security research and
                                         consultancy. We are focused on delivering new ideas and solutions to this field.
                                         Areas of concern include network and system vulnerabilities, malware and
                                         cryptography.


                                         Copyright © 2008 Harmony Security

More Related Content

What's hot

Next Stop, Android
Next Stop, AndroidNext Stop, Android
Next Stop, Android
National Cheng Kung University
 
Security Applications For Emulation
Security Applications For EmulationSecurity Applications For Emulation
Security Applications For EmulationSilvio Cesare
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friend
Alexandre Moneger
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
Temesgen Molla
 
Loader and Its types
Loader and Its typesLoader and Its types
Loader and Its types
Parth Dodiya
 
What is-java
What is-javaWhat is-java
What is-java
Shahid Rasheed
 
Something About Dynamic Linking
Something About Dynamic LinkingSomething About Dynamic Linking
Something About Dynamic Linking
Wang Hsiangkai
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
Riccardo Cardin
 
Java se7 features
Java se7 featuresJava se7 features
Java se7 features
Kumaraswamy M
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
Chun-Yu Wang
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loadersTech_MX
 
C programming session 14
C programming session 14C programming session 14
C programming session 14Vivek Singh
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkers
kunj desai
 
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
MindShare_kk
 
Efficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ serverEfficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ serverShuo Chen
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
Ron Munitz
 
Java vs .net
Java vs .netJava vs .net
Java vs .netTech_MX
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthingtonoscon2007
 

What's hot (20)

Next Stop, Android
Next Stop, AndroidNext Stop, Android
Next Stop, Android
 
Security Applications For Emulation
Security Applications For EmulationSecurity Applications For Emulation
Security Applications For Emulation
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friend
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Loader and Its types
Loader and Its typesLoader and Its types
Loader and Its types
 
What is-java
What is-javaWhat is-java
What is-java
 
Something About Dynamic Linking
Something About Dynamic LinkingSomething About Dynamic Linking
Something About Dynamic Linking
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
 
Java se7 features
Java se7 featuresJava se7 features
Java se7 features
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
C programming session 14
C programming session 14C programming session 14
C programming session 14
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkers
 
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
 
Efficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ serverEfficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ server
 
Loaders
LoadersLoaders
Loaders
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
 
Java vs .net
Java vs .netJava vs .net
Java vs .net
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 

Viewers also liked

Owned By An iPod
Owned By An iPodOwned By An iPod
Owned By An iPodKarlFrank99
 
Chroł I Dziadosz
Chroł I DziadoszChroł I Dziadosz
Chroł I Dziadoszguestd35c8d
 
Presentation
PresentationPresentation
Presentationrapbhan
 
1st Year of Creative Commons Hong Kong @ BarCamp HK 09
1st Year of Creative Commons Hong Kong @ BarCamp HK 091st Year of Creative Commons Hong Kong @ BarCamp HK 09
1st Year of Creative Commons Hong Kong @ BarCamp HK 09Haggen So
 
My Hometown
My HometownMy Hometown
My Hometown
IEmichael0
 
Atomic Bomb Tutorial En
Atomic Bomb Tutorial EnAtomic Bomb Tutorial En
Atomic Bomb Tutorial EnKarlFrank99
 
Succesvol Werven 120309
Succesvol Werven 120309Succesvol Werven 120309
Succesvol Werven 120309
Marc de Vries
 
Instant Words 1 16
Instant Words 1 16Instant Words 1 16
Instant Words 1 164stars
 
Hack
HackHack
Hack
Haggen So
 
Gemeente enschede 250610
Gemeente enschede 250610Gemeente enschede 250610
Gemeente enschede 250610
Marc de Vries
 
96/8/24全人教育營隊-鐵馬環島PPT
96/8/24全人教育營隊-鐵馬環島PPT96/8/24全人教育營隊-鐵馬環島PPT
96/8/24全人教育營隊-鐵馬環島PPTyichihchung
 
Mimar Sinan
Mimar SinanMimar Sinan
Mimar Sinanmdkuru
 
The Liberated Customer is Good for Business
The Liberated Customer is Good for BusinessThe Liberated Customer is Good for Business
The Liberated Customer is Good for BusinessDoc Searls
 
Bloggers Twitteraars Meet Hyves
Bloggers Twitteraars Meet HyvesBloggers Twitteraars Meet Hyves
Bloggers Twitteraars Meet Hyves
Marc de Vries
 
走出技術自主路:自由軟件開源軟件掂唔掂?
走出技術自主路:自由軟件開源軟件掂唔掂?走出技術自主路:自由軟件開源軟件掂唔掂?
走出技術自主路:自由軟件開源軟件掂唔掂?
Haggen So
 
Le mini-guide di ARGON:Le animazioni
Le mini-guide di ARGON:Le animazioniLe mini-guide di ARGON:Le animazioni
Le mini-guide di ARGON:Le animazioni
ARGON
 

Viewers also liked (20)

Owned By An iPod
Owned By An iPodOwned By An iPod
Owned By An iPod
 
Dsohowto
DsohowtoDsohowto
Dsohowto
 
Buzzzzzstory
BuzzzzzstoryBuzzzzzstory
Buzzzzzstory
 
Chroł I Dziadosz
Chroł I DziadoszChroł I Dziadosz
Chroł I Dziadosz
 
Spl Ragnhild Og Rm
Spl Ragnhild Og RmSpl Ragnhild Og Rm
Spl Ragnhild Og Rm
 
Presentation
PresentationPresentation
Presentation
 
1st Year of Creative Commons Hong Kong @ BarCamp HK 09
1st Year of Creative Commons Hong Kong @ BarCamp HK 091st Year of Creative Commons Hong Kong @ BarCamp HK 09
1st Year of Creative Commons Hong Kong @ BarCamp HK 09
 
My Hometown
My HometownMy Hometown
My Hometown
 
10602
1060210602
10602
 
Atomic Bomb Tutorial En
Atomic Bomb Tutorial EnAtomic Bomb Tutorial En
Atomic Bomb Tutorial En
 
Succesvol Werven 120309
Succesvol Werven 120309Succesvol Werven 120309
Succesvol Werven 120309
 
Instant Words 1 16
Instant Words 1 16Instant Words 1 16
Instant Words 1 16
 
Hack
HackHack
Hack
 
Gemeente enschede 250610
Gemeente enschede 250610Gemeente enschede 250610
Gemeente enschede 250610
 
96/8/24全人教育營隊-鐵馬環島PPT
96/8/24全人教育營隊-鐵馬環島PPT96/8/24全人教育營隊-鐵馬環島PPT
96/8/24全人教育營隊-鐵馬環島PPT
 
Mimar Sinan
Mimar SinanMimar Sinan
Mimar Sinan
 
The Liberated Customer is Good for Business
The Liberated Customer is Good for BusinessThe Liberated Customer is Good for Business
The Liberated Customer is Good for Business
 
Bloggers Twitteraars Meet Hyves
Bloggers Twitteraars Meet HyvesBloggers Twitteraars Meet Hyves
Bloggers Twitteraars Meet Hyves
 
走出技術自主路:自由軟件開源軟件掂唔掂?
走出技術自主路:自由軟件開源軟件掂唔掂?走出技術自主路:自由軟件開源軟件掂唔掂?
走出技術自主路:自由軟件開源軟件掂唔掂?
 
Le mini-guide di ARGON:Le animazioni
Le mini-guide di ARGON:Le animazioniLe mini-guide di ARGON:Le animazioni
Le mini-guide di ARGON:Le animazioni
 

Similar to Hs P005 Reflective Dll Injection

Malicious pdf Exploit Unravelled
Malicious pdf Exploit UnravelledMalicious pdf Exploit Unravelled
Malicious pdf Exploit Unravelled
Nitin Ramesh
 
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Vincenzo Iozzo
 
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
Moabi.com
 
Os7 2
Os7 2Os7 2
Os7 2issbp
 
Containerization and Docker
Containerization and DockerContainerization and Docker
Containerization and Docker
Megha Bansal
 
Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
Gonçalo Gomes
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building Blocks
Max Kleiner
 
Hack the whale
Hack the whaleHack the whale
Hack the whale
Marco Ferrigno
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploitshughpearse
 
Livecode widget course
Livecode widget courseLivecode widget course
Livecode widget course
crazyaxe
 
DLL Injection
DLL InjectionDLL Injection
DLL Injection
Hossein Yavari
 
olibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linuxolibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linux
National Cheng Kung University
 
Linux Container Technology inside Docker with RHEL7
Linux Container Technology inside Docker with RHEL7Linux Container Technology inside Docker with RHEL7
Linux Container Technology inside Docker with RHEL7Etsuji Nakai
 
DLL Tutor maXbox starter28
DLL Tutor maXbox starter28DLL Tutor maXbox starter28
DLL Tutor maXbox starter28
Max Kleiner
 
Let your Mach-O fly, Black Hat DC 2009
Let your Mach-O fly, Black Hat DC 2009Let your Mach-O fly, Black Hat DC 2009
Let your Mach-O fly, Black Hat DC 2009
Vincenzo Iozzo
 
Failure Of DEP And ASLR
Failure Of DEP And ASLRFailure Of DEP And ASLR
Failure Of DEP And ASLR
n|u - The Open Security Community
 
Openshift meetup Paris - 21/03/2018
Openshift meetup Paris - 21/03/2018Openshift meetup Paris - 21/03/2018
Openshift meetup Paris - 21/03/2018
kanedafromparis
 
Ippevent : openshift Introduction
Ippevent : openshift IntroductionIppevent : openshift Introduction
Ippevent : openshift Introduction
kanedafromparis
 
Docker Security
Docker SecurityDocker Security
Docker Security
BladE0341
 

Similar to Hs P005 Reflective Dll Injection (20)

Malicious pdf Exploit Unravelled
Malicious pdf Exploit UnravelledMalicious pdf Exploit Unravelled
Malicious pdf Exploit Unravelled
 
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
 
Eusecwest
EusecwestEusecwest
Eusecwest
 
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
 
Os7 2
Os7 2Os7 2
Os7 2
 
Containerization and Docker
Containerization and DockerContainerization and Docker
Containerization and Docker
 
Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building Blocks
 
Hack the whale
Hack the whaleHack the whale
Hack the whale
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
 
Livecode widget course
Livecode widget courseLivecode widget course
Livecode widget course
 
DLL Injection
DLL InjectionDLL Injection
DLL Injection
 
olibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linuxolibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linux
 
Linux Container Technology inside Docker with RHEL7
Linux Container Technology inside Docker with RHEL7Linux Container Technology inside Docker with RHEL7
Linux Container Technology inside Docker with RHEL7
 
DLL Tutor maXbox starter28
DLL Tutor maXbox starter28DLL Tutor maXbox starter28
DLL Tutor maXbox starter28
 
Let your Mach-O fly, Black Hat DC 2009
Let your Mach-O fly, Black Hat DC 2009Let your Mach-O fly, Black Hat DC 2009
Let your Mach-O fly, Black Hat DC 2009
 
Failure Of DEP And ASLR
Failure Of DEP And ASLRFailure Of DEP And ASLR
Failure Of DEP And ASLR
 
Openshift meetup Paris - 21/03/2018
Openshift meetup Paris - 21/03/2018Openshift meetup Paris - 21/03/2018
Openshift meetup Paris - 21/03/2018
 
Ippevent : openshift Introduction
Ippevent : openshift IntroductionIppevent : openshift Introduction
Ippevent : openshift Introduction
 
Docker Security
Docker SecurityDocker Security
Docker Security
 

More from KarlFrank99

Sandboxie process isolation with kernel hooks
Sandboxie process isolation with kernel hooksSandboxie process isolation with kernel hooks
Sandboxie process isolation with kernel hooks
KarlFrank99
 
Comodo q1 2018
Comodo q1 2018Comodo q1 2018
Comodo q1 2018
KarlFrank99
 
Double agent zero-day code injection and persistence technique
Double agent  zero-day code injection and persistence techniqueDouble agent  zero-day code injection and persistence technique
Double agent zero-day code injection and persistence technique
KarlFrank99
 
Process Doppelgänging
Process Doppelgänging Process Doppelgänging
Process Doppelgänging
KarlFrank99
 
Osteoblast-Osteoclast Interactions
Osteoblast-Osteoclast InteractionsOsteoblast-Osteoclast Interactions
Osteoblast-Osteoclast Interactions
KarlFrank99
 
Role of autophagy in tumor necrosis factor-α- induced apoptosis of osteoblast...
Role of autophagy in tumor necrosis factor-α- induced apoptosis of osteoblast...Role of autophagy in tumor necrosis factor-α- induced apoptosis of osteoblast...
Role of autophagy in tumor necrosis factor-α- induced apoptosis of osteoblast...
KarlFrank99
 
Osteoblast and Osteoclast Crosstalks: From OAF to Ephrin
Osteoblast and Osteoclast Crosstalks: From OAF to EphrinOsteoblast and Osteoclast Crosstalks: From OAF to Ephrin
Osteoblast and Osteoclast Crosstalks: From OAF to Ephrin
KarlFrank99
 
The Tight Relationship Between Osteoclasts and the Immune System
The Tight Relationship Between Osteoclasts and the Immune SystemThe Tight Relationship Between Osteoclasts and the Immune System
The Tight Relationship Between Osteoclasts and the Immune System
KarlFrank99
 
No association between circulating concentrations of vitamin D and risk of lu...
No association between circulating concentrations of vitamin D and risk of lu...No association between circulating concentrations of vitamin D and risk of lu...
No association between circulating concentrations of vitamin D and risk of lu...
KarlFrank99
 
20180426_EcbMeeting_DiffStatement
20180426_EcbMeeting_DiffStatement20180426_EcbMeeting_DiffStatement
20180426_EcbMeeting_DiffStatement
KarlFrank99
 
20180420__DanskeResearch_ECBPreview
20180420__DanskeResearch_ECBPreview20180420__DanskeResearch_ECBPreview
20180420__DanskeResearch_ECBPreview
KarlFrank99
 
20180420__DanskeResearcch_WeeklyFocus
20180420__DanskeResearcch_WeeklyFocus20180420__DanskeResearcch_WeeklyFocus
20180420__DanskeResearcch_WeeklyFocus
KarlFrank99
 
20180417_DanskeResearch_FX_Forecast_Update
20180417_DanskeResearch_FX_Forecast_Update20180417_DanskeResearch_FX_Forecast_Update
20180417_DanskeResearch_FX_Forecast_Update
KarlFrank99
 
20180418_NordeaResearch_EAInfl_n_ECB
20180418_NordeaResearch_EAInfl_n_ECB20180418_NordeaResearch_EAInfl_n_ECB
20180418_NordeaResearch_EAInfl_n_ECB
KarlFrank99
 
NordeaResearch_EcbWatch_20180423
NordeaResearch_EcbWatch_20180423NordeaResearch_EcbWatch_20180423
NordeaResearch_EcbWatch_20180423
KarlFrank99
 
20170426_CommerzbankResearch__BullionWeeklyTechnicals
20170426_CommerzbankResearch__BullionWeeklyTechnicals20170426_CommerzbankResearch__BullionWeeklyTechnicals
20170426_CommerzbankResearch__BullionWeeklyTechnicals
KarlFrank99
 
Bh Usa 07 Butler And Kendall
Bh Usa 07 Butler And KendallBh Usa 07 Butler And Kendall
Bh Usa 07 Butler And KendallKarlFrank99
 
Vistaceic2007 from CEIC 2007
Vistaceic2007 from CEIC 2007Vistaceic2007 from CEIC 2007
Vistaceic2007 from CEIC 2007
KarlFrank99
 

More from KarlFrank99 (20)

Sandboxie process isolation with kernel hooks
Sandboxie process isolation with kernel hooksSandboxie process isolation with kernel hooks
Sandboxie process isolation with kernel hooks
 
Comodo q1 2018
Comodo q1 2018Comodo q1 2018
Comodo q1 2018
 
Double agent zero-day code injection and persistence technique
Double agent  zero-day code injection and persistence techniqueDouble agent  zero-day code injection and persistence technique
Double agent zero-day code injection and persistence technique
 
Process Doppelgänging
Process Doppelgänging Process Doppelgänging
Process Doppelgänging
 
Osteoblast-Osteoclast Interactions
Osteoblast-Osteoclast InteractionsOsteoblast-Osteoclast Interactions
Osteoblast-Osteoclast Interactions
 
Role of autophagy in tumor necrosis factor-α- induced apoptosis of osteoblast...
Role of autophagy in tumor necrosis factor-α- induced apoptosis of osteoblast...Role of autophagy in tumor necrosis factor-α- induced apoptosis of osteoblast...
Role of autophagy in tumor necrosis factor-α- induced apoptosis of osteoblast...
 
Osteoblast and Osteoclast Crosstalks: From OAF to Ephrin
Osteoblast and Osteoclast Crosstalks: From OAF to EphrinOsteoblast and Osteoclast Crosstalks: From OAF to Ephrin
Osteoblast and Osteoclast Crosstalks: From OAF to Ephrin
 
The Tight Relationship Between Osteoclasts and the Immune System
The Tight Relationship Between Osteoclasts and the Immune SystemThe Tight Relationship Between Osteoclasts and the Immune System
The Tight Relationship Between Osteoclasts and the Immune System
 
No association between circulating concentrations of vitamin D and risk of lu...
No association between circulating concentrations of vitamin D and risk of lu...No association between circulating concentrations of vitamin D and risk of lu...
No association between circulating concentrations of vitamin D and risk of lu...
 
20180426_EcbMeeting_DiffStatement
20180426_EcbMeeting_DiffStatement20180426_EcbMeeting_DiffStatement
20180426_EcbMeeting_DiffStatement
 
20180420__DanskeResearch_ECBPreview
20180420__DanskeResearch_ECBPreview20180420__DanskeResearch_ECBPreview
20180420__DanskeResearch_ECBPreview
 
20180420__DanskeResearcch_WeeklyFocus
20180420__DanskeResearcch_WeeklyFocus20180420__DanskeResearcch_WeeklyFocus
20180420__DanskeResearcch_WeeklyFocus
 
20180417_DanskeResearch_FX_Forecast_Update
20180417_DanskeResearch_FX_Forecast_Update20180417_DanskeResearch_FX_Forecast_Update
20180417_DanskeResearch_FX_Forecast_Update
 
20180418_NordeaResearch_EAInfl_n_ECB
20180418_NordeaResearch_EAInfl_n_ECB20180418_NordeaResearch_EAInfl_n_ECB
20180418_NordeaResearch_EAInfl_n_ECB
 
NordeaResearch_EcbWatch_20180423
NordeaResearch_EcbWatch_20180423NordeaResearch_EcbWatch_20180423
NordeaResearch_EcbWatch_20180423
 
20170426_CommerzbankResearch__BullionWeeklyTechnicals
20170426_CommerzbankResearch__BullionWeeklyTechnicals20170426_CommerzbankResearch__BullionWeeklyTechnicals
20170426_CommerzbankResearch__BullionWeeklyTechnicals
 
Tesi Laurea
Tesi LaureaTesi Laurea
Tesi Laurea
 
Bh Usa 07 Butler And Kendall
Bh Usa 07 Butler And KendallBh Usa 07 Butler And Kendall
Bh Usa 07 Butler And Kendall
 
Dll injection
Dll injectionDll injection
Dll injection
 
Vistaceic2007 from CEIC 2007
Vistaceic2007 from CEIC 2007Vistaceic2007 from CEIC 2007
Vistaceic2007 from CEIC 2007
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 

Hs P005 Reflective Dll Injection

  • 1.  www.harmonysecurity.com  info@harmonysecurity.com Reflective DLL Injection v1.0 By Stephen Fewer 31st October 2008
  • 2. Contents Disclaimer......................................................................................................................................2 Introduction...................................................................................................................................3 Overview........................................................................................................................................4 Implementation.............................................................................................................................5 Detection........................................................................................................................................6 References.....................................................................................................................................7 Disclaimer The information in this paper is believed to be accurate at the time of publishing based on currently available information. Use of the information constitutes acceptance for use in an AS IS condition. There are no warranties, implied or express, with regard to this information. In no event shall the author be liable for any direct or indirect damages whatsoever arising out of or in connection with the use or spread of this information. Any use of this information is at the reader's own risk.
  • 3. Introduction Under the Windows platform, library injection techniques both local and remote have been around for many years. Remote library injection as an exploitation technique was introduced in 2004 by Skape and JT[1]. Their technique employs shellcode to patch the host processes ntdll library at run time and forces the native Windows loader to load a Dynamic Link Library (DLL) image from memory. As an alternative to this technique I present Reflective DLL Injection. Reflective DLL injection is a library injection technique in which the concept of reflective programming is employed to perform the loading of a library from memory into a host process. As such the library is responsible for loading itself by implementing a minimal Portable Executable (PE) file loader. It can then govern, with minimal interaction with the host system and process, how it will load and interact with the host. Previous work in the security field of building PE file loaders include the bo2k server by DilDog[2]. The main advantage of the library loading itself is that it is not registered in any way with the host system and as a result is largely undetectable at both a system and process level. When employed as an exploitation technique, Reflective DLL Injection requires a minimal amount of shellcode, further reducing its detection footprint against host and network based intrusion detection and prevention systems.
  • 4. Overview The process of remotely injecting a library into a process is two fold. Firstly, the library you wish to inject must be written into the address space of the target process (Herein referred to as the host process). Secondly the library must be loaded into that host process in such a way that the library's run time expectations are met, such as resolving its imports or relocating it to a suitable location in memory. For any of these steps to occur you should have some form of code execution in the host process, presumably obtained through exploitation of a remote code execution vulnerability. Assuming we have code execution in the host process and the library we wish to inject has been written into an arbitrary location of memory in the host process, (for example via a first stage shellcode), Reflective DLL Injection works as follows. ● Execution is passed, via a tiny bootstrap shellcode, to the library's ReflectiveLoader function which is an exported function found in the library's export table. ● As the library's image will currently exists in an arbitrary location in memory the ReflectiveLoader will first calculate its own image's current location in memory so as to be able to parse its own headers for use later on. ● The ReflectiveLoader will then parse the host processes kernels export table in order to calculate the addresses of three functions required by the loader, namely LoadLibraryA, GetProcAddress and VirtualAlloc. ● The ReflectiveLoader will now allocate a continuous region of memory into which it will proceed to load its own image. The location is not important as the loader will correctly relocate the image later on. ● The library's headers and sections are loaded into their new locations in memory. ● The ReflectiveLoader will then process the newly loaded copy of its image's import table, loading any additional library's and resolving their respective imported function addresses. ● The ReflectiveLoader will then process the newly loaded copy of its image's relocation table. ● The ReflectiveLoader will then call its newly loaded image's entry point function, DllMain with DLL_PROCESS_ATTACH. The library has now been successfully loaded into memory. ● Finally the ReflectiveLoader will return execution to the initial bootstrap shellcode which called it.
  • 5. Implementation A skeleton Reflective DLL project for building library's for use with Reflective DLL Injection is available under the three clause BSD license[7]. Support for Reflective DLL Injection has also been added to Metasploit[6] in the form of a payload stage and a modified VNC DLL. The ReflectiveLoader itself is implemented in position independent C code with a minimal amount of inlined assembler. The ReflectiveLoader code has been heavily commented and for a thorough understanding you should read through this code. A good understanding of the PE file format[3] is recommended when reading through the source code. Matt Pietrek has written a number of good articles detailing the PE file format[4] [5] which are also recommended reading. Under Metasploit, the Ruby module Payload::Windows::ReflectiveDllInject implements a new stage for injecting a DLL which contains a ReflectiveLoader. This stage will calculate the offset to the library's exported ReflectiveLoader function and proceed to generate a small bootstrap shellcode, as show below in Listing 1, which is patched into the DLL images MZ header. This allows execution to be passed to the ReflectiveLoader after the Metasploit intermediate stager loads the entire library into the host process. dec ebp ; M pop edx ; Z call 0 ; call next instruction pop ebx ; get our location (+7) push edx ; push edx back inc ebp ; restore ebp push ebp ; save ebp mov ebp, esp ; setup fresh stack frame add ebx, 0x???????? ; add offset to ReflectiveLoader call ebx ; call ReflectiveLoader mov ebx, eax ; save DllMain for second call push edi ; our socket push 0x4 ; signal we have attached push eax ; some value for hinstance call eax ; call DllMain( somevalue, DLL_METASPLOIT_ATTACH, socket ) push 0x???????? ; our EXITFUNC placeholder push 0x5 ; signal we have detached push eax ; some value for hinstance call ebx ; call DllMain( somevalue, DLL_METASPLOIT_DETACH, exitfunk ) ; we only return if we don't set a valid EXITFUNC Listing 1: Bootstrap Shellcode. The bootstrap shellcode also lets us attach Metasploit by passing in the payloads socket and finally the payloads exit function via calls to DllMain for compatibility with the Metasploit payload system.
  • 6. Detection Successfully detecting a DLL that has been loaded into a host process through Reflective DLL Injection will be difficult. Previous methods of detecting injected libraries will be largely obsolete, such as inspecting a process's currently loaded library's for irregularities or detecting hooked library functions. As a reflectively loaded library will not be registered in the host processes list of loaded modules, specifically the list held in the Process Environment Block (PEB) which is modified during API calls such as kernel32's LoadLibrary and LoadLibraryEx, any attempt to enumerate the host processes modules will not yield the injected library. This is because the injected library's ReflectiveLoader does not register itself with its host process at any stage. Similarly, detecting hooked library functions is redundant as no library functions are required to be hooked for the ReflectiveLoader to work. At a process level the only indicators that the library exists is that their will be a chunk of allocated memory present, via VirtualAlloc, where the loaded library resides. This memory will be marked as readable, writable and executable. Their will also be a thread of execution which will be, periodically at least, executing code from this memory chunk. By periodically scanning all threads of execution and cross referencing the legitimately loaded libraries in the process with a call trace of each thread it may be possible to identify unusual locations of code. This will inevitably lead to many false positives as there are many reasons to execute code in a location of memory other then a library's code sections. Examples of this are packed or protected executables and languages that use techniques like just in time (JIT) compilation, such as Java or .NET. At a system level when using Reflective DLL Injection in remote exploitation, the library should be undetectable by file scanners, such as Anti Virus, as it never touches disk. This leaves the main detection surface being the network, although many IDS evasion techniques are available[8] to aid circumventing detection such as polymorphic shellcode.
  • 7. References [1] Skape and JT, Remote Library Injection http://www.nologin.org/Downloads/Papers/remote-library-injection.pdf [2] DilDog, Back Orifice 2000 http://sourceforge.net/projects/bo2k/ [3] Microsoft, Microsoft Portable Executable and Common Object File Format Specification http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx [4] Matt Pietrek, An In-Depth Look into the Win32 Portable Executable File Format http://msdn.microsoft.com/en-gb/magazine/cc301805.aspx [5] Matt Pietrek, Peering Inside the PE: A Tour of the Win32 Portable Executable File Format http://msdn.microsoft.com/en-gb/magazine/ms809762.aspx [6] Metasploit LLC, Metasploit http://www.metasploit.com [7] Stephen Fewer, Reflective Dll Injection http://www.harmonysecurity.com/ReflectiveDllInjection.html [8] Kevin Tim, IDS Evasion Techniques and Tactics http://www.securityfocus.com/infocus/1577 Harmony Security provides computer and network security research and consultancy. We are focused on delivering new ideas and solutions to this field. Areas of concern include network and system vulnerabilities, malware and cryptography. Copyright © 2008 Harmony Security