post metasploitation

52
POST METASPLOITATION

Upload: egypt

Post on 14-Jan-2015

4.383 views

Category:

Technology


1 download

DESCRIPTION

Presented at Defcon 20

TRANSCRIPT

Page 1: Post Metasploitation

POST METASPLOITATION

Page 2: Post Metasploitation

egypt

Page 3: Post Metasploitation
Page 4: Post Metasploitation
Page 5: Post Metasploitation
Page 6: Post Metasploitation

WHY THIS TALK?

• Get more shells

• Get better shells

• Do more with them, faster

Page 7: Post Metasploitation

ASSUMPTIONS

• You’ve heard of Metasploit

• You’ve got a shell

• You have some goal that isn’t that shell

Page 8: Post Metasploitation

WHY METASPLOIT?

Page 9: Post Metasploitation
Page 10: Post Metasploitation

LARGE OPEN SOURCE COMMUNITY

Page 11: Post Metasploitation

> C

Page 12: Post Metasploitation

POST MODULE DESIGN

Should be minimal

• Complexity is hard to debug and maintain

• Do one thing and do it well

– Resource scripts can automate multiple modules

Page 13: Post Metasploitation

POST MODULE DESIGN

Should be readable

• Consistent structure

• Consistent option names

• Consistent output

Page 14: Post Metasploitation

POST MODULE DESIGN

Should be reliable

• Detect relevant variables

• Never crash session/host if you can avoid it

• Clean up

Page 15: Post Metasploitation

POST MODULE DEVELOPMENT

Like Aux modules in many ways

• Define a run() method

• Optional setup(), cleanup() methods

• Have Actions

• Can include Exploit / Auxiliary mixins

• Should report something

Page 16: Post Metasploitation

POST MODULE STRUCTURE

Page 17: Post Metasploitation

METASPLOIT POST API

• DSL*-like interface for automating shells

• Abstracts out common stuff

• Platform-agnostic methods for

– Reading/writing binary files

– Running shell commands

– Listing users

*Domain Specific Language

Page 18: Post Metasploitation

POST-EXPLOITATION SECRET SAUCE

Page 19: Post Metasploitation

Presence

Persistence

Pivoting

[1]: I totally stole this from Mubix

Page 20: Post Metasploitation

PRESENCE

• Examine your environment

– Users

– Machine

• One issue here is getting an unfamiliar shell

– Never played on Solaris, what do you do?

Page 21: Post Metasploitation

WHAT USERS ARE/HAVE LOGGED IN?

Page 22: Post Metasploitation

PRESENCE - THE MACHINE

• What does this box do?

• What processes are running?

– AV, Tripwire

– ssh-agent, pageant

– Editors

– Database servers

• What does it talk to?

Page 23: Post Metasploitation

WHAT DOES THIS MACHINE TALK TO?

Page 24: Post Metasploitation

PERSISTENCE

• Passwords!

• Backdoors

• Re-introducing vulnerabilities

Page 25: Post Metasploitation

TEMPORARY PERSISTENCE

• Reverse http(s) payloads

• Doesn't survive reboot but useful for keeping shells when network is spotty

Page 26: Post Metasploitation

MORE PERMANENT OPTIONS

• Autoruns

– Drop an exe in the right place, maybe mod registry

– Simple, effective

• Task scheduler, cron, launchd

• Enable RDP

• Enable root login for ssh

Page 27: Post Metasploitation

PIVOTING

• Passwords!

• Privilege escalation

• Trust relationships

• Route, portfwd

• auxiliary/server/socks4a

• Explicit "comm" arg to Rex::Socket creation

Page 28: Post Metasploitation

POST-EXPLOITATION EXPLOITATION

• For when you absolutely, positively have to have root

– (and don’t mind the occasional kernel panic)

• We can kinda blur the line between local and remote here

Page 29: Post Metasploitation

$ -> #

• Just like with network exploitation, not always an exploit

• Passwords (sudo)

