Top Banner
“I Hunt Sys Admins” (U) Will @harmj0y Version 2.0
51

I hunt sys admins 2.0

Apr 21, 2017

Download

Internet

will-schroeder
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: I hunt sys admins 2.0

“I Hunt Sys Admins”

(U) Will@harmj0y

Version 2.0

Page 2: I hunt sys admins 2.0

$ whoami● 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:o Shmoocon ‘14: AV Evasion with the Veil Frameworko Defcon ‘14: Veil-Pillage: Post-exploitation 2.0o Derbycon ‘14: Passing the Torch: Old School Red

Teaming, New School Tactics?

Page 3: I hunt sys admins 2.0

What this is● Ways to hunt for target users on Windows

domains

● Ya really, that’s it

● Will cover as many tools and technique for doing this as I have time for

Page 4: I hunt sys admins 2.0

● Setting the stage

● Existing toolso psloggedon.exe, netsess.exe, PVEFindADUser.exe,

netview.exe, Nmap, smbexec, Veil-Pillage

● Domain data sourceso homeDirectory, profilePath, event logs, email

headers, SPNs

● PowerShellzo Sidenote: PowerShell WinAPI accesso PowerView

tl;dr

Page 5: I hunt sys admins 2.0

Setting the Stage● This talk is from the “assume breach”

perspectiveo i.e. assume foothold/access to a Windows domain

machine

● I’m also going to assume you know (more or less) what users you’re targeting

● PowerShell methods are going to heavily rely on PowerViewo https://github.com/veil-framework/PowerTools

Page 6: I hunt sys admins 2.0

User Hunting: Lateral Spread● Most common:

o If you have a privileged account, or local admin account, you want to figure out where high value users are logged in

● Hunt -> pop box -> Mimikatz -> profit

● Knowing what users log in to what boxes from where can give you a better understanding of a network layout and implicit trust relationships

Page 7: I hunt sys admins 2.0

“I Hunt Domain Admins”

Page 8: I hunt sys admins 2.0

“I Hunt Domain Admins”

Page 9: I hunt sys admins 2.0

“I Hunt Domain Admins”

Page 10: I hunt sys admins 2.0

User Hunting: Post DA● Red teaming isn’t about access, it’s about

data and showing impact!

● Once you get privileged access (like domain admin) there are likely specific targets you might want to go after

● Think incident response teams, CEOs, the linux team, database admins, etc.

Page 11: I hunt sys admins 2.0

Does the CEO Care?

Page 12: I hunt sys admins 2.0

How About Now?

Page 13: I hunt sys admins 2.0

Where my sysadmins at?Finding your prey

Page 14: I hunt sys admins 2.0

Existing Tools● Several tools have been written that allow

you to figure out who’s logged in where

● I’ll cover what’s already out there, including the positives/negatives for each

● “Offensive in depth”o You always want multiple ways of achieving the

same objective

Page 15: I hunt sys admins 2.0

● Component of Microsoft’s Sysinternalso “...determines who is logged on by scanning the

keys under the HKEY_USERS key.”o “To determine who is logged onto a computer via

resource shares, PsLoggedOn uses the NetSessionEnum API.”

● Needs remote registry access to determine who’s logged ino i.e. admin privileges on a remote machine

http://technet.microsoft.com/en-us/sysinternals/bb897545.aspx

psloggedon.exe

Page 16: I hunt sys admins 2.0

psloggedon.exe

Page 17: I hunt sys admins 2.0

netsess.exe● Component of

http://www.joeware.net/freetools/

● Utilizes the NetSessionEnum API callo http://msdn.microsoft.com/en-us/library/windows/des

ktop/bb525382(v=vs.85).aspx

● Think a version of “net session” that works on remote machines!o great for targeting file servers :)o no admin privs needed!

Page 18: I hunt sys admins 2.0

netsess.exe

Page 19: I hunt sys admins 2.0

PVEFindADUser.exe● Tool released by corelanc0d3r in 2009

