shellfirm 0.4.2

`shellfirm` will intercept any risky patterns (default or defined by you) and prompt you a small challenge for double verification, kinda like a captcha for your terminal.
Documentation
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
---
# -- base:bash_fork_bomb --
- test: ':(){ :|:& };:'
  description: "match fork bomb command"
  expect_ids: ["base:bash_fork_bomb"]
- test: ':(){ echo hello; };:'
  description: "similar syntax but not a fork bomb"
  expect_ids: []

# -- base:delete_all_cron_tasks --
- test: "crontab -r"
  description: "match command"
  expect_ids: ["base:delete_all_cron_tasks"]
- test: "crontab   -r"
  description: "match command with multiple spaces"
  expect_ids: ["base:delete_all_cron_tasks"]
- test: " crontab   -r"
  description: "match command with multiple spaces"
  expect_ids: ["base:delete_all_cron_tasks"]
- test: "crontab-r"
  description: "invalid command"
  expect_ids: []

# -- base:execute_all_history_commands --
- test: "history | bash"
  description: "match command that end with bash"
  expect_ids: ["base:execute_all_history_commands"]
- test: "history | sh"
  description: "match command that end with sh"
  expect_ids: ["base:execute_all_history_commands"]
- test: "history   |   sh"
  description: "match command with multiple spaces"
  expect_ids: ["base:execute_all_history_commands"]
- test: "history | grep -v  | bash"
  description: "match command"
  expect_ids: ["base:execute_all_history_commands"]
- test: "history|bash"
  description: "match command without spaces"
  expect_ids: ["base:execute_all_history_commands"]
- test: "history | shh"
  description: "not end with sh"
  expect_ids: []
- test: "history | bashh"
  description: "not end with bash"
  expect_ids: []

# -- base:reboot_machine --
- test: "reboot"
  description: "match command"
  expect_ids: ["base:reboot_machine"]
- test: "reboot -r"
  description: "match command with flag"
  expect_ids: ["base:reboot_machine"]
- test: "reboot -r now"
  description: "match command with flag value"
  expect_ids: ["base:reboot_machine"]
- test: "reboot    -r   now"
  description: "match command with spaces"
  expect_ids: ["base:reboot_machine"]
- test: "reboot"
  description: "match command with spaces"
  expect_ids: ["base:reboot_machine"]
- test: "reboot  now   -r"
  description: "match command with flag value"
  expect_ids: ["base:reboot_machine"]
- test: "reboott"
  description: "not match"
  expect_ids: []

# -- base:shutdown_machine --
- test: "shutdown"
  description: "match command"
  expect_ids: ["base:shutdown_machine", "redis:interactive_shutdown"]
- test: "shutdown -r"
  description: "match command with flag"
  expect_ids: ["base:shutdown_machine"]
- test: "shutdown -r now"
  description: "match command with flag value"
  expect_ids: ["base:shutdown_machine"]
- test: "shutdown  -r    now"
  description: "match command with spaces"
  expect_ids: ["base:shutdown_machine"]
- test: "shutdown    now  -r"
  description: "match command with spaces"
  expect_ids: ["base:shutdown_machine"]
- test: "shutdown"
  description: "match command with spaces"
  expect_ids: ["base:shutdown_machine", "redis:interactive_shutdown"]
- test: "shutdownn"
  description: "not match"
  expect_ids: []

# -- process:kill_9 --
- test: "kill -9 1234"
  description: "match kill -9 with PID"
  expect_ids: ["process:kill_9"]
- test: "kill -9 $(pgrep nginx)"
  description: "match kill -9 with command substitution"
  expect_ids: ["process:kill_9"]
- test: "kill 1234"
  description: "negative: regular kill should not match"
  expect_ids: []
- test: "kill -15 1234"
  description: "negative: SIGTERM should not match"
  expect_ids: []

# -- process:killall --
- test: "killall nginx"
  description: "match killall with process name"
  expect_ids: ["process:killall"]
- test: "killall -9 node"
  description: "match killall with signal"
  expect_ids: ["process:killall"]
- test: "kill 1234"
  description: "negative: kill single process should not match killall"
  expect_ids: []

# -- process:pkill --
- test: "pkill nginx"
  description: "match pkill with pattern"
  expect_ids: ["process:pkill"]
- test: "pkill -f 'node server.js'"
  description: "match pkill with full command match"
  expect_ids: ["process:pkill"]
