Documentation
¶
Overview ¶
Package sshlog extracts the client address and outcome from OpenSSH server log lines.
sshd logs the user name a client sends verbatim, so a client can put text that looks like an address into it:
Invalid user x from 192.0.2.7 port 1 from 198.51.100.10 port 36465
Every pattern here therefore takes the address from a part of the line the client does not control: the fixed end of the line, or a field sshd fills from its own state. The exported patterns use RE2 syntax, so a database that extracts with RE2 (ClickHouse's extract, for example) can use them unchanged.
This holds only for messages sshd sends to syslog (the journal included), where it escapes control characters. With -e it writes to standard error without escaping, so a user name with a newline in it can forge a whole line. Only count lines that sshd itself logged through syslog.
Index ¶
Constants ¶
const ( InvalidUserPattern = `^Invalid user .* from (\S+) port \d+$` NotAllowedPattern = `^User \S+ from (\S+) not allowed because ` DropPattern = `^drop connection #\d+ from \[([^\]]+)\]:\d+ on ` AuthClosedPattern = `^Connection closed by authenticating user \S+ (\S+) port \d+ \[preauth\]$` // AcceptedPattern's groups are the user, the address and the key's // SHA256 fingerprint; for a certificate, the certified key's, followed by // the CA-signed ID, serial and CA key. AcceptedPattern = `^Accepted publickey for (\S+) from (\S+) port \d+ ssh2: \S+ (SHA256:\S+)(?: ID .*)?$` )
RE2 patterns, each with the address as its first group.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
Kind Kind
Address netip.Addr
User string // Accepted only
Fingerprint string // Accepted only
}
Event is what one line records.
type Kind ¶
type Kind string
Kind is the outcome a line records.
const ( // InvalidUser means the client named a user that does not exist. InvalidUser Kind = "invalid_user" // NotAllowed means the user exists but AllowUsers, AllowGroups, DenyUsers or // DenyGroups refuse it. sshd prints the account's name from the password // database here, not the client's string. NotAllowed Kind = "not_allowed" // PenaltyDrop means sshd refused a connection because its source is serving a // PerSourcePenalties penalty. PenaltyDrop Kind = "penalty_drop" // MaxStartupsDrop means sshd refused a connection because too many were // unauthenticated. It hits whoever is unlucky, not only the cause. MaxStartupsDrop Kind = "maxstartups_drop" // AuthClosed means a client for a real account disconnected before // authenticating, such as with a wrong key. AuthClosed Kind = "auth_closed" // Accepted means a public key login succeeded. Accepted Kind = "accepted_publickey" )