This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
bug-shell.py
executable file
·226 lines (162 loc) · 6.15 KB
/
bug-shell.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python
import os
import sys
import json
from yum.mdparser import MDParser
from yum import repoMDObject
import cmd
import subprocess
blurb = """
$ pip install requests
"""
try:
import requests
except ImportError as exc:
print(exc)
print("Dependencies not met, use following steps!")
print(blurb)
sys.exit(-1)
BASE_URL = "http://dl.fedoraproject.org/pub/fedora/linux/development/19/x86_64/os/"
database = {}
sections = {}
bug_template = """
Description of problem:
http://fedoraproject.org/wiki/Packaging:Guidelines#PIE says that "you MUST
enable the PIE compiler flags if your package is long running ...".
However, currently %s is not being built with PIE flags. This is a
clear violation of the packaging guidelines.
This issue (in its wider scope) is being discussed at,
https://fedorahosted.org/fesco/ticket/1104
https://lists.fedoraproject.org/pipermail/devel/2013-March/180827.html
Version-Release number of selected component (if applicable):
%s
How reproducible:
You can use following programs to check if a package is hardened:
http://people.redhat.com/sgrubb/files/rpm-chksec
OR
https://github.com/kholia/checksec
Steps to Reproduce:
Get scanner.py from https://github.com/kholia/checksec
$ ./scanner.py %s
%s"""
bug_template_setxid = """
Description of problem:
http://fedoraproject.org/wiki/Packaging:Guidelines#PIE says that "you MUST
enable the PIE compiler flags if your package has suid binaries...".
However, currently %s is not being built with PIE flags. This is a
clear violation of the packaging guidelines.
This issue (in its wider scope) is being discussed at,
https://fedorahosted.org/fesco/ticket/1104
https://lists.fedoraproject.org/pipermail/devel/2013-March/180827.html
Version-Release number of selected component (if applicable):
%s
How reproducible:
You can use following programs to check if a package is hardened:
http://people.redhat.com/sgrubb/files/rpm-chksec
OR
https://github.com/kholia/checksec
Steps to Reproduce:
Get scanner.py from https://github.com/kholia/checksec
$ ./scanner.py %s
%s"""
from scanner import analyze
pkg = None
def fetch(url, destination):
r = requests.get(url)
with open(destination, "wb") as f:
f.write(r.content)
def load():
repomdpath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"data", "repodata", "repomd.xml")
rmdo = repoMDObject.RepoMD("F19", repomdpath)
plocation = rmdo.repoData["primary"].location[1]
plocation = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"data", plocation)
parser = MDParser(plocation)
for pkg in parser:
database[pkg["name"]] = dict(pkg)
print 'read: %s packages (%s suggested)' % (parser.count, parser.total)
class Fedora(cmd.Cmd):
def do_search(self, package):
for key in database.keys():
if package in key:
print(key)
def do_analyze(self, package):
try:
filename = os.path.basename(database[package]["location_href"])
except:
print("package not found!")
return
destination = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"data", ".cache", filename)
url = BASE_URL + database[package]["location_href"]
if not os.path.exists(destination):
print(url, "=>", destination)
fetch(url, destination)
data = json.loads(analyze(destination, show_errors=False))
print json.dumps(data, sort_keys=True, indent=4,
separators=(',', ': '))
def do_describe(self, package):
print "description:", database[package]["description"]
print "group:", database[package]["group"]
print "ver + rel:", database[package]["ver"], database[package]["rel"]
def do_dump(self, line):
print(database.keys())
def do_report(self, package):
try:
filename = os.path.basename(database[package]["location_href"])
except:
print("package not found!")
return
destination = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"data", ".cache", filename)
url = BASE_URL + database[package]["location_href"]
if not os.path.exists(destination):
print(url, "=>", destination)
fetch(url, destination)
data = analyze(destination, show_errors=False, opformat="csv")
lines = data.split('\n')
build = lines[0].split(',')[1]
if pkg and package.startswith(pkg):
package = pkg
print "\n!!!! Setting package to %s !!!!\n\n\n" % pkg
elif pkg:
print "%s is too different from %s" % (pkg, package)
return
bug_summary = "%s package should be built with PIE flags" % package
bug_data = bug_template % (package, build, build, data)
# cmd = "bugzilla --bugzilla=https://partner-bugzilla.redhat.com/xmlrpc.cgi new --product Fedora " \
cmd = "bugzilla new --product Fedora " \
"--component '%s' --version '19' --summary '%s' --comment '%s'" % \
(package, bug_summary, bug_data)
print cmd
p = subprocess.Popen(cmd, shell=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
o, e = p.communicate()
print o,e
def do_setpkg(self, line):
global pkg
pkg = line.rstrip()
def do_unsetpkg(self, line):
global pkg
pkg = None
def do_about(self, line):
print("rpm-shell v0.01 ;)")
def do_sections(self, line=None):
for key in database.keys():
v = database[key]
l = sections.get(v["group"], [])
l.append(key)
sections[v["group"]] = l
print(sections.keys())
def do_section(self, line):
self.do_sections()
for key in sections.keys():
if line in key:
print("List for", key, ":", sections[key])
def preloop(self):
print("Loading database ...")
load()
def do_EOF(self, line):
return True
if __name__ == "__main__":
Fedora().cmdloop()