- test: "pgrep nginx"
  description: "negative: pgrep should not match pkill"
  expect_ids: []

# -- systemd:disable_service --
- test: "systemctl disable nginx"
  description: "match systemctl disable"
  expect_ids: ["systemd:disable_service"]
- test: "systemctl mask docker"
  description: "match systemctl mask"
  expect_ids: ["systemd:disable_service"]
- test: "systemctl enable nginx"
  description: "enable is not a disable, but starts the service at every boot (Low)"
  expect_ids: ["base:systemctl_enable"]
- test: "systemctl start nginx"
  description: "negative: start should not match"
  expect_ids: []

# -- systemd:stop_critical_service --
- test: "systemctl stop docker"
  description: "match stopping docker"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop sshd"
  description: "match stopping sshd"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop nginx"
  description: "match stopping nginx"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop postgresql"
  description: "match stopping postgresql"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop mysql"
  description: "match stopping mysql"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop redis"
  description: "match stopping redis"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop myapp"
  description: "negative: stopping non-critical service should not match"
  expect_ids: []
- test: "systemctl restart nginx"
  description: "negative: restart should not match stop check"
  expect_ids: []

# -- ssh:delete_all_identities --
- test: "ssh-add -D"
  description: "match ssh-add -D"
  expect_ids: ["ssh:delete_all_identities"]
- test: "ssh-add -l"
  description: "negative: list identities should not match"
  expect_ids: []

# -- ssh:remove_known_host --
- test: "ssh-keygen -R example.com"
  description: "match removing known host"
  expect_ids: ["ssh:remove_known_host"]
- test: "ssh-keygen -R 192.168.1.1"
  description: "match removing known host by IP"
  expect_ids: ["ssh:remove_known_host"]
- test: "ssh-keygen -t rsa"
  description: "negative: generating key should not match"
  expect_ids: []

# -- base:poweroff_machine --
- test: "halt"
  description: "match halt command"
  expect_ids: ["base:poweroff_machine"]
- test: "poweroff"
  description: "match poweroff command"
  expect_ids: ["base:poweroff_machine"]
- test: "halt -f"
  description: "match halt with flag"
  expect_ids: ["base:poweroff_machine"]
- test: "poweroff -f"
  description: "match poweroff with flag"
  expect_ids: ["base:poweroff_machine"]
- test: "halting"
  description: "negative: word starting with halt should not match"
  expect_ids: []
- test: "powerofff"
  description: "negative: misspelled poweroff should not match"
  expect_ids: []

# -- base:init_shutdown_reboot --
- test: "init 0"
  description: "match init 0 (shutdown)"
  expect_ids: ["base:init_shutdown_reboot"]
- test: "init 6"
  description: "match init 6 (reboot)"
  expect_ids: ["base:init_shutdown_reboot"]
- test: "init  0"
  description: "match init 0 with extra spaces"
  expect_ids: ["base:init_shutdown_reboot"]
- test: "init 1"
  description: "negative: init 1 (single user) should not match"
  expect_ids: []
- test: "init 3"
  description: "negative: init 3 (multi-user) should not match"
  expect_ids: []

# ====== EDGE CASE / STRESS TESTS ======

# -- base:reboot_machine edge cases --
- test: "sudo reboot"
  description: "EDGE: sudo reboot"
  expect_ids: ["base:reboot_machine"]
- test: "myreboot"
  description: "negative: substring should not match - reboot requires word boundary"
  expect_ids: []

# -- base:shutdown_machine edge cases --
- test: "sudo shutdown -h now"
  description: "EDGE: sudo shutdown with flags"
  expect_ids: ["base:shutdown_machine"]
- test: "myshutdown"
  description: "negative: substring should not match - shutdown requires word boundary"
  expect_ids: []

# -- systemd:stop_critical_service edge cases --
- test: "systemctl stop docker.service"
  description: "match stopping docker with .service suffix"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop redis-server"
  description: "match stopping redis-server variant"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop postgresql-14"
  description: "match stopping postgresql with version suffix"
  expect_ids: ["systemd:stop_critical_service"]

# -- base:delete_all_cron_tasks edge cases --
- test: "sudo crontab -r"
  description: "EDGE: sudo prefix"
  expect_ids: ["base:delete_all_cron_tasks"]
- test: "crontab -l"
  description: "EDGE: list should not match"
  expect_ids: []

