一、简介
Metasploit框架提供了不同的mixins,可以用于开发浏览器漏洞利用,主要包括Msf::Exploit::Remote::HttpServer
、Msf::Exploit::Remote::HttpServer::HTML
和Msf::Exploit::Remote::BrowserExploitServer
。本文将介绍HttpServer
mixin。
二、HttpServer mixin
HttpServer
mixin是所有HTTP服务器mixins的基础(如BrowserExploitServer
和HttpServer::HTML
)。要使用它,您的模块需要有一个on_request_uri
方法,这是当HTTP服务器从浏览器接收到HTTP请求时触发的回调。
1、on_request_uri示例
以下是设置on_request_uri
的示例:
#
# 监听HTTP请求。
# cli是socket对象,request是Rex::Proto::Http::Request对象
#
def on_request_uri(cli, request)
print_status("客户端请求URI: #{request.uri}")
end
on_request_uri
方法也是你可以创建HTTP响应的地方。以下是你可以使用的几种方法:
send_not_found(cli)
- 向客户端发送404响应。确保传递cli(socket)对象。send_redirect(cli, location='/', body='', headers={})
- 将客户端重定向到新的位置。send_response(cli, body, headers={})
- 向客户端发送响应。这个方法是你在大多数情况下会使用的。
三、HttpServer::HTML
如果你看过我们的某些漏洞利用模块,你还会看到它们使用Exploit::Remote::HttpServer::HTML
而不是Exploit::Remote::HttpServer
。用法大体相同,区别在于Exploit::Remote::HttpServer::HTML
mixin提供了对一些JavaScript函数的访问,如Base64、堆喷射、操作系统检测等。
这是一个发送HTTP响应的示例:
#
# 向客户端发送“Hello, world!”
#
def on_request_uri(cli, request)
html = "Hello, world!"
send_response(cli, html)
end
1、get_resource方法
另外请注意,为了处理HTTP请求,必须包含基础的URIPATH
,默认情况下是随机的。这意味着如果你想处理多个URI(在需要处理重定向或链接时可能会遇到这种情况),还需要确保它们包含基础URIPATH
。要获取基础URIPATH
,可以使用get_resource
方法,示例如下:
def serve_page_1(cli)
html = "This is page 1"
send_response(cli, html)
end
def serve_page_2(cli)
html = "This is page 2"
send_response(cli, html)
end
def serve_default_page(cli)
html = %Q|
<html>
<a href="#{get_resource.chomp('/')}/page_1.html">Go to page 1</a><br>
<a href="#{get_resource.chomp('/')}/page_2.html">Go to page 2</a>
</html>
|
send_response(cli, html)
end
def on_request_uri(cli, request)
case request.uri
when /page_1\.html$/
serve_page_1(cli)
when /page_2\.html$/
serve_page_2(cli)
else
serve_default_page(cli)
end
end
当然,在编写Metasploit浏览器漏洞利用时,你需要考虑更多的因素。例如,你的模块可能需要进行浏览器检测,因为如果让Chrome接收Internet Explorer(IE)的漏洞利用显然不合理,对吧?你可能还需要构建针对目标的特定有效负载,这意味着你的模块需要知道它所攻击的目标,并且你必须构建一个方法来根据目标自定义漏洞利用,等等。HttpServer
和HttpServer::HTML
混入提供了各种方法来帮助你实现这些目标。确保查看API文档(你可以通过运行msf/documentation/gendocs.sh
,或者在msf目录中直接运行“yard”),或者查看现有的代码示例(尤其是最近的代码)。
要开始开发,你可以使用以下模板来开始编写你的浏览器漏洞利用:
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = NormalRanking
include Msf::Exploit::Remote::HttpServer
def initialize(info = {})
super(
update_info(
info,
'Name' => 'HttpServer mixin example',
'Description' => %q{
Here's an example of using the HttpServer mixin
},
'License' => MSF_LICENSE,
'Author' => [ 'sinn3r' ],
'References' => [
[ 'URL', 'http://metasploit.com' ]
],
'Platform' => 'win',
'Targets' => [
[ 'Generic', {} ],
],
'DisclosureDate' => '2013-04-01',
'DefaultTarget' => 0
)
)
end
def on_request_uri(cli, _request)
html = 'hello'
send_response(cli, html)
end
end
如果你想更深入地了解这个混入能做什么,可以查看以下链接:https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/exploit/http/server.rb