Script PowerShell Check IP via API(VirusTotal, AbuseIPDB)

SoNaJaa_!!
3 min readFeb 1, 2025

--

#Check_IP_Reputation
#เป็นเพียงแนวคิดหรือความคิดของผู้เขียนผิดพลาดประการใดต้องขออภัยด้วยครับจัดทำขึ้นมาเพื่อShareครับโดยไม่มีจุดประสงค์อื่นครับ

Script PowerShell Check IP via API(VirusTotal, AbuseIPDB). หรือถ้ามี TI อื่น ๆก็เอา API มา เพิ่มเติมได้เลยนะครับ อันนี้เป็นแค่ Example:
ปกติแล้ว เวลาที่เราต้องการ Check IP Reputation เรามักจะเปิด VirusTotal เป็นเว็บไซต์แรก ๆ ใช่ไหมครับ? 😆 แต่ปัญหาคือ ถ้ามีหลาย ๆ IP เราต้องเปิดหลายแท็บในเบราว์เซอร์ ซึ่งบางครั้งก็ลืมไปแล้วว่าเช็ก IP นี้ไปหรือยัง 555!

นอกจากนี้ บางครั้งเรายังต้องเปรียบเทียบกับ Threat Intelligence (TI) อื่น ๆ ด้วย เพื่อยืนยันว่า IP ที่เราตรวจสอบมีความเสี่ยงจริง ก่อนจะทำการ block หรือตรวจสอบความเสี่ยง ของ IP ต่าง ๆ อะครับ
เพื่อแก้ปัญหานี้ ผมลองเขียน PowerShell Script ขึ้นมา เพื่อช่วยประหยัดเวลาในการ Re-Check นอกจากนี้ยังสามารถ export ผลลัพธ์เป็น CSV ได้ด้วย ทำข้อมูลเพิ่มเติม แบบว่า อ่อ IP พวกนี้มันมีความเสี่ยงจริง ๆ

รายละเอียดเพิ่มเติมดูได้ด้านล่างครับ! 🚀

# ⚠️ Replace these with your actual API keys ⚠️

$VirusTotalAPIKey = “fe9560620695483xxxxxxxxxxxxx”

$AbuseIPDBAPIKey = “f61e0f11fe421f0cf8f095f8xxxxxxxxxxxxx”

# List of IP addresses to check

$IPAddresses = @(“14.103.93.44”, “209.38.228.147”, “202.157.176.165”, “180.106.83.59”, “92.222.141.85”, “122.49.220.99”, “182.229.12.141”)

# Define the output CSV file

$timestamp = Get-Date -Format “yyyyMMdd_HHmmss”

$csvFile = “.\IP_Report_$timestamp.csv”

# Initialize an empty array for storing results

$ReportData = @()

# Function to check IP with VirusTotal

function Check-IPVirusTotal {

param ([string]$IPAddress)

# VirusTotal API URL

$url = “https://www.virustotal.com/api/v3/ip_addresses/$IPAddress"

# Headers

$headers = @{

“x-apikey” = $VirusTotalAPIKey

}

try {

# API Request

$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get

# Extract analysis results

$data = $response.data.attributes

$totalEngines = $data.last_analysis_stats.malicious + $data.last_analysis_stats.harmless + $data.last_analysis_stats.suspicious

$maliciousCount = $data.last_analysis_stats.malicious

# Return structured data

return @{

“VirusTotal_MaliciousCount” = $maliciousCount

“VirusTotal_TotalEngines” = $totalEngines

}

}

catch {

Write-Host “❌ Error checking $IPAddress on VirusTotal.” -ForegroundColor Red

return @{

“VirusTotal_MaliciousCount” = “Error”

“VirusTotal_TotalEngines” = “Error”

}

}

}

# Function to check IP with AbuseIPDB

