mirror of
https://github.com/nettitude/PoshC2
synced 2026-06-08 16:22:47 +00:00
37 lines
1.1 KiB
PowerShell
37 lines
1.1 KiB
PowerShell
<#
|
|
.Synopsis
|
|
Execute Sharp Assembly in PowerhShell
|
|
.DESCRIPTION
|
|
Execute Sharp Assembly in PowerhShell
|
|
.EXAMPLE
|
|
PS C:\> Invoke-Sharp -asmName "ASMNAME" -asmArgs @("--listAll", "local", "\")
|
|
.EXAMPLE
|
|
PS C:\> Invoke-Sharp -asmName "ASMNAME" -asmArgs @("--addTask", "local", "09:30", "\", "TaskName", "Task Description", "C:\Windows\system32\cmd.exe", "/c calc.exe")
|
|
#>
|
|
function Invoke-Sharp {
|
|
param (
|
|
[string]$asmName,
|
|
[string[]]$asmArgs
|
|
)
|
|
$sw = New-Object System.IO.StringWriter
|
|
$originalOut = [Console]::Out
|
|
try {
|
|
[Console]::SetOut($sw)
|
|
$asm = [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq $asmName }
|
|
if ($asm -and $asm.EntryPoint) {
|
|
echo "[+] Found Assembly"
|
|
$asm.EntryPoint.Invoke($null, @(, $asmArgs))
|
|
} else {
|
|
echo "[-] Assembly Not Found"
|
|
}
|
|
} finally {
|
|
$sw.Flush()
|
|
[Console]::SetOut($originalOut)
|
|
}
|
|
$output = $sw.ToString()
|
|
$sw.Close()
|
|
return $output
|
|
}
|
|
function List-Assemblies {
|
|
[AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object { $_.FullName }
|
|
} |