Fellow excel experts
Author
Discussion

Moonhawk

Original Poster:

10,730 posts

250 months

Wednesday 21st March 2018
quotequote all
I have been working on a way of locking down an excel workbook to prevent users from making unauthorised changes - whilst leaving the ability to make authorised ones.

I have come up with a method - but would like some thoughts on whether it can be circumvented by a relatively lay person.

1. Workbook and all worksheets are protected with a password and I have security macros running. The macros cannot be interrupted by the users (e.g. enablecanclekey = false).

2. To ensure that the user enables macros when they open the workbook - I have hidden all sheets except a warning sheet (which tells them they cannot use the workbook without macros active). If the workbook is opened and macros are not activated - only the warning sheet is displayed. If the user enables macros, the warning sheet is hidden on-open and the normal worksheets are un-hidden. Since the workbook is password protected by default, manual un-hiding of worksheets should not be possible even if macros are not activated.

3. Once opened with macros running, I have macros that upon a change of cell selection, right click or activation/deactivation of a worksheet, a macro re-locks all worksheets and workbook with a new randomised password.

4. I randomise the password at each re-lock using the following method. I generate a random 10 digit number using the RND function. I multiply this number by the current time, then convert the result to a Hex string. This becomes the current password.

5. The current password is stored on a "very hidden" worksheet - and is updated every time I go through steps 3 and 4. This ensures that the password is never more than 1 event old before being reset and that even if the user somehow unlocks the worksheet/workbook, as soon as they trigger an event, the worksheet/workbook is relocked and the password reset. Even if the user could somehow unhide the sheet the current password is stored on - as soon as they deselect the sheet and go to another sheet to make a change - the sheets/workbook will be re-locked and the password re-randomised.

Can anyone see any issues/workarounds whereby the user could intentionally or unintentionally circumvent this?

davepoth

29,395 posts

230 months

Wednesday 21st March 2018
quotequote all
Were I to try to hack it, I'd probably make a personal.xlsb with a deliberately wrong workbook open event to throw an error at the right place, pop into debug and then use the immediate window to unveryhide everything and re-enable cancelkey while VBA is stopped. Havoc could then be wreaked.

But the question you're asking is wrong - what you really need to ask is "Should I really be doing this with Excel?" and the answer to that question is usually "No!"

It sounds like you are using excel as a data-entry tool, in which case I think you should consider using Access instead - the nice thing about Access is that it can compile the VBA into an executable and then distribute it with the runtime instead of full Access, which is much better from a security standpoint.

Doofus

34,767 posts

204 months

Wednesday 21st March 2018
quotequote all
So the macros are only there to unprotect the sheet and then lock it again?

Why not protect the sheet, unlock the cells the user is allowed to use, and then use whatever (static) password you like?

Alternatively, unhide a data entry sheet, and hide the others, which pull data from that first sheet. Then use whatever (static) password you like.

Unless I've wildly misunderstood, I think you're really overcomplicating this

Moonhawk

Original Poster:

10,730 posts

250 months

Wednesday 21st March 2018
quotequote all
davepoth said:
Were I to try to hack it, I'd probably make a personal.xlsb with a deliberately wrong workbook open event to throw an error at the right place, pop into debug and then use the immediate window to unveryhide everything and re-enable cancelkey while VBA is stopped. Havoc could then be wreaked.

But the question you're asking is wrong - what you really need to ask is "Should I really be doing this with Excel?" and the answer to that question is usually "No!"

It sounds like you are using excel as a data-entry tool, in which case I think you should consider using Access instead - the nice thing about Access is that it can compile the VBA into an executable and then distribute it with the runtime instead of full Access, which is much better from a security standpoint.
I have error handlers which mean that it should not be possible to cause a break point in my code - any error will immediately hand off to the error handler - whose only function is to capture the error and display a pop up error. The error handlers themselves utilise "on error resume next" in them - so they should not cause a break point either.

My VBA project is also password protected - so even if they can somehow get into the VB editor - they should not be able to view or modify code.

I know, in an ideal world, I shouldn't be using excel - but i'm trying to get the company to a better position than they are in now (unrestricted, unlocked and uncontrolled spreadsheets).

If I can at least put some controls around what they have - it's a start.

I suspect creating an xlsb with code designed specifically to cause a break point is a little beyond the capabilities of a lay person. I'm not trying to prevent hackers messing with this file - just 'normal users'.

Edited by Moonhawk on Wednesday 21st March 23:32

Moonhawk

Original Poster:

10,730 posts

250 months

