|
5 | 5 | "fmt" |
6 | 6 | "net" |
7 | 7 | "os" |
| 8 | + "os/user" |
8 | 9 | "reflect" |
9 | 10 | "regexp" |
10 | 11 | "strconv" |
@@ -47,6 +48,7 @@ const ( |
47 | 48 | OpProcessHashMD5 = Operand("process.hash.md5") |
48 | 49 | OpProcessHashSHA1 = Operand("process.hash.sha1") |
49 | 50 | OpUserID = Operand("user.id") |
| 51 | + OpUserName = Operand("user.name") |
50 | 52 | OpSrcIP = Operand("source.ip") |
51 | 53 | OpSrcPort = Operand("source.port") |
52 | 54 | OpDstIP = Operand("dest.ip") |
@@ -209,6 +211,15 @@ func (o *Operator) Compile() error { |
209 | 211 | o.cb = o.cmpNetwork |
210 | 212 | } |
211 | 213 | } |
| 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 | + } |
212 | 223 | if o.Operand == OpDomainsLists { |
213 | 224 | if o.Data == "" { |
214 | 225 | 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 { |
382 | 393 | return o.cb(con.DstHost) |
383 | 394 | } else if o.Operand == OpIPLists { |
384 | 395 | return o.cb(con.DstIP.String()) |
385 | | - } else if o.Operand == OpUserID { |
| 396 | + } else if o.Operand == OpUserID || o.Operand == OpUserName { |
386 | 397 | return o.cb(strconv.Itoa(con.Entry.UserId)) |
387 | 398 | } else if o.Operand == OpDstNetwork { |
388 | 399 | return o.cb(con.DstIP) |
|
0 commit comments