function Check-IPAbuseIPDB {

param ([string]$IPAddress)

# AbuseIPDB API URL

$url = “https://api.abuseipdb.com/api/v2/check?ipAddress=$IPAddress&maxAgeInDays=90"

# Headers

$headers = @{

“Key” = $AbuseIPDBAPIKey

“Accept” = “application/json”

}

try {

# API Request

$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get

# Extract reputation data

$abuseConfidence = $response.data.abuseConfidenceScore

$totalReports = $response.data.totalReports

$lastReportedAt = $response.data.lastReportedAt

# Return structured data

return @{

“AbuseIPDB_ConfidenceScore” = $abuseConfidence

“AbuseIPDB_TotalReports” = $totalReports

“AbuseIPDB_LastReportedAt” = $lastReportedAt

}

}

catch {

Write-Host “❌ Error checking $IPAddress on AbuseIPDB.” -ForegroundColor Red

return @{

“AbuseIPDB_ConfidenceScore” = “Error”

“AbuseIPDB_TotalReports” = “Error”

“AbuseIPDB_LastReportedAt” = “Error”

}

}

}

# Loop through each IP and check both VirusTotal & AbuseIPDB

foreach ($IP in $IPAddresses) {

Write-Host “ — — — — — — — — — — — — — — — — — — — — “ -ForegroundColor Cyan

Write-Host “Checking IP: $IP” -ForegroundColor Yellow

Write-Host “ — — — — — — — — — — — — — — — — — — — — “

$VTResults = Check-IPVirusTotal -IPAddress $IP

Start-Sleep -Seconds 15 # Prevent API rate limit issues

$AbuseResults = Check-IPAbuseIPDB -IPAddress $IP

Start-Sleep -Seconds 2 # Prevent API rate limit issues

# Combine results into one object

$ReportEntry = [PSCustomObject]@{

“IP Address” = $IP

“VirusTotal Malicious Count” = $VTResults[“VirusTotal_MaliciousCount”]

“VirusTotal Total Engines” = $VTResults[“VirusTotal_TotalEngines”]

“AbuseIPDB Confidence Score” = $AbuseResults[“AbuseIPDB_ConfidenceScore”]

“AbuseIPDB Total Reports” = $AbuseResults[“AbuseIPDB_TotalReports”]

“AbuseIPDB Last Reported At” = $AbuseResults[“AbuseIPDB_LastReportedAt”]

“Timestamp” = Get-Date -Format “yyyy-MM-dd HH:mm:ss”

}

# Add to the report data array

$ReportData += $ReportEntry

}

# Export results to CSV

$ReportData | Export-Csv -Path $csvFile -NoTypeInformation -Encoding UTF8

Write-Host “`n✅ Report saved to: $csvFile” -ForegroundColor Green

Example: Script PowerShell (Change API Key.)

Example: Script PowerShell

Example Export CSV File

Example Export CSV File

Remark: ประหยัดเวลาในการตรวจสอบ และก็ มี Report ยืนยันด้วยฮะ!!!🙏🙏

Remark: สำหรับตรงนี้ จุดประสงค์ของ Admin เกี่ยวกับ Script PowerShell Check TI ตรงนี้คือ Admin จะเอามา Check IOCs Backlist ที่ อยู่ใน Policy ทุก ๆ 6 เดือนว่า ค่า Score IP นั้น ๆ ที่เคย Blocked อยู่บน Policy IP Backlist นั้นว่ามัน กลับมาปกติยัง ถ้ากลับมาเป็นปกติแล้วก็เอา IP นั้นออกจาก Policy แบบว่าเป็นการ Review IP Backlist in Policy ครับ🙏🙏🙏🙏🙏🙏🙏

ใครเห็นด้วยหรือมีความคิดเห็นยังไงมาแชร์กันได้นะครับ ขอบคุณทุกคนที่เข้ามาอ่านครับ! 🙏
#หวังว่าเนื้อหานี้จะเป็นประโยชน์กับทุกคนครับแล้วเจอกันใหม่ในบทความต่อไปครับ!
#แบ่งปัน
#เป็นเพียงแนวคิดหรือความคิดของผู้เขียนผิดพลาดประการใดต้องขออภัยด้วยครับ
#การเรียนรู้ไม่มีที่สิ้นสุด_เล่นไปเรื่อยๆ_ยิ่งเล่นยิ่งสนุก
#ผู้เขียนจัดทำเพื่อแชร์ความรู้และประสบการณ์นะครับผิดพลาดประการใดต้องขออภัยด้วยครับ
#มือใหม่กำลังหัดเขียนมีอะไรแนะนำได้เลยนะครับ
#Share_Knowledge_and_Experience

--

--

SoNaJaa_!!
SoNaJaa_!!

Written by SoNaJaa_!!

My Dream is Specialist Cybersecurity | Threat Hunting, DFIR | Blue Team | Red Team.

No responses yet