SlideShare a Scribd company logo
Will
@harmj0y
Veris Group
Adaptive Threat Division
$ whoami
 Security researcher and penetration tester/red teamer
for Veris Group’s Adaptive Threat Division
 Co-founder of the Veil-Framework #avlol
 www.veil-framework.com
 Shmoocon ‘14: AV Evasion with the Veil Framework
 co-wrote Veil-Evasion, wrote Veil-Catapult and Veil-
PowerView
 BSides ATX ‘14: Wielding a Cortana
 Defcon ‘14 (accepted): Post-Exploitation 2.0
tl;dr
 Why we use Pyinstaller
 DEP, Pyinstaller, and a weird Veil-Evasion bug
 How Pyinstaller works
 Pwnstaller v1.0
 Questions
Caveat
 This is a proof of concept based off of an idea
 Going to detail through the problem that prompted
thinking about this, and walk through the thought
process that led to the PoC solution
 Probably a better way to do this, but seemed like an
interesting concept and wanted to get the idea out there
Pyinstaller 101
 Pyinstaller is “a program that converts (packages) Python
programs into stand-alone executables”
 http://www.pyinstaller.org/
 Packages Python scripts into OSX, Linux, or Windows
self-extracting executables
 Lets developers distribute projects without relying on an
existing Python installation
Pyinstaller Repurposed
 Pentesters realized a few years ago that we could use it
to package malicious scripts
 advantageous, as legitimate projects use Pyinstaller
 www.pyinstaller.org/wiki/ProjectsUsingPyInstaller
 Dave Kennedy’s “PyInjector” was released in 2012 based
on Debasish Mandal’s original post:
 https://www.trustedsec.com/august-2012/new-tool-
pyinjector-released-python-shellcode-injection/
 http://www.debasish.in/2012_04_01_archive.html
Pyinstaller in Veil-
Evasion
 Veil-Evasion sets up Pyinstaller under Wine so Python
payloads can be compliled natively to Windows .exe’s
 Generation is transparent to the user
 Allows for the dynamic generation of Windows Python
payloads, all on Kali!
 We always want to preserve a single attack platform
Veil Payloads and DEP
 Void pointer casting for shellcode injection may fail, as
the memory location used is not explicitly marked X
(*(void(*)()) shellcode)();
 Most systems tend to default to an opt-in DEP
enforcement policy
 if the executable you're running opts-in, void pointer
casting will fail with a memory access violation
A Weird Veil Bug
 Python void pointer payloads worked as .py files, but
failed as Pyinstaller executables
 The python.exe interpreter used by Pyinstaller is not
DEP enabled, but the resulting Pyinstaller payloads do
in fact opt in to this protection
see http://www.veil-evasion.com/dep-pyinstaller/
How Pyinstaller Works
 Pyinstaller uses the CArchive data structure to package
up the main python .dll, any necessary libraries, and
your target script
 Basically like a compressed ZIP container
 This CArchive is attached to then end of a “launcher”
executable
 We use the runw.exe version so we can hide the window,
making execution transparent to the user
Pyinstaller
.exe’s
http://www.pyinstaller.org/expor
t/develop/project/doc/Manua
l.html#two-pass-execution
How Pyinstaller Works
 On execution, the launcher executable:
 Decompresses the CArchive to a temporary location
 Loads the python15.dll using LoadLibraryExA
 Maps all the entry points in the python .dll for necessary
methods
 Sets up env stuff and starts the Python process
 Imports all specified necessary modules
 Runs the extracted script using PyRun_SimpleString
How Pyinstaller Works:
English
 When the Pyinstaller produced executable is run, a
minimal Python environment is extracted from a
compressed attachment
 Components necessary for the environment are
registered and set up
 The script attached is run
 Lets you run Python scripts without Python being
installed on a target machine!
Solving The Veil Bug
 So the DEP opt-in policy is determined by the launcher
.exe, not the Python interpreter
 Our next step was to generate a Pyinstaller launcher that
didn’t opt-in to DEP
 Luckily Pyinstaller is open source
 https://www.veil-framework.com/dep-pyinstaller/
Solving The Veil Bug
 Pyinstaller holds precompiled copies of 32-bit and 64-bit
