Post by haydent » Thu Oct 17, 2024 6:02 am

So recently had a admin account login 'leaked' and used by a 'hacker' to deface site. It made me realise once you get multiple admin users this sort of thing is inevitable. So I looked into 2FA options, as if an intruder has access to a users email account, 2fa via email is no use. OC 4 has 2 step by email as an option, and it was very simple too convert it to use an authy/google authenticator TOTP app instead.

https://github.com/opencart/opencart/discussions/14182

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by JNeuhoff » Thu Oct 17, 2024 7:16 pm

What exactly are you trying to accomplish? Also, will it work from a desktop device with a web browser like FireFox or Chrome?

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by paulfeakins » Thu Oct 17, 2024 9:44 pm

haydent wrote:
Thu Oct 17, 2024 6:02 am
if an intruder has access to a users email account
If an intruder has access to your email account, you're in big trouble anyway.

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 haydent » Fri Oct 18, 2024 4:04 am

JNeuhoff wrote:
Thu Oct 17, 2024 7:16 pm
What exactly are you trying to accomplish? Also, will it work from a desktop device with a web browser like FireFox or Chrome?
which bit ? this is using a mobile auth app as an extra step in the sign in process for the admin viewed in a browser

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by haydent » Fri Oct 18, 2024 4:05 am

paulfeakins wrote:
Thu Oct 17, 2024 9:44 pm
haydent wrote:
Thu Oct 17, 2024 6:02 am
if an intruder has access to a users email account
If an intruder has access to your email account, you're in big trouble anyway.
it does happen, or credentials are re-used, this protects your store and is very common.

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by khnaz35 » Fri Oct 18, 2024 2:04 pm

This is good and solid starting point when you used

Code: Select all

pragmarx/google2fa bacon/bacon-qr-code
, i would most likely also use

Code: Select all

defuse/php-encryption

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 JNeuhoff » Fri Oct 18, 2024 5:12 pm

haydent wrote:
Fri Oct 18, 2024 4:04 am
JNeuhoff wrote:
Thu Oct 17, 2024 7:16 pm
What exactly are you trying to accomplish? Also, will it work from a desktop device with a web browser like FireFox or Chrome?
which bit ? this is using a mobile auth app as an extra step in the sign in process for the admin viewed in a browser
So without an extra mobile device on hand, your approach won't work for desktop users?

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by haydent » Fri Oct 18, 2024 6:22 pm

khnaz35 wrote:
Fri Oct 18, 2024 2:04 pm
This is good and solid starting point when you used

Code: Select all

pragmarx/google2fa bacon/bacon-qr-code
, i would most likely also use

Code: Select all

defuse/php-encryption
what are you suggesting to encrypt ?

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by haydent » Fri Oct 18, 2024 6:24 pm

JNeuhoff wrote:
Fri Oct 18, 2024 5:12 pm
haydent wrote:
Fri Oct 18, 2024 4:04 am
JNeuhoff wrote:
Thu Oct 17, 2024 7:16 pm
What exactly are you trying to accomplish? Also, will it work from a desktop device with a web browser like FireFox or Chrome?
which bit ? this is using a mobile auth app as an extra step in the sign in process for the admin viewed in a browser
So without an extra mobile device on hand, your approach won't work for desktop users?
you just use your phone, no need for an extra one, the whole idea is that it takes a second device (a mobile) to login to the admin

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by OSWorX » Fri Oct 18, 2024 6:30 pm

haydent wrote:
Fri Oct 18, 2024 6:24 pm
you just use your phone, no need for an extra one, the whole idea is that it takes a second device (a mobile) to login to the admin
That's common practice by many (if not all) banking apps.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by ADD Creative » Fri Oct 18, 2024 7:33 pm

JNeuhoff wrote:
Fri Oct 18, 2024 5:12 pm
So without an extra mobile device on hand, your approach won't work for desktop users?
There are 2FA applications and web browser extensions for desktops. Of course if it's not tied to some sort of security key it won't be as good as using second device.

www.add-creative.co.uk


Guru Member

Posts

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

Post by haydent » Sat Oct 19, 2024 3:34 am

