Post by jrr » Tue Jan 14, 2025 2:50 pm

OC 3.0.4.0, PHP 8.x.
Got about 150 of these tonight (7:53-7:54PM) from a number of multiple IP addresses. Was this an attack or possibly an extension error. Have not added any new extensions in the past couple of days, nor reinstalling any though - and I've not seen this error message before.

Code: Select all

Error Message 	PHP Warning: mysqli::query(): (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?', search_term = '' where tracking_id='258#'' at line 1 in /.../catalog_oc/system/library/db/mysqli.php on line 25 (tracking_id='258#' where # = 0 - 9)
URL 	https://flippers.com/catalog_oc/index.php?route='
Customer 	Guest Customer
IP 	161.77.235.150 (161.77.0.27)(161.77.143.64)(45.85.204.9)(45.85.205.10)(and more...)
User Agent 	Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36  (<--this line never changed)
Referring URL 	https://flippers.com/catalog_oc/index.php?route='
Thanks!
John :-#(#
Last edited by jrr on Fri Jan 17, 2025 1:20 am, edited 2 times in total.

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by nonnedelectari » Tue Jan 14, 2025 3:23 pm

jrr wrote:
Tue Jan 14, 2025 2:50 pm
OC 3.0.4.0, PHP 8.x.
Got about 150 of these tonight (7:53-7:54PM) from a number of multiple IP addresses. Was this an attack or possibly an extension error. Have not added any new extensions in the past couple of days, nor reinstalling any though - and I've not seen this error message before.

Code: Select all

Error Message 	PHP Warning: mysqli::query(): (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?', search_term = '' where tracking_id='258#'' at line 1 in /.../catalog_oc/system/library/db/mysqli.php on line 25 (tracking_id='258#' where # = 0 - 9)
URL 	https://flippers.com/catalog_oc/index.php?route='
Customer 	Guest Customer
IP 	161.77.235.150 (161.77.0.27)(161.77.143.64)(45.85.204.9)(45.85.205.10)(and more...)
User Agent 	Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36  (<--this line never changed)
Referring URL 	https://flippers.com/catalog_oc/index.php?route='
Thanks!
John :-#(#
probably both.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by jrr » Wed Jan 15, 2025 3:04 am

Right...

How do I find which extension might be creating this problem - if it is actually a problem and not the system trying to protect my site from an attach of some sort?

It was a one-off situation, hasn't happened before or since.

Thanks!

John :-#)#

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by nonnedelectari » Wed Jan 15, 2025 9:27 am

jrr wrote:
Wed Jan 15, 2025 3:04 am
Right...

How do I find which extension might be creating this problem - if it is actually a problem and not the system trying to protect my site from an attach of some sort?

It was a one-off situation, hasn't happened before or since.

Thanks!

John :-#)#
It is rare that a system is trying to protect your site via an sql syntax error.

I would search your sources for the keywords "search_term" and "tracking_id".
Then you might find the sql construction which appartently is vulnerable for external input.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by khnaz35 » Wed Jan 15, 2025 1:49 pm

open your terminal and then you can search your resource like this.

Code: Select all

grep -rnw '/path/to/your/project' -e 'tracking_id' --include=\*.php | grep -E 'UPDATE|INSERT|SELECT'

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by paulfeakins » Wed Jan 15, 2025 8:58 pm

jrr wrote:
Tue Jan 14, 2025 2:50 pm

Code: Select all

Error Message 	PHP Warning: mysqli::query(): (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use 
My guess would be an extension you have installed is vulnerable to SQL injection and someone is trying to run SQL on your server through it. You need to get that fixed ASAP.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by jrr » Thu Jan 16, 2025 3:38 pm

paulfeakins wrote:
Wed Jan 15, 2025 8:58 pm
jrr wrote:
Tue Jan 14, 2025 2:50 pm

Code: Select all

Error Message 	PHP Warning: mysqli::query(): (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use 
My guess would be an extension you have installed is vulnerable to SQL injection and someone is trying to run SQL on your server through it. You need to get that fixed ASAP.
The only extensions I have that use the expression tracking_id are in admin - one is for checking who is online (I will send a note to the developer), the other is pp_express which is not enabled on my site.

I'm inclined to think the PayPal Express would be the target as it is more likely to be used by OpenCart sites...

Thanks!

John :-#)#

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by nonnedelectari » Thu Jan 16, 2025 6:39 pm

jrr wrote:
Thu Jan 16, 2025 3:38 pm
paulfeakins wrote:
Wed Jan 15, 2025 8:58 pm
jrr wrote:
Tue Jan 14, 2025 2:50 pm

Code: Select all

Error Message 	PHP Warning: mysqli::query(): (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use 
My guess would be an extension you have installed is vulnerable to SQL injection and someone is trying to run SQL on your server through it. You need to get that fixed ASAP.
The only extensions I have that use the expression tracking_id are in admin - one is for checking who is online (I will send a note to the developer), the other is pp_express which is not enabled on my site.

I'm inclined to think the PayPal Express would be the target as it is more likely to be used by OpenCart sites...

Thanks!

John :-#)#
Well, inclinations are fine but you have an sql construct which contains "where tracking_id = ...." somewhere and I don't see that in pp_express.
Did you review your access logs to see what the original requests look like?

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by paulfeakins » Thu Jan 16, 2025 6:51 pm

nonnedelectari wrote:
Thu Jan 16, 2025 6:39 pm
Well, inclinations are fine but you have an sql construct which contains "where tracking_id = ...." somewhere and I don't see that in pp_express.
Indeed, and it's disabled.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by jrr » Fri Jan 17, 2025 12:14 am

paulfeakins wrote:
Thu Jan 16, 2025 6:51 pm
nonnedelectari wrote:
Thu Jan 16, 2025 6:39 pm
Well, inclinations are fine but you have an sql construct which contains "where tracking_id = ...." somewhere and I don't see that in pp_express.
Indeed, and it's disabled.
I'm putting this down to an attempted attack on PayPal Express and move on - (not [solved] - and I was wrong on that call, see below...

The other extension that uses tracking_id does NOT use tracking_id= whereas PayPal Express does.

So anyone that is running PayPal Express should update it or switch to a more secure PayPal setup as someone is trying to exploit a weakness there...

I do find it handy that having my error messages are emailed to me for reviewing, that is a useful extension for those of us still learning about security on our sites. I could turn off warnings but I figure I will have a better idea of possible problems building if I keep it active.

Thanks for the comments folks!

John :-#)#
Last edited by jrr on Fri Jan 17, 2025 1:21 am, edited 1 time in total.

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by ADD Creative » Fri Jan 17, 2025 12:39 am

The tracking_id in admin/model/extension/payment/pp_express.php is not used in an SQL query, so it is not that. Also disabling a payment extension won't necessarily stop it being used in an attack.

Remember to also search the modifications directory and and vQmod cache.

As suggested by nonnedelectari, did you review your access logs to see what the original requests look like?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by jrr » Fri Jan 17, 2025 1:20 am

ADD Creative wrote:
Fri Jan 17, 2025 12:39 am
The tracking_id in admin/model/extension/payment/pp_express.php is not used in an SQL query, so it is not that. Also disabling a payment extension won't necessarily stop it being used in an attack.

Remember to also search the modifications directory and and vQmod cache.

As suggested by nonnedelectari, did you review your access logs to see what the original requests look like?
What I did for my search was check my desktop mirror of my site for tracking_id and tracking_id= that search turned up only the two extensions. I then searched my DB backup for the same terms and that turned up nothing.

Not sure how to search the modifications directory and vQmod cache...

Store_Error.Log shows all the occurrences on Jan 13 for that message - no extra info that I can see.

So, not [solved] then? I'll delete that...

John :-#(#
Last edited by jrr on Fri Mar 07, 2025 9:44 am, edited 1 time in total.

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by nonnedelectari » Fri Jan 17, 2025 9:05 am

jrr wrote:
Fri Jan 17, 2025 1:20 am
ADD Creative wrote:
Fri Jan 17, 2025 12:39 am
The tracking_id in admin/model/extension/payment/pp_express.php is not used in an SQL query, so it is not that. Also disabling a payment extension won't necessarily stop it being used in an attack.

Remember to also search the modifications directory and and vQmod cache.

As suggested by nonnedelectari, did you review your access logs to see what the original requests look like?
What I did for my search was check my desktop mirror of my site for tracking_id and tracking_id= that search turned up only the two extensions. I then searched my DB backup for the same terms and that turned up nothing.

Not sure how to search the modifications directory and vQmod cache...

Store_Error.Log shows all the occurrences on Jan 13 for that message - no extra info that I can see.

So, not [solved] then? I'll delete that...

John :-#(#
I suggested to have a look at your access log (where all requests are logged) because this part "'?', search_term = '' where tracking_id='258#'" on the error message might have been provided as a parameter in a request as opposed to being part of your source code. That would still mean you have an sql sanitation issue but the actual request might give you a clue as to where.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by khnaz35 » Fri Jan 17, 2025 9:14 am

nonnedelectari wrote:
Fri Jan 17, 2025 9:05 am
because this part "'?', search_term = '' where tracking_id='258#'" on the error message might have been provided as a parameter in a request as opposed to being part of your source code.
This could also mean a possible SQL injection attack or test. Can you confirm if the tracking_id='258#' was the same across all 100 request logs, or was it changing dynamically?

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by paulfeakins » Fri Jan 17, 2025 8:05 pm

ADD Creative wrote:
Fri Jan 17, 2025 12:39 am
Also disabling a payment extension won't necessarily stop it being used in an attack.
Yes that's true if it's possible to access files directly etc.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by jrr » Sat Jan 18, 2025 3:38 am

khnaz35 wrote:
Fri Jan 17, 2025 9:14 am
nonnedelectari wrote:
Fri Jan 17, 2025 9:05 am
because this part "'?', search_term = '' where tracking_id='258#'" on the error message might have been provided as a parameter in a request as opposed to being part of your source code.
This could also mean a possible SQL injection attack or test. Can you confirm if the tracking_id='258#' was the same across all 100 request logs, or was it changing dynamically?
Where I said search_term = '' where tracking_id='258#'" the 258# was tried for every variation from '2580' '2581' ....through '2589' over and over again. That is why I think it was an attempted attack.
I'll see tonight if I can find the logs and dig out more information. I have not seen this attack before or since, other than a weak attempt the next day - only three or four numbers tried...
Thanks!
John :-#)#
Last edited by jrr on Fri Mar 07, 2025 9:45 am, edited 1 time in total.

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by jrr » Wed Jan 22, 2025 2:13 am

Dang - just got hit with around 240 attempts:

Code: Select all

PHP Warning: mysqli::query(): (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?', search_term = '' where tracking_id='1018'' at line 1 in /.../catalog_oc/system/library/db/mysqli.php on line 25
This time they only tried tracking_id='1018'.

Sigh.

Don't people have better things to do than bugging small businesses?

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by nonnedelectari » Wed Jan 22, 2025 8:07 am

jrr wrote:
Wed Jan 22, 2025 2:13 am
Dang - just got hit with around 240 attempts:

Code: Select all

PHP Warning: mysqli::query(): (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?', search_term = '' where tracking_id='1018'' at line 1 in /.../catalog_oc/system/library/db/mysqli.php on line 25
This time they only tried tracking_id='1018'.

Sigh.

Don't people have better things to do than bugging small businesses?
the sql exception is like this:

Code: Select all

throw new \Exception('Error: ' . $this->connection->error  . '<br />Error No: ' . $this->connection->errno . '<br />' . $sql);
so where is the last part of that in your error log? the actual $sql query?
What were the requests in your access log?
Not sure why OC is still throwing exceptions without catching and handling them properly with set_exception_handler().

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by nonnedelectari » Wed Jan 22, 2025 9:18 am

On exception catching:

We use this in system/framework.php

Code: Select all

function exit_nicely () {
	$headers = array_change_key_case(apache_request_headers(),CASE_LOWER);
	$json_req = ((array_key_exists("accept",$headers) && stristr($headers['accept'],'application/json')) ? true : false);
	$ajax_req = ((array_key_exists("x-requested-with",$headers) && $headers['x-requested-with'] == 'XMLHttpRequest') ? true : false);
	error_log('Framework: exiting nicely');
	if ($json_req || $ajax_req) {
		error_log('Exception handler: Returning json error record to '.$_SERVER['REMOTE_ADDR'].' for '.$_SERVER['REQUEST_URI']);
		$json = array();
		$json['error']['warning'] = 'Sorry, we seem to be experiencing some difficulties, please try again or contact us directly.';
		$json['success'] = 'Sorry, we seem to be experiencing some difficulties, please try again or contact us directly.';
		$json_serial = json_encode($json);
		error_log($json_serial);
		header('Content-Type: application/json');
		echo $json_serial;
	} else {
		error_log('Exception Handler: Showing static maintenance page to '.$_SERVER['REMOTE_ADDR'].' for '.$_SERVER['REQUEST_URI']);
		ob_start();
		include('maintenance.html');
		$problem_page = ob_get_clean();
		http_response_code(503);
		echo $problem_page;
	}	
	die();	
}

set_exception_handler("handle_exception");
function handle_exception ($exception) {
	error_log($exception->getFile().' - line: '.$exception->getLine().' - Message: '.$exception->getMessage().' - '.$exception->getTraceAsString());
	exit_nicely();
}
catches the exceptions and returns a static maintenance page (maintenance.html) or a json encoded record with a non technical message in case an ajax request was made (takes care of those awkward json syntax error popups with html error messages).
In the meantime it logs the necessary info in your php error log.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by Joe1234 » Fri Apr 18, 2025 1:48 pm

nonnedelectari wrote:
Wed Jan 22, 2025 9:18 am
On exception catching:

We use this in system/framework.php

Code: Select all

function exit_nicely () {
	$headers = array_change_key_case(apache_request_headers(),CASE_LOWER);
	$json_req = ((array_key_exists("accept",$headers) && stristr($headers['accept'],'application/json')) ? true : false);
	$ajax_req = ((array_key_exists("x-requested-with",$headers) && $headers['x-requested-with'] == 'XMLHttpRequest') ? true : false);
	error_log('Framework: exiting nicely');
	if ($json_req || $ajax_req) {
		error_log('Exception handler: Returning json error record to '.$_SERVER['REMOTE_ADDR'].' for '.$_SERVER['REQUEST_URI']);
		$json = array();
		$json['error']['warning'] = 'Sorry, we seem to be experiencing some difficulties, please try again or contact us directly.';
		$json['success'] = 'Sorry, we seem to be experiencing some difficulties, please try again or contact us directly.';
		$json_serial = json_encode($json);
		error_log($json_serial);
		header('Content-Type: application/json');
		echo $json_serial;
	} else {
		error_log('Exception Handler: Showing static maintenance page to '.$_SERVER['REMOTE_ADDR'].' for '.$_SERVER['REQUEST_URI']);
		ob_start();
		include('maintenance.html');
		$problem_page = ob_get_clean();
		http_response_code(503);
		echo $problem_page;
	}	
	die();	
}

set_exception_handler("handle_exception");
function handle_exception ($exception) {
	error_log($exception->getFile().' - line: '.$exception->getLine().' - Message: '.$exception->getMessage().' - '.$exception->getTraceAsString());
	exit_nicely();
}
catches the exceptions and returns a static maintenance page (maintenance.html) or a json encoded record with a non technical message in case an ajax request was made (takes care of those awkward json syntax error popups with html error messages).
In the meantime it logs the necessary info in your php error log.
HI, a few questions:
1/ How specifically can I test this, force the error, to make sure it is functioning correctly on my site as opposed waiting to see if I get the similar errors ever again?
2/ Should this code be inserted at a specific point in the file (just to make sure something doesn't need to be activated first)?
3/ What directory should 'maintenance.html' be placed in?
Thanks.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am
Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 49 guests