# 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 %}