Repository navigation
Expand file tree
/
Copy pathrails_xml_yaml_scanner.rb
More file actions
95 lines (82 loc) · 3.04 KB
/
Copy pathrails_xml_yaml_scanner.rb
File metadata and controls
95 lines (82 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::Scanner
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Ruby on Rails XML Processor YAML Deserialization Scanner',
'Description' => %q{
This module attempts to identify Ruby on Rails instances vulnerable to
an arbitrary object instantiation flaw in the XML request processor.
},
'Author' => [
'hdm', # author
'jjarmoc' # improvements
],
'License' => MSF_LICENSE,
'References' => [
['CVE', '2013-0156'],
['URL', 'https://www.rapid7.com/blog/post/2013/01/09/serialization-mischief-in-ruby-land-cve-2013-0156/']
],
'Notes' => {
'Reliability' => UNKNOWN_RELIABILITY,
'Stability' => UNKNOWN_STABILITY,
'SideEffects' => UNKNOWN_SIDE_EFFECTS
}
)
)
register_options([
OptString.new('URIPATH', [true, "The URI to test", "/"]),
OptEnum.new('HTTP_METHOD', [true, 'HTTP Method', 'POST', ['GET', 'POST', 'PUT'] ]),
])
end
def send_probe(ptype, pdata)
odata = %Q^<?xml version="1.0" encoding="UTF-8"?>\n<probe type="#{ptype}"><![CDATA[\n#{pdata}\n]]></probe>^
res = send_request_cgi({
'uri' => datastore['URIPATH'] || "/",
'method' => datastore['HTTP_METHOD'],
'ctype' => 'application/xml',
'data' => odata
}, 25)
end
def run_host(ip)
res1 = send_probe("string", "hello")
unless res1
vprint_status("#{Rex::Socket.to_authority(rhost, rport)} No reply to the initial XML request")
return
end
if res1.code.to_s =~ /^[5]/
vprint_status("#{Rex::Socket.to_authority(rhost, rport)} The server replied with #{res1.code} for our initial XML request, double check URIPATH")
return
end
res2 = send_probe("yaml", "--- !ruby/object:Time {}\n")
unless res2
vprint_status("#{Rex::Socket.to_authority(rhost, rport)} No reply to the initial YAML probe")
return
end
res3 = send_probe("yaml", "--- !ruby/object:\x00")
unless res3
vprint_status("#{Rex::Socket.to_authority(rhost, rport)} No reply to the second YAML probe")
return
end
vprint_status("Probe response codes: #{res1.code} / #{res2.code} / #{res3.code}")
if (res2.code == res1.code) and (res3.code != res2.code) and (res3.code != 200)
print_good("#{Rex::Socket.to_authority(rhost, rport)} is likely vulnerable due to a #{res3.code} reply for invalid YAML")
report_vuln({
:host => rhost,
:port => rport,
:proto => 'tcp',
:name => self.name,
:info => "Module triggered a #{res3.code} reply",
:refs => self.references
})
else
vprint_status("#{Rex::Socket.to_authority(rhost, rport)} is not likely to be vulnerable or URIPATH & HTTP_METHOD must be set")
end
end
end