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/windows/gather/enum_chocolatey_applications.rb
Views: 11655
# This module requires Metasploit: https://metasploit.com/download1# Current source: https://github.com/rapid7/metasploit-framework23class MetasploitModule < Msf::Post4def initialize(info = {})5super(6update_info(7info,8'Name' => 'Windows Gather Installed Application Within Chocolatey Enumeration',9'Description' => ' This module will enumerate all installed applications on a Windows system with chocolatey installed ',10'License' => MSF_LICENSE,11'Author' => ['Nick Cottrell <ncottrellweb[at]gmail.com>'],12'Platform' => ['win'],13'Privileged' => false,14'SessionTypes' => %w[meterpreter shell],15'Notes' => {16'Stability' => [CRASH_SAFE],17'Reliability' => [REPEATABLE_SESSION],18'SideEffects' => []19}20)21)22register_advanced_options(23[24OptString.new('ChocoPath', [false, 'The path to the chocolatey executable if it\'s not on default path', 'choco.exe']),25]26)27end2829def chocopath30if chocolatey?(datastore['ChocoPath'])31return datastore['ChocoPath']32elsif chocolatey?(cmd_exec('where.exe', 'choco.exe'))33return cmd_exec('where.exe', 'choco.exe')34elsif chocolatey?(cmd_exec('where.exe', 'chocolatey.exe'))35return cmd_exec('where.exe', 'chocolatey.exe')36end3738nil39end4041def chocolatey?(path)42!!(cmd_exec(path, '-v') =~ /\d+\.\d+\.\d+/m)43rescue Rex::Post::Meterpreter::RequestError44false45end4647def run48# checking that session is meterpreter and session has powershell49choco_path = chocopath50fail_with(Failure::NotFound, 'Chocolatey path not found') unless choco_path5152print_status("Enumerating applications installed on #{sysinfo['Computer']}") if session.type == 'meterpreter'5354# getting chocolatey version55choco_version = cmd_exec(choco_path, '-v')56print_status("Targets Chocolatey version: #{choco_version}")5758# Getting results of listing chocolatey applications59print_status('Getting chocolatey applications.')6061# checking if chocolatey is 2+ or 1.0.062data = if choco_version.match(/^[10]\.\d+\.\d+$/)63# its version 1, use local only64cmd_exec(choco_path, 'list -lo')65elsif choco_version.match(/^(?:[2-9]|\d{2,})\.\d+\.\d+$/)66# its version 2 or above, no need for local67cmd_exec(choco_path, 'list')68else69fail_with(Failure::UnexpectedReply, "Failed to get chocolatey version. Result was unexpected: #{choco_version}")70end71print_good('Successfully grabbed all items')7273# making table to better organize applications and their versions74table = Rex::Text::Table.new(75'Header' => 'Installed Chocolatey Applications',76'Indent' => 1,77'Columns' => %w[78Name79Version80]81)8283# collecting all lines that match and placing them into table.84items = data.scan(/^(\S+)\s(\d+(?:\.\d+)*)\r?\n/m)85items.each do |set|86table << set87end88results = table.to_s8990# giving results91print_line(results.to_s)92report_note(93host: session.session_host,94type: 'chocolatey.software.enum',95data: items,96update: :unique_data97)98end99end100101102