forked from SerpicoProject/Serpico
-
Notifications
You must be signed in to change notification settings - Fork 2
/
master.rb
349 lines (296 loc) · 12.1 KB
/
master.rb
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
require 'rubygems'
require 'data_mapper'
require 'digest/sha1'
require 'dm-migrations'
# Initialize the Master DB
DataMapper.setup(:default, "sqlite://#{Dir.pwd}/db/master.db")
class TemplateFindings
include DataMapper::Resource
property :id, Serial
property :title, String, :required => true, :length => 200
property :type, String, :required => false
property :overview, String, :length => 20000, :required => false
property :poc, String, :length => 20000, :required => false
property :remediation, String, :length => 20000, :required => false
property :references, String, :length => 20000, :required => false
property :approved, Boolean, :required => false, :default => true
property :affected_hosts, String, :length => 20000, :required => false
# CVSS
property :cvss_score, String, :required => false
property :cvss_vector, String, :required => false
property :cvss_severity, String, :required => false
# tag
property :tags, String, :required => false
# ehat
property :parameter, String, :required => false
property :method, String, :required => false
# nlp
property :summary, String, :required => false
# legacy fields for OLD Serpico compatibility
property :damage, Integer, :required => false
property :reproducability, Integer, :required => false
property :exploitability, Integer, :required => false
property :affected_users, Integer, :required => false
property :discoverability, Integer, :required => false
property :dread_total, Integer, :required => false
property :effort, String, :required => false
property :risk, Integer, :required => false
property :av, String, :required => false
property :ac, String, :required => false
property :au, String, :required => false
property :c, String, :required => false
property :i, String, :required => false
property :a, String, :required => false
property :e, String, :required => false
property :rl, String, :required => false
property :rc, String, :required => false
property :cdp, String, :required => false
property :td, String, :required => false
property :cr, String, :required => false
property :ir, String, :required => false
property :ar, String, :required => false
property :cvss_base, Float, :required => false
property :cvss_impact, Float, :required => false
property :cvss_exploitability, Float, :required => false
property :cvss_temporal, Float, :required => false
property :cvss_environmental, Float, :required => false
property :cvss_modified_impact, Float, :required => false
property :cvss_total, Float, :required => false
property :ease, String, :required => false
end
class Findings
include DataMapper::Resource
property :id, Serial
property :title, String, :required => true, :length => 200
property :report_id, Integer, :required => true
property :master_id, Integer, :required => false
property :finding_modified, Boolean, :required => false
property :effort, String, :required => false
property :type, String, :required => false
property :overview, String, :length => 20000, :required => false
property :poc, String, :length => 20000, :required => false
property :remediation, String, :length => 20000, :required => false
property :notes, String, :length => 1000000, :required => false
property :assessment_type, String, :required => false
property :references, String, :length => 20000, :required => false
property :risk, Integer, :required => false
property :affected_hosts, String, :length => 1000000, :required => false
property :presentation_points, String, :length => 100000, :required => false
property :presentation_rem_points, String, :length => 100000, :required => false
property :cve, String, :required => false
#CVSS
property :cvss_score, String, :required => false
property :cvss_vector, String, :required => false
property :cvss_severity, String, :required => false
# tag
property :tags, String, :required => false
# ehat
property :parameter, String, :required => false
property :method, String, :required => false
# nlp
property :summary, String, :required => false
# legacy fields for OLD Serpico compatibility
property :damage, Integer, :required => false
property :reproducability, Integer, :required => false
property :exploitability, Integer, :required => false
property :affected_users, Integer, :required => false
property :discoverability, Integer, :required => false
property :dread_total, Integer, :required => false
property :risk, Integer, :required => false
property :av, String, :required => false
property :ac, String, :required => false
property :au, String, :required => false
property :c, String, :required => false
property :i, String, :required => false
property :a, String, :required => false
property :e, String, :required => false
property :rl, String, :required => false
property :rc, String, :required => false
property :cdp, String, :required => false
property :td, String, :required => false
property :cr, String, :required => false
property :ir, String, :required => false
property :ar, String, :required => false
property :cvss_base, Float, :required => false
property :cvss_impact, Float, :required => false
property :cvss_exploitability, Float, :required => false
property :cvss_temporal, Float, :required => false
property :cvss_environmental, Float, :required => false
property :cvss_modified_impact, Float, :required => false
property :cvss_total, Float, :required => false
property :ease, String, :required => false
end
class TemplateReports
include DataMapper::Resource
property :id, Serial
property :consultant_name, String, :required => false, :length => 200
property :consultant_company, String, :required => false, :length => 200
property :consultant_phone, String
property :consultant_email, String, :required => false, :length => 200
property :contact_name, String, :required => false, :length => 200
property :contact_phone, String
property :contact_email, String
property :full_company_name, String, :required => true, :length => 200
property :short_company_name, String, :required => true, :length => 200
property :company_website, String
property :approved, String
property :deadline, String
property :contact_city, String
property :contact_address, String
property :contact_zip, String
end
class User
include DataMapper::Resource
property :id, Serial
property :username, String, :key => true, :length => (3..40), :required => true
property :hashed_password, String
property :salt, String
property :type, String
property :plugin, Boolean, :required => false, :default => false
property :auth_type, String, :required => false
property :created_at, DateTime, :default => DateTime.now
property :consultant_name, String, :required => false
property :consultant_company, String, :required => false
property :consultant_phone, String, :required => false
property :consultant_email, String, :required => false
property :consultant_title, String, :required => false
attr_accessor :password
validates_presence_of :username
def password=(pass)
@password = pass
self.salt = rand(36**12).to_s(36) unless self.salt
self.hashed_password = User.encrypt(@password, self.salt)
end
def self.encrypt(pass, salt)
return Digest::SHA1.hexdigest(pass + salt)
end
def self.authenticate(username, pass)
user = User.first(:username => username)
if user
return user.username if User.encrypt(pass, user.salt) == user.hashed_password
end
end
end
class Sessions
include DataMapper::Resource
property :id, Serial
property :session_key, String, :length => 128
property :username, String, :length => (3..40), :required => true
def self.is_valid?(session_key)
sessions = Sessions.first(:session_key => session_key)
return true if sessions
end
def self.type(session_key)
sess = Sessions.first(:session_key => session_key)
if sess
return User.first(:username => sess.username).type
end
end
def self.get_username(session_key)
sess = Sessions.first(:session_key => session_key)
if sess
return sess.username
end
end
def self.is_plugin?(session_key)
sess = Sessions.first(:session_key => session_key)
if sess
return User.first(:username => sess.username).plugin
end
end
end
# For a metasploit connector eventually
class RemoteEndpoints
include DataMapper::Resource
property :id, Serial
property :ip, String
property :port, String
property :type, String
property :report_id, Integer
property :workspace, String
property :user, String
property :pass, String
end
class VulnMappings
include DataMapper::Resource
property :id, Serial
property :templatefindings_id, String, :required => true
property :msf_ref, String, :required => true
#property :type, String, :required => true
end
class NessusMapping
include DataMapper::Resource
property :id, Serial
property :templatefindings_id, String, :required => true
property :pluginid, String, :required => true
end
class BurpMapping
include DataMapper::Resource
property :id, Serial
property :templatefindings_id, String, :required => true
property :pluginid, String, :required => true
end
class NexposeMapping
include DataMapper::Resource
property :id, Serial
property :templatefindings_id, String, :required => true
property :pluginid, String, :required => true
end
class Reports
include DataMapper::Resource
property :id, Serial
property :date, String, :length => 20
property :report_type, String, :length => 200
property :report_name, String, :length => 200
property :consultant_name, String, :length => 200
property :consultant_company, String, :length => 200
property :consultant_phone, String
property :consultant_title, String, :length => 200
property :consultant_email, String, :length => 200
property :contact_name, String, :length => 200
property :contact_phone, String
property :contact_title, String, :length => 200
property :contact_city, String
property :contact_address, String, :length => 200
property :contact_state, String
property :contact_zip, String
property :contact_email, String, :length => 200
property :full_company_name, String, :length => 200
property :short_company_name, String, :length => 200
property :company_website, String, :length => 200
property :owner, String, :length => 200
property :authors, CommaSeparatedList, :required => false, :lazy => false
property :user_defined_variables, String, :length => 10000
# calendar
property :start_date, String, :length => 20, :required => true
property :end_date, String, :length => 20, :required => true
property :color, String, :length => 10
end
class Attachments
include DataMapper::Resource
property :id, Serial
property :filename, String, :length => 400
property :filename_location, String, :length => 400
property :report_id, String, :length => 30
property :description, String, :length => 500
end
class Hosts
include DataMapper::Resource
property :id, Serial
property :ip, String
property :port, String
end
class Xslt
include DataMapper::Resource
property :id, Serial
property :docx_location, String, :length => 400
property :description, String, :length => 400
property :xslt_location, String, :length => 400
property :report_type, String, :length => 400
property :finding_template, Boolean, :required => false, :default => false
property :status_template, Boolean, :required => false, :default => false
end
DataMapper.finalize
# any differences between the data store and the data model should be fixed by this
# As discussed in http://datamapper.org/why.html it is limited. Hopefully we never create conflicts.
DataMapper.auto_upgrade!