ADD Creative wrote:
Fri Oct 18, 2024 7:33 pm
JNeuhoff wrote:
Fri Oct 18, 2024 5:12 pm
So without an extra mobile device on hand, your approach won't work for desktop users?
There are 2FA applications and web browser extensions for desktops. Of course if it's not tied to some sort of security key it won't be as good as using second device.
id actually thought there might be, i think by nature they have to be tied to a secret key, i think its more so long as that secret key cant be accessed, so maybe it would be less secure just by the fact that it would be less likely to have 2 devices compromised at the same time than 1

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by khnaz35 » Sat Oct 19, 2024 8:33 am

haydent wrote:
Fri Oct 18, 2024 6:22 pm
what are you suggesting to encrypt ?
Something like this just an idea

Code: Select all


// Load required libraries
require $_SERVER['DOCUMENT_ROOT'] . '/../totp/vendor/autoload.php';
$google2fa = new \PragmaRX\Google2FA\Google2FA();

// Generate TOTP secret
$secret = $google2fa->generateSecretKey();
// Encrypt the secret before storing it
$encryptedSecret = \Defuse\Crypto\Crypto::encrypt($secret, 'your-encryption-key-here');

$title = explode('.', HTTP_SERVER);
array_shift($title);
$title = implode('.', $title);

$qrCodeData = $google2fa->getQRCodeUrl(
    $title,
    $this->user->getId(),
    $secret
);

// Generate QR code
$renderer = new \BaconQrCode\Renderer\ImageRenderer(
    new \BaconQrCode\Renderer\RendererStyle\RendererStyle(300),
    new \BaconQrCode\Renderer\Image\ImagickImageBackEnd()
);

$writer = new \BaconQrCode\Writer($renderer);
$data['qr_image'] = base64_encode($writer->writeString($qrCodeData));	
$data['qr_secret'] = $encryptedSecret; // Store encrypted secret

...

// Decrypt the stored secret
$secret = \Defuse\Crypto\Crypto::decrypt($login_info['secret'], 'your-encryption-key-here');

// Validate TOTP code
if(!isset($this->request->post['code']) || !$google2fa->verifyKey($secret, $this->request->post['code'])){
    $json['error'] = $this->language->get('error_code');	
}

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 haydent » Mon Oct 21, 2024 5:53 am

Right so you are encrypting the totp secret keys,
But where are you keeping the key for that, which is more secure than where the secret keys are kept ?

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by khnaz35 » Mon Oct 21, 2024 9:14 pm

haydent wrote:
Mon Oct 21, 2024 5:53 am
Right so you are encrypting the totp secret keys,
But where are you keeping the key for that, which is more secure than where the secret keys are kept ?
how about In a .htaccess file (for Apache-based hosting):

Code: Select all

SetEnv TOTP_ENCRYPTION_KEY "super_secure_random_generated_key"
or In the server configuration (e.g., Nginx):

Code: Select all

env TOTP_ENCRYPTION_KEY="super_secure_random_generated_key";

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 haydent » Tue Oct 22, 2024 3:39 am

So I guess this would only help if the intruder has gotten db access (eg via an injection) but not file/php access, which can happen.

But if they have db access, does it really matter if they can login into the admin or not ? As protecting the admin is just about protecting the DB really, there's not much else that can be wrecked there.

Or am I missing something.

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by khnaz35 » Tue Oct 22, 2024 9:47 am

haydent wrote:
Tue Oct 22, 2024 3:39 am
Or am I missing something.
No, TOTP secrets are not designed to directly protect the database. They are intended to protect access to the system, which in turn could allow an attacker to indirectly manipulate the database via the admin interface.

If an attacker already has database access, TOTP secrets (encrypted or not) will not protect the data stored in the database. The value of TOTP at that point is diminished because the attacker can already view or alter data directly without needing admin panel access.

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 haydent » Tue Oct 22, 2024 10:02 am

OK, so why encrypt the secrets? What's the scenario that it would help?

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by khnaz35 » Thu Oct 24, 2024 8:07 pm

haydent wrote:
Tue Oct 22, 2024 10:02 am
OK, so why encrypt the secrets? What's the scenario that it would help?
If your infrastructure is set up in such a way that attackers can potentially gain access to the database but not to your application environment, encryption might add a layer of defense. However, this isn't the most common scenario, especially in a standard deployment where compromising the database is often part of a broader system compromise.

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 haydent » Fri Oct 25, 2024 3:40 am

So this is my point, admin is only there to edit the database , and protecting the admin is just protecting the database, and if you have a compromised db by othermeans, someone having admin access on top of that is not really going to be any worse.

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia
Who is online

Users browsing this forum: gunownergear and 6 guests