building an empyre with python

52
Building an Empyre with Python

Upload: will-schroeder

Post on 14-Jan-2017

2.455 views

Category:

Internet


9 download

TRANSCRIPT

Page 1: Building an EmPyre with Python

Building an Empyre with

Python

Page 2: Building an EmPyre with Python

@harmj0y× Researcher/red teamer for the Adaptive Threat

Division

× Co-founder/active developer of the Veil-Framework | PowerView | PowerUp | Empire

× Microsoft CDM/PowerShell MVP and active PowerSploit developer

Page 3: Building an EmPyre with Python

@424f424f× U.S. Army Infrantry combat veteran

× Red teamer/Penetration Tester for the Adaptive Threat Division

× Instructor for ATD’s “Adaptive Penetration Testing” course

Page 4: Building an EmPyre with Python

@killswitch_gui× Previous US Army Soldier

× Red teamer/Penetration Tester for the Adaptive Threat Division

× Developed SimplyEmail / SimplyTemplate

Page 5: Building an EmPyre with Python

tl;dr

× Overview/”Why Build This”/RATs 101× EmPyre

× Stagers× Host/network triage× Lateral movement× Persistence

× The Future× Demos throughout!

Page 6: Building an EmPyre with Python

Why Build this?

Page 7: Building an EmPyre with Python

Motivations

× A high-security client wanted a penetration test against their corporate infrastructure× which was 80% OS X …

× We did our research and found very few options for ‘complete’ OS X agents

× though small post-exploitation pieces did exist

Page 8: Building an EmPyre with Python

Adversarial OS X

× WireLurker (Trojanized applications, Infects connected ios devices)

× XcodeGhost (Infected xcode package in China)× Hacking Team (Remote Code Systems compromise

platform)× OceanLotus (Flash Dropper, download Mach-O binary)× KeRanger (Ransomware, infected transmission package)

Page 9: Building an EmPyre with Python

OS X Challenges

× Not nearly as many public OS X attack toolsets out there as there are for Windows

× Access vectors are significantly more limited than Windows as well

× Lateral spread is complicated a bit (no pth!)

Page 10: Building an EmPyre with Python

RATS 101

× We have a number of broad design goals for our solution:

× Staging flexibility× Modularity× (Reasonably) strong crypto

× The “Staging problem”× Your malicious code has to SOMEHOW get to the target

Page 11: Building an EmPyre with Python

Empyre

Page 12: Building an EmPyre with Python
Page 13: Building an EmPyre with Python

background

× Python agent and controller× heavily based on the PowerShell Empire project× OS X/Linux 2.7 and 2.6 compatible/“living off the land”

× Asynchronous communications (HTTP[s])× Diffie-Hellman based Encrypted Key Exchange

× Variety of post-exploitation modules

Page 14: Building an EmPyre with Python

Module development

× Like Empire, development is quick due to the modular structure and use of a scripting language

× Modules == metadata containers for an embedded Python script

× Things like option sets, needs admin, opsec safe, save file output, etc

Page 15: Building an EmPyre with Python

stagers

Page 16: Building an EmPyre with Python

OS X MAcros

× Works on Office 2011 and below, otherwise, we’re stuck in the...

Page 17: Building an EmPyre with Python
Page 18: Building an EmPyre with Python

Mach-o binaries

× Mach object file format for executables, object code, shared libraries, dynamically-loaded code and core dumps

× We hot-patch a binary with the EmPyre stager code

× Binary contains the python interpreter

Page 19: Building an EmPyre with Python

Dylib Hijacking

× Ported from @patrickwardle research× https://www.virusbulletin.com/uploads/pdf/magazin

e/2015/vb201503-dylib-hijacking.pdf

× Abuses search-order loading

× Also a method of persistence in EmPyre

Page 20: Building an EmPyre with Python

Hijack Scanner

Page 21: Building an EmPyre with Python

Dylib Hiijacker

Page 22: Building an EmPyre with Python

Demo: Phishing with EmPyre

Page 23: Building an EmPyre with Python

Host triage

Page 24: Building an EmPyre with Python

Privilege escalation

× Users often run as admin

× Two prompt modules for credential collection:× Mac app prompting - osascript × Screensaver alleyoop - osascript / security

× Elevate using sudo_spawn to spawn a new EmPyre agent

Page 25: Building an EmPyre with Python

Privilege escalation

Page 26: Building an EmPyre with Python

Chainbreaker

× Keychaindump (juuso)× Keychain exploitable prior to OS X yosemite to

recover master key from memory × Decrypt keychain store using master key candidate

× Keychaindump_chainbreaker (n0fate)× Allows masterkey and password input for decryption

of entire keychain.× Fully ported to allow on target dumps rather offline

Page 27: Building an EmPyre with Python

