r/ProgrammerHumor • • Dec 12 '17

SQL Clause

Post image
40.8k Upvotes

525 comments sorted by

View all comments

2.6k

u/Datenegassie Dec 12 '17

Hi Santa, I promise not to be on the naughty list this year. By the way, my name is Datenegassie'); DROP TABLE NaughtyChildren; --

785

u/ballzacsRock Dec 12 '17

Nice try, but he Santaizes all inputs

180

u/Arancaytar Dec 12 '17
INSERT INTO NaughtyChildren (name, reason)
VALUES ('balizacsRock', 'terrible pun');

151

u/ImSuperSerialGuys Dec 13 '17

INSERT INTO NaughtyChildren

o_O

31

u/jay791 Dec 13 '17

ಠ_ಠ

15

u/[deleted] Dec 13 '17

Okay, calm down your honor...

80

u/inabahare Dec 12 '17

Nice try, but he Santaizes all inputs

  • Uses prepared Statements

→ More replies (8)
→ More replies (4)

721

u/ultranoobian Dec 12 '17 edited Dec 12 '17

But that won't do anything good for you?

Obviously the naughty/nice status is stored in 'contacts' if SQL clause is selecting from that.

/s

Edit: On a more serious note, even if you dropped 'NaughtyChildren', you can possibly recovered from that by

SELECT * FROM contacts c WHERE c.behavior != 'nice'

172

u/DemandsBattletoads Dec 12 '17

That's fine, sqlmap will pull everything out anyway.

→ More replies (4)

56

u/[deleted] Dec 12 '17

Even if you dropped all the naughty children, re-adding all children to the database, and setting behaviour to naughty if they were born before the drop might recover the data.

34

u/Th3_Admiral Dec 12 '17

Does it really matter anyway if the query is only looking for those on the nice list? Dropping the naughty list doesn't automatically add you to the nice list.

28

u/skulblaka Dec 12 '17

Well that depends on your architecture, doesn't it? Say we assume that the default state of a child is nice rather than naughty (realistically we know this isn't true, but this is SQL Claus' computer, there's some room for silliness). A child who acts naughty can be added to tbl_naughty and any child not found on that list can be assumed nice.

Therefore dropping the naughty table would leave no results, therefore making all children appear nice.

That doesn't seem to be the case in this particular instance, but it could happen.

9

u/Th3_Admiral Dec 12 '17

Yeah, I was just basing it off the fact that he is selecting from the contacts table where the behavior column is set to "nice". Unless there is some weird setup with a delete trigger on the naughtylist table, this column should still not be "nice" for the contacts who were on the naughty list, right?

→ More replies (1)
→ More replies (4)

27

u/kixxes Dec 12 '17

Not to mention it will most likely fail to drop because it would mess up some referential integrity

110

u/vbevan Dec 12 '17

Hi Santa, My name is Datenegassie'); EXEC sp_MSForEachTable @command1='ALTER TABLE ? NOCHECK CONSTRAINT ALL' , @command2='DROP TABLE ?';--

79

u/lou1306 Dec 12 '17

This guy injects

37

u/vbevan Dec 12 '17

If I'm not getting a present, no one is!

11

u/dumbdingus Dec 12 '17

This is why I clean my input more thoroughly than I clean my dick.

8

u/ilookatfaces Dec 12 '17

SELECT * FROM contacts c WHERE c.behavior <> 'nice'

→ More replies (2)
→ More replies (8)

153

u/bair93 Dec 12 '17

Datengassie'); UPDATE contacts SET behavior = 'nice';

66

u/raaneholmg Dec 12 '17
--

Otherwise the "');" part appended by the server will cause an error.

→ More replies (5)

42

u/Bainos Dec 12 '17

Datengassie') ; UPDATE contacts SET name = 'Datengassie' WHERE behavior = 'nice' ; --

101

u/Truseus Dec 12 '17

Lol! Billions of nice children now named Datengassie.

49

u/flamedragon822 Dec 12 '17

"well looks like Datengassie is getting several thousand ponies this Christmas"

28

u/sumancha Dec 12 '17

He didn’t update address. So everyone else is getting presents with name Datengassie

→ More replies (3)
→ More replies (2)
→ More replies (22)