SlideShare a Scribd company logo
Python: Process Injection for Everyone!
Darren Martyn
Xiphos Research
darren.martyn@xiphosresearch.co.uk
whoami
β€’ Darren Martyn / infodox
β€’ Penetration Tester & Researcher @ Xiphos Research Ltd
β€’ Forensics & Chemistry Student @ GMIT
what
β€’ Manipulating what another process is doing in memory
β€’ Memory-resident, process-less backdoors
β€’ Doing all this in Python
Use Cases
β€’ Getting around weird runtime packers, such as those used by
malware developers to obfuscate code.
β€’ Cheating in video games!
β€’ Extending / Modifying a programs functionality at runtime!
β€’ Developing forensically challenging code.
Today…
β€’ We will talk about being bad guys!
β€’ Because, quite frankly, using this to develop a proof of concept
version of a sneaky malware is the best way to demonstrate
risk.
Today…
Forensically Challenging
β€’ The concepts outlined here will demonstrate how to create a
forensically-challenging to detect piece of malware.
β€’ Note that this is not impossible to detect or mitigate against,
we will discuss mitigations and suchlike later in the talk.
Before I begin… The basics.
β€’ First off, before we begin, we need to understand how the
stack works.
β€’ Quite simple, will use the x86 stack as an example.
Stack – General Registers
Stack – General Layout
Stack – How code gets executed…
β€’ The EIP, or Extended Instruction Pointer, is the place on the
stack where the next instruction to be executed sits.
β€’ In exploit development, overwriting the EIP with a return to an
attacker controlled address is the β€œnormal” way to get code to
execute.
β€’ Conceptually, what we are doing is somewhat similar to exploit
development, in that we wish to gain control of EIP and point it
at our code.
Stack – How we are executing code
β€’ Instead of triggering a vulnerability such as in a buffer overflow
exploit to gain control of the EIP, we are simply overwriting it
using the powers of ptrace().
β€’ The ptrace() system call is used for debugging software. It can
both read and write arbitrary data to a process’s memory.
β€’ This allows us to directly manipulate the stack, and execute
code or alter the programs state at runtime.
Process Injection 101
β€’ Attach to process
β€’ Pause Process (this happens when attach)
β€’ Get EIP/RIP
β€’ Overwrite EIP/RIP with shellcode
β€’ Set EBX/RBX to 0
β€’ Continue Process
β€’ Shellcode runs
Process Injection 101
Prior art of note…
β€’ Process injection has been done before on Linux.
β€’ One example of prior art is β€œCymothoa”, by Crossbower.
β€’ Written in C, and released via Phrack magazine (a publication
in which hackers publish research), it worked on x86 Linux and
was extremely effective for injecting backdoors into other
processes.
Prior art of note…
β€’ There is also some research done by elfmaster in vx-heaven.
β€’ Libhijack, by lattera, implements a whole library of functions to
do this in an easy-to-use format.
β€’ Parasite, by jtripper, also uses these techniques to inject a bind
shell into running processes.
β€’ None of the prior art to the best of my knowledge has been in
anything other than C/ASM.
Python Code (warning: wall of text)
process = attach(pid) # Attach to target PID
rip = process.getInstrPointer() # get RIP
bytes = process.writeBytes(rip, shellcode)
# overwrite RIP with shellcode…
process.setreg("rbx", 0) # set RBX to 0
process.cont() # Let process continue :)
Live Demo
Lets recap a little…
Quick recap and suchlike to ensure everyone here is up to
speed…
Problems
β€’ Host process usually crashes after shellcode exits
β€’ If it doesn’t crash, it will at LEAST act really weirdly
β€’ This is ugly
β€’ What do?
Problems
So we need a solution…
β€’ We have our code running in the infected processes memory
β€’ We need our code to not interfere with the process, and run
along side it
β€’ How?
So we need a solution…
Let’s Fork()
β€’ Prepend our payload with some fork() shellcode
β€’ Process is forked, new clone runs with our shellcode running in
it
β€’ Original process continues (theoretically) unchanged
Prepending Fork
β€’ β€œPrepending” means we affix something ahead of our main
payload.
β€’ The fork syscall basically creates a new process, identical to the
parent, as a β€œchild” process.
β€’ This helps us avoid killing/damaging the parent process and
causing possible loss of data or alerting administrators to our
presence.
Prepending Fork
β€’ We prepend a shellcode to our shellcode which does the
following:
Step 1: Fork parent process.
Step 2: Run our shellcode.
Note: I even drew a terrible picture to explain this!
Prepending Fork
Parent Process
Parent Process Continues
Child process spawned with shellcode in it, so
it is infected
fork()
Execution flow of process….
Lets fork() – a demonstration of forking
β€’ Demo of forking (probably pre-recorded if live not working
out).
Problems with forking
β€’ With fork, we create a new process
β€’ New process shows up in process listings
β€’ In future, I will be playing with clone() ala Cymothoa, but
simply could not get it working for this yet
Back to the python
β€’ So far, we have scratched the surface of memory injection
β€’ So why Python for this?
β€’ Simplicity.
Python: Making the hard stuff easy
β€’ The injection code is incredibly short
β€’ We can very easily improve it if we feel the need
β€’ Can spend more time working on the rest of the project (like,
say, the hard bit: shellcode!)
Enhancing our injector
β€’ So, the more astute of you may be wondering why I am
clobbering the stack here, and leaving it in a fairly clobbered-
state…
β€’ In this bit, I am going to *attempt* to restore the registers
post-injection. This is not always successful, mind…
Enhancing our injector
Restoring the Registers (1)
β€’ This is a bit of a filthy hack, but worked well enough for me to
consider it
β€’ Method I am using is a filthy hack and I should feel terrible
β€’ Again, be warned. This might crash
Restoring the Registers (2)
β€’ After process.cont(), we sleep for a second
β€’ We then restore the registers to pre-injection state
β€’ We then pray the fork prepender worked and that the stack is
now unclobbered
Live Demo (this may well fail)
No, really. You might want to close your eyes for this one
Moving swiftly on…
β€’ Now for the extra shiny fun part
β€’ Because its Python, our injector is portable
β€’ Write once, pwn everything
β€’ Well, kind of...
Writing a multi-arch injector
β€’ Our next toy is a process injector that magically determines if
its on an x86 or x84_64 system, and reacts accordingly
β€’ So, let’s write the getArch() function, eh?
β€’ This is easy… 2 lines of code
Getting OS Architecture
import platform # import platform module
arch = platform.machine() # get architecture
print arch # print architecture
Test on 64bit
Test on 32bit
Porting to x86
β€’ Step 1 (hard bit). Rewrite shellcode for x86.
β€’ Step 2 (easy bit). Rewrite injector part for x86.
β€’ Porting injector part is easy!
β€’ s/rip/eip/
β€’ s/rbx/ebx/
Demo of injection on x86
This is a demo of injecting a bindshell on x86. Not live, this box is x86_64.
Bonus! Porting to ARM (last minute
addition)
β€’ x86 and x86_64 not too much of a challlenge…
β€’ Realized I could chroot Linux on Nexus 7 tablet… Which is
ARMv7l.
β€’ Let’s explore ARMv7l…
ARMv7l – the important bits…
β€’ On ARM, the β€œEIP” is the PC register.
β€’ Our EBX equivalent is the R1 register.
β€’ Other registers not so important for our purposes.
ARMv7l – Challenges
β€’ First attempts were failures because my shellcodes seemed to simply
be too large, causing segfaults.
β€’ Segfault, or segmentation fault, being a crash. This is bad, and will
set off alarms.
β€’ Not an ARM expert, but guessing I was clobbering other registers
with my bulky shellcodes.
β€’ Ended up using a staged Metasploit payload. No prepend-fork yet, so
this is a work in progress! On exit, the parent does get killed!
ARMv7l – IT WORKS!
Adding Logic to our injector…
β€’ We can autodetect target machines architecture.
β€’ We can inject into all three architectures demonstrated.
β€’ One injector to rule them all!
Testing EnchantedMushroom…
β€’ Wrote a quick β€œstager” that runs python code in memory over
SSH. β€œDiabolicalMouse”.
β€’ Decided to use this to test our newly created cross architecture
injector tool, to see if we could get it working without dropping
anything to disc…
β€’ Fairly hacky code, works for this demos purposes!
Demo of EnchantedMushroom/DiabolicalMouse
Prerecorded demo as setting it up was a bit complex!
Future Ideas…
β€’ Explore this further on OSX/*BSD and Windows.
β€’ Automatic OS detection to go with Architecture detection?
β€’ More architectures! MIPSLE/BE, SPARC, PPC?
β€’ Improved shellcodes?
β€’ Remove python-ptrace dependency entirely…
Future Ideas… (2)
β€’ Implement our own ptrace using ctypes to avoid any non-
native dependencies?
β€’ Lots of further research to do! Stuff like injecting entire ELF
files in memory and suchlike!
β€’ Barrier of entry to exploring this stuff very low, anyone and
everyone can make some research!
Limitations as an attack vector
β€’ As is, the attacker has to be able to execute code on your
system to employ these kinds of techniques.
β€’ This means that by the time the attacker can do this, you are
already compromised, by, say, weak login passwords, or
exploitation of vulnerable software on your system.
β€’ *POST* exploitation technique, will not gain you any further
access to a system.
Forensically Detecting This…
β€’ Forensic analysts should be aware of this vector of attack.
β€’ Some analysts only investigate artifacts written to disc.
β€’ This kind of analysis is useless against this kind of attack,
wherin nothing is written to disc.
β€’ Analysts should dump the RAM on a suspected-compromised
host to determine if anything exists in-memory.
Forensically Detecting This…
β€’ By comparing dumped memory against β€œgood” samples, it may
be possible to actually detect this after the fact.
β€’ Anti-malware solutions that actively scan memory might also
be a decent defence against this kind of thing.
β€’ Network forensics may also assist in detection – observing the
attack actually happening, unusual network connections, etc,
could be a good indicator something has gone terribly wrong.
Possible Mitigations
β€’ Prevent access to ptrace() system call by non-root users.
β€’ Some distributions take this approach, but badly.
β€’ Disable ptrace() entirely on production webservers where
debugging access is not required.
β€’ This is doable with certain kernel patches. Grsecurity locks
down ptrace quite well (but is bypassable)
β€’ Monitor process memory and alert on any β€œunusual”
alterations to said memoryspace.
Summary
β€’ Python makes hard things like memory hacking easy!
β€’ Writing cross architecture in-memory malware/implants is
accessible to anyone!
β€’ Most architectures can be owned with very little
effort/modification of existing code!
β€’ Further research needed into forensic detection of process
manipulation and in-memory backdoors.
Thanks!
Thanks to the SteelCon organizers for having me here today and
allowing me to give this talk!
Also thanks to my co-workers at Xiphos Research for helping me
get this off the ground.
Finally, thanks to all of you for listening!

More Related Content

PDF
λ””μ§€ν„Έ 트윈 ν”Œλž«νΌ 기술과 사둀(LX곡사 νŠΉκ°•)
PPTX
Tipos de usuario cms
PDF
UX λ””μžμΈ 7κ°€μ§€ λΉ„λ°€: λΉ„λ°€ 4
PDF
Process injection - Malware style
PPTX
Code Injection in Windows
PPTX
Injection on Steroids: Codeless code injection and 0-day techniques
Β 
PDF
Packers
PPTX
Steelcon 2015 - 0wning the internet of trash
λ””μ§€ν„Έ 트윈 ν”Œλž«νΌ 기술과 사둀(LX곡사 νŠΉκ°•)
Tipos de usuario cms
UX λ””μžμΈ 7κ°€μ§€ λΉ„λ°€: λΉ„λ°€ 4
Process injection - Malware style
Code Injection in Windows
Injection on Steroids: Codeless code injection and 0-day techniques
Β 
Packers
Steelcon 2015 - 0wning the internet of trash

Similar to Steelcon 2014 - Process Injection with Python (20)

PPTX
Vulnerability, exploit to metasploit
PDF
Exploitation and State Machines
PDF
Reverse Engineering Presentation.pdf
PDF
Scratching the itch, making Scratch for the Raspberry Pie
Β 
PPTX
EhTrace -- RoP Hooks
PDF
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
PPT
Introduction to the intermediate Python - v1.1
PDF
Common technique in Bypassing Stuff in Python.
PDF
Eusecwest
PPTX
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
PPTX
Advanced SOHO Router Exploitation XCON
PDF
Basic buffer overflow part1
PDF
Project Basecamp: News From Camp 4
PDF
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
PPTX
Tranning-2
PDF
Sonatype DevSecOps Leadership forum 2020
PDF
Reverse Engineering the TomTom Runner pt. 2
PPTX
Burp plugin development for java n00bs (44 con)
PPTX
Creating Havoc using Human Interface Device
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Vulnerability, exploit to metasploit
Exploitation and State Machines
Reverse Engineering Presentation.pdf
Scratching the itch, making Scratch for the Raspberry Pie
Β 
EhTrace -- RoP Hooks
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
Introduction to the intermediate Python - v1.1
Common technique in Bypassing Stuff in Python.
Eusecwest
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Advanced SOHO Router Exploitation XCON
Basic buffer overflow part1
Project Basecamp: News From Camp 4
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Tranning-2
Sonatype DevSecOps Leadership forum 2020
Reverse Engineering the TomTom Runner pt. 2
Burp plugin development for java n00bs (44 con)
Creating Havoc using Human Interface Device
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Ad

Recently uploaded (20)

PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
Β 
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
DOCX
Unit-3 cyber security network security of internet system
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
The Internet -By the Numbers, Sri Lanka Edition
Β 
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PDF
Testing WebRTC applications at scale.pdf
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPT
tcp ip networks nd ip layering assotred slides
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
Introuction about WHO-FIC in ICD-10.pptx
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Introuction about ICD -10 and ICD-11 PPT.pptx
international classification of diseases ICD-10 review PPT.pptx
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
RPKI Status Update, presented by Makito Lay at IDNOG 10
Β 
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Unit-3 cyber security network security of internet system
Unit-1 introduction to cyber security discuss about how to secure a system
The Internet -By the Numbers, Sri Lanka Edition
Β 
Tenda Login Guide: Access Your Router in 5 Easy Steps
Testing WebRTC applications at scale.pdf
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
tcp ip networks nd ip layering assotred slides
introduction about ICD -10 & ICD-11 ppt.pptx
SAP Ariba Sourcing PPT for learning material
Module 1 - Cyber Law and Ethics 101.pptx
Ad

Steelcon 2014 - Process Injection with Python

  • 1. Python: Process Injection for Everyone! Darren Martyn Xiphos Research darren.martyn@xiphosresearch.co.uk
  • 2. whoami β€’ Darren Martyn / infodox β€’ Penetration Tester & Researcher @ Xiphos Research Ltd β€’ Forensics & Chemistry Student @ GMIT
  • 3. what β€’ Manipulating what another process is doing in memory β€’ Memory-resident, process-less backdoors β€’ Doing all this in Python
  • 4. Use Cases β€’ Getting around weird runtime packers, such as those used by malware developers to obfuscate code. β€’ Cheating in video games! β€’ Extending / Modifying a programs functionality at runtime! β€’ Developing forensically challenging code.
  • 5. Today… β€’ We will talk about being bad guys! β€’ Because, quite frankly, using this to develop a proof of concept version of a sneaky malware is the best way to demonstrate risk.
  • 7. Forensically Challenging β€’ The concepts outlined here will demonstrate how to create a forensically-challenging to detect piece of malware. β€’ Note that this is not impossible to detect or mitigate against, we will discuss mitigations and suchlike later in the talk.
  • 8. Before I begin… The basics. β€’ First off, before we begin, we need to understand how the stack works. β€’ Quite simple, will use the x86 stack as an example.
  • 11. Stack – How code gets executed… β€’ The EIP, or Extended Instruction Pointer, is the place on the stack where the next instruction to be executed sits. β€’ In exploit development, overwriting the EIP with a return to an attacker controlled address is the β€œnormal” way to get code to execute. β€’ Conceptually, what we are doing is somewhat similar to exploit development, in that we wish to gain control of EIP and point it at our code.
  • 12. Stack – How we are executing code β€’ Instead of triggering a vulnerability such as in a buffer overflow exploit to gain control of the EIP, we are simply overwriting it using the powers of ptrace(). β€’ The ptrace() system call is used for debugging software. It can both read and write arbitrary data to a process’s memory. β€’ This allows us to directly manipulate the stack, and execute code or alter the programs state at runtime.
  • 13. Process Injection 101 β€’ Attach to process β€’ Pause Process (this happens when attach) β€’ Get EIP/RIP β€’ Overwrite EIP/RIP with shellcode β€’ Set EBX/RBX to 0 β€’ Continue Process β€’ Shellcode runs
  • 15. Prior art of note… β€’ Process injection has been done before on Linux. β€’ One example of prior art is β€œCymothoa”, by Crossbower. β€’ Written in C, and released via Phrack magazine (a publication in which hackers publish research), it worked on x86 Linux and was extremely effective for injecting backdoors into other processes.
  • 16. Prior art of note… β€’ There is also some research done by elfmaster in vx-heaven. β€’ Libhijack, by lattera, implements a whole library of functions to do this in an easy-to-use format. β€’ Parasite, by jtripper, also uses these techniques to inject a bind shell into running processes. β€’ None of the prior art to the best of my knowledge has been in anything other than C/ASM.
  • 17. Python Code (warning: wall of text) process = attach(pid) # Attach to target PID rip = process.getInstrPointer() # get RIP bytes = process.writeBytes(rip, shellcode) # overwrite RIP with shellcode… process.setreg("rbx", 0) # set RBX to 0 process.cont() # Let process continue :)
  • 19. Lets recap a little… Quick recap and suchlike to ensure everyone here is up to speed…
  • 20. Problems β€’ Host process usually crashes after shellcode exits β€’ If it doesn’t crash, it will at LEAST act really weirdly β€’ This is ugly β€’ What do?
  • 22. So we need a solution… β€’ We have our code running in the infected processes memory β€’ We need our code to not interfere with the process, and run along side it β€’ How?
  • 23. So we need a solution…
  • 24. Let’s Fork() β€’ Prepend our payload with some fork() shellcode β€’ Process is forked, new clone runs with our shellcode running in it β€’ Original process continues (theoretically) unchanged
  • 25. Prepending Fork β€’ β€œPrepending” means we affix something ahead of our main payload. β€’ The fork syscall basically creates a new process, identical to the parent, as a β€œchild” process. β€’ This helps us avoid killing/damaging the parent process and causing possible loss of data or alerting administrators to our presence.
  • 26. Prepending Fork β€’ We prepend a shellcode to our shellcode which does the following: Step 1: Fork parent process. Step 2: Run our shellcode. Note: I even drew a terrible picture to explain this!
  • 27. Prepending Fork Parent Process Parent Process Continues Child process spawned with shellcode in it, so it is infected fork() Execution flow of process….
  • 28. Lets fork() – a demonstration of forking β€’ Demo of forking (probably pre-recorded if live not working out).
  • 29. Problems with forking β€’ With fork, we create a new process β€’ New process shows up in process listings β€’ In future, I will be playing with clone() ala Cymothoa, but simply could not get it working for this yet
  • 30. Back to the python β€’ So far, we have scratched the surface of memory injection β€’ So why Python for this? β€’ Simplicity.
  • 31. Python: Making the hard stuff easy β€’ The injection code is incredibly short β€’ We can very easily improve it if we feel the need β€’ Can spend more time working on the rest of the project (like, say, the hard bit: shellcode!)
  • 32. Enhancing our injector β€’ So, the more astute of you may be wondering why I am clobbering the stack here, and leaving it in a fairly clobbered- state… β€’ In this bit, I am going to *attempt* to restore the registers post-injection. This is not always successful, mind…
  • 34. Restoring the Registers (1) β€’ This is a bit of a filthy hack, but worked well enough for me to consider it β€’ Method I am using is a filthy hack and I should feel terrible β€’ Again, be warned. This might crash
  • 35. Restoring the Registers (2) β€’ After process.cont(), we sleep for a second β€’ We then restore the registers to pre-injection state β€’ We then pray the fork prepender worked and that the stack is now unclobbered
  • 36. Live Demo (this may well fail) No, really. You might want to close your eyes for this one
  • 37. Moving swiftly on… β€’ Now for the extra shiny fun part β€’ Because its Python, our injector is portable β€’ Write once, pwn everything β€’ Well, kind of...
  • 38. Writing a multi-arch injector β€’ Our next toy is a process injector that magically determines if its on an x86 or x84_64 system, and reacts accordingly β€’ So, let’s write the getArch() function, eh? β€’ This is easy… 2 lines of code
  • 39. Getting OS Architecture import platform # import platform module arch = platform.machine() # get architecture print arch # print architecture Test on 64bit Test on 32bit
  • 40. Porting to x86 β€’ Step 1 (hard bit). Rewrite shellcode for x86. β€’ Step 2 (easy bit). Rewrite injector part for x86. β€’ Porting injector part is easy! β€’ s/rip/eip/ β€’ s/rbx/ebx/
  • 41. Demo of injection on x86 This is a demo of injecting a bindshell on x86. Not live, this box is x86_64.
  • 42. Bonus! Porting to ARM (last minute addition) β€’ x86 and x86_64 not too much of a challlenge… β€’ Realized I could chroot Linux on Nexus 7 tablet… Which is ARMv7l. β€’ Let’s explore ARMv7l…
  • 43. ARMv7l – the important bits… β€’ On ARM, the β€œEIP” is the PC register. β€’ Our EBX equivalent is the R1 register. β€’ Other registers not so important for our purposes.
  • 44. ARMv7l – Challenges β€’ First attempts were failures because my shellcodes seemed to simply be too large, causing segfaults. β€’ Segfault, or segmentation fault, being a crash. This is bad, and will set off alarms. β€’ Not an ARM expert, but guessing I was clobbering other registers with my bulky shellcodes. β€’ Ended up using a staged Metasploit payload. No prepend-fork yet, so this is a work in progress! On exit, the parent does get killed!
  • 46. Adding Logic to our injector… β€’ We can autodetect target machines architecture. β€’ We can inject into all three architectures demonstrated. β€’ One injector to rule them all!
  • 47. Testing EnchantedMushroom… β€’ Wrote a quick β€œstager” that runs python code in memory over SSH. β€œDiabolicalMouse”. β€’ Decided to use this to test our newly created cross architecture injector tool, to see if we could get it working without dropping anything to disc… β€’ Fairly hacky code, works for this demos purposes!
  • 48. Demo of EnchantedMushroom/DiabolicalMouse Prerecorded demo as setting it up was a bit complex!
  • 49. Future Ideas… β€’ Explore this further on OSX/*BSD and Windows. β€’ Automatic OS detection to go with Architecture detection? β€’ More architectures! MIPSLE/BE, SPARC, PPC? β€’ Improved shellcodes? β€’ Remove python-ptrace dependency entirely…
  • 50. Future Ideas… (2) β€’ Implement our own ptrace using ctypes to avoid any non- native dependencies? β€’ Lots of further research to do! Stuff like injecting entire ELF files in memory and suchlike! β€’ Barrier of entry to exploring this stuff very low, anyone and everyone can make some research!
  • 51. Limitations as an attack vector β€’ As is, the attacker has to be able to execute code on your system to employ these kinds of techniques. β€’ This means that by the time the attacker can do this, you are already compromised, by, say, weak login passwords, or exploitation of vulnerable software on your system. β€’ *POST* exploitation technique, will not gain you any further access to a system.
  • 52. Forensically Detecting This… β€’ Forensic analysts should be aware of this vector of attack. β€’ Some analysts only investigate artifacts written to disc. β€’ This kind of analysis is useless against this kind of attack, wherin nothing is written to disc. β€’ Analysts should dump the RAM on a suspected-compromised host to determine if anything exists in-memory.
  • 53. Forensically Detecting This… β€’ By comparing dumped memory against β€œgood” samples, it may be possible to actually detect this after the fact. β€’ Anti-malware solutions that actively scan memory might also be a decent defence against this kind of thing. β€’ Network forensics may also assist in detection – observing the attack actually happening, unusual network connections, etc, could be a good indicator something has gone terribly wrong.
  • 54. Possible Mitigations β€’ Prevent access to ptrace() system call by non-root users. β€’ Some distributions take this approach, but badly. β€’ Disable ptrace() entirely on production webservers where debugging access is not required. β€’ This is doable with certain kernel patches. Grsecurity locks down ptrace quite well (but is bypassable) β€’ Monitor process memory and alert on any β€œunusual” alterations to said memoryspace.
  • 55. Summary β€’ Python makes hard things like memory hacking easy! β€’ Writing cross architecture in-memory malware/implants is accessible to anyone! β€’ Most architectures can be owned with very little effort/modification of existing code! β€’ Further research needed into forensic detection of process manipulation and in-memory backdoors.
  • 56. Thanks! Thanks to the SteelCon organizers for having me here today and allowing me to give this talk! Also thanks to my co-workers at Xiphos Research for helping me get this off the ground. Finally, thanks to all of you for listening!