# -- process:kill_init_or_all --
- test: "kill -9 1"
  description: "SIGKILL to init"
  expect_ids: ["process:kill_init_or_all", "process:kill_9"]
- test: "kill -9 -1"
  description: "SIGKILL to every process"
  expect_ids: ["process:kill_init_or_all", "process:kill_9"]
- test: "kill -s KILL 1"
  description: "signal by name"
  expect_ids: ["process:kill_init_or_all"]
- test: "kill -- -1"
  description: "-- separator"
  expect_ids: ["process:kill_init_or_all"]
- test: "kill -9 1234"
  description: "negative: an ordinary pid"
  expect_ids: ["process:kill_9"]
- test: "kill 12"
  description: "negative: pid 12"
  expect_ids: []
# -- base:clear_history --
- test: "history -c"
  description: "erases history"
  expect_ids: ["base:clear_history"]
- test: "history -cw"
  description: "clustered flags"
  expect_ids: ["base:clear_history"]
- test: "history 20"
  description: "negative: listing history"
  expect_ids: []
- test: "history -s kubectl delete namespace prod"
  description: "negative: history -s only stores text"
  expect_ids: []
- test: "print -s git push -f origin main"
  description: "negative: zsh print -s only stores text"
  expect_ids: []
# -- base:userdel_remove_home / base:passwd_delete --
- test: 'userdel -r bob'
  description: "delete user and home"
  expect_ids: ["base:userdel_remove_home"]
- test: 'userdel bob'
  description: "negative: keeps the home directory"
  expect_ids: []
- test: 'passwd -d root'
  description: "remove a password"
  expect_ids: ["base:passwd_delete"]
- test: 'passwd bob'
  description: "negative: change a password"
  expect_ids: []
- test: "deluser --remove-home alice"
  description: "Debian deluser with the home directory"
  expect_ids: ["base:userdel_remove_home"]
- test: "deluser alice"
  description: "deluser keeps the home directory"
  expect_ids: []
- test: "echo o | sudo tee /proc/sysrq-trigger"
  description: "power off through sysrq"
  expect_ids: ["base:sysrq_trigger"]

# -- base:crontab_replace --
- test: "crontab /tmp/cron"
  description: "replacing the crontab with a file"
  expect_ids: ["base:crontab_replace"]
- test: "crontab -"
  description: "replacing the crontab from stdin"
  expect_ids: ["base:crontab_replace"]
- test: "crontab -l"
  description: "negative: listing"
  expect_ids: []
- test: "crontab -e"
  description: "negative: editing interactively"
  expect_ids: []

# -- base:systemctl_enable --
- test: "systemctl --user enable x.service"
  description: "a user service started at every login"
  expect_ids: ["base:systemctl_enable"]
- test: "sudo systemctl enable --now nginx"
  description: "a system service started at boot"
  expect_ids: ["base:systemctl_enable"]
- test: "systemctl status nginx"
  description: "negative: status"
  expect_ids: []
- test: "sudo systemctl stop kubelet"
  description: "stopping the kubelet"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl stop containerd"
  description: "stopping the container runtime"
  expect_ids: ["systemd:stop_critical_service"]
- test: "sudo service postgresql stop"
  description: "the SysV service form"
  expect_ids: ["systemd:stop_critical_service"]
- test: "systemctl status kubelet"
  description: "negative: status"
  expect_ids: []
- test: "sudo systemctl isolate rescue.target"
  description: "single-user mode"
  expect_ids: ["systemd:isolate_rescue"]
- test: "systemctl isolate graphical.target"
  description: "negative: a normal target"
  expect_ids: []
- test: "sudo passwd -l root"
  description: "locking root"
  expect_ids: ["base:lock_root_account"]
- test: "passwd -l alice"
  description: "negative: another account"
  expect_ids: []
- test: "sudo mount -o remount,ro /"
  description: "root read-only"
  expect_ids: ["base:remount_root_readonly"]
- test: "sudo mount -o remount,rw /"
  description: "negative: read-write again"
  expect_ids: []
- test: "journalctl --vacuum-time=1s"
  description: "deleting the journal"
  expect_ids: ["base:journal_vacuum"]
- test: "journalctl -u nginx --since today"
  description: "negative: reading the journal"
  expect_ids: []
# -- systemd:isolate_rescue (systemctl rescue) --
- test: "systemctl rescue"
  description: "the short form of isolate rescue.target"
  expect_ids: ["systemd:isolate_rescue"]
