views:

348

answers:

10

We have a Delphi 2006 application that drives a MS SQL Server database.

We have found a vulnerability where it is possible to load the executable into a hex editor and modify the SQL.

Our long term plan is to move this SQL to CLR stored procedures but this is some way off since many of our clients still use SQL 2000.

We've thought about obfuscating the strings, does anyone have a recommendation for a tool for doing this?

Is there a better solution, maybe code signing?

+1  A: 

I think you should use a exe packer which makes it hard for anyone to modify the stuff using hex editor.

Sarfraz
Do you know one that guaranteed has no depacker?
Marco van de Voort
As I said in another comment, a debugger is just as easy to use as a hex editor.
Leonardo Herrera
@Marco van de Voort what is the perfect solution then?
Sarfraz
This is not a case of "looking for perfect being the enemy of implementing the good." I think it's more likely that it's a case of "implementing a half-assed solution being the enemy of analyzing the actual problem."
Craig Stuntz
+7  A: 

If embedded SQL is being hacked, then it implies that your database is quite open and anyone with MSQRY32.EXE (that is, MS Office) can get your data.

If you are a vendor, then you can't rely on CLR being enabled at your clients. So, why not use non-CLR stored procedures and correct permissioning in the database that is version independent?

gbn
I assume the database is not his, otherwise he could force version. I don't see the link with the need for CLR stored procedures either though. To run them, you still need to be authenticated.
Marco van de Voort
@Marco: I meant the database is the vendors but the platform is the clients, sorry
gbn
The database is ours and we use stored procedures already but we don't want to put some of our more sensitive sql queries in stored procedures as they are easy to backwards engineer/modify.
Mattl
This last comment makes no sense to me. Are you handing your database to your clients?
Leonardo Herrera
Yes, we provide delphi compiled executables + a database.
Mattl
As I said in my answer, in that case you have absolutely no way to protect that data. No matter how many fences you put in, at some point you need the actual data in memory and there it can be easily read.
Leonardo Herrera
A: 

There are "protection" suites that encrypt and/or validate your exe before running. searching for "encrypt exe" or "validate exe" or so will probably help. Usually they are payware, but sub $100.

The principle is the same as an exe packer (and has some of its downsides, like cheaper antivirus heuristics sometimes reacting on them, a slightly elevated memory load), just more focussed on security. A problem is also that for most exe packers, depackers exist.

I use dinkeydongle's wares, but that is a kind that also ties into an hardware dongle, so that might be a bridge to far for you.

Marco van de Voort
We can't use dongles as our software can often be run on many virtual machines on a single machine. We're also not concerned about piracy, this is not an issue for us.I'm also not overly keen on using a packer as it may cause issues with run time libraries amongst other things.
Mattl
As said, there are similar things without the dongle. I just can't come up with a name fast because I use one with. Otherwise, the only solution is to encrypt all constants, and decrypt them before use manually in code. (and hope nobody peeks your process' memory).All CONST segment encryption tools will fail due to your runtime library requirement.
Marco van de Voort
+3  A: 

It will never be possible to protect completely, but you can make "casual attack" harder. The simple system that I use is a "ROT47" type system which is like ROT13 but wider ranging. The code then gets to look like the following:

frmLogin.Caption := xIniFile.ReadString(Rot47('$JDE6>' {CODEME'System'}),

The key here is that I have a comment which includes the string so both I can see it, but more importantly so can the utility that I run in my FinalBuilder build script. This allows me to ensure that strings are up-to-date at all times in release code. The utility looks for {CODEME in the lines, and if found knows the format of the data to output appropriately.

mj2008
That's a nice solution, did you write the utility yourself?
Mattl
+1  A: 

First - do an analysis of your threat. Who is using your vulnerability, why is this a problem. Then act accordingly.

If your application is win32 and your threat are some kids witch are just having fun, a free exe packer (e.g. upx) might be the solution. On .NET applications signing might be what you want.

If you need more than that, it's going to be expensive and it's going to be more difficult to develop your application. Perhaps you even need to restructure it. Commercial protection schemes are available (perhaps with dongle?) - even protection schemes where you store your strings on some external hardware. If the hardware is not present, no SQL-Strings. But, as I said, that's more expensive.

Tobias Langner
Native executables may be signed as well.
ldsandon
+1  A: 

Can't you encrypt all your queries and put them to the resource file? During runtime, firstly you would have to:

  1. Load your query string from resource.
  2. Decrypt it.

Then you just run your query as before.

That should not be a big problem. Of course if you are not storing your queries in some resource / folder than you need to refactor your application a bit. But you should store them anyway in some organized manner. So you will be hitting a two birds with one stone here ;-)

For encryption of the strings you could use a free library called DCPCrypt.

Wodzu
This does seem like the way to go and we already use DCPCrypt so would not be too much of a headache to implement. Thanks for the suggestion.
Mattl
You are relocating your vulnerability, not fixing it. A debugger is just as easy to use as an hex editor.
Leonardo Herrera
Yes but he'll feel better, so problem solved. I haven't seen any evidence of a real threat of a hex-editor based attack. So probably it's a case where a customer has an IT guy who is smart enough to do his own "mini audit" and suggest this as a problem to the vendor, who is complying meekly.
Warren P
@Leaonardo I think you are exaggerate here. Debugging compiled file is not as easy as replacing string data under hexeditor. It requires a lot more of knowledge and time. I think this solution provides good security to cost ratio. After all, there is no ultimate fix for this problem.
Wodzu
@Warren P You've hit the nail on the head, this is more a political issue with people being confident with the system. A mini audit was performed and this was highlighted as a concern. Encrypting it will make the problem "disapear" from the auditors radar.
Mattl
+9  A: 

Sorry for being blunt, but if you are thinking of applying "security" measures in your executable you are doomed. No scrambling schema will retain an average hacker.

You also haven't explained how is your app designed. Is the database hosted by you, or resides in your client's premises? If the latter, then just forget about security and start hiring a lawyer to get a good confidentiality contract so your clients behave. If the former, then using stored procedures is the easiest way.

Leonardo Herrera
+5  A: 

This is not a vulnerability. If your machines are vulnerable to having people locally modify EXEs, that is your vulnerability.

All EXEs can be hacked, if someone has local admin account access, your game is over long before they get near your resource strings.

Warren P
+1  A: 
  1. Move DB interface to stored procedures. Normal regular stored procedures without any CLR. It's not a big deal if you already have queries to put inside.

  2. If you don't want to learn T-SQL for some reasons, simple move all you query string to database and store in application single query, which purpose is reading SQL code with given query ID from database only.

All tricks with encoding produces a lot of troubles, but don't give any real security because must use reversable encrypting (dictated by the nature of the problem) and all keys for decoding placed in application executable too.

ThinkJet
+2  A: 

A solution that would require a deep restructuring of the application would be to use a multi-tier approach - most the of the SQL code would be in the application server module, that being on a server should be more protected than a client side exe.

ldsandon