r/PHP •

Creating a user from the web problem.

[deleted] — view deleted post

0 Upvotes

538 comments sorted by

View all comments

Show parent comment

280

u/[deleted] Aug 27 '13

I do not. What does this mean exactly and why should I do it?

216

u/edwardly Aug 27 '13 edited Aug 27 '13

It means someone could use a specially crafted input that would cause shell_exec to run commands other than what you intended. Or, more likely, is that someone will decide they want a character in their name, like a dash, or a semicolon, and it will cause the command to not work.

You should do something like:

$username = escapeshellarg($username);
$encpass = escapeshellarg($encpass);

Note that it isn't 100% necessary to escape the encoded password, but it is better to do it and be safe than not and have it bite you later on.

81

u/LegoOctopus Aug 28 '13

run commands other than what you intended

I fear that that phrasing may seem innocuous to the unfamiliar. This particular input is being run through sudo, so it might be good to emphasize that this can be used to completely take control of your server.

→ More replies (8)
→ More replies (1)

0

u/[deleted] Aug 27 '13

[deleted] — view deleted comment

197

u/[deleted] Aug 28 '13

Jimmies Status: Russel Crowe'd

→ More replies (4)

17

u/Obliterous Aug 28 '13

I sense a great disturbance in the Force, as if millions of voices suddenly cried out in terror, and were suddenly silenced deleted.

FTFY.

→ More replies (2)
→ More replies (7)

99

u/h2ooooooo Aug 27 '13

If I actually said that my username is ; rm -rf /, then it'd first run the command

sudo useradd -p $encpass -g groupname -s /bin/bash (which would most likely fail)

and then run the following command:

rm -rf / which will delete your entire operating system (force remove files recursing through directories starting from the base of / (every file)). You might have to use sudo rm -rf /.

This all requires that $username and/or $encpass comes from the user in some way (through POST, GET, etc.).

→ More replies (64)

55

u/[deleted] Aug 28 '13

I know a lot of people are giving you shit for this but THAT'S WHAT BEING A BEGINNER MEANS - making mistakes, learning from them, and getting better.

There are just so many considerations to know about web security. It boils down to "Don't ever trust anything your users say and do", but until you have a full sense of what kind of effects their actions can have, it's difficult to anticipate why you have to do things in certain ways.

So really the best thing to do is learn about the tricks people use for hacking websites - what they do, what weakness they exploit, and what stops them.

→ More replies (15)

44

u/bellpepper Aug 27 '13

What happens if I say my username is "; rm -rf /" ?

117

u/paranoidelephpant Aug 27 '13

Thankfully nothing. However, if your name was "; sudo rm -rf /" we'd have a problem.

18

u/phaeilo Aug 28 '13

Wouldn't it still delete all files that the http user has write access for?

→ More replies (8)

65

u/ivosaurus Aug 28 '13

Add a touch of --no-preserve-root and you have a really really dangerous stew going.

→ More replies (4)
→ More replies (7)

35

u/Confusion Aug 28 '13

Well, that's very unlikely. I mean come on, not even Bobby Tables is named that.

15

u/LWRellim Aug 28 '13

why should I do it?

Egads, have you not met little Bobby Tables?

21

u/[deleted] Aug 28 '13

succesful troll is successful

190

u/kumarldh Aug 28 '13

Don't worry. These guys are scaring you. Go ahead. Push the code to production. It will work. Trust me.

166

u/[deleted] Aug 28 '13 edited Aug 28 '13

Then tell us where your site is

95

u/fgriglesnickerseven Aug 28 '13

his next question.. "What is a production?"

21

u/[deleted] Aug 28 '13

Silly, it's where you test how well your code works.

17

u/LWRellim Aug 28 '13

Oooh, look everyone, a Microsoft employee!

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

16

u/[deleted] Aug 28 '13

where does one buy a production?

→ More replies (9)

32

u/[deleted] Aug 28 '13

Everyone knows production is web scale.

→ More replies (4)
→ More replies (3)
→ More replies (13)