loaders for Linux, OSX and Windows in
pyinstaller/support/loader/*
 The sources for the loaders are included in
pyinstaller/source/*
 runw.exe is the loader we want to regenerate
 used for “windowed” executables
DEP
Turning Off DEP
 The binaries utilize the WAF build system to build the
loaders
 ./pyinstaller/source/wscript
 add conf.env.append_value('LINKFLAGS',
'/NXCOMPAT:NO') right after the other flags on lines 209
and 211
 This will instruct the Visual Studio linker to turn off DEP
compatibility
Problem?
 Sweet, we have a shiny new launcher.exe
 But our project is focused on evading AV
 Including a static, custom-compiled launcher executable
is a GREAT way to say “Hey vendors, check out this
Veil-Evasion payload! Signatures lolz”
Solution
 Besides running Pyinstaller itself natively on Kali, we
can dynamically recompile the Pyinstaller launcher on
using mingw!
 This makes it trivial to makes some small changes and
get a different SHA1 signature each time
 Why don’t we make it *a little* harder to flag on?
Obfuscation: Phase 1
 There are only a handful of source files needed to
recompile runw.exe
 utils.c - some helper methods (246 lines)
 launch.c - “where the magic happens” (1617 lines)
 main.c - invokes launch.c (165 lines)
 ./zlib/* - extract of zlib v1.2.3
 Lets start with some basic obfuscation
Obfuscation: Phase 1
 The initial goal: make ssdeep as useless as possible
against “families” of our generated launcher
 Any unnecessary code was stripped out (i.e. code for
OSX and Linux binaries)
 Thought process: randomize/shuffle wherever we can
 A selection of random libraries imports thrown in
Obfuscation: Phase 2
 Let’s go just a bit further and have a some fun with
anything doing basic dynamic analysis
 How about interspersing lots of nested processing
methods throughout the code
 similar to our c/meterpreter/* payloads
 This mucks up the call tree of the program without
altering the actual execution
Finishing Touches
 The Pyinstaller icon is kind
of recognizable
 How about some randomized .ico’s instead?
Putting It All Together
 The end result, every time the generator runs:
 obfuscated code for all* source files associated with the
Pyinstaller launcher are generated
 a randomized icon is chosen for the final packaged result
 mingw32 is used to compile everything into a new
runw.exe, all on Kali
 the new runw.exe is copied into the correct resource
location to be used by Pyinstaller
*except some known zlib libraries
ssdeep comparison
 ssdeep is a ‘fuzzy hashing’ static malware comparison tool,
allowing for the comparison of malware families
 Generated a run of 1000 runw.exe loaders
 (1000 choose 2) = 499500 possible comparison combinations
 367,073 pairings (74%) scored 30/100 or better
 228,961 pairings (46%) scored 50/100 or better
 34,420 pairings (7%) scored 70/100 or better
 0 pairings scored at 90/100 or better
 What this means: none of the loader pairings scored as a
closely ‘similar’ malware family
ssdeep comparison
0
5000
10000
15000
20000
25000
30000
35000
40000
45000
0 10 20 30 40 50 60 70 80 90 100
occurances
match %
ssdeep matches
In Plain English
 Each generated Pyinstaller loader is reasonably unique
from a basic static malware analysis perspective
 Competent reversers will be able to figure out what’s
going on in very little time
 But hopefully this is relatively resistant against static
signatures
 I’m sure there are better obfuscation methods, so go
implement them!
Pwnstaller v1.0
 http://www.harmj0y.net/blog/python/pwnstaller-1-
0/
 The code is up on github:
https://github.com/HarmJ0y/Pwnstaller
 And it’s been integrated into Veil-Evasion
 In the development branch now, hitting the master branch
on the 5/15/2014 V-Day
 All Python payloads can now utilize a dynamically
generated Pwnstaller loader by choosing “2 - Pwnstaller”
from the Python compilation menu
Pwnstaller in Veil-
Evasion
Recap
 Pyinstaller is some cool stuff
 Pwnstaller will hopefully extend the lifetime of Veil-
Evasion Python payloads by making static signatures
reasonably difficult to write
 “This is script-kiddie garbage that will harm users of
Pyinstaller when AVs flag it without benefiting
anyone who matters. Hope you get booed off at
Bsides.” – The Internet
Shameless Sidebar
 Want to research cool stuff like this?
 Want to work with 9 x OSCPs and 4 x OSCEs?
 Want to do some sweet red teaming?
 Hit me up to join the Adaptive Threat Division
Questions?
 Contact me:
 @harmj0y
 will@harmj0y.net
 Read more:
 http://www.harmj0y.net/blog/python/pwnstaller-1-0/
 Get Pwnstaller:
 https://github.com/HarmJ0y/Pwnstaller
 Now in Veil-Evasion!

More Related Content

What's hot

PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege Escalation
Will Schroeder
 
PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016
Russel Van Tuyl
 
Continuous intrusion: Why CI tools are an attacker’s best friends
Continuous intrusion: Why CI tools are an attacker’s best friendsContinuous intrusion: Why CI tools are an attacker’s best friends
Continuous intrusion: Why CI tools are an attacker’s best friends
Nikhil Mittal
 
Get-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for EvilGet-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for Evil
jaredhaight
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
Nikhil Mittal
 
Defending Your "Gold"
Defending Your "Gold"Defending Your "Gold"
Defending Your "Gold"
Will Schroeder
 
Defcon - Veil-Pillage
Defcon - Veil-PillageDefcon - Veil-Pillage
Defcon - Veil-Pillage
VeilFramework
 
Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, PowershellRoo7break
 
Obfuscating The Empire
Obfuscating The EmpireObfuscating The Empire
Obfuscating The Empire
Ryan Cobb
 
Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017
Daniel Bohannon
 
BH Arsenal '14 TurboTalk: The Veil-framework
BH Arsenal '14 TurboTalk: The Veil-frameworkBH Arsenal '14 TurboTalk: The Veil-framework
BH Arsenal '14 TurboTalk: The Veil-framework
VeilFramework
 
Pwning with powershell
Pwning with powershellPwning with powershell
Pwning with powershell
jaredhaight
 
Teensy Programming for Everyone
Teensy Programming for EveryoneTeensy Programming for Everyone
Teensy Programming for Everyone
Nikhil Mittal
 
Windows Attacks AT is the new black
Windows Attacks   AT is the new blackWindows Attacks   AT is the new black
Windows Attacks AT is the new black
Rob Fuller
 
Veil-PowerView - NovaHackers
Veil-PowerView - NovaHackersVeil-PowerView - NovaHackers
Veil-PowerView - NovaHackers
VeilFramework
 
Workshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration TestersWorkshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration Testers
Nikhil Mittal
 
A Case Study in Attacking KeePass
A Case Study in Attacking KeePassA Case Study in Attacking KeePass
A Case Study in Attacking KeePass
Will Schroeder
 
Mitigating Exploits Using Apple's Endpoint Security
Mitigating Exploits Using Apple's Endpoint SecurityMitigating Exploits Using Apple's Endpoint Security
Mitigating Exploits Using Apple's Endpoint Security
Csaba Fitzl
 
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting ClassThe Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
Rob Fuller
 
Attacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkAttacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkChris Gates
 

What's hot (20)

PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege Escalation
 
PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016
 
Continuous intrusion: Why CI tools are an attacker’s best friends
Continuous intrusion: Why CI tools are an attacker’s best friendsContinuous intrusion: Why CI tools are an attacker’s best friends
Continuous intrusion: Why CI tools are an attacker’s best friends
 
Get-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for EvilGet-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for Evil
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
 
Defending Your "Gold"
Defending Your "Gold"Defending Your "Gold"
Defending Your "Gold"
 
Defcon - Veil-Pillage
Defcon - Veil-PillageDefcon - Veil-Pillage
Defcon - Veil-Pillage
 
Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, Powershell
 
Obfuscating The Empire
Obfuscating The EmpireObfuscating The Empire
Obfuscating The Empire
 
Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017
 
BH Arsenal '14 TurboTalk: The Veil-framework
BH Arsenal '14 TurboTalk: The Veil-frameworkBH Arsenal '14 TurboTalk: The Veil-framework
BH Arsenal '14 TurboTalk: The Veil-framework
 
Pwning with powershell
Pwning with powershellPwning with powershell
Pwning with powershell
 
Teensy Programming for Everyone
Teensy Programming for EveryoneTeensy Programming for Everyone
Teensy Programming for Everyone
 
Windows Attacks AT is the new black
Windows Attacks   AT is the new blackWindows Attacks   AT is the new black
Windows Attacks AT is the new black
 
Veil-PowerView - NovaHackers
Veil-PowerView - NovaHackersVeil-PowerView - NovaHackers
Veil-PowerView - NovaHackers
 
Workshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration TestersWorkshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration Testers
 
A Case Study in Attacking KeePass
A Case Study in Attacking KeePassA Case Study in Attacking KeePass
A Case Study in Attacking KeePass
 
Mitigating Exploits Using Apple's Endpoint Security
Mitigating Exploits Using Apple's Endpoint SecurityMitigating Exploits Using Apple's Endpoint Security
Mitigating Exploits Using Apple's Endpoint Security
 
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting ClassThe Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
 
Attacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkAttacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit Framework
 

Viewers also liked

Trusts You Might Have Missed - 44con
Trusts You Might Have Missed - 44conTrusts You Might Have Missed - 44con
Trusts You Might Have Missed - 44con
Will Schroeder
 
I Have the Power(View)
I Have the Power(View)I Have the Power(View)
I Have the Power(View)
Will Schroeder
 
Derbycon - Passing the Torch
Derbycon - Passing the TorchDerbycon - Passing the Torch
Derbycon - Passing the Torch
Will Schroeder
 
Bridging the Gap
Bridging the GapBridging the Gap
Bridging the Gap
Will Schroeder
 
I hunt sys admins 2.0
I hunt sys admins 2.0I hunt sys admins 2.0
I hunt sys admins 2.0
Will Schroeder
 
PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)
Will Schroeder
 
Building an EmPyre with Python
Building an EmPyre with PythonBuilding an EmPyre with Python
Building an EmPyre with Python
Will Schroeder
 
The Travelling Pentester: Diaries of the Shortest Path to Compromise
The Travelling Pentester: Diaries of the Shortest Path to CompromiseThe Travelling Pentester: Diaries of the Shortest Path to Compromise
The Travelling Pentester: Diaries of the Shortest Path to Compromise
Will Schroeder
 
Trusts You Might Have Missed
Trusts You Might Have MissedTrusts You Might Have Missed
Trusts You Might Have Missed
Will Schroeder
 
Powerpreter: Post Exploitation like a Boss
Powerpreter: Post Exploitation like a BossPowerpreter: Post Exploitation like a Boss
Powerpreter: Post Exploitation like a Boss
Nikhil Mittal
 
Six Degrees of Domain Admin - BloodHound at DEF CON 24
Six Degrees of Domain Admin - BloodHound at DEF CON 24Six Degrees of Domain Admin - BloodHound at DEF CON 24
Six Degrees of Domain Admin - BloodHound at DEF CON 24
Andy Robbins
 
Drilling deeper with Veil's PowerTools
Drilling deeper with Veil's PowerToolsDrilling deeper with Veil's PowerTools
Drilling deeper with Veil's PowerTools
Will Schroeder
 
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does ItAMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
Nikhil Mittal
 

Viewers also liked (13)

Trusts You Might Have Missed - 44con
Trusts You Might Have Missed - 44conTrusts You Might Have Missed - 44con
Trusts You Might Have Missed - 44con
 
I Have the Power(View)
I Have the Power(View)I Have the Power(View)
I Have the Power(View)
 
Derbycon - Passing the Torch
Derbycon - Passing the TorchDerbycon - Passing the Torch
Derbycon - Passing the Torch
 
Bridging the Gap
Bridging the GapBridging the Gap
Bridging the Gap
 
I hunt sys admins 2.0
I hunt sys admins 2.0I hunt sys admins 2.0
I hunt sys admins 2.0
 
PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)
 
Building an EmPyre with Python
Building an EmPyre with PythonBuilding an EmPyre with Python
Building an EmPyre with Python
 
The Travelling Pentester: Diaries of the Shortest Path to Compromise
The Travelling Pentester: Diaries of the Shortest Path to CompromiseThe Travelling Pentester: Diaries of the Shortest Path to Compromise
The Travelling Pentester: Diaries of the Shortest Path to Compromise
 
Trusts You Might Have Missed
Trusts You Might Have MissedTrusts You Might Have Missed
Trusts You Might Have Missed
 
Powerpreter: Post Exploitation like a Boss
Powerpreter: Post Exploitation like a BossPowerpreter: Post Exploitation like a Boss
Powerpreter: Post Exploitation like a Boss
 
Six Degrees of Domain Admin - BloodHound at DEF CON 24
Six Degrees of Domain Admin - BloodHound at DEF CON 24Six Degrees of Domain Admin - BloodHound at DEF CON 24
Six Degrees of Domain Admin - BloodHound at DEF CON 24
 
Drilling deeper with Veil's PowerTools
Drilling deeper with Veil's PowerToolsDrilling deeper with Veil's PowerTools
Drilling deeper with Veil's PowerTools
 
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does ItAMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
 

Similar to Pwnstaller

AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideAWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
RapidValue
 
2600 av evasion_deuce
2600 av evasion_deuce2600 av evasion_deuce
2600 av evasion_deuceDb Cooper
 
5 minute intro to virtualenv
5 minute intro to virtualenv5 minute intro to virtualenv
5 minute intro to virtualenvamenasse
 
Django Deployment
Django DeploymentDjango Deployment
Django Deployment
Tareque Hossain
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
Vlatko Kosturjak
 
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Inside the Matrix,How to Build Transparent Sandbox for Malware AnalysisInside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Chong-Kuan Chen
 
Dev Environments: The Next Generation
Dev Environments: The Next GenerationDev Environments: The Next Generation
Dev Environments: The Next Generation
Travis Thieman
 
Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.
ldaws
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guide
vjvarenya
 
AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0
CTruncer
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Christian Schneider
 
LVPHP.org
LVPHP.orgLVPHP.org
LVPHP.org
Joshua Copeland
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
Saeed Hajizade
 
Boot-To-Root KIOPTRIX Level -1
Boot-To-Root KIOPTRIX Level -1Boot-To-Root KIOPTRIX Level -1
Boot-To-Root KIOPTRIX Level -1
Venkat Raman
 
Lessons Learned Building a Container App Library
Lessons Learned Building a Container App LibraryLessons Learned Building a Container App Library
Lessons Learned Building a Container App Library
Adnan Abdulhussein
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
Adam Englander
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworksphanleson
 
Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)
Ivan Rossi
 
HPX and PVS-Studio
HPX and PVS-StudioHPX and PVS-Studio
HPX and PVS-Studio
PVS-Studio
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Codemotion
 

Similar to Pwnstaller (20)

AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideAWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
 
2600 av evasion_deuce
2600 av evasion_deuce2600 av evasion_deuce
2600 av evasion_deuce
 
5 minute intro to virtualenv
5 minute intro to virtualenv5 minute intro to virtualenv
5 minute intro to virtualenv
 
Django Deployment
Django DeploymentDjango Deployment
Django Deployment
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Inside the Matrix,How to Build Transparent Sandbox for Malware AnalysisInside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
 
Dev Environments: The Next Generation
Dev Environments: The Next GenerationDev Environments: The Next Generation
Dev Environments: The Next Generation
 
Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guide
 
AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
 
LVPHP.org
LVPHP.orgLVPHP.org
LVPHP.org
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 
Boot-To-Root KIOPTRIX Level -1
Boot-To-Root KIOPTRIX Level -1Boot-To-Root KIOPTRIX Level -1
Boot-To-Root KIOPTRIX Level -1
 
Lessons Learned Building a Container App Library
Lessons Learned Building a Container App LibraryLessons Learned Building a Container App Library
Lessons Learned Building a Container App Library
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworks
 
Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)Introduction to Ansible (Pycon7 2016)
Introduction to Ansible (Pycon7 2016)
 
HPX and PVS-Studio
HPX and PVS-StudioHPX and PVS-Studio
HPX and PVS-Studio
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
 

More from Will Schroeder

Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Will Schroeder
 
Nemesis - SAINTCON.pdf
Nemesis - SAINTCON.pdfNemesis - SAINTCON.pdf
Nemesis - SAINTCON.pdf
Will Schroeder
 
ReCertifying Active Directory
ReCertifying Active DirectoryReCertifying Active Directory
ReCertifying Active Directory
Will Schroeder
 
Certified Pre-Owned
Certified Pre-OwnedCertified Pre-Owned
Certified Pre-Owned
Will Schroeder
 
SpecterOps Webinar Week - Kerberoasting Revisisted
SpecterOps Webinar Week - Kerberoasting RevisistedSpecterOps Webinar Week - Kerberoasting Revisisted
SpecterOps Webinar Week - Kerberoasting Revisisted
Will Schroeder
 
DerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting RevisitedDerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting Revisited
Will Schroeder
 
Not a Security Boundary
Not a Security BoundaryNot a Security Boundary
Not a Security Boundary
Will Schroeder
 
Derbycon - The Unintended Risks of Trusting Active Directory
Derbycon - The Unintended Risks of Trusting Active DirectoryDerbycon - The Unintended Risks of Trusting Active Directory
Derbycon - The Unintended Risks of Trusting Active Directory
Will Schroeder
 
The Unintended Risks of Trusting Active Directory
The Unintended Risks of Trusting Active DirectoryThe Unintended Risks of Trusting Active Directory
The Unintended Risks of Trusting Active Directory
Will Schroeder
 
An ACE in the Hole - Stealthy Host Persistence via Security Descriptors
An ACE in the Hole - Stealthy Host Persistence via Security DescriptorsAn ACE in the Hole - Stealthy Host Persistence via Security Descriptors
An ACE in the Hole - Stealthy Host Persistence via Security Descriptors
Will Schroeder
 
Ace Up the Sleeve
Ace Up the SleeveAce Up the Sleeve
Ace Up the Sleeve
Will Schroeder
 

More from Will Schroeder (11)

Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Nemesis - SAINTCON.pdf
Nemesis - SAINTCON.pdfNemesis - SAINTCON.pdf
Nemesis - SAINTCON.pdf
 
ReCertifying Active Directory
ReCertifying Active DirectoryReCertifying Active Directory
ReCertifying Active Directory
 
Certified Pre-Owned
Certified Pre-OwnedCertified Pre-Owned
Certified Pre-Owned
 
SpecterOps Webinar Week - Kerberoasting Revisisted
SpecterOps Webinar Week - Kerberoasting RevisistedSpecterOps Webinar Week - Kerberoasting Revisisted
SpecterOps Webinar Week - Kerberoasting Revisisted
 
DerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting RevisitedDerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting Revisited
 
Not a Security Boundary
Not a Security BoundaryNot a Security Boundary
Not a Security Boundary
 
Derbycon - The Unintended Risks of Trusting Active Directory
Derbycon - The Unintended Risks of Trusting Active DirectoryDerbycon - The Unintended Risks of Trusting Active Directory
Derbycon - The Unintended Risks of Trusting Active Directory
 
The Unintended Risks of Trusting Active Directory
The Unintended Risks of Trusting Active DirectoryThe Unintended Risks of Trusting Active Directory
The Unintended Risks of Trusting Active Directory
 
An ACE in the Hole - Stealthy Host Persistence via Security Descriptors
An ACE in the Hole - Stealthy Host Persistence via Security DescriptorsAn ACE in the Hole - Stealthy Host Persistence via Security Descriptors
An ACE in the Hole - Stealthy Host Persistence via Security Descriptors
 
Ace Up the Sleeve
Ace Up the SleeveAce Up the Sleeve
Ace Up the Sleeve
 

Recently uploaded

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
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
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
 
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
 
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
 
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
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
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
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 

Recently uploaded (20)

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
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
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
 
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
 
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
 
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 !
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
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)
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 

Pwnstaller

  • 2. $ whoami  Security researcher and penetration tester/red teamer for Veris Group’s Adaptive Threat Division  Co-founder of the Veil-Framework #avlol  www.veil-framework.com  Shmoocon ‘14: AV Evasion with the Veil Framework  co-wrote Veil-Evasion, wrote Veil-Catapult and Veil- PowerView  BSides ATX ‘14: Wielding a Cortana  Defcon ‘14 (accepted): Post-Exploitation 2.0
  • 3. tl;dr  Why we use Pyinstaller  DEP, Pyinstaller, and a weird Veil-Evasion bug  How Pyinstaller works  Pwnstaller v1.0  Questions
  • 4. Caveat  This is a proof of concept based off of an idea  Going to detail through the problem that prompted thinking about this, and walk through the thought process that led to the PoC solution  Probably a better way to do this, but seemed like an interesting concept and wanted to get the idea out there
  • 5. Pyinstaller 101  Pyinstaller is “a program that converts (packages) Python programs into stand-alone executables”  http://www.pyinstaller.org/  Packages Python scripts into OSX, Linux, or Windows self-extracting executables  Lets developers distribute projects without relying on an existing Python installation
  • 6. Pyinstaller Repurposed  Pentesters realized a few years ago that we could use it to package malicious scripts  advantageous, as legitimate projects use Pyinstaller  www.pyinstaller.org/wiki/ProjectsUsingPyInstaller  Dave Kennedy’s “PyInjector” was released in 2012 based on Debasish Mandal’s original post:  https://www.trustedsec.com/august-2012/new-tool- pyinjector-released-python-shellcode-injection/  http://www.debasish.in/2012_04_01_archive.html
  • 7. Pyinstaller in Veil- Evasion  Veil-Evasion sets up Pyinstaller under Wine so Python payloads can be compliled natively to Windows .exe’s  Generation is transparent to the user  Allows for the dynamic generation of Windows Python payloads, all on Kali!  We always want to preserve a single attack platform
  • 8. Veil Payloads and DEP  Void pointer casting for shellcode injection may fail, as the memory location used is not explicitly marked X (*(void(*)()) shellcode)();  Most systems tend to default to an opt-in DEP enforcement policy  if the executable you're running opts-in, void pointer casting will fail with a memory access violation
  • 9. A Weird Veil Bug  Python void pointer payloads worked as .py files, but failed as Pyinstaller executables  The python.exe interpreter used by Pyinstaller is not DEP enabled, but the resulting Pyinstaller payloads do in fact opt in to this protection see http://www.veil-evasion.com/dep-pyinstaller/
  • 10. How Pyinstaller Works  Pyinstaller uses the CArchive data structure to package up the main python .dll, any necessary libraries, and your target script  Basically like a compressed ZIP container  This CArchive is attached to then end of a “launcher” executable  We use the runw.exe version so we can hide the window, making execution transparent to the user
  • 12. How Pyinstaller Works  On execution, the launcher executable:  Decompresses the CArchive to a temporary location  Loads the python15.dll using LoadLibraryExA  Maps all the entry points in the python .dll for necessary methods  Sets up env stuff and starts the Python process  Imports all specified necessary modules  Runs the extracted script using PyRun_SimpleString
  • 13. How Pyinstaller Works: English  When the Pyinstaller produced executable is run, a minimal Python environment is extracted from a compressed attachment  Components necessary for the environment are registered and set up  The script attached is run  Lets you run Python scripts without Python being installed on a target machine!
  • 14. Solving The Veil Bug  So the DEP opt-in policy is determined by the launcher .exe, not the Python interpreter  Our next step was to generate a Pyinstaller launcher that didn’t opt-in to DEP  Luckily Pyinstaller is open source  https://www.veil-framework.com/dep-pyinstaller/
  • 15. Solving The Veil Bug  Pyinstaller holds precompiled copies of 32-bit and 64-bit loaders for Linux, OSX and Windows in pyinstaller/support/loader/*  The sources for the loaders are included in pyinstaller/source/*  runw.exe is the loader we want to regenerate  used for “windowed” executables DEP
  • 16. Turning Off DEP  The binaries utilize the WAF build system to build the loaders  ./pyinstaller/source/wscript  add conf.env.append_value('LINKFLAGS', '/NXCOMPAT:NO') right after the other flags on lines 209 and 211  This will instruct the Visual Studio linker to turn off DEP compatibility
  • 17. Problem?  Sweet, we have a shiny new launcher.exe  But our project is focused on evading AV  Including a static, custom-compiled launcher executable is a GREAT way to say “Hey vendors, check out this Veil-Evasion payload! Signatures lolz”
  • 18. Solution  Besides running Pyinstaller itself natively on Kali, we can dynamically recompile the Pyinstaller launcher on using mingw!  This makes it trivial to makes some small changes and get a different SHA1 signature each time  Why don’t we make it *a little* harder to flag on?
  • 19. Obfuscation: Phase 1  There are only a handful of source files needed to recompile runw.exe  utils.c - some helper methods (246 lines)  launch.c - “where the magic happens” (1617 lines)  main.c - invokes launch.c (165 lines)  ./zlib/* - extract of zlib v1.2.3  Lets start with some basic obfuscation
  • 20. Obfuscation: Phase 1  The initial goal: make ssdeep as useless as possible against “families” of our generated launcher  Any unnecessary code was stripped out (i.e. code for OSX and Linux binaries)  Thought process: randomize/shuffle wherever we can  A selection of random libraries imports thrown in
  • 21.
  • 22. Obfuscation: Phase 2  Let’s go just a bit further and have a some fun with anything doing basic dynamic analysis  How about interspersing lots of nested processing methods throughout the code  similar to our c/meterpreter/* payloads  This mucks up the call tree of the program without altering the actual execution
  • 23. Finishing Touches  The Pyinstaller icon is kind of recognizable  How about some randomized .ico’s instead?
  • 24. Putting It All Together  The end result, every time the generator runs:  obfuscated code for all* source files associated with the Pyinstaller launcher are generated  a randomized icon is chosen for the final packaged result  mingw32 is used to compile everything into a new runw.exe, all on Kali  the new runw.exe is copied into the correct resource location to be used by Pyinstaller *except some known zlib libraries
  • 25. ssdeep comparison  ssdeep is a ‘fuzzy hashing’ static malware comparison tool, allowing for the comparison of malware families  Generated a run of 1000 runw.exe loaders  (1000 choose 2) = 499500 possible comparison combinations  367,073 pairings (74%) scored 30/100 or better  228,961 pairings (46%) scored 50/100 or better  34,420 pairings (7%) scored 70/100 or better  0 pairings scored at 90/100 or better  What this means: none of the loader pairings scored as a closely ‘similar’ malware family
  • 26. ssdeep comparison 0 5000 10000 15000 20000 25000 30000 35000 40000 45000 0 10 20 30 40 50 60 70 80 90 100 occurances match % ssdeep matches
  • 27. In Plain English  Each generated Pyinstaller loader is reasonably unique from a basic static malware analysis perspective  Competent reversers will be able to figure out what’s going on in very little time  But hopefully this is relatively resistant against static signatures  I’m sure there are better obfuscation methods, so go implement them!
  • 28. Pwnstaller v1.0  http://www.harmj0y.net/blog/python/pwnstaller-1- 0/  The code is up on github: https://github.com/HarmJ0y/Pwnstaller  And it’s been integrated into Veil-Evasion  In the development branch now, hitting the master branch on the 5/15/2014 V-Day  All Python payloads can now utilize a dynamically generated Pwnstaller loader by choosing “2 - Pwnstaller” from the Python compilation menu
  • 30. Recap  Pyinstaller is some cool stuff  Pwnstaller will hopefully extend the lifetime of Veil- Evasion Python payloads by making static signatures reasonably difficult to write  “This is script-kiddie garbage that will harm users of Pyinstaller when AVs flag it without benefiting anyone who matters. Hope you get booed off at Bsides.” – The Internet
  • 31. Shameless Sidebar  Want to research cool stuff like this?  Want to work with 9 x OSCPs and 4 x OSCEs?  Want to do some sweet red teaming?  Hit me up to join the Adaptive Threat Division
  • 32. Questions?  Contact me:  @harmj0y  will@harmj0y.net  Read more:  http://www.harmj0y.net/blog/python/pwnstaller-1-0/  Get Pwnstaller:  https://github.com/HarmJ0y/Pwnstaller  Now in Veil-Evasion!

Editor's Notes

  1. Around since ~2003/2004
  2. VirtualAlloc / RtlMoveMemory / CreateThread / WaitForSingleObject
  3. manually revamp this image?
  4. aka “context triggered piecewise hashes” “can match inputs that have homologies” – biology term, fancy way to saying degree of shared ancestry