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/linux/gather/enum_commands.rb
Views: 11704
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Linux::System89def initialize10super(11'Name' => 'Gather Available Shell Commands',12'Description' => %q{13This module will check which shell commands are available on a system."14},15'Author' => 'Alberto Rafael Rodriguez Iglesias <albertocysec[at]gmail.com>',16'License' => MSF_LICENSE,17'Platform' => ['linux', 'unix'],18'SessionTypes' => ['shell', 'meterpreter'],19'Notes' => {20'Stability' => [CRASH_SAFE],21'Reliability' => [],22'SideEffects' => []23}24)25register_options([26OptString.new('DIR', [false, 'Optional directory name to list (in addition to default system PATH and common paths)', ''])27])28end2930def run31path = get_path3233print_warning('System PATH is empty!') if path.blank?3435paths = []36path.split(':').each do |p|37paths << p.chomp('/')38end3940common_dirs = [41'/root/local/bin',42'/usr/local/sbin',43'/usr/local/bin',44'/usr/sbin',45'/usr/bin',46'/sbin',47'/bin',48'/usr/local/go/bin'49]5051common_dirs << datastore['DIR'] unless datastore['DIR'].blank?5253common_dirs.each do |p|54paths << p.chomp('/')55end5657binaries = []5859paths.sort.uniq.each do |p|60next unless directory?(p)6162files = dir(p)6364next if files.blank?6566files.each do |f|67binaries << "#{p}/#{f.strip}"68end69end7071# BusyBox commands72busybox_path = nil73if command_exists?('busybox')74busybox_path = 'busybox'75elsif command_exists?('/bin/busybox')76busybox_path = '/bin/busybox'77end7879unless busybox_path.blank?80busybox_cmds = cmd_exec("#{busybox_path} --list")81busybox_cmds.each_line do |cmd|82binaries << "busybox #{cmd.strip}"83end84end8586# A recursive `ls /` or `find / -executable -type f`87# could be added to find extra binaries.8889print_good("Found #{binaries.sort.uniq.length} executable binaries/commands")9091binaries.uniq.sort.each do |bin|92print_line(bin)93end94end95end969798