Module: Msf::Payload::UUID::Options

Overview

This module provides datastore option definitions and helper methods for payload modules that support UUIDs

Constant Summary

Constants included from Rex::Payloads::Meterpreter::UriChecksum

Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN_MAX_LEN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITJ, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITP, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITW, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INIT_CONN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_MIN_LEN, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_MODES, Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_UUID_MIN_LEN

Instance Method Summary collapse

Methods included from Rex::Payloads::Meterpreter::UriChecksum

#generate_uri_checksum, #generate_uri_uuid, #process_uri_resource, #uri_checksum_lookup

Instance Method Details

#generate_payload_uuid(conf = {}) ⇒ Object

Generate a Payload UUID



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/msf/core/payload/uuid/options.rb', line 50

def generate_payload_uuid(conf = {})

  conf[:arch] ||= self.arch
  conf[:platform] ||= self.platform

  # Handle user-specified seed values
  if datastore['PayloadUUIDSeed'].to_s.length > 0
    conf[:seed] = datastore['PayloadUUIDSeed'].to_s
  end

  # Handle user-specified raw payload UID values
  if datastore['PayloadUUIDRaw'].to_s.length > 0
    puid_raw = [datastore['PayloadUUIDRaw'].to_s].pack("H*")
    if puid_raw.length != 8
      raise ArgumentError, "The PayloadUUIDRaw value must be exactly 16 bytes of hex"
    end
    conf.delete(:seed)
    conf[:puid] = puid_raw
  end

  if datastore['PayloadUUIDName'].to_s.length > 0 && ! datastore['PayloadUUIDTracking']
    raise ArgumentError, "The PayloadUUIDName value is ignored unless PayloadUUIDTracking is enabled"
  end

  # Generate the UUID object
  uuid = Msf::Payload::UUID.new(conf)
  record_payload_uuid(uuid)

  uuid
end

#generate_uri_uuid_mode(mode, len = nil, uuid: nil) ⇒ String

Generates a URI with a given checksum and optionally with an embedded UUID if the desired length can accommodate it.

Parameters:

  • mode (Symbol)

    The type of checksum to generate (:connect, :init_native, :init_python, :init_java)

  • len (Integer) (defaults to: nil)

    The length of the URI not including the leading slash, optionally nil for random

Returns:

  • (String)

    A URI with a leading slash that hashes to the checksum, with an optional UUID



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/msf/core/payload/uuid/options.rb', line 30

def generate_uri_uuid_mode(mode, len = nil, uuid: nil)
  sum = uri_checksum_lookup(mode)

  # The URI length may not have room for an embedded UUID
  if len && len < URI_CHECKSUM_UUID_MIN_LEN
    # Throw an error if the user set a seed, but there is no room for it
    if datastore['PayloadUUIDSeed'].to_s.length > 0 || datastore['PayloadUUIDRaw'].to_s.length > 0
      raise ArgumentError, "A PayloadUUIDSeed or PayloadUUIDRaw value was specified, but this payload doesn't have enough room for a UUID"
    end
    return "/" + generate_uri_checksum(sum, len, prefix="")
  end

  uuid ||= generate_payload_uuid
  uri  = generate_uri_uuid(sum, uuid, len)
  record_payload_uuid_url(uuid, uri)

  uri
end

#initialize(info = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/msf/core/payload/uuid/options.rb', line 11

def initialize(info = {})
  super
  register_advanced_options(
    [
      Msf::OptString.new('PayloadUUIDSeed', [ false, 'A string to use when generating the payload UUID (deterministic)']),
      Msf::OptString.new('PayloadUUIDRaw', [ false, 'A hex string representing the raw 8-byte PUID value for the UUID']),
      Msf::OptString.new('PayloadUUIDName', [ false, 'A human-friendly name to reference this unique payload (requires tracking)']),
      Msf::OptBool.new('PayloadUUIDTracking', [ true, 'Whether or not to automatically register generated UUIDs', false]),
    ], self.class)
end

#record_payload_uuid(uuid, info = {}) ⇒ Object

Store a UUID in the JSON database if tracking is enabled



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/msf/core/payload/uuid/options.rb', line 82

def record_payload_uuid(uuid, info={})
  return unless datastore['PayloadUUIDTracking']
  # skip if there is no active database
  return if !(framework.db && framework.db.active)

  uuid_info = info.merge({
    uuid:  uuid.puid_hex,
    arch: uuid.arch,
    platform: uuid.platform,
    timestamp: uuid.timestamp,
  })

  if datastore['PayloadUUIDSeed'].to_s.length > 0
    uuid_info[:seed] = datastore['PayloadUUIDSeed']
  end

  if datastore['PayloadUUIDName'].to_s.length > 0
    uuid_info[:name] = datastore['PayloadUUIDName']
  end

  framework.db.create_payload(uuid_info)
end

#record_payload_uuid_url(uuid, url) ⇒ Object

Store a UUID URL in the database if tracking is enabled



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/msf/core/payload/uuid/options.rb', line 106

def record_payload_uuid_url(uuid, url)
  return unless datastore['PayloadUUIDTracking']
  # skip if there is no active database
  if (framework.db && framework.db.active)
    payload_info = {
        uuid: uuid.puid_hex,
    }
    payload = framework.db.payloads(payload_info).first
    unless payload.nil?
      urls = payload.urls.nil? ? [] : payload.urls
      urls << url
      urls.uniq!
      framework.db.update_payload({id: payload.id, urls: urls})
    end
  else
    print_warning('Without a database connected that payload UUID tracking will not work!')
  end
end