feat: resolve and append PTR hostnames to findings in the database output
Build and Push / build (nucleus, amd64, linux) (push) Successful in 18s
Build and Push / build (nucleus, amd64, linux) (push) Successful in 18s
This commit is contained in:
@@ -3,8 +3,11 @@ package runner
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"nucleus/internal/db"
|
"nucleus/internal/db"
|
||||||
@@ -57,11 +60,23 @@ func RunScan(targetID int, isManual bool) {
|
|||||||
line := scanner.Bytes()
|
line := scanner.Bytes()
|
||||||
var nf models.NucleiFinding
|
var nf models.NucleiFinding
|
||||||
if err := json.Unmarshal(line, &nf); err == nil {
|
if err := json.Unmarshal(line, &nf); err == nil {
|
||||||
|
displayHost := nf.Host
|
||||||
|
ipStr := displayHost
|
||||||
|
if hostPart, _, err := net.SplitHostPort(displayHost); err == nil {
|
||||||
|
ipStr = hostPart
|
||||||
|
}
|
||||||
|
if ip := net.ParseIP(ipStr); ip != nil {
|
||||||
|
if names, err := net.LookupAddr(ip.String()); err == nil && len(names) > 0 {
|
||||||
|
hostname := strings.TrimSuffix(names[0], ".")
|
||||||
|
displayHost = fmt.Sprintf("%s (%s)", hostname, displayHost)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Insert finding
|
// Insert finding
|
||||||
res, err := db.DB.Exec(`
|
res, err := db.DB.Exec(`
|
||||||
INSERT INTO findings (scan_id, template_id, name, severity, host, matched_at, description)
|
INSERT INTO findings (scan_id, template_id, name, severity, host, matched_at, description)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
`, scanID, nf.TemplateID, nf.Info.Name, nf.Info.Severity, nf.Host, nf.MatchedAt, nf.Info.Description)
|
`, scanID, nf.TemplateID, nf.Info.Name, nf.Info.Severity, displayHost, nf.MatchedAt, nf.Info.Description)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fid, _ := res.LastInsertId()
|
fid, _ := res.LastInsertId()
|
||||||
@@ -71,7 +86,7 @@ func RunScan(targetID int, isManual bool) {
|
|||||||
TemplateID: nf.TemplateID,
|
TemplateID: nf.TemplateID,
|
||||||
Name: nf.Info.Name,
|
Name: nf.Info.Name,
|
||||||
Severity: nf.Info.Severity,
|
Severity: nf.Info.Severity,
|
||||||
Host: nf.Host,
|
Host: displayHost,
|
||||||
MatchedAt: nf.MatchedAt,
|
MatchedAt: nf.MatchedAt,
|
||||||
Description: nf.Info.Description,
|
Description: nf.Info.Description,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user