- test: "sudo systemctl emergency"
  description: "emergency mode"
  expect_ids: ["systemd:isolate_rescue"]
- test: "systemctl status rescue.service"
  description: "negative: a status query"
  expect_ids: []

# ---- anchoring and housekeeping ----
# -- base:kill_9 --
- test: "pkill_9 x"
  description: "not kill"
  expect_ids: []
- test: "vssadmin delete shadows /all /quiet"
  description: "vssadmin delete shadows /all /quiet"
  expect_ids: ["base:delete_shadow_copies"]
- test: "Set-MpPreference -DisableRealtimeMonitoring $true"
  description: "Set-MpPreference -DisableRealtimeMonitoring $true"
  expect_ids: ["base:disable_antivirus"]
# -- Windows AV / backup / event-log breadth --
- test: "Set-MpPreference -DisableRealtimeMonitoring:$true"
  description: "colon form of DisableRealtimeMonitoring"
  expect_ids: ["base:disable_antivirus"]
- test: "Set-MpPreference -DisableBehaviorMonitoring $true"
  description: "disable behavior monitoring"
  expect_ids: ["base:disable_antivirus"]
- test: "sc stop WinDefend"
  description: "stop the Defender service"
  expect_ids: ["base:disable_antivirus"]
- test: "sc.exe delete WinDefend"
  description: "delete the Defender service"
  expect_ids: ["base:disable_antivirus"]
- test: "MpCmdRun.exe -RemoveDefinitions -All"
  description: "remove Defender definitions"
  expect_ids: ["base:disable_antivirus"]
- test: "reg add \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows Defender\" /v DisableAntiSpyware /t REG_DWORD /d 1 /f"
  description: "DisableAntiSpyware registry key"
  expect_ids: ["base:disable_antivirus"]
- test: "Get-MpComputerStatus"
  description: "negative: reading Defender status"
  expect_ids: []
- test: "vssadmin resize shadowstorage /for=C: /on=C: /maxsize=401MB"
  description: "shrink shadow storage to drop copies"
  expect_ids: ["base:delete_shadow_copies"]
- test: "bcdedit /set {default} recoveryenabled No"
  description: "disable Windows recovery"
  expect_ids: ["base:delete_shadow_copies"]
- test: "Get-WmiObject Win32_Shadowcopy | ForEach-Object { $_.Delete() }"
  description: "WMI shadow copy delete"
  expect_ids: ["base:delete_shadow_copies"]
- test: "Get-CimInstance Win32_Shadowcopy | Remove-CimInstance"
  description: "CIM shadow copy delete"
  expect_ids: ["base:delete_shadow_copies"]
- test: "wevtutil cl Security"
  description: "clear the Security event log"
  expect_ids: ["base:clear_event_logs"]
- test: "Clear-EventLog -LogName Application"
  description: "Clear-EventLog"
  expect_ids: ["base:clear_event_logs"]
- test: "wevtutil el"
  description: "negative: listing event logs"
  expect_ids: []
- test: "tmutil delete /Volumes/Backup/2026-01-01-000000"
  description: "delete a Time Machine backup"
  expect_ids: ["base:delete_backups_macos"]
- test: "tmutil deletelocalsnapshots /"
  description: "delete local APFS snapshots"
  expect_ids: ["base:delete_backups_macos"]
- test: "tmutil listbackups"
  description: "negative: listing backups"
  expect_ids: []
# -- more Defender-off forms --
- test: "net stop WinDefend"
  description: "stop Defender via net stop"
  expect_ids: ["base:disable_antivirus"]
- test: "Stop-Service -Name WinDefend"
  description: "Stop-Service Defender"
  expect_ids: ["base:disable_antivirus"]
- test: "taskkill /F /IM MsMpEng.exe"
  description: "kill the Defender engine process"
  expect_ids: ["base:disable_antivirus"]
- test: "net stop spooler"
  description: "negative: stopping an unrelated service"
  expect_ids: []
- test: "Stop-Service nginx"
  description: "negative: stopping an unrelated service"
  expect_ids: []
# -- macOS security disable, more Defender-off forms --
- test: "csrutil disable"
  description: "disabling macOS System Integrity Protection"
  expect_ids: ["base:disable_macos_security"]
- test: "spctl --master-disable"
  description: "disabling macOS Gatekeeper"
  expect_ids: ["base:disable_macos_security"]
