Skip to content

Commit 4f3bc9b

Browse files
committed
Merge branch 'store-tweaks'
* store-tweaks: Improve updateBruteResult behavior remove batch size for scan queue, just scan everything
2 parents 5ae14c5 + e7e23bf commit 4f3bc9b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ from cron every hour to to perform a constant audit.
5656
$ ./ssh-auditor addcredential admin admin
5757
$ ./ssh-auditor addcredential guest guest --scan-interval 1 #check this once per day
5858

59-
### Try credentials against discovered hosts in a batch of 20000
59+
### Try credentials against discovered hosts
6060

6161
$ ./ssh-auditor scan
6262

sshauditor/store.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (s *SQLiteStore) getScanQueue() ([]ScanRequest, error) {
350350
where hosts.hostport = host_creds.hostport and
351351
last_tested < datetime('now', 'localtime', -scan_interval || ' day') and
352352
hosts.fingerprint != '' and
353-
seen_last > datetime('now', 'localtime', '-7 day') order by last_tested ASC limit 20000`
353+
seen_last > datetime('now', 'localtime', '-7 day') order by last_tested ASC`
354354
return s.getScanQueueHelper(q)
355355
}
356356
func (s *SQLiteStore) getScanQueueSize() (int, error) {
@@ -365,14 +365,28 @@ func (s *SQLiteStore) getScanQueueSize() (int, error) {
365365
return cnt, errors.Wrap(err, "getScanQueueSize")
366366
}
367367
func (s *SQLiteStore) getRescanQueue() ([]ScanRequest, error) {
368-
q := `select * from host_creds where result !='' order by last_tested ASC limit 20000`
368+
q := `select * from host_creds where result !='' order by last_tested ASC`
369369
return s.getScanQueueHelper(q)
370370
}
371371

372372
func (s *SQLiteStore) updateBruteResult(br BruteForceResult) error {
373+
if br.err != nil {
374+
//If this BruteForceResult was an error.. as in, not a positive or
375+
//negative result, don't update anything. We can't say definitively
376+
//that the credential does or does not work.
377+
return nil
378+
}
373379
_, err := s.Exec(`UPDATE host_creds set last_tested=datetime('now', 'localtime'), result=$1
374380
WHERE hostport=$2 AND user=$3 AND password=$4`,
375381
br.result, br.hostport, br.cred.User, br.cred.Password)
382+
if err != nil {
383+
return errors.Wrap(err, "updateBruteResult")
384+
}
385+
//Also update the seen_last field on the hosts table, since a non-err
386+
//BruteForceResult means the system was reachable.
387+
_, err = s.Exec(
388+
"UPDATE hosts SET seen_last=datetime('now', 'localtime') WHERE hostport=$1",
389+
br.hostport)
376390
return errors.Wrap(err, "updateBruteResult")
377391
}
378392

0 commit comments

Comments
 (0)