Skip to content

Commit 9a94923

Browse files
pxivory-maxxiaow-aiclaude
authored
fix: correctly extract username from "invalid user" SSH log lines (#31)
The USER_REGEX matched "for" then captured "invalid" as the username. Add a more specific INVALID_USER_REGEX that matches the full "for invalid user <name>" pattern and try it first. Fixes #26 Co-authored-by: xiaow-ai <xiaow-ai@ugig.net> Co-authored-by: Claude <noreply@anthropic.com>
1 parent e96dc75 commit 9a94923

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

apps/cli/src/core/log-parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const SYSLOG_REGEX = /^(\w+\s+\d+\s+[\d:]+)\s+\S+\s+(\S+?)(?:\[\d+\])?:\s+(.*)/;
1414

1515
// Extract IP from auth messages
1616
const IP_REGEX = /(?:from|FROM)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;
17+
const INVALID_USER_REGEX = /(?:for\s+invalid\s+user)\s+(\S+?)(?:\s+from|\s*$)/;
1718
const USER_REGEX = /(?:for|user)\s+(\S+?)(?:\s+from|\s*$)/;
1819

1920
// Attack pattern signatures
@@ -73,7 +74,7 @@ export function parseAuthLog(line: string): AuthLogEntry | null {
7374
if (!match) return null;
7475

7576
const ipMatch = match[3].match(IP_REGEX);
76-
const userMatch = match[3].match(USER_REGEX);
77+
const userMatch = match[3].match(INVALID_USER_REGEX) || match[3].match(USER_REGEX);
7778

7879
return {
7980
timestamp: parseSyslogTimestamp(match[1]),

0 commit comments

Comments
 (0)