Hashdumping

× Built in hashdump module:× Sudo required of course× Output is hashcat ready

× Hash format is unique to different OS X series× 10.8 + uses Salted-SHA512-PBKDF2× Password -> Iterations -> salt -> hash_pbkd2 × Ultimately very slow hash to crack (H/S)

Page 28: Building an EmPyre with Python

Hashdumping

Page 29: Building an EmPyre with Python

Keylogging

× Uses ruby adapted code from MSF:× Captures and logs keystrokes to a file currently× Runs as a separate ruby process

Page 30: Building an EmPyre with Python

screenshots

× Currently supports two separate methods:× Native - screenshot builtin tool× Python - using Quartz API call’s

× Environment can dictate the use of native tools

× CGImageDestinationCreateWithUR() and screenshot only allows a output path for image

Page 31: Building an EmPyre with Python

Clipboard theft

× Great way to target and collect credentials

× Output to file or pipeline:× Timed collection allows continues monitoring using

background jobs× Uses non-native method via AppKit API:

× Native pbpaste may be signatured by Carbon Black

Page 32: Building an EmPyre with Python
Page 33: Building an EmPyre with Python

Demo: Host Triage with EmPyre

Page 34: Building an EmPyre with Python

Network situational awareness

Page 35: Building an EmPyre with Python

OS X is on the Domain Too!

× Admins want/need to:× Enforce corporate policy via Group Policy× Manage resources× Manage users× Advertise resources such as printers

× Benefit from single sign-on access to Active Directory resources through Kerberos

Page 36: Building an EmPyre with Python
Page 37: Building an EmPyre with Python

OS X and LDAP

× ldapsearch tool× opens a connection to an LDAP server, binds, and

performs a search using specified parameters

× dig -t SRV _ldap._tcp.example.com

Page 38: Building an EmPyre with Python

PowerView, OS X Style

× Wanted to mimic the features of PowerSploit’s PowerView to enumerate Active Directory

× Using ldapsearch, we can mimic “most” features

× Unfortunately, creates a log entry for every connection

Page 39: Building an EmPyre with Python

Situational Awareness, AD Enumeration× get_computers× get_domaincontrollers× get_fileservers× get_groupmembers× get_groupmemberships× get_groups× get_ous× get_userinformation× get_users

Page 40: Building an EmPyre with Python

PowerView, OS X Style

Page 41: Building an EmPyre with Python

Overpass-THE-HASH× Original research by @gentilkiwi and

@obscuresec and OS X research by @passingthehash

× Upgrading an NT hash into a full Kerberos ticket!

× Utilities× kinit - acquire initial Kerberos credentials× klist - list Kerberos credentials × kdestroy - remove Kerberos credentials

Page 42: Building an EmPyre with Python
Page 43: Building an EmPyre with Python

Demo: Domain Enumeration with EmPyre

Page 44: Building an EmPyre with Python

Lateral Movement

Page 45: Building an EmPyre with Python

Os x vs windows

× Common Windows lateral movement methods:× WMI, PSEXEC, WinRM, Remote Desktop

× OS X disappoints a bit on this front...× SSH is available but disabled by default× WinEXE installed through HomeBrew are possible

× EmPyre modules:× ssh_command / ssh_launcher

Page 46: Building an EmPyre with Python

Web Service Exploitation

× JBoss exploit× Pass exploit to Empire server

Page 47: Building an EmPyre with Python
Page 48: Building an EmPyre with Python

Persistence

Page 49: Building an EmPyre with Python

Os x vs windows× Common Windows persistence methods:

× Registry keys× Startup folders× WMI × DLL hijacks× Backdoor accounts

× OS X is also quite fruitful:× Crontabs× Loginhooks× Daemons × Dylib Hijacking

Page 50: Building an EmPyre with Python

Crontabs, Daemons, and Login Hooks× Login Hook - User Context

× Bash / Applescript / binary execution × User or any user logon executes payload× Sets com.apple.loginwindow

× Crontabs - User Context× Requires Bash / Applescript / binary × Timed execution of payload× Great for continued access

× Launch Daemons - Root Context× Requires sudo × Spawns determined by XML manifest (reboot)× Daemons (services) once started will restart upon agent loss

Page 51: Building an EmPyre with Python

Persistence with Dylib Hijacking× EmPyre implements @patrickwardle research

to scan for hijackable Dylibs!× rPath search, WeakLib import search

× CreateHijacker module × allows for quick exploitation× ease of generating payload × patching in the path to the legitimate Dylib for proper

execution

Page 52: Building an EmPyre with Python

Questions?@harmj0y / will [at] harmj0y.net

@424f424f / steveborosh [at] gmail.com

@killswitch_gui / a.rymdekoharvey [at] gmail.com