Skip to content

Authenticated users can craft a POST request to delete any file on the webserver

High
johnnyq published GHSA-mf57-hmpm-v357 May 12, 2023

Package

post.php (ITFlow)

Affected versions

51ee47913052eeb6440153d4a36c51599d572b2f and below

Patched versions

e67a75805cf68365e1b2abc99f18b63d33811a16

Description

Summary

A carefully crafted POST request to post.php allows authenticated users (accountants, technicians, and administrators) to delete any file on the server that www-data has permission to delete.

Details

The vulnerable code is here:

itflow/post.php

Lines 2731 to 2771 in 51ee479

if(isset($_POST['edit_expense'])){
require_once('models/expense.php');
$expense_id = intval($_POST['expense_id']);
$existing_file_name = sanitizeInput($_POST['existing_file_name']);
// Check for and process attachment
$extended_alert_description = '';
if ($_FILES['file']['tmp_name'] != '') {
if ($new_file_name = checkFileUpload($_FILES['file'], array('jpg', 'jpeg', 'gif', 'png', 'pdf'))) {
$file_tmp_path = $_FILES['file']['tmp_name'];
// directory in which the uploaded file will be moved
$upload_file_dir = "uploads/expenses/";
$dest_path = $upload_file_dir . $new_file_name;
move_uploaded_file($file_tmp_path, $dest_path);
//Delete old file
unlink("uploads/expenses/$existing_file_name");
mysqli_query($mysqli,"UPDATE expenses SET expense_receipt = '$new_file_name' WHERE expense_id = $expense_id");
$extended_alert_description = '. File successfully uploaded.';
} else {
$_SESSION['alert_type'] = "error";
$extended_alert_description = '. Error uploading file. Check upload directory is writable/correct file type/size';
}
}
mysqli_query($mysqli,"UPDATE expenses SET expense_date = '$date', expense_amount = $amount, expense_account_id = $account, expense_vendor_id = $vendor, expense_client_id = $client, expense_category_id = $category, expense_description = '$description', expense_reference = '$reference' WHERE expense_id = $expense_id");
$_SESSION['alert_message'] = "Expense modified" . $extended_alert_description;
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Expense', log_action = 'Modify', log_description = '$description', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
header("Location: " . $_SERVER["HTTP_REFERER"]);
}

The cause of the vulnerability stems from the variable $existing_file_name never being verified to be the legitimate previous file name before it is unlinked.

This allows an attacker to take advantage of path traversal and unlink any file they want to -- provided that the webserver user has the permission to do so.

For example, this is form-data that would delete the login page: existing_file_name=../../login.php.

Impact

This vulnerability has the following impact:

  • Loss of availability
  • Catastrophic consequences if the webserver administrator is lazy and has www-data in the sudoers file
  • https://demo.itflow.org/ could potentially be taken down along with any other websites in the web directory
  • Security breach in division of account roles (for example, the Expenses page and expenses-related functions should not be available to technicians)

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
Required
Scope
Unchanged
Confidentiality
None
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:H/A:H

CVE ID

No known CVE

Credits