Skip to content

Conversation

@wodny
Copy link
Contributor

@wodny wodny commented Oct 27, 2015

Fixing (at least partially) #348.

@axkibe
Copy link
Collaborator

axkibe commented Nov 25, 2016

Honestly I don't think there is an ejection possible. The arguments are passed seperately anyway.

At least I don't manage to shell inject:

  src$ touch \`touch\ x\`
  src$ ls
  `touch x`
  src$ ls ../trg/
  `touch x`
  src$ 
  src$ touch "; touch x"
 src$ ls -l ../trg/
  total 0
  -rw-r--r-- 1 axel axel 0 Nov 25 15:30 ; touch x
  -rw-r--r-- 1 axel axel 0 Nov 25 15:29 `touch x`

This is because Lsyncd never plainly spawned shells as one string command, but always using an exec call that provides the arguments as array.

@axkibe axkibe closed this Nov 25, 2016
@wodny
Copy link
Contributor Author

wodny commented Nov 25, 2016

Have you tried the examples I gave in #348?

@axkibe axkibe reopened this Nov 25, 2016
@axkibe
Copy link
Collaborator

axkibe commented Nov 25, 2016

Ah sorry, my fault. You're correct.

@axkibe axkibe merged commit b3f46e2 into lsyncd:master Nov 25, 2016
@axkibe
Copy link
Collaborator

axkibe commented Nov 25, 2016

let me check if providing " in the filenames breaks it again

@axkibe
Copy link
Collaborator

axkibe commented Nov 25, 2016

src$ mv "; touch x"   "\" x \"; touch x"
src$ ls -al
total 8
drwxr-xr-x  2 axel axel 4096 Nov 25 15:44 .
drwxr-xr-x 11 axel axel 4096 Nov 25 15:42 ..
-rw-r--r--  1 axel axel    0 Nov 25 15:30 "; touch b
-rw-r--r--  1 axel axel    0 Nov 25 15:31 " x "; touch x
src$ 
src$ ls -al ../trg/
total 8
drwxr-xr-x  2 axel axel 4096 Nov 25 15:44 .
drwxr-xr-x 11 axel axel 4096 Nov 25 15:42 ..
-rw-r--r--  1 axel axel    0 Nov 25 15:30 "; touch b
-rw-r--r--  1 axel axel    0 Nov 25 15:31 " x "; touch x
src$ 

Looks good to me, anything else one could do to escape/break it?

@wodny
Copy link
Contributor Author

wodny commented Nov 25, 2016

Now probably only special names beginning with a dash would be a problem (will be treated as parameters), but as I mentioned in #348 - lsyncd requires passing absolute paths to work correctly so the potential exploit will usually be prevented by the user running the daemon. Nevertheless, that bug should probably be corrected as well if the patch (e.g. adding '--') wouldn't break lsyncd on non GNU/Linux platforms.

@axkibe
Copy link
Collaborator

axkibe commented Nov 25, 2016

I see, in -nodaemon mode paths can be relative, but it will always prepend at least a directory name before it. So I don't think it can happen

@axkibe
Copy link
Collaborator

axkibe commented Nov 25, 2016

That is as long the user doesn't provide a target name starting with a dash.

@axkibe
Copy link
Collaborator

axkibe commented Nov 25, 2016

Just tested it on a fairly old OSX i got around. Shell utils accept "--", so I see no reason to not add them

@axkibe
Copy link
Collaborator

axkibe commented Nov 25, 2016

Done. Sorry i delayed this by a year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants