r/ProgrammerHumor • • Dec 02 '18

Quality "Assurance"

Post image
69k Upvotes

656 comments sorted by

View all comments

Show parent comment

61

u/MrShlash Dec 02 '18

I’m curious, why didn’t you add —— after the semicolon?

94

u/redlaWw Dec 02 '18

So it crashes when it tries to find outstanding-tabs in the remaining SQL.

I don't know anything about databases please don't hurt me

105

u/MrShlash Dec 02 '18

Adding two dashes at the end makes the rest of the sql code a comment that doesn’t execute.

Whenever I saw an SQL injection joke around here they don’t use the dashes and that confuses me, is there a benefit to ending with a semicolon?

57

u/burningpineapples Dec 02 '18

We have a database we use for development at work. I'm totally trying this tomorrow.

146

u/[deleted] Dec 02 '18

Hint: don’t

97

u/[deleted] Dec 02 '18

Jeremy Clarkson's voice: But he did

7

u/VAShumpmaker Dec 02 '18

Th' Moanstah... unda tha baun-et

7

u/WinstonWelles Dec 02 '18

I'd never seen a phonetic transcription of Arnold Shwarzenegger doing an impression of Jeremy Clarkson before. Reddit is amazing.

4

u/VAShumpmaker Dec 02 '18

There's one episode of TG where they look at all the features of some muscle car looking thing, and then Jeremy says "now let's take a look at the monster under bonnet" but like... So weirdly. My girlfriend didn't understand why I rewound the episode 3 times to hear it again

21

u/Bojangly7 Dec 02 '18

Don't mess with work databases that's a good way to find yourself out of a job.

15

u/LordAgbo Dec 02 '18

Also, you’re 2 or 3 terminal commands away of getting a local database to mess up all you want. Look “docker” up. You’re welcome.

→ More replies (3)

12

u/MrShlash Dec 02 '18

My undergrad’s in CompSci InfoSec and that’s how we’ve done sql injection attacks.

3

u/Totally_Generic_Name Dec 02 '18

Do it in production! don't actually do this

→ More replies (1)

15

u/redoverture Dec 02 '18

Your code won’t be valid unless it’s there. Same reason the injection starts with ‘);’. You’re inserting code where an input should be.

input( var ) ... some other code ... is exploitable

input( ); DROP TABLE table; ) ... some other code would throw errors and likely not do what you want it to do

input(); DROP TABLE table; — — ) ... some other code ... keeps everything ‘happy’ and exploits the query.

→ More replies (5)

5

u/[deleted] Dec 02 '18

We're not going to hurt you.

You're one of the lucky ones.

12

u/[deleted] Dec 02 '18

Wouldn't change anything would it? Cause the drop table was executed anyway. or am I missing a joke?

32

u/MrShlash Dec 02 '18

The drop table command is injected into the code, supposing that there are still lines of code after the injection, using two dashes would make sure those lines are commented out and not executed. Therefore the sql code would only execute up to the drop table command.

10

u/[deleted] Dec 02 '18

But the harm is already done, why would you care of the rest gets executed?

46

u/thedr0wranger Dec 02 '18

Because the remaining fragment of whatever code you injected into is probably invalid and will crash, preventing return, possibly rolling back a transaction and certainly easier to spot

6

u/indigo121 Dec 02 '18

Correct me if this is out of date, but don't most common SQL implementations force a commit when you execute a Drop, so the rollback wouldn't even matter?

9

u/ric2b Dec 02 '18

PostgreSQL doesn't

→ More replies (3)

9

u/JuvenileEloquent Dec 02 '18

Suppressing possible errors lets you see if the injected code worked or not - maybe you're guessing the table name or can't tell if it actually got dropped or not, and maybe you'll hit gold and have the error from the DB server dumped to you in production code.

Plus in general you're not simply dropping tables when you do SQL injection, that's just common vandalism and doesn't achieve anything.

→ More replies (1)

6

u/MrShlash Dec 02 '18

You wouldn’t want to raise any flags, and you might be interested to see if the injected code had any effect.

→ More replies (2)
→ More replies (1)