● “Helps you find where AD users are logged in”o Can also check who’s logged into specific machines

● But “...you also need to have admin access on the computers you are running the utility against.”

https://www.corelan.be/index.php/2009/07/12/free-tool-find-where-ad-users-are-logged-on-into/

Page 20: I hunt sys admins 2.0

PVEFindADUser.exe

Page 21: I hunt sys admins 2.0

netview.exe● Rob Fuller’s (@mubix) netview.exe project,

presented at Derbycon 2012, is a tool to “enumerate systems using WinAPI calls”

● Finds all machines on the network, enumerates shares, sessions, and logged in users for each hosto And now can check share access, highlight high

value users, and use a delay/jitter :)o and also, no admin privs needed!

https://github.com/mubix/netview

Page 22: I hunt sys admins 2.0

netview.exe

Page 23: I hunt sys admins 2.0

Nmap● If you have a valid domain account, or local

account valid for several machines, you can use smb-enum-sessions.nse

● Don’t need to have admin privileges!nmap -sU -sS --script smb-enum-sessions.nse --script-args 'smbuser=jasonf,smbpass=BusinessBusinessBusiness!' -p U:137,T:139 192.168.52.0/24

http://nmap.org/nsedoc/scripts/smb-enum-sessions.html

Page 24: I hunt sys admins 2.0

Nmap

Page 25: I hunt sys admins 2.0

Smbexec● Awesome post-exploitation framework built

on top of patched Samba binaries

● The enumeration/checkda module can check machines for domain admin processes/sessions on particular targets

● However:o requires local admin on the target machineo only can target domain admins

Page 26: I hunt sys admins 2.0

Veil-Pillage● Veil-Pillage is a post-exploitation framework

conceptually similiar to Smbexec

● The enumeration/domain/group_hunter and enumeration/host/user_hunter modules will do the same tasklist and qwinsta process to hunt for specific target groups

● However:o requires local admin on the target machineo but can target more than just domain admins

Page 27: I hunt sys admins 2.0

Domain Data Sources“It’s a feature”

Page 28: I hunt sys admins 2.0

Active Directory Sources● There are a few components of Active

Directory user objects that warrant interest

● homeDirectoryo path to a user’s auto-mounted home directory

● profilePatho path to a user’s roaming profile

● Why?o Enumerating remote sessions against common

network servers lots of people use gives an excellent mapping of what users are where

Page 29: I hunt sys admins 2.0

Event Logs● Sometimes you have DA, but need to target

specific users (think the IR team :)

● If you can query the event logs on a domain controller, you can extract:o logon type (interactive/network), account name,

source network address

● @sixdub rolled this into a PowerShell script, which has since been incorporated into PowerView, more on this later

http://sixdub.net/2014/11/offensive-event-parsing-bringing-home-trophies/

Page 30: I hunt sys admins 2.0

Email Headers● If you have access to someone’s email

(Mimikatz+OWA, etc.) internal headers can provide a wealth of information

● Search for any chains to/from target users, and examine headers for given email chains

● If the “X-Originating-IP” header is present, you can trace where a user sent a given email from

Page 31: I hunt sys admins 2.0

Service Principal Names● SPNs aren’t just for machines

● Registering a service to run on a machine under a particular user account will register that machine/service for that user in ADo Makes a great place to check for users, all with a

single AD query

● Scott Sutherland (@_nullbind) has a great article on this:o https://blog.netspi.com/faster-domain-escalation-usin

g-ldap/

Page 32: I hunt sys admins 2.0

Manual Checks● To find your targets:

o net user “Domain Admins” /domain

● To find your file servers:o AdFind.exe -f "samAccountType=805306368" attr

homeDirectory | findstr /c:"homeDirectory"

● To find where your targets are:o NetSess.exe \\FILESERVER

Page 33: I hunt sys admins 2.0

Wrapping in VBScript● You can wrap some of these tools in some

