wielding a cortana

44
Will @harmj0y Veris Group Wielding a Cortana

Upload: harmj0y

Post on 13-Dec-2014

646 views

Category:

Technology


0 download

DESCRIPTION

These slides were presented at BSidesAustin 2014, and cover Cortana attack scripting, its background, and five implemented use cases.

TRANSCRIPT

Page 1: Wielding a cortana

Will@harmj0y

Veris Group

Wielding a Cortana

Page 2: Wielding a cortana

$ whoami

• Security researcher and penetration tester for Veris Group

• Co-founder of the Veil-Framework #avlolo www.veil-framework.como Shmoocon ‘14: AV Evasion with the Veil Frameworko co-wrote Veil-Evasion, wrote Veil-Catapult and Veil-

PowerView

• https://github.com/HarmJ0y/

• http://harmj0y.net

Page 3: Wielding a cortana

tl;dr

• Cortana? wtf

• OK that’s cool, what can I do

• Cortana use cases:o grabcreds.cna - auto hash dumpingo safetynet.cna - saving shellso veil_evasion.cna - #avlol :)o user_hunter.cna - find DAso beacon.cna - graphical beacons*

Page 4: Wielding a cortana

Cortana? wtf

• Raphael Mudge’s DARPA cyber fast track project

• Allows for the scripting of Armitage and/or Metasploit itselfo Some of this functionality is restricted to Cobalt

Strike - marked by a *

• Doesn’t seem to have publically caught ono Which is dumb, since it’s incredibly useful

Page 5: Wielding a cortana

Cortana: Why Use It

• Allows for the easy customization of an already existing, powerful tool

• Many standard pentest actions can be automated and manipulated in useful ways

• Lets you minimize the time spent doing repetitive tasks

Page 6: Wielding a cortana

Cortana Background

• Cortana is a set of extensions to the Sleep language that allows for the control of Armitage/Metasploit

• Sleep = Java-based scripting language heavily inspired by Perl and written by Raphael

o http://sleep.dashnine.org/documentation.htmlo http://www.fastandeasyhacking.com/download/corta

na/cortana_tutorial.pdf

Page 7: Wielding a cortana

Sleep 101

• “Sleep is primarily a glue language and was designed from the ground up to be embedded in Java applications…[it] brings the power of Perl to the Java platform.”

• Much of the backend of Armitage is actually written in Sleep

https://today.java.net/pub/a/today/2005/07/14/sleep.html

Page 8: Wielding a cortana

Cortana 101

• Interaction with Metasploit is baked in through utilization of MSF’s RPC interface

• You can send commands to a Meterpreter session, interact with the backend database, launch modules, etc.

• m_cmd($1, “sysinfo”);

• host_info($address);

• exploit("windows/smb/ms08_067_netapi", $addr);

Page 9: Wielding a cortana

Cortana 101

• Triggers can be set up to asynchronously fire on various actions/events:

o new sessionso meterpreter/shell commandso new hosts/services/routes/etc.

• Lets you perform contextual actions and automate a lot of post-exploitation

Page 10: Wielding a cortana

Cortana 101

Page 11: Wielding a cortana

Cortana 101

• The user interface for Armitage can be easily modified:

o new program menuso new meterpreter action menuso changeable host icons

• Lots of examples at:

https://github.com/rsmudge/cortana-scripts

https://github.com/HarmJ0y/cortana

Page 12: Wielding a cortana

Cortana Use Cases

Page 13: Wielding a cortana

Use Case #1

• On each meterpreter session that comes in, we always like to grab all credentials we can from the box:

o hashdumpo run mimikatzo see if a user we want is logged in

• ASPNET? Guest? SUPPORT_*? no thx

Page 14: Wielding a cortana

How Can Cortana Help?

• grabcreds.cnao on session_sync { … }o m_cmd($1, "wdigest");o on meterpreter_wdigest { … }

• On each host that comes in:o run hashdump and mimikatzo filter out account names we don’t wanto dump creds to the databaseo check users found against a designated listo announce results on the team chat*

Page 15: Wielding a cortana

grabcreds.cna

Page 16: Wielding a cortana

Use Case #2

• Losing shells sucks

• Our standard procedure is to inject additional sessions (or beacons*) for fallback in case our main working session dieso and not to just one C2 server

● This becomes tedious when you’re dealing with A LOT of shells and various handlers

Page 17: Wielding a cortana

How Can Cortana Help?

• safetynet.cnao on session_sync { … }o launch("post", …)

• automatically runs a payload inject module against each hosto injects a “safetynet” payload

• Problem:o we want to inject two payloads, one from the existing

process context and one into explorer.exe

Page 18: Wielding a cortana

Sidenote: smart_payload_inject.rb

• Existing payload_inject.rb only allows for injection against predefined process IDs

• smart_migrate.rb allows for “smart” migration into explorer.exe

• Combine the two -> easy injection into a specific process name, explorer.exe default

Page 19: Wielding a cortana

safetynet.cna - interface

Page 20: Wielding a cortana

Adding From Existing Listeners*

