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

Remote command execution vulnerability in 3.3.16 #1352

Open
PicklerBox opened this issue Sep 24, 2022 · 4 comments
Open

Remote command execution vulnerability in 3.3.16 #1352

PicklerBox opened this issue Sep 24, 2022 · 4 comments

Comments

@PicklerBox
Copy link

Go to the edit-theme. PHP file, click the sava Changes button below, and grab the package.
a9
b
Use.. / to change the edited_file parameter in the request package
c
Then we access index.php
d
e

@PicklerBox PicklerBox changed the title Remote command execution vulnerability in 3.3.17 Remote command execution vulnerability in 3.3.16 Sep 24, 2022
@PicklerBox
Copy link
Author

`if((isset($_POST['submitsave']))){

# check for csrf
if (!defined('GSNOCSRF') || (GSNOCSRF == FALSE) ) {
	$nonce = $_POST['nonce'];
	if(!check_nonce($nonce, "save")) {
		die("CSRF detected!");
	}
}

# save edited template file
$SavedFile = $_POST['edited_file'];
$FileContents = get_magic_quotes_gpc() ? stripslashes($_POST['content']) : $_POST['content'];	
$fh = fopen(GSTHEMESPATH . $SavedFile, 'w') or die("can't open file");
fwrite($fh, $FileContents);
fclose($fh);
$success = sprintf(i18n_r('TEMPLATE_FILE'), $SavedFile);

}`
The savedFile and FileContents parameters are not filtered, so you can write files across directories

@tablatronix
Copy link
Member

Thanks, looks like this was not completely back-patched from 3.4

@risingisland
Copy link

Is there a fix/patch for this that can be applied?
Example code or Pull Request?

@tablatronix
Copy link
Member

tablatronix commented Apr 20, 2024

This looks easy, just check the same code in 3.4 and backport it

	# save edited template file
	$SavedFile = $_POST['edited_file'];
	if(!filepath_is_safe($themepath.$SavedFile,GSTHEMESPATH,true)) die();	 // mitigation check
	$FileContents = get_magic_quotes_gpc() ? stripslashes($_POST['content']) : $_POST['content'];	

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

No branches or pull requests

3 participants