-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve TLV Type handling #16258
Improve TLV Type handling #16258
Conversation
2610869
to
7511738
Compare
@msjenkins-r7 test this please. |
lib/rex/post/meterpreter/packet.rb
Outdated
clazz.constants.each do |const| | ||
next unless const.to_s.start_with?('TLV_TYPE_') || const.to_s.start_with?('PACKET_') | ||
|
||
@@cached_tlv_types[const] = clazz.const_get(const) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's a weird edge case for returning multiple values here:
>> ([::Rex::Post::Meterpreter] + ::Rex::Post::Meterpreter::ExtensionMapper.get_extension_klasses).flat_map { |klass| klass.constants.map { |const| (klass.to_s + "::" + const.to_s) } }.select { |name| name.incl
ude?('TLV') || name.include?('PACKET') }.group_by { |name| eval(name) }.select { |id, names| names.length > 1 }
=>
{0=>
["Rex::Post::Meterpreter::PACKET_TYPE_REQUEST",
"Rex::Post::Meterpreter::TLV_META_TYPE_NONE",
"Rex::Post::Meterpreter::TLV_RESERVED",
"Rex::Post::Meterpreter::TLV_TYPE_ANY",
"Rex::Post::Meterpreter::Extensions::Sniffer::TLV_TYPE_EXTENSION_SNIFFER",
"Rex::Post::Meterpreter::Extensions::Extapi::TLV_TYPE_EXTENSION_EXTAPI"],
151075=>
["Rex::Post::Meterpreter::Extensions::Sniffer::TLV_TYPE_SNIFFER_INTERFACE_HANDLE",
"Rex::Post::Meterpreter::Extensions::Lanattacks::TLV_TYPE_LANATTACKS_UINT",
"Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_WEBCAM_QUALITY"],
1073761825=>["Rex::Post::Meterpreter::Extensions::Sniffer::TLV_TYPE_SNIFFER_INTERFACES", "Rex::Post::Meterpreter::Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_GROUP"],
151074=>
["Rex::Post::Meterpreter::Extensions::Sniffer::TLV_TYPE_SNIFFER_INTERFACE_ID",
"Rex::Post::Meterpreter::Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_PID",
"Rex::Post::Meterpreter::Extensions::Peinjector::TLV_TYPE_PEINJECTOR_SHELLCODE_SIZE",
"Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_WEBCAM_INTERFACE_ID"],
151076=>
["Rex::Post::Meterpreter::Extensions::Sniffer::TLV_TYPE_SNIFFER_PACKET_COUNT",
"Rex::Post::Meterpreter::Extensions::Python::TLV_TYPE_PYTHON_CODE_LEN",
"Rex::Post::Meterpreter::Extensions::Powershell::TLV_TYPE_POWERSHELL_ASSEMBLY_SIZE",
"Rex::Post::Meterpreter::Extensions::Incognito::TLV_TYPE_INCOGNITO_LIST_TOKENS_ORDER"],
85546=>["Rex::Post::Meterpreter::Extensions::Sniffer::TLV_TYPE_SNIFFER_ADDITIONAL_FILTER", "Rex::Post::Meterpreter::Extensions::Incognito::TLV_TYPE_INCOGNITO_GROUPNAME"],
151077=>["Rex::Post::Meterpreter::Extensions::Sniffer::TLV_TYPE_SNIFFER_BYTE_COUNT", "Rex::Post::Meterpreter::Extensions::Python::TLV_TYPE_PYTHON_CODE_TYPE"],
85540=>
["Rex::Post::Meterpreter::Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_TITLE",
"Rex::Post::Meterpreter::Extensions::Peinjector::TLV_TYPE_PEINJECTOR_TARGET_EXECUTABLE",
"Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_WEBCAM_NAME"],
85542=>
["Rex::Post::Meterpreter::Extensions::Extapi::TLV_TYPE_EXT_WINDOW_ENUM_CLASSNAME",
"Rex::Post::Meterpreter::Extensions::Python::TLV_TYPE_PYTHON_NAME",
"Rex::Post::Meterpreter::Extensions::Incognito::TLV_TYPE_INCOGNITO_GENERIC_RESPONSE"],
85537=>
["Rex::Post::Meterpreter::Extensions::Python::TLV_TYPE_PYTHON_STDOUT",
"Rex::Post::Meterpreter::Extensions::Powershell::TLV_TYPE_POWERSHELL_SESSIONID",
"Rex::Post::Meterpreter::Extensions::Priv::TLV_TYPE_SAM_HASHES"],
85538=>
["Rex::Post::Meterpreter::Extensions::Python::TLV_TYPE_PYTHON_STDERR",
"Rex::Post::Meterpreter::Extensions::Powershell::TLV_TYPE_POWERSHELL_CODE",
"Rex::Post::Meterpreter::Extensions::Lanattacks::TLV_TYPE_LANATTACKS_OPTION_NAME",
"Rex::Post::Meterpreter::Extensions::Incognito::TLV_TYPE_INCOGNITO_LIST_TOKENS_DELEGATION"],
85543=>["Rex::Post::Meterpreter::Extensions::Python::TLV_TYPE_PYTHON_RESULT_VAR", "Rex::Post::Meterpreter::Extensions::Incognito::TLV_TYPE_INCOGNITO_USERNAME"],
85544=>["Rex::Post::Meterpreter::Extensions::Python::TLV_TYPE_PYTHON_RESULT", "Rex::Post::Meterpreter::Extensions::Incognito::TLV_TYPE_INCOGNITO_PASSWORD"],
151073=>["Rex::Post::Meterpreter::Extensions::Unhook::TLV_TYPE_UNHOOK_ERROR_CODE", "Rex::Post::Meterpreter::Extensions::Winpmem::TLV_TYPE_WINPMEM_ERROR_CODE"],
85539=>["Rex::Post::Meterpreter::Extensions::Powershell::TLV_TYPE_POWERSHELL_RESULT", "Rex::Post::Meterpreter::Extensions::Incognito::TLV_TYPE_INCOGNITO_LIST_TOKENS_IMPERSONATION"],
282145=>
["Rex::Post::Meterpreter::Extensions::Lanattacks::TLV_TYPE_LANATTACKS_OPTION",
"Rex::Post::Meterpreter::Extensions::Peinjector::TLV_TYPE_PEINJECTOR_SHELLCODE",
"Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_WEBCAM_IMAGE"],
85541=>["Rex::Post::Meterpreter::Extensions::Incognito::TLV_TYPE_INCOGNITO_IMPERSONATE_TOKEN", "Rex::Post::Meterpreter::Extensions::Peinjector::TLV_TYPE_PEINJECTOR_RESULT"],
1073770846=>["Rex::Post::Meterpreter::Extensions::Android::TLV_TYPE_WLAN_GROUP", "Rex::Post::Meterpreter::Extensions::Android::TLV_TYPE_COLLECT_RESULT_WIFI"],
94560=>["Rex::Post::Meterpreter::Extensions::Android::TLV_TYPE_WLAN_SSID", "Rex::Post::Meterpreter::Extensions::Android::TLV_TYPE_COLLECT_RESULT_WIFI_SSID"],
94559=>["Rex::Post::Meterpreter::Extensions::Android::TLV_TYPE_WLAN_BSSID", "Rex::Post::Meterpreter::Extensions::Android::TLV_TYPE_COLLECT_RESULT_WIFI_BSSID"],
160097=>["Rex::Post::Meterpreter::Extensions::Android::TLV_TYPE_WLAN_LEVEL", "Rex::Post::Meterpreter::Extensions::Android::TLV_TYPE_COLLECT_RESULT_WIFI_LEVEL"],
1049576=>["Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_HKEY", "Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_ROOT_KEY"]}
283041c
to
9b2b13e
Compare
@@ -97,6 +98,30 @@ def self.get_commands(*extensions) | |||
commands | |||
end | |||
|
|||
def self.create_tlv_types_cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since, for now, this can return an array
def self.create_tlv_types_cache | |
def self.get_tlv_names(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great to sprinkle some yard doc metadata here, specifically the @param
and @return
metadata with a link to #16267 explaining why it can return an array
Context: https://github.com/lsegal/yard
9b2b13e
to
38b8f2c
Compare
586782c
to
373ba0c
Compare
373ba0c
to
2df72c8
Compare
2df72c8
to
ae704eb
Compare
For future travellers, cross-referencing the PR that allow configurable tlv logging via |
Release NotesThis improves Meterpreter's TLV logging support to show human readable names for the Meterpreter TLV values. To view this functionality run |
This PR changes how TLV packet types are output when logging TLV packets.
Verification
msfconsole
def dispatch_inbound_packet(packet)
anddef send_packet(packet, opts={})
Stdapi
types are shown as human-readable namesBefore
After