WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit ff3ac66

Browse files
allow to filter connections by username
Added new rule operand 'user.name' to filter connections by username. More info #1236
1 parent c0be3d1 commit ff3ac66

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

daemon/rule/operator.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net"
77
"os"
8+
"os/user"
89
"reflect"
910
"regexp"
1011
"strconv"
@@ -47,6 +48,7 @@ const (
4748
OpProcessHashMD5 = Operand("process.hash.md5")
4849
OpProcessHashSHA1 = Operand("process.hash.sha1")
4950
OpUserID = Operand("user.id")
51+
OpUserName = Operand("user.name")
5052
OpSrcIP = Operand("source.ip")
5153
OpSrcPort = Operand("source.port")
5254
OpDstIP = Operand("dest.ip")
@@ -209,6 +211,15 @@ func (o *Operator) Compile() error {
209211
o.cb = o.cmpNetwork
210212
}
211213
}
214+
if o.Operand == OpUserName && o.Type == Simple {
215+
// TODO: allow regexps, take into account users from containers.
216+
u, err := user.Lookup(o.Data)
217+
if err != nil {
218+
return fmt.Errorf("user.name Operand error: %s", err)
219+
}
220+
o.cb = o.simpleCmp
221+
o.Data = u.Uid
222+
}
212223
if o.Operand == OpDomainsLists {
213224
if o.Data == "" {
214225
return fmt.Errorf("Operand lists is empty, nothing to load: %s", o)
@@ -382,7 +393,7 @@ func (o *Operator) Match(con *conman.Connection, hasChecksums bool) bool {
382393
return o.cb(con.DstHost)
383394
} else if o.Operand == OpIPLists {
384395
return o.cb(con.DstIP.String())
385-
} else if o.Operand == OpUserID {
396+
} else if o.Operand == OpUserID || o.Operand == OpUserName {
386397
return o.cb(strconv.Itoa(con.Entry.UserId))
387398
} else if o.Operand == OpDstNetwork {
388399
return o.cb(con.DstIP)

0 commit comments

Comments
 (0)