-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
225d67a
commit 6e17608
Showing
5 changed files
with
121 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package apis | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"soc-cli/internal/util" | ||
) | ||
|
||
const abuseAPIURL = "https://api.abuseipdb.com/api/v2/check?ipAddress=%s&maxAgeInDays=90" | ||
|
||
type abuseIPDBResponse struct { | ||
Data struct { | ||
IPAddress string `json:"ipAddress"` | ||
IsPublic bool `json:"isPublic"` | ||
IPVersion int `json:"ipVersion"` | ||
IsWhitelisted bool `json:"isWhitelisted"` | ||
AbuseConfidenceScore int `json:"abuseConfidenceScore"` | ||
CountryCode string `json:"countryCode"` | ||
UsageType string `json:"usageType"` | ||
ISP string `json:"isp"` | ||
Domain string `json:"domain"` | ||
Hostnames []string `json:"hostnames"` | ||
TotalReports int `json:"totalReports"` | ||
LastReportedAt string `json:"lastReportedAt"` | ||
Reports []struct { | ||
ReporterID int `json:"reporterId"` | ||
ReporterCountry string `json:"reporterCountry"` | ||
ReportedAt string `json:"reportedAt"` | ||
Comment string `json:"comment"` | ||
} `json:"reports"` | ||
} `json:"data"` | ||
} | ||
|
||
// getAbuseIPDBInfo fetches data from AbuseIPDB for a specific IP address | ||
func GetAbuseIPDBInfo(ip string, apiKey string) *abuseIPDBResponse { | ||
apiUrl := fmt.Sprintf(abuseAPIURL, ip) | ||
|
||
headers := map[string]string{ | ||
"Key": apiKey, | ||
"Accept": "application/json", | ||
} | ||
|
||
var data abuseIPDBResponse | ||
|
||
err := util.MakeAPIRequest(apiUrl, headers, &data) | ||
if err != nil { | ||
log.Fatalf("Error fetching AbuseIPDB info: %v", err) | ||
} | ||
|
||
return &data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package apis | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"soc-cli/internal/util" | ||
) | ||
|
||
const greyNoiseAPIURL = "https://api.greynoise.io/v3/community/%s" | ||
|
||
type greyNoiseInfo struct { | ||
IP string `json:"ip"` | ||
Noise bool `json:"noise"` | ||
Riot bool `json:"riot"` | ||
Classification string `json:"classification"` | ||
Name string `json:"name"` | ||
Link string `json:"link"` | ||
} | ||
|
||
// Get threat intelligence from GreyNoise API | ||
func GetGreyNoiseData(ip string, apiKey string) *greyNoiseInfo { | ||
apiUrl := fmt.Sprintf(greyNoiseAPIURL, ip) | ||
|
||
headers := map[string]string{ | ||
"key": apiKey, | ||
} | ||
|
||
var greyNoiseData greyNoiseInfo | ||
|
||
err := util.MakeAPIRequest(apiUrl, headers, &greyNoiseData) | ||
if err != nil { | ||
log.Fatalf("Error fetching AbuseIPDB info: %v", err) | ||
} | ||
|
||
return &greyNoiseData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package apis | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"soc-cli/internal/util" | ||
) | ||
|
||
const ipInfoAPIURL = "https://ipinfo.io/%s?token=%s" | ||
|
||
type ipInfo struct { | ||
IP string `json:"ip"` | ||
Country string `json:"country"` | ||
Hostname string `json:"hostname"` | ||
Org string `json:"org"` | ||
} | ||
|
||
func GetIPInfo(ip string, apiKey string) *ipInfo { | ||
apiUrl := fmt.Sprintf(ipInfoAPIURL, ip, apiKey) | ||
|
||
var info ipInfo | ||
|
||
err := util.MakeAPIRequest(apiUrl, nil, &info) | ||
if err != nil { | ||
log.Fatalf("Error fetching IP info: %v", err) | ||
} | ||
|
||
return &info | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cmd | ||
package util | ||
|
||
import ( | ||
"encoding/json" | ||
|