# WmiExec
{% hint style="success" %}
Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** ๐ฌ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** ๐ฆ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
## How It Works Explained
ํ๋ก์ธ์ค๋ ์ฌ์ฉ์ ์ด๋ฆ๊ณผ ๋น๋ฐ๋ฒํธ ๋๋ ํด์๊ฐ ์๋ ค์ง ํธ์คํธ์์ WMI๋ฅผ ์ฌ์ฉํ์ฌ ์ด ์ ์์ต๋๋ค. Wmiexec๋ฅผ ์ฌ์ฉํ์ฌ WMI๋ฅผ ํตํด ๋ช
๋ น์ด ์คํ๋๋ฉฐ, ๋ฐ๋ํ๋ฉด ์
ธ ๊ฒฝํ์ ์ ๊ณตํฉ๋๋ค.
**dcomexec.py:** ๋ค์ํ DCOM ์๋ํฌ์ธํธ๋ฅผ ํ์ฉํ์ฌ ์ด ์คํฌ๋ฆฝํธ๋ wmiexec.py์ ์ ์ฌํ ๋ฐ๋ํ๋ฉด ์
ธ์ ์ ๊ณตํ๋ฉฐ, ํนํ ShellBrowserWindow DCOM ๊ฐ์ฒด๋ฅผ ํ์ฉํฉ๋๋ค. ํ์ฌ MMC20, Application, Shell Windows ๋ฐ Shell Browser Window ๊ฐ์ฒด๋ฅผ ์ง์ํฉ๋๋ค. (์ถ์ฒ: [Hacking Articles](https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/))
## WMI Fundamentals
### Namespace
๋๋ ํ ๋ฆฌ ์คํ์ผ์ ๊ณ์ธต ๊ตฌ์กฐ๋ก ๊ตฌ์ฑ๋ WMI์ ์ต์์ ์ปจํ
์ด๋๋ \root์ด๋ฉฐ, ๊ทธ ์๋์ ๋ค์์คํ์ด์ค๋ผ๊ณ ๋ถ๋ฆฌ๋ ์ถ๊ฐ ๋๋ ํ ๋ฆฌ๊ฐ ์กฐ์ง๋์ด ์์ต๋๋ค.
๋ค์์คํ์ด์ค๋ฅผ ๋์ดํ๋ ๋ช
๋ น:
```bash
# Retrieval of Root namespaces
gwmi -namespace "root" -Class "__Namespace" | Select Name
# Enumeration of all namespaces (administrator privileges may be required)
Get-WmiObject -Class "__Namespace" -Namespace "Root" -List -Recurse 2> $null | select __Namespace | sort __Namespace
# Listing of namespaces within "root\cimv2"
Get-WmiObject -Class "__Namespace" -Namespace "root\cimv2" -List -Recurse 2> $null | select __Namespace | sort __Namespace
```
๋ค์์คํ์ด์ค ๋ด์ ํด๋์ค๋ฅผ ๋์ดํ๋ ค๋ฉด ๋ค์์ ์ฌ์ฉํฉ๋๋ค:
```bash
gwmwi -List -Recurse # Defaults to "root\cimv2" if no namespace specified
gwmi -Namespace "root/microsoft" -List -Recurse
```
### **ํด๋์ค**
WMI ํด๋์ค ์ด๋ฆ, ์๋ฅผ ๋ค์ด win32\_process, ๋ฐ ๊ทธ๊ฒ์ด ์์นํ ๋ค์์คํ์ด์ค๋ฅผ ์๋ ๊ฒ์ ๋ชจ๋ WMI ์์
์ ์ค์ํฉ๋๋ค.
`win32`๋ก ์์ํ๋ ํด๋์ค๋ฅผ ๋์ดํ๋ ๋ช
๋ น:
```bash
Get-WmiObject -Recurse -List -class win32* | more # Defaults to "root\cimv2"
gwmi -Namespace "root/microsoft" -List -Recurse -Class "MSFT_MpComput*"
```
ํด๋์ค ํธ์ถ:
```bash
# Defaults to "root/cimv2" when namespace isn't specified
Get-WmiObject -Class win32_share
Get-WmiObject -Namespace "root/microsoft/windows/defender" -Class MSFT_MpComputerStatus
```
### Methods
๋ฉ์๋๋ WMI ํด๋์ค์ ํ๋ ์ด์์ ์คํ ๊ฐ๋ฅํ ํจ์๋ก, ์คํํ ์ ์์ต๋๋ค.
```bash
# Class loading, method listing, and execution
$c = [wmiclass]"win32_share"
$c.methods
# To create a share: $c.Create("c:\share\path","name",0,$null,"My Description")
```
```bash
# Method listing and invocation
Invoke-WmiMethod -Class win32_share -Name Create -ArgumentList @($null, "Description", $null, "Name", $null, "c:\share\path",0)
```
## WMI ์ด๊ฑฐ
### WMI ์๋น์ค ์ํ
WMI ์๋น์ค๊ฐ ์๋ํ๋์ง ํ์ธํ๋ ๋ช
๋ น:
```bash
# WMI service status check
Get-Service Winmgmt
# Via CMD
net start | findstr "Instrumentation"
```
### ์์คํ
๋ฐ ํ๋ก์ธ์ค ์ ๋ณด
WMI๋ฅผ ํตํด ์์คํ
๋ฐ ํ๋ก์ธ์ค ์ ๋ณด ์์ง:
```bash
Get-WmiObject -ClassName win32_operatingsystem | select * | more
Get-WmiObject win32_process | Select Name, Processid
```
๊ณต๊ฒฉ์์๊ฒ WMI๋ ์์คํ
๋๋ ๋๋ฉ์ธ์ ๋ํ ๋ฏผ๊ฐํ ๋ฐ์ดํฐ๋ฅผ ์ด๊ฑฐํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ์
๋๋ค.
```bash
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
```
์๊ฒฉ์ผ๋ก WMI๋ฅผ ์ฟผ๋ฆฌํ์ฌ ๋ก์ปฌ ๊ด๋ฆฌ์๋ ๋ก๊ทธ์ธํ ์ฌ์ฉ์์ ๊ฐ์ ํน์ ์ ๋ณด๋ฅผ ์ป๋ ๊ฒ์ ์ ์คํ ๋ช
๋ น ๊ตฌ์ฑ์ผ๋ก ๊ฐ๋ฅํฉ๋๋ค.
### **์๋ ์๊ฒฉ WMI ์ฟผ๋ฆฌ**
์๊ฒฉ ๋จธ์ ์์ ๋ก์ปฌ ๊ด๋ฆฌ์๋ฅผ ์๋ฐํ๊ฒ ์๋ณํ๊ณ ๋ก๊ทธ์ธํ ์ฌ์ฉ์๋ฅผ ํ์ธํ๋ ๊ฒ์ ํน์ WMI ์ฟผ๋ฆฌ๋ฅผ ํตํด ๋ฌ์ฑํ ์ ์์ต๋๋ค. `wmic`๋ ์ฌ๋ฌ ๋
ธ๋์์ ๋์์ ๋ช
๋ น์ ์คํํ๊ธฐ ์ํด ํ
์คํธ ํ์ผ์์ ์ฝ๋ ๊ฒ๋ ์ง์ํฉ๋๋ค.
WMI๋ฅผ ํตํด ํ๋ก์ธ์ค๋ฅผ ์๊ฒฉ์ผ๋ก ์คํํ๊ธฐ ์ํด, ์๋ฅผ ๋ค์ด Empire ์์ด์ ํธ๋ฅผ ๋ฐฐํฌํ๋ ๊ฒฝ์ฐ, ๋ค์๊ณผ ๊ฐ์ ๋ช
๋ น ๊ตฌ์กฐ๊ฐ ์ฌ์ฉ๋๋ฉฐ, ์ฑ๊ณต์ ์ธ ์คํ์ "0"์ ๋ฐํ ๊ฐ์ผ๋ก ํ์๋ฉ๋๋ค:
```bash
wmic /node:hostname /user:user path win32_process call create "empire launcher string here"
```
์ด ํ๋ก์ธ์ค๋ ์๊ฒฉ ์คํ ๋ฐ ์์คํ
์ด๊ฑฐ๋ฅผ ์ํ WMI์ ๊ธฐ๋ฅ์ ๋ณด์ฌ์ฃผ๋ฉฐ, ์์คํ
๊ด๋ฆฌ ๋ฐ ์นจํฌ ํ
์คํธ ๋ชจ๋์ ๋ํ ์ ์ฉ์ฑ์ ๊ฐ์กฐํฉ๋๋ค.
## References
* [https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-3-wmi-and-winrm/](https://blog.ropnop.com/using-credentials-to-own-windows-boxes-part-2-psexec-and-services/)
## Automatic Tools
* [**SharpLateral**](https://github.com/mertdas/SharpLateral):
{% code overflow="wrap" %}
```bash
SharpLateral redwmi HOSTNAME C:\\Users\\Administrator\\Desktop\\malware.exe
```
{% endcode %}
{% hint style="success" %}
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
HackTricks ์ง์ํ๊ธฐ
* [**๊ตฌ๋
๊ณํ**](https://github.com/sponsors/carlospolop) ํ์ธํ๊ธฐ!
* **๐ฌ [**Discord ๊ทธ๋ฃน**](https://discord.gg/hRep4RUj7f) ๋๋ [**ํ
๋ ๊ทธ๋จ ๊ทธ๋ฃน**](https://t.me/peass)์ ์ฐธ์ฌํ๊ฑฐ๋ **Twitter** ๐ฆ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**๋ฅผ ํ๋ก์ฐํ์ธ์.**
* **[**HackTricks**](https://github.com/carlospolop/hacktricks) ๋ฐ [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.**
{% endhint %}