views:

255

answers:

7

I want to secure events stored in one table, which has relations to others. Events are inserted through windows service, that is connecting to hardware and reading from the hardware.

In events table is PK, date and time, and 3 different values.

The problem is that every admin can log in and insert/update/delete data in this table e.g. using sql management studio. I create triggers to prevent update and delete, so if admin doesn't know triggers, he fail to change data, but if he knows trigger, he can easily disable trigger and do whatever he wants.

So after long thinking I have one idea, to add new column (field) to table and store something like checksum in this field, this checksum will be calculated based on other values. This checksum will be generated in insert/update statements. If someone insert/update something manually I will know it, because if I check data with checksum, there will be mismatches.

My question is, if you have similar problem, how do you solve it? What algorithm use for checksum? How to secure against delete statement (I know about empty numbers in PK, but it is not enough) ?

I'm using SQL Server 2005.

+8  A: 

Security through obscurity is a bad idea. If there's a formula to calculate a checksum, someone can do it manually.

If you can't trust your DB admins, you have bigger problems.

Dave Bauman
He's not proposing "security through obscurity." All security involves keeping secrets--secret keys or private keys. There's no need to design this sort of system in such a way that absolute trustworthiness is required of a single person.
erickson
+1 for trust issue
Nathan Koop
+1 there's no algorithm that will prevent a privileged user from tampering with the contents of a table. adding constraints and triggers can help prevent unintentional updates, but a knowledgeable user with privileges will be able to workaround it if they have reason or need to.
spencer7593
A: 

It might be more effective to try to lock down permissions on the table. With the checksum, it seems like a malicious user might be able spoof it, or insert data that appears to be valid.

http://www.databasejournal.com/features/mssql/article.php/2246271/Managing-Users-Permissions-on-SQL-Server.htm

Andy White
Admins can change the permissions back, can't they?
Vinko Vrsalovic
+4  A: 

Ultimately, even if admins do not have delete rights, they can give themselves access, make the change to not deny deletes, delete the row and then restore the permission and then revoke their access to make permission changes.

If you are auditing that, then when they give themselves access, you fire them.

As far as an effective tamper-resistant checksum, it's possible to use public/private key signing. This will mean that if the signature matches the message, then no one except who the record says created/modified the record could have done it. Anyone can change and sign the record with their own key, but not as someone else.

Cade Roux
A: 

If you are concerned about people modifying the data, you should also be concerned about them modifying the checksum.

Can you not simply password protect certain permissions on that database?

Matt
Not from an administrator. They, by definition, have access to the database.
Vinko Vrsalovic
Well, it depends on the type of administrator, and the roles that they have been given. If they have been given permission to administer the database but not overall system administration rights then a simple change to the tables permissions will suffice. If they have global administrator access then his only option is to either revoke that access or learn to trust his administrators (auditing is a great help here).
Matt
+1  A: 

The idea of a checksum computed by the application is a good one. I would suggest that you research Message Authentication Codes, or MACs, for a more secure method.

Briefly, some MAC algorithms (HMAC) use a hash function, and include a secret key as part of the hash input. Thus, even if the admin knows the hash function that is used, he can't reproduce the hash, because he doesn't know all of the input.

Also, in your case, a sequential number should be part of the hash input, to prevent deletion of entire entries.

Ideally, you should use a strong cryptographic hash function from the SHA-2 family. MD5 has known vulnerabilities, and similar problems are suspected in SHA-1.

erickson
+1 This is a different case than the question I linked to, right. Here you control the app, and HMAC or a similar scheme would work, true.
Vinko Vrsalovic
+3  A: 

Anything you do at the server level the admin can undo. That's the very definition of its role and there's nothing you can do to prevent it.

In SQL 2008 you can request auditing of the said SQL server with X events, see http://msdn.microsoft.com/en-us/library/cc280386.aspx. This is CC compliant solution that is tamper evident. That means the admin can stop the audit and do its mischievous actions, but the stopping of the audit is recorded.

In SQL 2005 the auditing solution recommended is using the profiler infrastructure. This can be made tamper evident when correctly deployed. You would prevent data changes with triggers and constraints and audit DDL changes. If the admin changes the triggers, this is visible in the audit. If the admin stops the audit, this is also visible in the audit.

Do you plan this as a one time action against a rogue admin or as a feature to be added to your product? Using digital signatures to sign all your application data can be very costly in app cycles. You also have to design a secure scheme to show that records were not deleted, including last records (ie. not a simple gap in an identity column). Eg. you could compute CHECSUM_AGG over BINARY_CHECKSUM(*), sign the result in the app and store the signed value for each table after each update. Needles to say, this will slow down your application as basically you serialize every operation. For individual rows cheksums/hashes you would have to compute the entire signature in your app, and that would require possibly values your app does not yet have (ie. the identity column value to be assigned to your insert). And how far do you want to go? A simple hash can be broken if the admin gets hold of your app and monitors what you hash, in what order (this is trivial to achieve). He then can recompute the same hash. An HMAC requires you to store a secret in the application which is basically impossible against a a determined hacker. These concerns may seem overkill, but if this is an application you sell for instance then all it takes is for one hacker to break your hash sequence or hmac secret. Google will make sure everyone else finds out about it, eventually.

My point is that you're up the hill facing a loosing battle if you're trying to deter the admin via technology. The admin is a person you trust and if this is broken in your case, the problem is trust, not technology.

Remus Rusanu
+1 good answer, helpful tips on auditing. do your best to avoid unintentional changes (constraints, triggers, auditing), and to detect intentional changes, but in the end, it boils down to a problem of trust.
spencer7593