- test: "spctl --global-disable"
  description: "disabling Gatekeeper (newer flag)"
  expect_ids: ["base:disable_macos_security"]
- test: "Set-MpPreference -MAPSReporting Disabled"
  description: "turning off Defender cloud reporting"
  expect_ids: ["base:disable_antivirus"]
- test: "Stop-Service WinDefend"
  description: "stopping Defender by bare service name"
  expect_ids: ["base:disable_antivirus"]
- test: "csrutil status"
  description: "negative: querying SIP status is read-only"
  expect_ids: []

# -- base:disable_history --
- test: "unset HISTFILE"
  description: "unset HISTFILE"
  expect_ids: ["base:disable_history"]
- test: "export HISTFILE=/dev/null"
  description: "HISTFILE to /dev/null"
  expect_ids: ["base:disable_history"]
- test: "set +o history"
  description: "set +o history"
  expect_ids: ["base:disable_history"]
- test: "HISTFILE=/dev/null"
  description: "plain assignment"
  expect_ids: ["base:disable_history"]
- test: "export HISTSIZE=0"
  description: "history size zero"
  expect_ids: ["base:disable_history"]
- test: "unset HISTFILE HISTSIZE"
  description: "several names"
  expect_ids: ["base:disable_history"]
- test: "export HISTSIZE=10000"
  description: "negative: a larger history"
  expect_ids: []
- test: "export HISTFILE=~/.zsh_history"
  description: "negative: a history file path"
  expect_ids: []
- test: "set -o history"
  description: "negative: set -o history"
  expect_ids: []
- test: "set -euo pipefail"
  description: "negative: strict mode"
  expect_ids: []
- test: "unset NODE_OPTIONS"
  description: "negative: unset another variable"
  expect_ids: []

# -- base:disable_history (shopt) --
- test: "shopt -u -o history"
  description: "history option off"
  expect_ids: ["base:disable_history"]
- test: "shopt -ou history"
  description: "bundled -ou"
  expect_ids: ["base:disable_history"]
- test: "shopt -s -o history"
  description: "negative: history on"
  expect_ids: []
- test: "shopt -u histappend"
  description: "negative: another option"
  expect_ids: []

# -- base:clear_history_file --
- test: "rm -f ~/.bash_history"
  description: "the bash history deleted"
  expect_ids: ["base:clear_history_file", "fs-strict:any_deletion"]
- test: "rm ~/.zsh_history"
  description: "the zsh history deleted"
  expect_ids: ["base:clear_history_file", "fs-strict:any_deletion"]
- test: "> ~/.bash_history"
  description: "emptied by a redirection"
  expect_ids: ["base:clear_history_file", "fs:flush_file_content"]
- test: ": > ~/.zsh_history"
  description: "emptied with :"
  expect_ids: ["base:clear_history_file", "fs:flush_file_content"]
- test: "truncate -s0 ~/.zsh_history"
  description: "truncated"
  expect_ids: ["base:clear_history_file", "fs:truncate_zero"]
- test: "ln -sf /dev/null ~/.bash_history"
  description: "pointed at /dev/null"
  expect_ids: ["base:clear_history_file", "fs:clobber_with_dev_null"]
- test: "rm -f ./history.txt"
  description: "negative: an ordinary file"
  expect_ids: ["fs-strict:any_deletion"]
- test: "history | grep ssh"
  description: "negative: reading history"
  expect_ids: []

# -- base:wipe_system_logs --
- test: "truncate -s 0 /var/log/auth.log"
  description: "the login log emptied"
  expect_ids: ["base:wipe_system_logs"]
- test: "sudo truncate -s 0 /var/log/*"
  description: "every system log emptied"
  expect_ids: ["base:wipe_system_logs", "fs:truncate_zero"]
- test: ": > /var/log/syslog"
  description: "the syslog emptied"
  expect_ids: ["base:wipe_system_logs", "fs:flush_file_content"]
- test: "cat /dev/null > /var/log/wtmp"
  description: "the login records emptied"
  expect_ids: ["base:wipe_system_logs", "fs:flush_file_content"]
- test: "truncate -s 0 app.log"
  description: "negative: a project log"
  expect_ids: []
- test: ": > ./build.log"
  description: "negative: a build log"
  expect_ids: []
- test: "tail -f /var/log/syslog"
  description: "negative: reading the syslog"
  expect_ids: []