Page 21: Wielding a cortana

Custom Safetynet Payloads

Page 22: Wielding a cortana

Installing Safetynets

Page 23: Wielding a cortana

Use Case #3

• Armitage/Cobalt Strike are great, but sometimes we want specific gui modifications

• Say we want to have a Cobalt Strike workspace containing only hosts with active beacons*

*http://www.advancedpentest.com/help-beacon

Page 24: Wielding a cortana

How Can Cortana Help?

• We can grab the active beacon listo @beacons = call('beacon.list');

• We can setup ‘heartbeat’ callbacks to periodically perform actionso on heartbeat_5s {…}

• We can modify our gui in useful wayso filter host_image { …change a host’s gui image …}o bind Ctrl+B { open_beacon_browser(); }

Page 25: Wielding a cortana

Graphical Beacons

Page 26: Wielding a cortana

Use Case #4

• psexec in Metasploit is great, but the standard exe templates = no good

• Veil-Evasion does a great job at generating AV-evading executables :)

• But generating each time, reconfiguring paths, etc. is a pain

Page 27: Wielding a cortana

How Can Cortana Help?

• veil_evasion.cnao filter user_launch { … }o exec(SYSTEM COMMAND);

• Invokes Veil-Evasion to generate a binary, intercepts psexec calls in Armitage, and substitutes this in for a custom EXE

• No more caught payloads :)

Page 28: Wielding a cortana

Sidenote: swing >_<

• Exposed Cortana functions are great, but didn’t quite cover exactly what we wanted

• Luckily, Cortana scripts can integrate various java/swing GUI manipulations

• And guess what? Armitage has examples. And it’s BSD-licensed

Page 29: Wielding a cortana

Armitage Backend

Page 30: Wielding a cortana

Armitage Backend

Page 31: Wielding a cortana

veil_evasion.cna - Main Menu

Page 32: Wielding a cortana

veil_evasion.cna - Main Interface

Page 33: Wielding a cortana

Use case #5

• What’s the usual goal for a smash-and-grab pentest?

• Find out who the domain admins are

• Find where they’re logged into

• Find a set of credentials that gives us SYSTEM on their box

• psexec, pop a box, mimikatz, profit

Page 34: Wielding a cortana

Situational Awareness 101

• Manual process on the domain side:

• net user /domain

• net group /domain

• net view

• net view \\<hostname>

• net sessions \\<hostname>

Page 35: Wielding a cortana

Netview.exe

• Rub Fuller (@mubix) released a tool at Derbycon 2012 called Netview, which “enumerates systems using WinAPI calls”

• Can find hosts, shares, and logged on users across a network

• Two API calls really interest us:o NetServerEnum – enumerate (from the DC) domain

systems of a certain typeo NetWkstaUserEnum – get users logged onto a

system

Page 36: Wielding a cortana

Metasploit

• Most of this type of functionality already exists in Metasploit (of course):

• smb_enumusers_domaino uses NetWkstaUserEnum (through railgun) to get

users logged into a particular machine

• local_admin_search_enumo checks a range of IPs to see if the current user has

admin access, and grabs the logged in users with NetWkstaUserEnum as well

Page 37: Wielding a cortana

Metasploit

• enum_domain_group_userso runs “net groups GROUP /domain” against a host

and parses the results

• computer_browser_discoveryo queries the default domain controller for all hosts of

a particular type using NetServerEnum

Page 38: Wielding a cortana

user_hunter.rb

• New Metasploit module, drawing from existing functionality

• Takes a username, userlist, or domain group to query against the local DC

• Takes a host list, or runs “net view” to try to enumerate all machines on a domain

Page 39: Wielding a cortana

user_hunter.rb

• Runs NetWkstaUserEnum against each target host to determine the users logged into the machine

• Compares this against the target user list, throwing a specific user.hunter note into the database when it finds a match

• point -> click -> be told where DA’s are

Page 40: Wielding a cortana

How Can Cortana Help?

• We can interact fully with the msf databaseo @notes = call("db.notes")["notes"];

• We can setup ‘heartbeat’ callbacks to periodically perform actionso on heartbeat_5s {…}

• We can modify our gui in useful wayso filter host_image { …change a host’s gui image …}

Page 41: Wielding a cortana

Cortana – user_hunter.cna

• Cortana script that periodically polls the MSF database for our user.hunter notes

• Modifies the host icons of any systems with found userso i.e. any systems where a DA is logged into!

• Also adds an option to launch the user_hunter.rb module from any meterpreter session

Page 42: Wielding a cortana

Demo

Page 43: Wielding a cortana

Recap

• Cortana is awesome, contribute!o https://github.com/rsmudge/cortana-scriptso https://github.com/HarmJ0y/cortana

• Many standard assessment actions can be automated and manipulated in useful ways

• The less time you spend doing repetitive actions = the more you can spend pwning the client

Page 44: Wielding a cortana

Questions?

Will

@harmj0y

[email protected]

harmj0y on Freenode - #veil and #armitage

Get the cortana pack-

https://github.com/HarmJ0y/cortana