当实战中
我们想在目标上运行一些相当复杂的功能,这些功能常是
EXE 文件的一部分。我不想直接在目标上放置一个二进制文件,因为这样可能会触发反病毒机制。
一个很好的思路就是
将二进制文件嵌入到
Powershell 脚本中,并直接通过脚本运行而不用将其写入到磁盘里。
大致思路流程
:将我们需要执行的
exe文件二进制进过编码转换成字符串,使其成为powershell脚本的一部分,再直接加载进内存运行。
靶机环境
:192.168.5.83 windows 8 x86
需求
:将helloworld.exe用powershell加载进内存运行
单独运行
helloworld.exe效果:
0x01
将二进制文件进行
base64
编码
可以使用以下函数:
function Convert-BinaryToString {
[CmdletBinding()] param (
[string] $FilePath
try {
$ByteArray = [System.IO.File]::ReadAllBytes($FilePath);
catch {
throw "Failed to read file. Ensure that you have permission to the file, and that the file path is correct.";
if ($ByteArray) {
$Base64String = [System.Convert]::ToBase64String($ByteArray);
else {
throw '$ByteArray is $null.';
Write-Output -InputObject $Base64String;
根据嵌入的不同二进制文件,可能会出现以下错误:
PE platform doesn’t match the architecture of the process it is being loaded in (32/64bit)
解决这个问题只需要运行 32 位的 PowerShell 即可。
静有所思,思有所想
------------------------------------------------------------------------------------
mail: 779783493@qq.com