r/shittyprogramming • • Jan 19 '16

Obfuscate your table names: it will prevent SQL infection!

Don't use obvious names for your database tables like 'users' or 'products'. This makes it easy for malicious users to enter things like ";DROP TABLE users" and drop your tabels. Instead make table names hard to guess by using the same strategies you should use for picking passwords:

  • Replace letters with numbers: 'us3rs', 'pr0ducts'

You can also prefix them with a salt: 'salt_us3rs', 'salt_pr0ducts'. This should secure any rainbow tables as well. This is really basic stuff and called security through obfuscatery. Take care!

238 Upvotes

48 comments sorted by

28

u/hatsune_aru Jan 19 '16

I like to have my table name encrypted as the MD4 of what it should be, like MD4("users").

12

u/aerosole Jan 19 '16

Ah, so even if someone gets to look at your database structure they can't infect it. Genius!

11

u/soup_feedback Jan 19 '16

MD4, genius!

5

u/hatsune_aru Jan 19 '16

Tried and trusted.

31

u/0hmyscience Jan 19 '16

It's better than MD5, because it's been around for longer

4

u/AgletsHowDoTheyWork Jan 19 '16

IMO Message Digest completely jumped the shark after MD3.

1

u/[deleted] Jan 20 '16

Trusted and tried.

1

u/[deleted] Jan 20 '16

Tired and thrusted

38

u/HelloYesThisIsDuck Jan 19 '16

salt_pr0ducts

I was doing great at obfuscating my tables, until you went and published the name of my bath salts table. Now I'll have to start over.

1

u/flsixtwo Jan 21 '16

Got to watch out naming tables BATH_SALTS, they will start cannibalizing the other tables in the database.

1

u/HugoNikanor Jan 22 '16

You can solve it by obfuscating and salting it a bit more:

salt_s41t_pr0ducts

2

u/TheBlackChinaman Jan 23 '16

Too much salt now. Counter act by adding PEPPER.

19

u/redneckrockuhtree Jan 19 '16

So....SAP?

5

u/hougaard Jan 19 '16

Thanks, that made my morning :) (Its funny cause its true)

3

u/nickcash Jan 20 '16

There's something about the combination of meaningless names like PA0001 and German abbreviations that makes them maddening to work with.

15

u/YMK1234 Jan 19 '16

Now we just need a way to obfuscate the system tables and we are done :D

6

u/causalNondeterminism Jan 19 '16

when I discovered select * from information_schema.columns, my job at a software company which didn't document much of anything improved dramatically.

7

u/YMK1234 Jan 19 '16

result like "column1, column2, column2a, column3, column_1, ..."

1

u/causalNondeterminism Jan 19 '16

*cringe* and then I found out that DB2 for i has a second set of column descriptors so they never had to care about SQL column names because those are the only ones which display on 5250.

12

u/ThisIsADogHello Jan 19 '16

Using salts is a pretty common technique and most hackers will expect it. Use some other less common spices instead, for example you may wish to use the table name basil_us3rs

6

u/[deleted] Jan 19 '16

never mention the war!

5

u/ThisIsADogHello Jan 19 '16

Well, you started it!

5

u/rocketman0739 Jan 19 '16

No we didn't, you invaded Poland!

2

u/flsixtwo Jan 21 '16

What if i use a multispice, like Adobo?

19

u/foonix Jan 19 '16

Just set the table prefix to "because_ima_f4g0rt_". Hackers will be too embarrassed to type that.

8

u/Neebat Jan 19 '16

If your table names are too obfuscated to query, does that mean you're using No-SQL?

3

u/Lucky_Chuck Jan 19 '16

Maybe all you need to do is use language that isn't standardized so SELECT would still be select, but it'll be in a different language that doesn't have a standard.

6

u/[deleted] Jan 19 '16

if you are haunted by a programming goblin, be sure to name at least one of your tables his name in reverse so that he might accidentally speak it out loud while muttering in front of his terminal, and get sucked back into the Sumerian puzzle cube he came from.

3

u/[deleted] Jan 19 '16

You used to work at my company, didn't you? You are an unsung genius, and I salute you. With one finger.

3

u/[deleted] Jan 19 '16

haha I actually got pissed off for a moment before I realized what sub I was in.

3

u/[deleted] Jan 19 '16

Does it have to be any kind of salt? Is chicken salt okay as well as table salt? I like chicken salt.

3

u/VelvetineRabbit Jan 20 '16

These answers are all terrible. Use a zero width non joiner! Attackers won't even be able to see it! And who knows? Maybe it will confuse malicious JOINers???

2

u/abermea Jan 19 '16

'salt_us3rs', 'salt_pr0ducts'

Well, last time I checked, people usually put salt on tables

2

u/[deleted] Jan 20 '16

So what salt should I use? Is common table salt OK, or is it more secure to use some more uncommon salt like cupric slufate?

2

u/Flywolfpack Jan 20 '16

Don't tell my boss but I think all SQL is obfuscated for me

2

u/[deleted] Jan 21 '16

I can't tell if this is supposed to be something stupid because I don't know enough about SQL

1

u/[deleted] Feb 08 '16

xkcd 327

0

u/[deleted] Jan 19 '16

[deleted]

36

u/HINDBRAIN Jan 19 '16

Will your orm escape the table name? Push to prod and find out!

4

u/DarkMio Jan 19 '16

Well, it escaped the semicoloncaust once...

0

u/[deleted] Jan 19 '16

[deleted]

14

u/AlGoreBestGore Jan 19 '16

Perfect table name right here.

0

u/[deleted] Jan 19 '16

[deleted]

8

u/[deleted] Jan 19 '16

💩💩💩😂 😂 😂

4

u/FlipTheTables Jan 19 '16

pls back off my table

┬─┬ノ(ಠ_ಠノ)

5

u/[deleted] Jan 19 '16

(o・_・)ノ”(ノ_<。)

Stop that.

(╯°□°)╯︵ ┻━┻

0

u/[deleted] Jan 19 '16

[deleted]

5

u/[deleted] Jan 19 '16

(ノಠ益ಠ)ノ彡~┻━┻☆(x x)

Now look what you made me do.

5

u/FlipTheTables Jan 19 '16

f it

┻━┻ ︵╰(°□°)╯︵ ┻━┻

3

u/[deleted] Jan 20 '16

◕ ‿ ◕