Skip to content

Commit e961b32

Browse files
committed
attempt at fixing #126
1 parent 684e11c commit e961b32

22 files changed

+337
-195
lines changed

.github/coverage/badge.svg

Lines changed: 1 addition & 1 deletion
Loading

.github/coverage/coverage.txt

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
ok github.com/0xrawsec/whids/agent 39.337s coverage: 51.0% of statements
2-
ok github.com/0xrawsec/whids/agent/config 2.372s coverage: 46.1% of statements
3-
ok github.com/0xrawsec/whids/agent/sysinfo 0.564s coverage: 95.2% of statements
4-
ok github.com/0xrawsec/whids/api/server 181.937s coverage: 68.0% of statements
5-
ok github.com/0xrawsec/whids/event 61.293s coverage: 75.3% of statements
6-
ok github.com/0xrawsec/whids/ioc 19.730s coverage: 73.3% of statements
7-
ok github.com/0xrawsec/whids/logger 47.841s coverage: 76.7% of statements
8-
ok github.com/0xrawsec/whids/sysmon 6.139s coverage: 83.1% of statements
9-
ok github.com/0xrawsec/whids/utils 11.080s coverage: 17.4% of statements
10-
ok github.com/0xrawsec/whids/utils/command 0.637s coverage: 100.0% of statements
1+
ok github.com/0xrawsec/whids/agent 53.872s coverage: 52.0% of statements
2+
ok github.com/0xrawsec/whids/agent/config 4.223s coverage: 46.1% of statements
3+
ok github.com/0xrawsec/whids/agent/sysinfo 0.966s coverage: 95.2% of statements
4+
ok github.com/0xrawsec/whids/api/server 220.042s coverage: 66.6% of statements
5+
ok github.com/0xrawsec/whids/event 92.751s coverage: 75.3% of statements
6+
ok github.com/0xrawsec/whids/ioc 44.868s coverage: 73.3% of statements
7+
ok github.com/0xrawsec/whids/logger 70.295s coverage: 76.7% of statements
8+
ok github.com/0xrawsec/whids/sysmon 9.328s coverage: 83.1% of statements
9+
ok github.com/0xrawsec/whids/utils 22.681s coverage: 17.1% of statements
10+
ok github.com/0xrawsec/whids/utils/command 1.058s coverage: 100.0% of statements
1111
github.com/0xrawsec/whids/agent/actions.go:72: NewActionHandler 100.0%
1212
github.com/0xrawsec/whids/agent/actions.go:81: dumpname 100.0%
1313
github.com/0xrawsec/whids/agent/actions.go:86: prepare 100.0%
@@ -45,7 +45,7 @@ github.com/0xrawsec/whids/agent/agent.go:518: updateSystemInfo 0.0%
4545
github.com/0xrawsec/whids/agent/agent.go:546: updateSysmon 0.0%
4646
github.com/0xrawsec/whids/agent/agent.go:592: updateSysmonConfig 0.0%
4747
github.com/0xrawsec/whids/agent/agent.go:652: cleanup 33.3%
48-
github.com/0xrawsec/whids/agent/agent.go:668: IsHIDSEvent 87.5%
48+
github.com/0xrawsec/whids/agent/agent.go:668: IsHIDSEvent 93.8%
4949
github.com/0xrawsec/whids/agent/agent.go:702: Report 0.0%
5050
github.com/0xrawsec/whids/agent/agent.go:729: Run 58.0%
5151
github.com/0xrawsec/whids/agent/agent.go:846: LogStats 0.0%
@@ -99,17 +99,17 @@ github.com/0xrawsec/whids/agent/filters.go:73: NewFilter 100.0%
9999
github.com/0xrawsec/whids/agent/filters.go:81: Match 100.0%
100100
github.com/0xrawsec/whids/agent/hookdefs.go:39: hookSetImageSize 82.4%
101101
github.com/0xrawsec/whids/agent/hookdefs.go:71: hookImageLoad 95.0%
102-
github.com/0xrawsec/whids/agent/hookdefs.go:108: trackSysmonProcessCreate 62.7%
102+
github.com/0xrawsec/whids/agent/hookdefs.go:108: trackSysmonProcessCreate 76.1%
103103
github.com/0xrawsec/whids/agent/hookdefs.go:229: hookTrack 50.0%
104104
github.com/0xrawsec/whids/agent/hookdefs.go:242: hookStats 98.2%
105105
github.com/0xrawsec/whids/agent/hookdefs.go:353: hookUpdateGeneScore 0.0%
106-
github.com/0xrawsec/whids/agent/hookdefs.go:370: hookTerminator 76.9%
106+
github.com/0xrawsec/whids/agent/hookdefs.go:370: hookTerminator 53.8%
107107
github.com/0xrawsec/whids/agent/hookdefs.go:398: hookProcTerm 87.5%
108108
github.com/0xrawsec/whids/agent/hookdefs.go:414: hookSelfGUID 75.0%
109109
github.com/0xrawsec/whids/agent/hookdefs.go:448: hookFileSystemAudit 0.0%
110110
github.com/0xrawsec/whids/agent/hookdefs.go:478: hookProcessIntegrityProcTamp 0.0%
111-
github.com/0xrawsec/whids/agent/hookdefs.go:554: hookEnrichServices 77.8%
112-
github.com/0xrawsec/whids/agent/hookdefs.go:632: hookEnrichAnySysmon 86.7%
111+
github.com/0xrawsec/whids/agent/hookdefs.go:554: hookEnrichServices 80.6%
112+
github.com/0xrawsec/whids/agent/hookdefs.go:632: hookEnrichAnySysmon 100.0%
113113
github.com/0xrawsec/whids/agent/hookdefs.go:754: hookClipboardEvents 0.0%
114114
github.com/0xrawsec/whids/agent/hookdefs.go:781: hookKernelFiles 0.0%
115115
github.com/0xrawsec/whids/agent/hooks.go:23: newHookCache 100.0%
@@ -121,7 +121,7 @@ github.com/0xrawsec/whids/agent/hooks.go:84: RunHooksOn 93.8%
121121
github.com/0xrawsec/whids/agent/hooks.go:123: getFunctionName 0.0%
122122
github.com/0xrawsec/whids/agent/hookutils.go:13: toString 100.0%
123123
github.com/0xrawsec/whids/agent/hookutils.go:17: toHex 66.7%
124-
github.com/0xrawsec/whids/agent/hookutils.go:25: terminate 87.5%
124+
github.com/0xrawsec/whids/agent/hookutils.go:25: terminate 0.0%
125125
github.com/0xrawsec/whids/agent/hookutils.go:41: isSysmonProcessTerminate 100.0%
126126
github.com/0xrawsec/whids/agent/hookutils.go:45: srcPIDFromEvent 0.0%
127127
github.com/0xrawsec/whids/agent/hookutils.go:58: hasAction 0.0%
@@ -149,10 +149,10 @@ github.com/0xrawsec/whids/agent/ptrack.go:301: KernelFileFromEvent 0.0%
149149
github.com/0xrawsec/whids/agent/ptrack.go:313: sourceGUIDFromEvent 88.9%
150150
github.com/0xrawsec/whids/agent/ptrack.go:334: targetGUIDFromEvent 70.0%
151151
github.com/0xrawsec/whids/agent/ptrack.go:376: NewActivityTracker 100.0%
152-
github.com/0xrawsec/whids/agent/ptrack.go:393: delete 83.3%
153-
github.com/0xrawsec/whids/agent/ptrack.go:406: freeRtn 80.0%
152+
github.com/0xrawsec/whids/agent/ptrack.go:393: delete 100.0%
153+
github.com/0xrawsec/whids/agent/ptrack.go:406: freeRtn 100.0%
154154
github.com/0xrawsec/whids/agent/ptrack.go:444: CheckDumpCountOrInc 100.0%
155-
github.com/0xrawsec/whids/agent/ptrack.go:458: Add 83.3%
155+
github.com/0xrawsec/whids/agent/ptrack.go:458: Add 100.0%
156156
github.com/0xrawsec/whids/agent/ptrack.go:469: PS 0.0%
157157
github.com/0xrawsec/whids/agent/ptrack.go:480: Blacklist 100.0%
158158
github.com/0xrawsec/whids/agent/ptrack.go:484: IsBlacklisted 100.0%
@@ -182,7 +182,7 @@ github.com/0xrawsec/whids/agent/stats.go:69: Detections 0.0%
182182
github.com/0xrawsec/whids/agent/stats.go:73: EPS 0.0%
183183
github.com/0xrawsec/whids/agent/stats.go:81: CriticalEPS 0.0%
184184
github.com/0xrawsec/whids/agent/stats.go:85: DynEPS 75.0%
185-
github.com/0xrawsec/whids/agent/stats.go:93: HasPerfIssue 30.8%
185+
github.com/0xrawsec/whids/agent/stats.go:93: HasPerfIssue 38.5%
186186
github.com/0xrawsec/whids/agent/stats.go:113: HasCriticalPerfIssue 0.0%
187187
github.com/0xrawsec/whids/agent/sysinfo/sysinfo.go:15: RegisterEdrInfo 0.0%
188188
github.com/0xrawsec/whids/agent/sysinfo/windows_sysinfo.go:31: NewSystemInfo 100.0%
@@ -261,24 +261,25 @@ github.com/0xrawsec/whids/api/server/manager_admin_api.go:1479: wsHandleControl
261261
github.com/0xrawsec/whids/api/server/manager_admin_api.go:1489: admAPIStreamEvents 71.4%
262262
github.com/0xrawsec/whids/api/server/manager_admin_api.go:1512: admAPIStreamDetections 0.0%
263263
github.com/0xrawsec/whids/api/server/manager_admin_api.go:1537: runAdminAPI 87.8%
264-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:33: eptAPIMutEndpointFromRequest 75.0%
265-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:43: endpointAuthorizationMiddleware 65.2%
266-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:86: isVerboseURL 100.0%
267-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:95: endptLogHTTPMiddleware 0.0%
268-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:103: endptQuietLogHTTPMiddleware 100.0%
269-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:113: runEndpointAPI 80.6%
270-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:182: eptAPIServerKey 100.0%
271-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:187: eptAPIRules 100.0%
272-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:194: eptAPIRulesSha256 100.0%
273-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:200: eptAPIIoCs 50.0%
274-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:209: eptAPIIoCsSha256 100.0%
275-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:214: eptAPIUploadDump 44.4%
276-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:247: eptAPICollect 86.0%
277-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:330: eptAPICommand 79.3%
278-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:386: eptAPISystemInfo 70.0%
279-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:405: eptAPISysmonConfig 87.5%
280-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:422: eptAPISysmonConfigSha256 100.0%
281-
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:435: eptAPITools 0.0%
264+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:34: eptAPIMutEndpointFromRequest 75.0%
265+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:44: endpointAuthorizationMiddleware 65.2%
266+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:87: isVerboseURL 100.0%
267+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:96: endptLogHTTPMiddleware 0.0%
268+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:104: endptQuietLogHTTPMiddleware 100.0%
269+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:114: runEndpointAPI 81.2%
270+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:184: eptAPIServerKey 100.0%
271+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:189: eptAPIRules 100.0%
272+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:196: eptAPIConfig 0.0%
273+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:249: eptAPIRulesSha256 100.0%
274+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:255: eptAPIIoCs 50.0%
275+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:264: eptAPIIoCsSha256 100.0%
276+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:269: eptAPIUploadDump 44.4%
277+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:302: eptAPICollect 86.0%
278+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:385: eptAPICommand 79.3%
279+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:441: eptAPISystemInfo 70.0%
280+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:460: eptAPISysmonConfig 87.5%
281+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:477: eptAPISysmonConfigSha256 100.0%
282+
github.com/0xrawsec/whids/api/server/manager_endpoint_api.go:490: eptAPITools 0.0%
282283
github.com/0xrawsec/whids/api/server/utils.go:14: muxGetVar 75.0%
283284
github.com/0xrawsec/whids/api/server/utils.go:22: format 100.0%
284285
github.com/0xrawsec/whids/api/server/utils.go:27: readPostAsJSON 80.0%
@@ -433,29 +434,31 @@ github.com/0xrawsec/whids/utils/net.go:19: PrevIP 0.0%
433434
github.com/0xrawsec/whids/utils/rand.go:10: UnsafeUUIDGen 100.0%
434435
github.com/0xrawsec/whids/utils/rand.go:19: UnsafeKeyGen 0.0%
435436
github.com/0xrawsec/whids/utils/utils.go:30: IsValidUUID 100.0%
436-
github.com/0xrawsec/whids/utils/utils.go:35: PrettyJson 0.0%
437+
github.com/0xrawsec/whids/utils/utils.go:35: PrettyJsonOrPanic 0.0%
437438
github.com/0xrawsec/whids/utils/utils.go:43: Json 0.0%
438-
github.com/0xrawsec/whids/utils/utils.go:52: JsonString 0.0%
439-
github.com/0xrawsec/whids/utils/utils.go:56: Toml 0.0%
440-
github.com/0xrawsec/whids/utils/utils.go:67: TomlString 0.0%
441-
github.com/0xrawsec/whids/utils/utils.go:76: ExpandEnvs 0.0%
442-
github.com/0xrawsec/whids/utils/utils.go:85: Sha256StringArray 0.0%
443-
github.com/0xrawsec/whids/utils/utils.go:95: HashEventBytes 0.0%
444-
github.com/0xrawsec/whids/utils/utils.go:100: HashInterface 0.0%
445-
github.com/0xrawsec/whids/utils/utils.go:110: GetCurFuncName 0.0%
446-
github.com/0xrawsec/whids/utils/utils.go:138: NewWindowsLogger 0.0%
447-
github.com/0xrawsec/whids/utils/utils.go:151: Log 0.0%
448-
github.com/0xrawsec/whids/utils/utils.go:162: Close 0.0%
449-
github.com/0xrawsec/whids/utils/utils.go:171: Round 0.0%
450-
github.com/0xrawsec/whids/utils/utils.go:177: RegQuery 0.0%
451-
github.com/0xrawsec/whids/utils/utils.go:189: Utf16ToUtf8 0.0%
452-
github.com/0xrawsec/whids/utils/utils.go:221: Len 0.0%
453-
github.com/0xrawsec/whids/utils/utils.go:225: Swap 0.0%
454-
github.com/0xrawsec/whids/utils/utils.go:231: Less 0.0%
439+
github.com/0xrawsec/whids/utils/utils.go:47: JsonString 0.0%
440+
github.com/0xrawsec/whids/utils/utils.go:56: JsonOrPanic 0.0%
441+
github.com/0xrawsec/whids/utils/utils.go:65: JsonStringOrPanic 0.0%
442+
github.com/0xrawsec/whids/utils/utils.go:69: Toml 0.0%
443+
github.com/0xrawsec/whids/utils/utils.go:80: TomlString 0.0%
444+
github.com/0xrawsec/whids/utils/utils.go:89: ExpandEnvs 0.0%
445+
github.com/0xrawsec/whids/utils/utils.go:98: Sha256StringArray 0.0%
446+
github.com/0xrawsec/whids/utils/utils.go:108: HashEventBytes 0.0%
447+
github.com/0xrawsec/whids/utils/utils.go:113: HashInterface 0.0%
448+
github.com/0xrawsec/whids/utils/utils.go:123: GetCurFuncName 0.0%
449+
github.com/0xrawsec/whids/utils/utils.go:151: NewWindowsLogger 0.0%
450+
github.com/0xrawsec/whids/utils/utils.go:164: Log 0.0%
451+
github.com/0xrawsec/whids/utils/utils.go:175: Close 0.0%
452+
github.com/0xrawsec/whids/utils/utils.go:184: Round 0.0%
453+
github.com/0xrawsec/whids/utils/utils.go:190: RegQuery 0.0%
454+
github.com/0xrawsec/whids/utils/utils.go:202: Utf16ToUtf8 0.0%
455+
github.com/0xrawsec/whids/utils/utils.go:234: Len 0.0%
456+
github.com/0xrawsec/whids/utils/utils.go:238: Swap 0.0%
457+
github.com/0xrawsec/whids/utils/utils.go:244: Less 0.0%
455458
github.com/0xrawsec/whids/utils/windows.go:22: ArgvFromCommandLine 0.0%
456459
github.com/0xrawsec/whids/utils/windows.go:41: HideFile 0.0%
457460
github.com/0xrawsec/whids/utils/windows.go:53: ResolveCDrive 0.0%
458461
github.com/0xrawsec/whids/utils/windows.go:76: RegValue 0.0%
459462
github.com/0xrawsec/whids/utils/windows.go:91: RegJoin 0.0%
460463
github.com/0xrawsec/whids/utils/windows.go:98: RegValueToString 0.0%
461-
total: (statements) 58.5%
464+
total: (statements) 58.4%