• Trust relationships (suid executables)

• Misconfiguration (all sorts of shit)

Page 30: Post Metasploitation

DEMO: MULTI/LOCAL/SETUID_NMAP

"Nmap should never be installed with special privileges (e.g. suid root) for

security reasons."

Page 31: Post Metasploitation
Page 32: Post Metasploitation

DEMO: LINUX/LOCAL/SOCK_SENDPAGE

AKA Wunderbar Emporium

Page 33: Post Metasploitation
Page 34: Post Metasploitation

EXPLOIT::LOCAL

• Inherit from Exploit

– Provides payloads and handlers

– Create executables, etc

• Include Post mixins

– Provides session interaction

– Write files, manipulate registry, etc

Page 35: Post Metasploitation

COMPILING/ASSEMBLING WITH METASM

• Can compile C for x86/x86_64

• Can assemble x86, x86_64, mips, arm, ppc and more

Page 36: Post Metasploitation

TRUST RELATIONSHIPS

• Windows Authentication

– NTLM auth is relay-able

– Automatic domain auth

Page 37: Post Metasploitation

SMB RELAY

Victim

Attacker Target

Victim begins NTLM authentication against the attacker

Page 38: Post Metasploitation

SMB RELAY

Victim

Attacker Target

Attacker begins NTLM auth against Target

Page 39: Post Metasploitation

SMB RELAY

Victim

Attacker Target

Target replies with 8-byte challenge

Page 40: Post Metasploitation

SMB RELAY

Victim

Attacker Target

Attacker sends Target's challenge to Victim

Page 41: Post Metasploitation

SMB RELAY

Victim

Attacker Target

Victim calculates challenge response and replies with final authentication packet

Page 42: Post Metasploitation

SMB RELAY

Victim

Attacker Target

Attacker logs into Target with Victim's credentials

Page 43: Post Metasploitation

SMB RELAY

• Well-known attack

• Some mitigations break it, but largely still useful and will be for a long time

Page 44: Post Metasploitation

Drop LNK file (post/windows/escalate/droplnk) Setup a relay (exploit/windows/smb/smb_relay) Wait for an Admin to open that directory

File Server Compromised Target

Create LNK file

Victim

SMB RELAY + LNK FILE

Page 45: Post Metasploitation

AUTOMATIC DOMAIN AUTH

• Windows stores creds in memory and does NTLM auth using your current token

• When you do something in the GUI that requires auth, it happens automatically using those creds

• If your user has Local Admin on another box, you can create/start services (usually)

Page 46: Post Metasploitation

SC_HANDLE WINAPI OpenSCManager(

__in_opt LPCTSTR lpMachineName,

__in_opt LPCTSTR lpDatabaseName,

__in DWORD dwDesiredAccess );

Page 47: Post Metasploitation

SC_HANDLE WINAPI CreateService(

__in SC_HANDLE hSCManager,

__in LPCTSTR lpServiceName,

__in_opt LPCTSTR lpDisplayName,

__in DWORD dwDesiredAccess,

__in DWORD dwServiceType,

__in DWORD dwStartType,

__in DWORD dwErrorControl,

__in_opt LPCTSTR lpBinaryPathName,

__in_opt LPCTSTR lpLoadOrderGroup,

__out_opt LPDWORD lpdwTagId,

__in_opt LPCTSTR lpDependencies,

__in_opt LPCTSTR lpServiceStartName,

__in_opt LPCTSTR lpPassword );

Page 48: Post Metasploitation

DEMO: OWNING DC USING DA TOKEN

Yay automatic authentication

Page 49: Post Metasploitation
Page 50: Post Metasploitation

CONCLUSIONS

• Metasploit is awesomesauce

• If it doesn't already do what you need, it's easy to add new modules

• Stick around for Dave's talk!

Page 51: Post Metasploitation

• Twitter: @egyp7

• IRC: #metasploit on FreeNode

QUESTIONS?

Page 52: Post Metasploitation