您好,我在記憶體中找到了執行 .NET exe 檔案的代碼:
$ByteArray = (Invoke-WebRequest "https://cdn.discordapp.com/attachments/1033846522636410930/1036311327850901636/DOTNETcsharpErrorBox.exe").Content
# Base64
$Base64String = [System.Convert]::ToBase64String($ByteArray);
$PsEBytes = [System.Convert]::FromBase64String($Base64String)
# Run EXE in memory
$assembly = [System.Reflection.Assembly]::Load($PsEBytes)
# Get the static method that is the executable's entry point.
# Note:
# * Assumes 'Program' as the class name,
# and a static method named 'Main' as the entry point.
# * Should there be several classes by that name, the *first*
# - public or non-public - type returned is used.
# If you know the desired type's namespace, use, e.g.
# $assembly.GetType('MyNameSpace.Program').GetMethod(...)
$entryPointMethod =
$assembly.GetTypes().Where({ $_.Name -eq 'Program' }, 'First').
GetMethod('Main', [Reflection.BindingFlags] 'Static, Public, NonPublic')
# Now you can call the entry point.
# This example passes two arguments, 'foo' and 'bar'
$entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
它適用于 .NET C# 控制臺應用程式 exe 檔案,但我嘗試了 .NET C# 表單應用程式 exe 檔案,但它給了我這個錯誤:
您不能對空值運算式呼叫方法。在 C:\Users\sadettin\Desktop\PE.ps1:30 字符:1
- $entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
CategoryInfo : InvalidOperation: (:) [], RuntimeException FullyQualifiedErrorId : InvokeMethodOnNull
但它適用于控制臺應用程式 exe 檔案!?有點奇怪...
我認為這部分的問題:$entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
我應該做什么或添加到此代碼???我是新手,也許有一件我不知道的簡單事情
uj5u.com熱心網友回復:
您的癥狀暗示變數$entryPointMethod包含$null,這反過來又暗示以下呼叫已回傳$null:
$assembly.GetTypes().Where({ $_.Name -eq 'Program' }, 'First').
GetMethod('Main', [Reflection.BindingFlags] 'Static, Public, NonPublic')
這意味著Program程式集中不存在名為 的類,或者它沒有名為 的方法Main。
如果您的程式集有一個命令列入口點,它確實有一個Main方法,但不一定在Program類中:雖然類名Program很常見,但給定的應用程式可以自由選擇不同的類名。
此外,Windows 表單應用程式通常不接受命令列引數,因此即使您確定了正確的方法,諸如 之類的呼叫$entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))也可能會失敗。
因此,請嘗試以下操作:
# Find ANY 'Main' method, regardless of the name of the class it is a part of.
$entryPointMethod =
@(
$assembly.GetTypes().GetMethod(
'Main',
[Reflection.BindingFlags] 'Static, Public, NonPublic'
)
) -ne $null
if ($null -eq $entryPointMethod) {
throw "No 'Main' method found; the assembly doesn't have a CLI entry point."
} elseif ($entryPointMethod.Count -gt 1) {
throw "MULTIPLE 'Main' methods found."
}
# Now you can call the entry point, without arguments in this example.
$entryPointMethod.Invoke($null, $null)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/537445.html
