Skip to content

Commit 3818bda

Browse files
committed
chg: [sshd] modify parser to accept any characters in hostname and username
1 parent 9be5c60 commit 3818bda

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

logparser/parser_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var expected = map[int]map[string]string{
1818
},
1919
1: map[string]string{
2020
"date": "Jan 22 11:37:19",
21-
"host": "sigmund",
21+
"host": "si.mund",
2222
"username": "gestion",
2323
"src": "159.89.153.54",
2424
},
@@ -37,7 +37,7 @@ var expected = map[int]map[string]string{
3737
4: map[string]string{
3838
"date": "Jan 22 11:29:16",
3939
"host": "sigmund",
40-
"username": "admin",
40+
"username": "a.min",
4141
"src": "185.56.8.191",
4242
},
4343
}
@@ -53,7 +53,7 @@ func TestSshdParser(t *testing.T) {
5353
scanner := bufio.NewScanner(f)
5454
c := 0
5555
for scanner.Scan() {
56-
re := regexp.MustCompile(`^(?P<date>[[:alpha:]]{3}\s\d{2}\s\d{2}:\d{2}:\d{2}) (?P<host>[[:word:]]+) sshd\[[[:alnum:]]+\]: Invalid user (?P<username>[[:word:]]+) from (?P<src>.*$)`)
56+
re := regexp.MustCompile(`^(?P<date>[[:alpha:]]{3}\s\d{2}\s\d{2}:\d{2}:\d{2}) (?P<host>[^ ]+) sshd\[[[:alnum:]]+\]: Invalid user (?P<username>[^ ]+) from (?P<src>.*$)`)
5757
n1 := re.SubexpNames()
5858
r2 := re.FindAllStringSubmatch(scanner.Text(), -1)[0]
5959

logparser/test.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Jan 22 11:59:37 sigmund sshd[26514]: Invalid user git from 106.12.14.144
2-
Jan 22 11:37:19 sigmund sshd[26143]: Invalid user gestion from 159.89.153.54
2+
Jan 22 11:37:19 si.mund sshd[26143]: Invalid user gestion from 159.89.153.54
33
Jan 22 11:34:46 sigmund sshd[26125]: Invalid user atpco from 177.152.124.21
44
Jan 22 11:33:07 sigmund sshd[26109]: Invalid user ki from 49.233.183.158
5-
Jan 22 11:29:16 sigmund sshd[26091]: Invalid user admin from 185.56.8.191
5+
Jan 22 11:29:16 sigmund sshd[26091]: Invalid user a.min from 185.56.8.191

0 commit comments

Comments
 (0)