Dalam lanskap digital saat ini, dengan cepat memahami apa yang terjadi di balik layar pada mesin individu bisa sangat penting. Memperkenalkan Connartistskrip PowerShell yang ramping dan intuitif yang dirancang khusus untuk memantau koneksi jaringan pada titik akhir tunggal – ideal untuk pemeriksaan keamanan atau tugas diagnostik tanpa memerlukan alat kelas berat seperti Wireshark.
Apa itu Connartist?
Connartist adalah alat pemantauan jaringan berbasis PowerShell yang sederhana namun kuat yang dibangun khusus untuk titik akhir tunggal. Sempurna untuk pemeriksaan cepat oleh analis keamanan, sysadmins, atau dukungan teknis, Connartist membantu Anda dengan cepat mengidentifikasi aktivitas jaringan yang tidak terduga atau bermasalah.
Dengan Connartist, Anda dapat:
- Log koneksi TCP aktif bersama dengan proses yang bertanggung jawab.
- Secara opsional menangkap kueri DNS yang dibuat oleh titik akhir.
- Saring lalu lintas IP lokal (pribadi) untuk log ringkas.
- Terus memantau dan mencegah penebangan berlebihan melalui deteksi duplikat pintar.
Bagaimana cara kerja Connartist?
Begini cara beroperasi:
Inisialisasi
Skrip mengajukan dua pertanyaan langsung:
- Apakah akan menyaring lalu lintas lokal (IP pribadi).
- Apakah akan menangkap kueri DNS.
Berdasarkan tanggapan Anda, Connartist menyesuaikan pemantauannya dengan tepat.
Pemantauan aktif
Connartist terus menerus:
- Log Koneksi TCP Aktif, termasuk metadata terperinci (waktu, proses, alamat jarak jauh, host jarak jauh).
- Secara opsional mencatat kueri DNS, menangkap nama kueri dan cap waktu.
- Menghindari entri duplikat dengan mempertahankan pelacakan internal.
Hapus logging
Data yang ditangkap diformat dengan rapi dan disimpan secara lokal:
- Koneksi TCP dicatat
tcp_log.txt
. - Kueri DNS disimpan di
dns_log.txt
.
Menerapkan Connartist
Langkah 1: Persiapan
- Simpan skrip PowerShell yang disediakan sebagai
ConnArtist.ps1
. - Pastikan Anda memiliki izin untuk menulis log (
C:\Users\Public\
).
Langkah 2: Eksekusi
-
Jalankan PowerShell sebagai administrator.
-
Jalankan skrip:
powershell.exe -ExecutionPolicy Bypass -File "C:\Path\To\ConnArtist.ps1"
-
Jawab petunjuk tentang penyaringan lalu lintas lokal dan penangkapan DNS berdasarkan kasus penggunaan Anda.
Langkah 3: Pemantauan Berkelanjutan
- Connartist memantau jaringan setiap 5 detik, memberikan wawasan waktu nyata.
- Tekan
Ctrl+C
untuk berhenti memantau kapan saja.
Contoh penggunaan kasus
- Pemeriksaan Keamanan: Identifikasi koneksi eksternal yang tidak terduga dengan cepat yang dapat menunjukkan malware atau aktivitas yang tidak sah.
- Tugas Diagnostik: Memecahkan masalah konektivitas dengan menunjukkan koneksi bermasalah atau resolusi DNS.
Menyesuaikan Connartist
Sesuaikan lokasi atau interval log sesuai kebutuhan:
$tcpLogFile = "C:\Users\Public\tcp_log.txt"
$dnsLogFile = "C:\Users\Public\dns_log.txt"
# Modify monitoring interval as desired
Start-Sleep -Seconds 5
Menyesuaikan pemfilteran jaringan lokal
Untuk pemfilteran yang akurat, Anda mungkin perlu menyesuaikan rentang IP pribadi jaringan lokal Anda. Ubah fungsi berikut untuk mencocokkan oktet jaringan Anda:
function IsPrivateIP($ipAddress) {
try {
$ip = [System.Net.IPAddress]::Parse($ipAddress)
if ($ip.AddressFamily -eq 'InterNetwork') { # IPv4
return ($ipAddress -like '10.*' -or
$ipAddress -like '172.16.*' -or
$ipAddress -like '192.168.*') # Modify these octets to your local network range
} elseif ($ip.AddressFamily -eq 'InterNetworkV6') { # IPv6
return ($ip.IsIPv6LinkLocal -or $ip.IsIPv6SiteLocal)
} else {
return $false
}
} catch {
return $false
}
}
Mengapa Menggunakan Connartist?
- Ringan: Tidak diperlukan instalasi atau pengaturan kompleks.
- Wawasan yang jelas: Log yang mudah dan mudah dibaca.
- Fokus: Dirancang untuk pemeriksaan poinpoint pada titik akhir tunggal.
- Pemantauan real-time: Deteksi cepat kegiatan yang tidak biasa atau masalah koneksi.
Connartist menyederhanakan visibilitas jaringan titik akhir, memungkinkan identifikasi cepat masalah keamanan potensial atau masalah pemecahan masalah jaringan dengan cepat dan efektif.
Selamat memantau!
#Another /\_[]_/\
# fine |] _||_ [|
# ___ \/ || \/
# /___\ ||
# (|0 0|) ||
# __/{\U/}\_ ___/vvv
# / \ {~} / _|_P|
# | /\ ~ /_/ []
# |_| (____)
# \_]/______\ Barberion
# _\_||_/_ Production
# (_,_||_,_)
#
# Define log file paths for TCP and DNS logs
$tcpLogFile = "C:\Users\Public\tcp_log.txt"
$dnsLogFile = "C:\Users\Public\dns_log.txt"
# Function to check if an IP address is private
function IsPrivateIP($ipAddress) {
try {
$ip = [System.Net.IPAddress]::Parse($ipAddress)
if ($ip.AddressFamily -eq 'InterNetwork') { # IPv4
return ($ipAddress -like '10.*' -or
$ipAddress -like '172.16.*' -or
$ipAddress -like '192.168.*')
} elseif ($ip.AddressFamily -eq 'InterNetworkV6') { # IPv6
return ($ip.IsIPv6LinkLocal -or $ip.IsIPv6SiteLocal)
} else {
return $false
}
} catch {
return $false
}
}
# Ask the user if they want to filter out local traffic
$filterPrivateIPs = (Read-Host "Do you want to filter out local traffic? (yes/no)").Trim().ToLower()
$filterPrivate = $filterPrivateIPs -eq 'yes' -or $filterPrivateIPs -eq 'y'
# Ask the user if they want to capture DNS requests
$dnsCaptureInput = (Read-Host "Do you want to capture DNS requests? (yes/no)").Trim().ToLower()
$captureDNS = $dnsCaptureInput -eq 'yes' -or $dnsCaptureInput -eq 'y'
# Output the monitoring message at the top
Write-Host "Monitoring network connections. Press Ctrl+C to stop."
Add-Content -Path $tcpLogFile -Value "Monitoring TCP connections. Press Ctrl+C to stop."
Add-Content -Path $dnsLogFile -Value "Monitoring DNS connections. Press Ctrl+C to stop."
# Define the headers
$tcpHeader = "{0,-20} {1,-20} {2,-25} {3}" -f "Date/Time", "Process", "Remote Address", "Remote Host"
$dnsHeader = "{0,-20} {1,-30}" -f "Date/Time", "DNS Query"
Write-Host $tcpHeader
Write-Host ("-" * 90)
Add-Content -Path $tcpLogFile -Value $tcpHeader
Add-Content -Path $tcpLogFile -Value ("-" * 90)
if ($captureDNS) {
$dnsLogName = "Microsoft-Windows-DNS-Client/Operational"
if (-not (Get-WinEvent -ListLog $dnsLogName).IsEnabled) {
Write-Host "Enabling DNS client operational log..."
try {
wevtutil sl $dnsLogName /e:true
} catch {
Write-Host "Failed to enable DNS client operational log. You may need to run PowerShell as Administrator."
$captureDNS = $false
}
}
if ($captureDNS) {
# Initialize the last DNS check time
$lastDNSCheckTime = Get-Date
# Output the DNS header
Write-Host $dnsHeader
Write-Host ("-" * 50)
Add-Content -Path $dnsLogFile -Value $dnsHeader
Add-Content -Path $dnsLogFile -Value ("-" * 50)
}
}
# To prevent duplication, maintain hashsets of logged connections and DNS queries
$loggedConnections = @{}
$loggedDNSQueries = @{}
while ($true) {
# Get current network connections
$currentConnections = Get-NetTCPConnection -State Established
if ($filterPrivate) {
$currentConnections = $currentConnections | Where-Object {
$_.RemoteAddress -ne '127.0.0.1' -and
$_.RemoteAddress -ne '::1'
}
}
foreach ($conn in $currentConnections) {
$connectionKey = "$($conn.OwningProcess)|$($conn.RemoteAddress):$($conn.RemotePort)"
if (-not $loggedConnections.ContainsKey($connectionKey)) {
if (-not $filterPrivate -or (-not (IsPrivateIP $conn.RemoteAddress))) {
$dateTime = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$process = Get-Process -Id $conn.OwningProcess -ErrorAction SilentlyContinue
$processName = if ($process) { $process.ProcessName } else { 'N/A' }
$remoteHost = $conn.RemoteAddress
try {
$dnsEntry = [System.Net.Dns]::GetHostEntry($conn.RemoteAddress)
$remoteHost = $dnsEntry.HostName
} catch {
# Could not resolve host
}
$remoteAddressPort = "$($conn.RemoteAddress):$($conn.RemotePort)"
$logEntry = "TCP {0,-20} {1,-20} {2,-25} {3}" -f $dateTime, $processName, $remoteAddressPort, $remoteHost
Add-Content -Path $tcpLogFile -Value $logEntry
Write-Host $logEntry
# Add the connection to the loggedConnections hashset to prevent future duplicates
$loggedConnections[$connectionKey] = $true
}
}
}
if ($captureDNS) {
try {
# Get new DNS query events
$dnsEvents = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-DNS-Client/Operational';
Id = 3008;
StartTime = $lastDNSCheckTime
} -ErrorAction SilentlyContinue
if ($dnsEvents) {
foreach ($event in $dnsEvents) {
$dateTime = $event.TimeCreated.ToString('yyyy-MM-dd HH:mm:ss')
$queryName = $event.Properties[0].Value
if (-not $loggedDNSQueries.ContainsKey($queryName)) {
$dnsEntry = "DNS {0,-20} {1,-30}" -f $dateTime, $queryName
Add-Content -Path $dnsLogFile -Value $dnsEntry
Write-Host $dnsEntry
# Add the DNS query to the loggedDNSQueries hashset to prevent future duplicates
$loggedDNSQueries[$queryName] = $true
}
}
# Update the last DNS check time
$lastDNSCheckTime = Get-Date
}
} catch {
# Suppress any errors related to DNS event fetching
}
}
Start-Sleep -Seconds 5
}