-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.yar
More file actions
722 lines (666 loc) · 20.3 KB
/
core.yar
File metadata and controls
722 lines (666 loc) · 20.3 KB
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
/*
* PipeGuard Core YARA Rules
* Detecting malicious patterns in curl|bash attacks
*
* Severity Levels:
* 1-6: Low (Warn)
* 7-8: Medium (Prompt)
* 9-10: High (Block)
*/
// =============================================================================
// Category 1: Base64 Obfuscation (Severity: 5)
// =============================================================================
rule base64_decode_execute {
meta:
severity = 5
description = "Base64 encoded payload with execution"
category = "obfuscation"
strings:
$decode1 = "base64 -d" nocase
$decode2 = "base64 --decode" nocase
$decode3 = "openssl base64 -d" nocase
$exec1 = "| bash"
$exec2 = "| sh"
$exec3 = "| zsh"
$exec4 = "eval $("
$exec5 = "eval \"$("
condition:
any of ($decode*) and any of ($exec*)
}
rule large_base64_blob {
meta:
severity = 5
description = "Large Base64 encoded data block"
category = "obfuscation"
strings:
$b64 = /[A-Za-z0-9+\/]{100,}={0,2}/
condition:
$b64
}
// =============================================================================
// Category 2: Staged Downloads (Severity: 7)
// =============================================================================
rule staged_download_pipe {
meta:
severity = 7
description = "Script downloads and pipes to shell interpreter"
category = "staged"
strings:
$dl1 = "curl" nocase
$dl2 = "wget" nocase
$dl3 = "fetch" nocase
$dl4 = "aria2c" nocase
$dl5 = "axel" nocase
$dl6 = "httpie" nocase
$pipe1 = "| bash"
$pipe2 = "| sh"
$pipe3 = "| zsh"
$pipe4 = "| python"
$pipe5 = "| perl"
condition:
any of ($dl*) and any of ($pipe*)
}
rule staged_download_exec {
meta:
severity = 7
description = "Script downloads file then executes it"
category = "staged"
strings:
$dl1 = "curl" nocase
$dl2 = "wget" nocase
$dl3 = "fetch" nocase
$dl4 = "aria2c" nocase
$dl5 = "axel" nocase
$dl6 = "httpie" nocase
$dl7 = "scp" nocase
$dl8 = "rsync" nocase
$exec1 = "&& bash"
$exec2 = "&& sh"
$exec3 = "&& zsh"
$exec4 = "; bash"
$exec5 = "; sh"
$exec6 = "; zsh"
$exec7 = "&& chmod +x"
$exec8 = "; chmod +x"
$exec9 = "&& ./"
$exec10 = "; ./"
condition:
any of ($dl*) and any of ($exec*)
}
rule multi_stage_download {
meta:
severity = 8
description = "Multiple download commands suggesting staged attack"
category = "staged"
strings:
$dl = /curl|wget|fetch|aria2c|axel|httpie|scp|rsync/ nocase
condition:
#dl >= 3
}
// =============================================================================
// Category 3: Reverse Shells (Severity: 10)
// =============================================================================
rule reverse_shell_bash {
meta:
severity = 10
description = "Bash reverse shell pattern"
category = "reverse_shell"
strings:
$bash_i = "bash -i"
$dev_tcp = "/dev/tcp/"
condition:
$bash_i and $dev_tcp
}
rule reverse_shell_nc {
meta:
severity = 10
description = "Netcat reverse shell pattern"
category = "reverse_shell"
strings:
$nc1 = /nc\s+-[elp]/ nocase
$nc2 = /netcat\s+-[elp]/ nocase
$nc3 = /ncat\s+-[elp]/ nocase
$shell = /\/bin\/(ba)?sh/
condition:
any of ($nc*) and $shell
}
rule reverse_shell_python {
meta:
severity = 10
description = "Python reverse shell pattern"
category = "reverse_shell"
strings:
$socket = "socket.socket"
$connect = ".connect("
$pty = "pty.spawn"
$subprocess = "subprocess.call"
condition:
($socket and $connect) or $pty or $subprocess
}
rule reverse_shell_perl {
meta:
severity = 10
description = "Perl reverse shell pattern"
category = "reverse_shell"
strings:
$perl_socket = "IO::Socket::INET"
$perl_exec = "exec(\"/bin/"
condition:
$perl_socket or $perl_exec
}
// =============================================================================
// Category 4: Persistence Mechanisms (Severity: 8)
// =============================================================================
rule persistence_launchagent {
meta:
severity = 8
description = "macOS LaunchAgent persistence"
category = "persistence"
strings:
$la_path1 = "~/Library/LaunchAgents"
$la_path2 = "/Library/LaunchAgents"
$la_path3 = "LaunchAgents/"
$plist = ".plist"
condition:
any of ($la_path*) and $plist
}
rule persistence_crontab {
meta:
severity = 8
description = "Crontab persistence"
category = "persistence"
strings:
// Match write operations: crontab file, crontab -e/-r, crontab - (stdin)
// Excludes: crontab -l (list)
$cron_write = /crontab\s+[^-l\s]|crontab\s+-[erw]|crontab\s+-\s*$/
$cron_pipe = /\|\s*crontab\s*-?\s*$/
$cron_etc = "/etc/crontab"
$cron_spool = "/var/spool/cron"
condition:
any of them
}
rule persistence_bashrc {
meta:
severity = 7
description = "Shell RC file modification"
category = "persistence"
strings:
$rc1 = ".bashrc"
$rc2 = ".zshrc"
$rc3 = ".profile"
$rc4 = ".bash_profile"
$write = />>|echo.*>>/
condition:
any of ($rc*) and $write
}
rule persistence_login_hook {
meta:
severity = 8
description = "macOS login hook persistence"
category = "persistence"
strings:
$hook = "LoginHook"
$defaults = "defaults write"
condition:
$hook or ($defaults and /loginwindow/)
}
// =============================================================================
// Category 5: Privilege Escalation (Severity: 7)
// =============================================================================
rule privesc_sudo_stdin {
meta:
severity = 7
description = "Sudo password from stdin"
category = "privilege_escalation"
strings:
$sudo_s = "sudo -S"
$echo_sudo = /echo.*\|.*sudo/
condition:
any of them
}
rule privesc_osascript_admin {
meta:
severity = 7
description = "AppleScript admin privilege request"
category = "privilege_escalation"
strings:
$osascript = "osascript"
$admin = "administrator privileges"
$password = "with prompt"
condition:
$osascript and ($admin or $password)
}
rule privesc_dscl {
meta:
severity = 8
description = "User account manipulation via dscl"
category = "privilege_escalation"
strings:
$dscl = "dscl"
$create = "create"
$admin = "admin"
condition:
$dscl and $create and $admin
}
// =============================================================================
// Category 6: Crypto Wallet Targeting (Severity: 9)
// =============================================================================
rule crypto_wallet_theft {
meta:
severity = 9
description = "Cryptocurrency wallet targeting"
category = "crypto_theft"
strings:
$wallet1 = "wallet.dat" nocase
$wallet2 = "keystore" nocase
$wallet3 = "electrum" nocase
$wallet4 = "exodus" nocase
$wallet5 = "atomic" nocase
$wallet6 = "metamask" nocase
$wallet7 = "phantom" nocase
$wallet8 = "solflare" nocase
$seed = "seed" nocase
$mnemonic = "mnemonic" nocase
condition:
any of ($wallet*) or ($seed and $mnemonic)
}
rule crypto_browser_extension {
meta:
severity = 9
description = "Browser crypto extension targeting"
category = "crypto_theft"
strings:
$ext_path = "Extensions"
$chrome = "Google/Chrome"
$brave = "BraveSoftware"
$ext_id1 = "nkbihfbeogaeaoehlefnkodbefgpgknn" // MetaMask
$ext_id2 = "bfnaelmomeimhlpmgjnjophhpkkoljpa" // Phantom
condition:
$ext_path and (any of ($chrome, $brave) or any of ($ext_id*))
}
// =============================================================================
// Category 7: Quarantine Bypass (Severity: 9)
// =============================================================================
rule quarantine_bypass_xattr {
meta:
severity = 9
description = "Gatekeeper quarantine attribute removal"
category = "quarantine_bypass"
strings:
$xattr = "xattr"
$quarantine = "com.apple.quarantine"
$delete = "-d"
$recursive = "-r"
condition:
$xattr and $quarantine and ($delete or $recursive)
}
rule quarantine_bypass_spctl {
meta:
severity = 9
description = "Gatekeeper disable via spctl"
category = "quarantine_bypass"
strings:
$spctl = "spctl"
$disable = "--master-disable"
$add = "--add"
condition:
$spctl and ($disable or $add)
}
// =============================================================================
// Category 8: AMOS/ClickFix IOCs (Severity: 10)
// =============================================================================
rule amos_stealer_indicators {
meta:
severity = 10
description = "AMOS Stealer indicators"
category = "amos"
strings:
$amos1 = "Atomic macOS Stealer" nocase
$amos2 = "atomicstealer" nocase
$amos3 = /keychain.*dump/i
$amos4 = "security find-generic-password"
$amos5 = "security dump-keychain"
condition:
any of them
}
rule clickfix_indicators {
meta:
severity = 10
description = "ClickFix campaign indicators"
category = "clickfix"
strings:
$cf1 = "I'm not a robot" nocase
$cf2 = "verify you are human" nocase
$cf3 = "press and hold" nocase
$cf4 = "Windows + R" nocase
$copy_paste = /copy.*paste|paste.*terminal/i
condition:
any of ($cf*) or $copy_paste
}
// =============================================================================
// Category 9: Environment Harvesting (Severity: 6)
// =============================================================================
rule env_harvesting {
meta:
severity = 6
description = "Environment variable harvesting"
category = "recon"
strings:
$env1 = "printenv"
$env2 = "$HOME"
$env3 = "$USER"
$env4 = "$PATH"
$env5 = "env |"
$send = /curl|wget|nc|aria2c|axel|httpie/
condition:
2 of ($env*) and $send
}
rule credential_harvesting {
meta:
severity = 8
description = "Credential file access"
category = "recon"
strings:
$aws = ".aws/credentials"
$ssh = ".ssh/"
$gpg = ".gnupg/"
$npm = ".npmrc"
$docker = ".docker/config.json"
$kube = ".kube/config"
condition:
any of them
}
// =============================================================================
// Category 10: Anti-Analysis (Severity: 5)
// =============================================================================
rule anti_analysis_vm_detect {
meta:
severity = 5
description = "Virtual machine detection"
category = "anti_analysis"
strings:
$vm1 = "VMware"
$vm2 = "VirtualBox"
$vm3 = "Parallels"
$vm4 = "QEMU"
$check = "system_profiler"
condition:
$check and any of ($vm*)
}
rule anti_analysis_sandbox_detect {
meta:
severity = 5
description = "Sandbox detection"
category = "anti_analysis"
strings:
$sb1 = "sandbox-exec"
$sb2 = "/Library/Sandboxes"
$sleep = /sleep\s+[0-9]{3,}/ // Long sleep (100+ seconds)
condition:
any of ($sb*) or $sleep
}
rule anti_analysis_debugger {
meta:
severity = 6
description = "Debugger detection"
category = "anti_analysis"
strings:
$ptrace = "ptrace"
$sysctl = "sysctl"
$debug = "P_TRACED"
condition:
$ptrace or ($sysctl and $debug)
}
// =============================================================================
// Category 11: Python Supply Chain Attacks (Severity: 7-9)
// Source: DataDog GuardDog patterns
// =============================================================================
rule python_subprocess_shell_injection {
meta:
severity = 8
description = "Python subprocess with shell injection"
category = "supply_chain"
strings:
$subprocess = "subprocess.Popen" nocase
$system = "os.system" nocase
$shell = "shell=True"
$curl = "curl" nocase
$wget = "wget" nocase
$aria2c = "aria2c" nocase
$axel = "axel" nocase
$bash = /bash|sh/
condition:
($subprocess and $shell) or ($system and ($curl or $wget or $aria2c or $axel or $bash))
}
rule python_exec_base64 {
meta:
severity = 8
description = "Python exec with base64 obfuscation"
category = "supply_chain"
strings:
$exec = /exec|eval/
$b64_module = "base64" nocase
$b64decode = "b64decode"
$import = "__import__"
condition:
$exec and ($b64decode or ($b64_module and $import))
}
rule python_exec_remote {
meta:
severity = 9
description = "Python exec/eval with remote code"
category = "supply_chain"
strings:
$exec = /exec|eval/
$urllib = "urllib" nocase
$urlopen = "urlopen"
$requests = "requests" nocase
$http = /https?:\/\//
condition:
$exec and ($urllib or $urlopen or $requests) and $http
}
rule python_env_exfiltration {
meta:
severity = 8
description = "Python environment variable exfiltration"
category = "supply_chain"
strings:
$os_environ = "os.environ"
$getenv = "os.getenv"
$aws_key = "AWS_ACCESS_KEY_ID" nocase
$aws_secret = "AWS_SECRET_ACCESS_KEY" nocase
$post = /requests\.post|urllib.*urlopen/
$http = /https?:\/\//
condition:
($os_environ or ($getenv and ($aws_key or $aws_secret))) and $post and $http
}
rule python_ssh_key_exfil {
meta:
severity = 9
description = "Python SSH key exfiltration"
category = "supply_chain"
strings:
$ssh_key = ".ssh/id_rsa"
$ssh_dir = ".ssh/"
$socket = "socket.socket"
$open_read = "open("
$send = /\.send|\.sendall/
condition:
($ssh_key or $ssh_dir) and $socket and $open_read and $send
}
rule python_download_execute {
meta:
severity = 8
description = "Python download and execute binary"
category = "supply_chain"
strings:
$urllib = "urllib.request.urlretrieve"
$chmod = "os.chmod"
$stat = "stat.S_IXUSR"
$system = "os.system"
$popen = "subprocess.Popen"
$http = /https?:\/\//
condition:
$urllib and $http and ($chmod or $stat) and ($system or $popen)
}
rule python_fileless_execution {
meta:
severity = 9
description = "Python fileless (memory-only) execution"
category = "supply_chain"
strings:
$exec = /exec|eval/
$urllib = "urllib" nocase
$urlopen = "urlopen"
$read = ".read()"
$http = /https?:\/\//
condition:
$exec and ($urllib or $urlopen) and $read and $http
}
rule python_nohup_background {
meta:
severity = 7
description = "Python silent background execution"
category = "supply_chain"
strings:
$nohup = "nohup"
$background = "&"
$devnull = "/dev/null"
$system = "os.system"
$curl = "curl" nocase
$wget = "wget" nocase
$aria2c = "aria2c" nocase
condition:
$nohup and $background and ($devnull or $system) and ($curl or $wget or $aria2c)
}
// =============================================================================
// Category 12: Node.js/npm Supply Chain Attacks (Severity: 7-8)
// =============================================================================
rule npm_malicious_install_script {
meta:
severity = 8
description = "npm install script with malicious command"
category = "supply_chain"
strings:
$scripts = "\"scripts\""
$postinstall = "postinstall" nocase
$preinstall = "preinstall" nocase
$curl = "curl" nocase
$wget = "wget" nocase
$aria2c = "aria2c" nocase
$axel = "axel" nocase
$bash = /\|\s*bash/
$sh = /\|\s*sh/
condition:
$scripts and ($postinstall or $preinstall) and ($curl or $wget or $aria2c or $axel) and ($bash or $sh)
}
rule npm_node_exec_injection {
meta:
severity = 8
description = "npm node -e with command injection"
category = "supply_chain"
strings:
$node_e = /node\s+-e/
$child_process = "child_process"
$exec = ".exec"
$curl = "curl" nocase
$wget = "wget" nocase
$aria2c = "aria2c" nocase
$eval = "eval"
condition:
$node_e and ($child_process and $exec) or ($node_e and ($curl or $wget or $aria2c) and $eval)
}
// =============================================================================
// Category 13: Real-World Attack Patterns (Severity: 9-10)
// =============================================================================
rule python_setuptools_custom_install {
meta:
severity = 9
description = "Suspicious setuptools custom install command"
category = "supply_chain"
strings:
$setuptools = "setuptools.command.install"
$custom_class = "class CustomInstallCommand"
$os_system = "os.system"
$subprocess = "subprocess"
$bash_i = "bash -i"
$dev_tcp = "/dev/tcp/"
condition:
$setuptools and $custom_class and ($os_system or $subprocess) and ($bash_i or $dev_tcp)
}
rule python_tempfile_exec_hidden {
meta:
severity = 8
description = "Temporary file with hidden execution (pythonw pattern)"
category = "supply_chain"
strings:
$tempfile = "tempfile" nocase
$namedtemp = "NamedTemporaryFile"
$exec = /exec|eval/
$urlopen = "urlopen"
$pythonw = "pythonw"
$sys_exec = "sys.executable"
condition:
($tempfile or $namedtemp) and $exec and ($urlopen or $pythonw or $sys_exec)
}
rule python_obfuscated_imports {
meta:
severity = 7
description = "Obfuscated Python imports"
category = "supply_chain"
strings:
$__import__ = "__import__"
$chr = "chr("
$ord = "ord("
$join = "join("
$exec = /exec|eval/
condition:
$__import__ and ($chr or $ord) and $join and $exec
}
rule python_pastebin_c2 {
meta:
severity = 9
description = "Pastebin used as C2 channel"
category = "supply_chain"
strings:
$pastebin = /paste\.bingner\.com|pastebin\.com|paste\.ee/
$raw = "/raw/"
$exec = /exec|eval/
$urllib = "urllib" nocase
condition:
$pastebin and ($raw or $exec) and $urllib
}
rule python_reverseshell_obfuscated {
meta:
severity = 10
description = "Obfuscated Python reverse shell"
category = "supply_chain"
strings:
$socket = "socket.socket"
$connect = ".connect"
$subprocess = "subprocess"
$popen = "Popen"
$stdin = "stdin"
$stdout = "stdout"
$base64 = "base64"
$b64decode = "b64decode"
condition:
$socket and $connect and ($subprocess or $popen) and ($stdin or $stdout) and ($base64 or $b64decode)
}
rule python_shell_command_substitution {
meta:
severity = 8
description = "Shell command substitution in Python"
category = "supply_chain"
strings:
$os_system = "os.system"
$subprocess = "subprocess"
$backtick = "`"
$dollar_paren = "$("
$curl = "curl" nocase
$wget = "wget" nocase
$aria2c = "aria2c" nocase
$eval = "eval"
condition:
($os_system or $subprocess) and ($backtick or $dollar_paren) and ($curl or $wget or $aria2c or $eval)
}