Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/post/meterpreter/extensions/extapi/wmi/wmi.rb
Views: 11795
# -*- coding: binary -*-12module Rex3module Post4module Meterpreter5module Extensions6module Extapi7module Wmi89###10#11# This meterpreter extension contains extended API functions for12# performing WMI queries.13#14###15class Wmi1617def initialize(client)18@client = client19end2021#22# Perform a generic wmi query against the target machine.23#24# @param query [String] The WMI query string.25# @param root [String] Specify root to target, otherwise defaults26# to 'root\cimv2'27#28# @return [Hash] Array of field names with associated values.29#30def query(query, root = nil)31request = Packet.create_request(COMMAND_ID_EXTAPI_WMI_QUERY)3233request.add_tlv(TLV_TYPE_EXT_WMI_DOMAIN, root) unless root.to_s.strip.empty?34request.add_tlv(TLV_TYPE_EXT_WMI_QUERY, query)3536response = client.send_request(request)3738# Bomb out with the right error messa39error_msg = response.get_tlv_value(TLV_TYPE_EXT_WMI_ERROR)40raise error_msg if error_msg4142fields = []43fields_tlv = response.get_tlv(TLV_TYPE_EXT_WMI_FIELDS)4445# If we didn't get any fields back, then we didn't get any results.46# The reason is because without results, we don't know which fields47# were requested in the first place48return nil unless fields_tlv4950fields_tlv.each(TLV_TYPE_EXT_WMI_FIELD) { |f|51fields << f.value52}5354values = []55response.each(TLV_TYPE_EXT_WMI_VALUES) { |r|56value = []57r.each(TLV_TYPE_EXT_WMI_VALUE) { |v|58value << v.value59}60values << value61}6263return {64:fields => fields,65:values => values66}67end6869attr_accessor :client7071end7273end; end; end; end; end; end74757677