Skip to content

Commit

Permalink
problem: json report is missing fields.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JustinAzoff committed Jul 17, 2018
1 parent 849290a commit bbe5f59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var reportJSONCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
auditor := sshauditor.New(store)
report, err := auditor.GetReport()
if err != nil {
log.Error(err.Error())
os.Exit(1)
}
w := json.NewEncoder(os.Stdout)
w.SetIndent("", " ")
err = w.Encode(report)
Expand Down
3 changes: 1 addition & 2 deletions sshauditor/auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ func (a *SSHAuditor) LogcheckReport(ls LogSearcher) error {
}

func (a *SSHAuditor) Vulnerabilities() ([]Vulnerability, error) {
vulns, err := a.store.GetVulnerabilities()
return vulns, errors.Wrap(err, "GetVulnerabilities failed")
return a.store.GetVulnerabilities()
}

func (a *SSHAuditor) GetReport() (AuditReport, error) {
Expand Down
8 changes: 5 additions & 3 deletions sshauditor/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c Credential) String() string {
}

type HostCredential struct {
Hostport string
Hostport string `json:"-"`
User string
Password string
LastTested string `db:"last_tested"`
Expand All @@ -85,7 +85,7 @@ type HostCredential struct {

type Vulnerability struct {
HostCredential
Host
Host `db:"host"`
}

type SQLiteStore struct {
Expand Down Expand Up @@ -364,7 +364,9 @@ func (s *SQLiteStore) updateBruteResult(br BruteForceResult) error {
func (s *SQLiteStore) GetVulnerabilities() ([]Vulnerability, error) {
creds := []Vulnerability{}
q := `select
hc.hostport, hc.user, hc.password, hc.result, hc.last_tested, h.version
hc.hostport, hc.user, hc.password, hc.result, hc.last_tested,
h.version "host.version", h.hostport "host.hostport",
h.seen_first "host.seen_first", h.seen_last "host.seen_last", h.fingerprint "host.fingerprint"
from
host_creds hc, hosts h
where
Expand Down

0 comments on commit bbe5f59

Please sign in to comment.