add PTR/rDNS match check and ASN/org lookup via WHOIS
- DNS: reverse DNS lookup on A record IPs to verify PTR configuration - Infra: ASN and organization lookup via whois.radb.net - Refactor checkARecords to return resolved IPs for downstream use Signed-off-by: Blake Ridgway <blake@blakeridgway.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
@@ -72,6 +73,20 @@ func Run(domain string, resolvedIPs []string) types.InfraResult {
|
||||
}
|
||||
result.CDN = cdn
|
||||
|
||||
// ASN / org lookup via WHOIS
|
||||
asn, org := lookupASN(targetIP)
|
||||
if asn != "" {
|
||||
result.ASN = asn
|
||||
result.Org = org
|
||||
msg := fmt.Sprintf("ASN: %s", asn)
|
||||
if org != "" {
|
||||
msg += fmt.Sprintf(" (%s)", org)
|
||||
}
|
||||
result.Checks = append(result.Checks, types.CheckResult{
|
||||
Status: types.StatusInfo, Message: msg,
|
||||
})
|
||||
}
|
||||
|
||||
// Common ports check
|
||||
result.Checks = append(result.Checks, checkPorts(targetIP)...)
|
||||
|
||||
@@ -107,6 +122,42 @@ func detectCDN(ip string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// lookupASN queries whois.radb.net for the ASN and organization of an IP.
|
||||
func lookupASN(ip string) (asn, org string) {
|
||||
conn, err := net.DialTimeout("tcp", "whois.radb.net:43", 5*time.Second)
|
||||
if err != nil {
|
||||
return "", ""
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Set a deadline for the entire WHOIS exchange.
|
||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
||||
|
||||
fmt.Fprintf(conn, "%s\r\n", ip)
|
||||
|
||||
scanner := bufio.NewScanner(conn)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if asn == "" && strings.HasPrefix(line, "origin:") {
|
||||
asn = strings.TrimSpace(strings.TrimPrefix(line, "origin:"))
|
||||
asn = strings.ToUpper(asn)
|
||||
}
|
||||
if org == "" && strings.HasPrefix(line, "descr:") {
|
||||
org = strings.TrimSpace(strings.TrimPrefix(line, "descr:"))
|
||||
}
|
||||
if asn != "" && org != "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Trim long descriptions to keep output readable.
|
||||
if len(org) > 80 {
|
||||
org = org[:77] + "..."
|
||||
}
|
||||
|
||||
return asn, org
|
||||
}
|
||||
|
||||
func checkPorts(ip string) []types.CheckResult {
|
||||
var checks []types.CheckResult
|
||||
var mu sync.Mutex
|
||||
|
||||
Reference in New Issue
Block a user