Skip to content

Commit 8ea7643

Browse files
committed
bug bashing & task scheduler scan improvements
1 parent 549ae75 commit 8ea7643

File tree

4 files changed

+51
-18
lines changed

4 files changed

+51
-18
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
## What is this project designed for?
66
_IRMA_ is a lightweight tool made for live forensics on Windows Platform. It is
7-
focused on two use cases:
7+
focused on three use cases:
88
* enpoint detection - live analysis, quarantine and eradication of malware on a workstation
99
* live analysis & sandbox host - logging and instant notifications for malware TTP's assesment
10+
* signatures quality test - scan your endpoint baseline and check for false positives
1011

1112
## How IRMA scan for malware behaviour?
1213
_IRMA_ is intended to work with both user or administrator rights.

filehelper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func FileAnalysis(path string, pQuarantine string, pKill bool, pAggressive bool,
8686

8787
// logging
8888
for _, match := range result {
89-
log.Println("[ALERT]", "YARA MATCH", path, match.Namespace, match.Rule)
89+
log.Println("[ALERT]", "YARA match", path, match.Namespace, match.Rule)
9090
}
9191

9292
// dump matching process to quarantine

procsmemory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ func MemoryAnalysisRoutine(pDump string, pQuarantine string, pKill bool, pAggres
5353
if len(result) > 0 {
5454
// windows notifications
5555
if pNotifications {
56-
NotifyUser("YARA match", proc.ProcessName+":"+fmt.Sprint(proc.PID)+" match "+fmt.Sprint(len(result))+" rules")
56+
NotifyUser("YARA match", proc.ProcessName+" - PID:"+fmt.Sprint(proc.PID)+" match "+fmt.Sprint(len(result))+" rules")
5757
}
5858

5959
// logging
6060
for _, match := range result {
61-
log.Println("[ALERT]", "YARA MATCH", proc.ProcessName, "PID:", fmt.Sprint(proc.PID), match.Namespace, match.Rule)
61+
log.Println("[ALERT]", "YARA match", proc.ProcessName, "PID:", fmt.Sprint(proc.PID), match.Namespace, match.Rule)
6262
}
6363

6464
// dump matching process to quarantine

windowstaskscheduler.go

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ type ExecAction struct {
2727
Arguments string
2828
}
2929

30+
var (
31+
unknown *ole.IUnknown
32+
variant *ole.VARIANT
33+
ts *ole.IDispatch
34+
)
35+
36+
var taskSchedulerInitialized bool = false
37+
3038
// TaskSchedulerAnalysisRoutine analyse Windows Task Scheduler executable every 15 seconds
3139
func TaskSchedulerAnalysisRoutine(pQuarantine string, pKill bool, pAggressive bool, pNotifications bool, pVerbose bool, rules *yara.Rules) {
3240
for true {
41+
defer UninitializeTaskScheduler()
3342
tasks, err := GetTasks()
3443
if err != nil && pVerbose {
3544
log.Println("[ERROR]", err)
@@ -48,29 +57,52 @@ func TaskSchedulerAnalysisRoutine(pQuarantine string, pKill bool, pAggressive bo
4857
}
4958
}
5059

51-
// GetTasks returns a list of all scheduled Tasks in Windows Task Scheduler
52-
func GetTasks() ([]Task, error) {
53-
// Initialize COM API
54-
if err := ole.CoInitialize(0); err != nil {
55-
return nil, errors.New("Could not initialize Windows COM API")
60+
// InitTaskScheduler Initialize COM API & Task scheduler connect
61+
func InitTaskScheduler() error {
62+
var err error
63+
if err = ole.CoInitializeEx(0, 0); err != nil {
64+
return errors.New("Could not initialize Windows COM API")
5665
}
57-
defer ole.CoUninitialize()
66+
5867
// Create an ITaskService object
59-
unknown, err := ole.CreateInstance(ole.NewGUID("{0f87369f-a4e5-4cfc-bd3e-73e6154572dd}"), nil)
68+
unknown, err = ole.CreateInstance(ole.NewGUID("{0f87369f-a4e5-4cfc-bd3e-73e6154572dd}"), nil)
6069
if err != nil {
61-
return nil, errors.New("Could not initialize Task Scheduler")
70+
return errors.New("Could not initialize Task Scheduler")
6271
}
63-
defer unknown.Release()
72+
6473
// Convert IUnknown to IDispatch to get more functions like CallMethod()
65-
ts, err := unknown.QueryInterface(ole.IID_IDispatch)
74+
ts, err = unknown.QueryInterface(ole.IID_IDispatch)
6675
if err != nil {
67-
return nil, errors.New("Could not prepare Task Scheduler")
76+
return errors.New("Could not prepare Task Scheduler")
6877
}
69-
defer ts.Release()
78+
7079
// Connect to the Task Scheduler
71-
if _, err := ts.CallMethod("Connect", "", "", "", ""); err != nil {
72-
return nil, errors.New("Could not connect to Task Scheduler")
80+
if _, err = ts.CallMethod("Connect", "", "", "", ""); err != nil {
81+
return errors.New("Could not connect to Task Scheduler")
7382
}
83+
84+
return nil
85+
}
86+
87+
// UninitializeTaskScheduler Release Task Scheduler COM API
88+
func UninitializeTaskScheduler() {
89+
ole.CoUninitialize()
90+
unknown.Release()
91+
ts.Release()
92+
}
93+
94+
// GetTasks returns a list of all scheduled Tasks in Windows Task Scheduler
95+
func GetTasks() ([]Task, error) {
96+
var err error
97+
98+
if !taskSchedulerInitialized {
99+
err = InitTaskScheduler()
100+
if err != nil {
101+
return nil, err
102+
}
103+
taskSchedulerInitialized = true
104+
}
105+
74106
// Get Root Directory of Task Scheduler and get all tasks recursively
75107
variant, err := oleutil.CallMethod(ts, "GetFolder", "\\")
76108
if err != nil {

0 commit comments

Comments
 (0)