basic VB script to automate it all up

● Run tool, filter for target users, etc.

● But why use VBScript, when you have...

Page 34: I hunt sys admins 2.0

PowerShell“Microsoft’s Post-Exploitation Language”

-@obscuresec

Page 35: I hunt sys admins 2.0

PowerShellz● PowerShell has some awesome AD hooks

and has various ways to access the lower-level Windows API

● You can also access the lower-level Win32 API for interesting functions○ NetSessionEnum for user sessions○ NetWkstaUserEnum for logged on users

● Thanks @mattifestation for lots of ways to access the underlying API functions!

Page 36: I hunt sys admins 2.0

Enumerating Targets● PowerView has several functions that can

help you enumerate target users and hunt them down

● Finding targets:o Get-NetGroups *wildcard* will return groups

containing specific wildcard termso Get-UserProperties will extract all user property

fields often interesting field names!

o Invoke-UserFieldSearch will search particular user fields for wildcard terms

Page 37: I hunt sys admins 2.0

Invoke-UserHunter● Flexible function that:

o queries AD for hosts or takes a target listo queries AD for users of a target group, or takes a

list/single usero uses Win32 API calls to enumerate sessions

(NetSessionEnum) and logged in users (NetWkstaUserEnum), matching against the target user list

● Can also check to see if you have local admin access on targetso but no admin privs needed to get good info!

Page 38: I hunt sys admins 2.0

Invoke-UserHunter

Page 39: I hunt sys admins 2.0

Invoke-UserHunter

Page 40: I hunt sys admins 2.0

Invoke-UserView● Several times on engagements we found

ourselves rerunning Invoke-UserHunter in order to re-hunt for specific users

● This creates a lot of unnecessary noise

● Invoke-UserView will run the exact same functions/checks that Invoke-UserHunter does, but preserves all output for later processing

Page 41: I hunt sys admins 2.0

Invoke-UserView

Page 42: I hunt sys admins 2.0

Invoke-StealthUserHunter● Uses an old red teaming trick

1. Queries AD for all users and extracts all homeDirectory fields to identify likely domain file servers

2. Runs NetSessionEnum against each file server to enumerate remote sessions, matching against target user list

● Gets reasonable coverage with a lot less traffic than UserHuntero and again, no admin privs needed

Page 43: I hunt sys admins 2.0

Invoke-StealthUserHunter

Page 44: I hunt sys admins 2.0

Invoke-StealthUserHunter

Page 45: I hunt sys admins 2.0

Invoke-UserProcessHunter● Utilizes the newly christened Get-

NetProcesseso this function makes it easy to enumerate running

processes on remote machines

● You will need admin privileges on the machines you’re enumerating

● Invoke-UserProcessHunter wraps this all up into a weaponized form

Page 46: I hunt sys admins 2.0

Invoke-UserProcessHunter

Page 47: I hunt sys admins 2.0

Invoke-UserEventHunter● Sometimes you have DA, but need to target

specific users (think the IR team :)

● Domain controller event logs make it trivial to track down domain users, provided you have domain admin access

● Get-UserLogonEvents implements @sixdub’s work on offensive event parsingo Invoke-UserEventHunt rolls this all into a

weaponized form

Page 48: I hunt sys admins 2.0

Invoke-UserEventHunter

Page 49: I hunt sys admins 2.0

Demo(s)

Page 50: I hunt sys admins 2.0

Shameless Sidebar● Want to research cool stuff like this?● Want to work with 13 x OSCPs and 3 x

OSCEs?● Want to do some sweet red teaming?● Hit me up to join Veris Group’s Adaptive

Threat Division

Page 51: I hunt sys admins 2.0

Questions?● Contact me:

o @harmj0yo will [at] harmj0y.neto harmj0y in #veil and #armitage on Freenode

● Read more:o http://blog.harmj0y.neto https://www.veil-framework.com

● Get PowerView:o https://github.com/Veil-Framework/PowerTools