Skip to content

Commit bbe5f59

Browse files
committed
problem: json report is missing fields.
go json encoder ignores conflicting fields, which was preventing Hostport from showing up. Also some of the fields weren't even being selected AND the hostport conflict also existed when the join results were deserialized. To fix that, fully qualify the 'host' fields.
1 parent 849290a commit bbe5f59

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

cmd/report.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var reportJSONCmd = &cobra.Command{
2424
Run: func(cmd *cobra.Command, args []string) {
2525
auditor := sshauditor.New(store)
2626
report, err := auditor.GetReport()
27+
if err != nil {
28+
log.Error(err.Error())
29+
os.Exit(1)
30+
}
2731
w := json.NewEncoder(os.Stdout)
2832
w.SetIndent("", " ")
2933
err = w.Encode(report)

sshauditor/auditor.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ func (a *SSHAuditor) LogcheckReport(ls LogSearcher) error {
355355
}
356356

357357
func (a *SSHAuditor) Vulnerabilities() ([]Vulnerability, error) {
358-
vulns, err := a.store.GetVulnerabilities()
359-
return vulns, errors.Wrap(err, "GetVulnerabilities failed")
358+
return a.store.GetVulnerabilities()
360359
}
361360

362361
func (a *SSHAuditor) GetReport() (AuditReport, error) {

sshauditor/store.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (c Credential) String() string {
7575
}
7676

7777
type HostCredential struct {
78-
Hostport string
78+
Hostport string `json:"-"`
7979
User string
8080
Password string
8181
LastTested string `db:"last_tested"`
@@ -85,7 +85,7 @@ type HostCredential struct {
8585

8686
type Vulnerability struct {
8787
HostCredential
88-
Host
88+
Host `db:"host"`
8989
}
9090

9191
type SQLiteStore struct {
@@ -364,7 +364,9 @@ func (s *SQLiteStore) updateBruteResult(br BruteForceResult) error {
364364
func (s *SQLiteStore) GetVulnerabilities() ([]Vulnerability, error) {
365365
creds := []Vulnerability{}
366366
q := `select
367-
hc.hostport, hc.user, hc.password, hc.result, hc.last_tested, h.version
367+
hc.hostport, hc.user, hc.password, hc.result, hc.last_tested,
368+
h.version "host.version", h.hostport "host.hostport",
369+
h.seen_first "host.seen_first", h.seen_last "host.seen_last", h.fingerprint "host.fingerprint"
368370
from
369371
host_creds hc, hosts h
370372
where

0 commit comments

Comments
 (0)