Wednesday 21st March 2018
quotequote all
Doofus said:
So the macros are only there to unprotect the sheet and then lock it again?

Why not protect the sheet, unlock the cells the user is allowed to use, and then use whatever (static) password you like?

Alternatively, unhide a data entry sheet, and hide the others, which pull data from that first sheet. Then use whatever (static) password you like.

Unless I've wildly misunderstood, I think you're really overcomplicating this
I'm using a randomised password - because a static password could at some point be guessed or inadvertently revealed.

By randomising the password with each event - I hopefully avoid the password getting out into the wild. The workbook essentially manages and protects the password itself.

I would of course have to use a static password for the VBA project - that is pretty much unavoidable - but it's one level of complexity further up the chain. Most 'normal' users won't even know about the VBA editor - let alone know enough about it to make it visible or start causing trouble within it - even if they did somehow know the password.

SystemParanoia

14,343 posts

229 months

Wednesday 21st March 2018
quotequote all
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?

Im with the guy that mentioned Access... a much saner approach!

even better, spin up sql server 2016 and develop a web front end for it....

how far down does the rabbit hole go ? smile

davepoth

29,395 posts

230 months

Wednesday 21st March 2018
quotequote all
Moonhawk said:
I suspect creating an xlsb with code designed specifically to cause a break point is a little beyond the capabilities of a lay person. I'm not trying to prevent hackers messing with this file - just 'normal users'.
I dunno - even I can manage to write macros that are guaranteed to cause an error. biggrin

Locking down spreadsheets hard like this (and I have tried something similar previously) can have some odd side effects, especially when there are other spreadsheets open. If any of those other spreadsheets have macros themselves (and it sounds like they might) they could well start interacting in strange ways.

If you don't want to jump to Access, what about using a form in Excel rather than a spreadsheet for the data entry?

Moonhawk

Original Poster:

10,730 posts

250 months

Wednesday 21st March 2018
quotequote all
SystemParanoia said:
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?
Would the average lay person know enough about xml to be able to do that, make an incognito change to a specific entry in the workbook - then reinstate the workbook to a functional state - without breaking the workbook - and without anyone knowing?


Edited by Moonhawk on Wednesday 21st March 23:43

Mr Pointy

13,455 posts

190 months

Wednesday 21st March 2018
quotequote all
You seem to be making it horribly complicated if all you want to do is stop users making changes. On the one hand you say they aren't up to VBA but you seem to think they will be able to crack a random 20 digit password. I'd start with a suitably complex password & then escalate if it's shown that this being compromised.

You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.

SystemParanoia

14,343 posts

229 months

Thursday 22nd March 2018
quotequote all
Moonhawk said:
SystemParanoia said:
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?
Would the average lay person know enough about xml to be able to do that, make an incognito change to a specific entry in the workbook - then reinstate the workbook to a functional state - without breaking the workbook - and without anyone knowing?


Edited by Moonhawk on Wednesday 21st March 23:43
If they're anything like the people I work with.. They'd just delete it and then disavow all knowledge laugh

Moonhawk

Original Poster:

10,730 posts

250 months

Thursday 22nd March 2018
quotequote all
Mr Pointy said:
You seem to be making it horribly complicated if all you want to do is stop users making changes. On the one hand you say they aren't up to VBA but you seem to think they will be able to crack a random 20 digit password. I'd start with a suitably complex password & then escalate if it's shown that this being compromised.

You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.
I dont think they will be able to crack the random password - that’s my point. A hard coded traditional password might get out in the open inadvertently - but having the workbook constantly randomise it would (in theory) reduce this risk.

As for me leaving/future maintenance - that’s not an issue. The VBA project password will still be available to suitably qualified and authorised individuals - and the radomisaton code can be disabled once you have unlocked the VBA project.

The workbook should only need unlocking if placed under change control.

Moonhawk

Original Poster:

10,730 posts

250 months

Thursday 22nd March 2018
quotequote all
SystemParanoia said:
If they're anything like the people I work with.. They'd just delete it and then disavow all knowledge laugh
Well yes - there is that smile

Luckily our file servers are snapshot every 2 hours biggrin

Aphex

2,160 posts

231 months

Thursday 22nd March 2018
quotequote all
If someone really wants to break what you're proposing then they will. Even with the latest Excel it isn't even slightly hard to remove the vba project password

louiebaby

11,025 posts

222 months

Thursday 22nd March 2018
quotequote all
How do you unlock it to make changes yourself? (Admin access.)