agent/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ func (h *Agent) Run() {
787787
// we keep process termination event because it is used to control if process termination is enabled
788788
if h.IsHIDSEvent(event) && !isSysmonProcessTerminate(event) {
789789
if h.PrintAll {
790-
fmt.Println(utils.JsonString(event))
790+
fmt.Println(utils.JsonStringOrPanic(event))
791791
}
792792
goto CONTINUE
793793
}
@@ -821,7 +821,7 @@ func (h *Agent) Run() {
821821

822822
// Print everything
823823
if h.PrintAll {
824-
fmt.Println(utils.JsonString(event))
824+
fmt.Println(utils.JsonStringOrPanic(event))
825825
}
826826

827827
// We log all events

agent/commands_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestCmdHash(t *testing.T) {
3737
fi, err := cmdHash(filepath.Join(testDir, testFile))
3838
tt.CheckErr(err)
3939
tt.Assert(fi.Type == "file")
40-
t.Log(utils.PrettyJson(fi))
40+
t.Log(utils.PrettyJsonOrPanic(fi))
4141
}
4242

4343
func TestCmdDir(t *testing.T) {
@@ -50,7 +50,7 @@ func TestCmdDir(t *testing.T) {
5050
for _, fi := range d {
5151
tt.Assert(fi.Dir == dir)
5252
}
53-
t.Log(utils.PrettyJson(d))
53+
t.Log(utils.PrettyJsonOrPanic(d))
5454
}
5555

5656
func TestCmdFind(t *testing.T) {

agent/defaults.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import (
1212
func BuildDefaultConfig(root string) *config.Agent {
1313

1414
logDir := filepath.Join(root, "Logs")
15+
dbDir := filepath.Join(root, "Database")
1516

1617
return &config.Agent{
18+
DatabasePath: filepath.Join(dbDir, "Sod"),
1719
RulesConfig: config.Rules{
18-
RulesDB: filepath.Join(root, "Database", "Rules"),
19-
ContainersDB: filepath.Join(root, "Database", "Containers"),
20+
RulesDB: filepath.Join(dbDir, "Rules"),
21+
ContainersDB: filepath.Join(dbDir, "Containers"),
2022
UpdateInterval: 60 * time.Second,
2123
},
2224

agent/hook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func installSysmon() {
123123
}
124124

125125
func testHook(h *Agent, e *event.EdrEvent) {
126-
fmt.Println(utils.PrettyJson(e))
126+
fmt.Println(utils.PrettyJsonOrPanic(e))
127127
}
128128

129129
func TestHooks(t *testing.T) {
@@ -176,5 +176,5 @@ func TestHooks(t *testing.T) {
176176

177177
tt.Assert(gotSysmonEvent, "failed to monitor Sysmon events")
178178

179-
t.Log(utils.PrettyJson(h.tracker.Modules()))
179+
t.Log(utils.PrettyJsonOrPanic(h.tracker.Modules()))
180180
}

agent/hookdefs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func hookUpdateGeneScore(h *Agent, e *event.EdrEvent) {
357357
return
358358
}
359359

360-
if t := h.tracker.SourceTrackFromEvent(e); t.IsZero() {
360+
if t = h.tracker.SourceTrackFromEvent(e); t.IsZero() {
361361
return
362362
}
363363

agent/sysinfo/sysinfo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestSystemInfo(t *testing.T) {
1414
if h, err = utils.HashInterface(info); err != nil {
1515
t.Error(err)
1616
}
17-
t.Log(utils.PrettyJson(info))
17+
t.Log(utils.PrettyJsonOrPanic(info))
1818
t.Logf("Structure hash: %s", h)
1919
for i := 0; i < 1000; i++ {
2020
if n, err := utils.HashInterface(info); err != nil {

0 commit comments

Comments
 (0)