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

PHP-Proxy <= 5.1.0 - The decrypt key is flawed and cause the vulnerability of LFI #139

Open
0xUhaw opened this issue Nov 30, 2018 · 8 comments

Comments

@0xUhaw
Copy link

0xUhaw commented Nov 30, 2018

We discovered the PHP-Proxy str_rot_pass encrypt function is flawed. Despite the user change the default key, the remote attacker can easily decrypt the key and cause the vulnerability of Local File Inclusion.

4-1

5

Detailed steps and sample payload:
https://github.com/0xUhaw/CVE-Bins/tree/master/PHP-Proxy

We suggest that the encryption rules should be strengthened because the logic of decryption is too easy.

@Benji-Collins
Copy link

Is there anything that regular users can do now other than simply stop using the proxy?

@0xUhaw
Copy link
Author

0xUhaw commented Nov 30, 2018

Since this is the encrypt key problem, this should be fixed by the official...
If it is a problem for LFI, you can disable curl file protocol.

@ariesclark
Copy link

Has this been fixed yet? Or has no comment been made?

@Benji-Collins
Copy link

@RubyTheRose No comment yet, but they fixed one of the other vulnerabilities (even if only a simple one).

@webaddicto
Copy link

webaddicto commented Jan 22, 2019

The problem seems to be when the proxy decrypts the value from the $_GET['q']

On this file:

https://github.com/Athlon1600/php-proxy-app/blob/master/index.php

We can see this on line 68:

// decode q parameter to get the real URL
$url = url_decrypt($_GET['q']);

So lets take a look at url_decrypt() function that is on this file at line 155:

https://github.com/Athlon1600/php-proxy/blob/master/src/helpers.php

As you can see, it uses str_rop_pass() to decrypt the string:

function url_decrypt($url, $key = false){
	$url = Config::get('url_mode') ? base64_url_decode($url) : rawurldecode($url);
	
	if($key){
		$url = str_rot_pass($url, $key, true);
	} else if(Config::get('encryption_key')){
		$url = str_rot_pass($url, Config::get('encryption_key'), true);
	}
	
	return $url;
}

A quick fix should be to validate the variable $url like this:

function url_decrypt($url, $key = false){
	$url = Config::get('url_mode') ? base64_url_decode($url) : rawurldecode($url);
	
	if($key){
		$url = str_rot_pass($url, $key, true);
	} else if(Config::get('encryption_key')){
		$url = str_rot_pass($url, Config::get('encryption_key'), true);
	}

	if (!filter_var($url, FILTER_VALIDATE_URL)) return "";
	
	if (!in_array(strtolower(parse_url($url, PHP_URL_SCHEME)), array("http","https"))) return "";
	
	return $url;
}

So we return "" if the url is not valid or if it has a non-http/https scheme (i.e file:// or ftp://).

You may also want to use my SecurityPlugin that already prevents the LFI vulnerability:

Athlon1600/php-proxy-plugin-bundle#2

It will increase the security of PHP-Proxy by validating many important things.

Hope this helps.

@Benji-Collins
Copy link

Benji-Collins commented Jan 22, 2019 via email

@webaddicto
Copy link

webaddicto commented Jan 22, 2019

@Benji-Collins

I just made a quick test now, and my SecurityPlugin prevents the $_GET['q'] LFI vulnerability.

It validates the URL scheme and returns "Scheme is not allowed" for file://

@Benji-Collins
Copy link

Benji-Collins commented Jan 22, 2019 via email

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

No branches or pull requests

4 participants