I had a little thing made so that the way to unlock it was to shift-click on the pi symbol that floated in the bottom right corner of the spreadsheet, and then required a password. The floating location was updated on a cell selection so it was always in the right place even for users with different sized monitors and so on.

I might have had a thing for Sandra Bullock in the 90s...

Mr Pointy

13,455 posts

190 months

Thursday 22nd March 2018
quotequote all
Moonhawk said:
Mr Pointy said:
You seem to be making it horribly complicated if all you want to do is stop users making changes. On the one hand you say they aren't up to VBA but you seem to think they will be able to crack a random 20 digit password. I'd start with a suitably complex password & then escalate if it's shown that this being compromised.

You should also think what will happen if you leave or fall under a bus. You should leave the company still able to function & it's much easier to do if a colleague has a single password sealed in an envelope rather than having to contact GCHQ to break into their own spreadsheet.
I dont think they will be able to crack the random password - that’s my point. A hard coded traditional password might get out in the open inadvertently - but having the workbook constantly randomise it would (in theory) reduce this risk.

As for me leaving/future maintenance - that’s not an issue. The VBA project password will still be available to suitably qualified and authorised individuals - and the radomisaton code can be disabled once you have unlocked the VBA project.

The workbook should only need unlocking if placed under change control.
I'm still struggling with the logic behind your plan. You say a hardcoded password could get out & then say the even more powerful VBA password is being made available. Why won't this get out in the same way that the other password might?

nyt

1,946 posts

181 months

Thursday 22nd March 2018
quotequote all
I've seen excel compilers used to secure spreadsheets in financial institutions, basically as a band-aid. The application had grown from a single user sheet to a departmental one so security hadn't been implemented at the server side.

I can't remember which products were used, but similar to these:

https://www.xlspadlock.com

http://doneex.com/how-to-compile-workbook/


Moonhawk

Original Poster:

10,730 posts

250 months

Thursday 22nd March 2018
quotequote all
Mr Pointy said:
I'm still struggling with the logic behind your plan. You say a hardcoded password could get out & then say the even more powerful VBA password is being made available. Why won't this get out in the same way that the other password might?
The worksheet and workbook level passwords would have to be hard coded into the VBA code - somebody could look over the devs shoulder and see them.

That's not true of the VBA project level password.

Moonhawk

Original Poster:

10,730 posts

250 months

Thursday 22nd March 2018
quotequote all
louiebaby said:
How do you unlock it to make changes yourself? (Admin access.)
I'd unlock the VBA console using the VBA project password - then set a developer flag I have built into the code which would unlock the workbook and worksheets and disable password randomisation the next time the password reset code ran.

Moonhawk

Original Poster:

10,730 posts

250 months

Thursday 22nd March 2018
quotequote all
SystemParanoia said:
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?
I have been thinking about this and it is surprisingly easy to modify data in an xlsx via this method (even a relatively lay person could do this as you are basically just text editing).

To help guard against these types of changes - I could compile all of the data in each worksheet into a string, then generate a hash value based on this string. I could then concatenate these hash values and generate a new workbook level hash from it. I could then store this hash value on save.

On open - I can regenerate the workbook level hash and compare with the stored value. This would highlight any changes to the underlying data in the worksheet. If there is an issue - I could flag it.

Of course - somebody who knew what they were doing could also modify the stored hash value via the xml - but that would require a hell of a lot of effort as they would have to know exactly what data I have used to generate it, in exactly the right order. They would also need to know the hash algorithm I had used.

Edited by Moonhawk on Thursday 22 March 17:17

SystemParanoia

14,343 posts

229 months

Thursday 22nd March 2018
quotequote all
Moonhawk said:
SystemParanoia said:
you do realise that you can just rename an *.xlsx file to *.zip, extract it and then wreak havoc anyway ?
I have been thinking about this and it is surprisingly easy to modify data in an xlsx via this method (even a relatively lay person could do this as you are basically just text editing).

To help guard against these types of changes - I could compile all of the data in each worksheet into a string, then generate a hash value based on this string. I could then concatenate these hash values and generate a new workbook level hash from it. I could then store this hash value on save.

On open - I can regenerate the workbook level hash and compare with the stored value. This would highlight any changes to the underlying data in the worksheet. If there is an issue - I could flag it.

Of course - somebody who knew what they were doing could also modify the stored hash value via the xml - but that would require a hell of a lot of effort as they would have to know exactly what data I have used to generate it, in exactly the right order. They would also need to know the hash algorithm I had used.

Edited by Moonhawk on Thursday 22 March 17:17
welcome to my world biggrin

Its not paranoia if they really are after you!