$ touch '"; echo world "'
$ find . -exec sh -c 'ls -l "$@"' sh {} \;
total 0
-rw-rw-r-- 1 t t 0 Jun 8 23:13 '"; echo world "'
-rw-rw-r-- 1 t t 0 Jun 8 23:13 './"; echo world "'
I was wondering why the beginning and ending double quotes in the filename not paired with the beginning and ending double quotes in "$@"
, so that echo world
in the filename can be run?
Is it because a quote must be recognized by sh
during lexical analysis of the shell command, in order to quote? Here the quotes in the filename appear in the shell command only after parameter expansion, which already passed lexical analysis and is too late for the quotes in the filename to be recognized? Similarly to https://unix.stackexchange.com/a/448643/674?
Differently, adding eval
does not make the injection work either, because although eval
will make "
and ;
in the filename recognizable by the shell, "
in the filename will also be removed by the shell:
$ find . -exec sh -c 'eval ls -l "$@"' sh {} \;
total 0
-rw-rw-r-- 1 t t 0 Jun 8 23:13 '"; echo world "'
ls: cannot access './; echo world ': No such file or directory
Debug to see what eval
actually executes:
$ find . -exec sh -c 'echo ls -l "$@"' sh {} \;
ls -l .
ls -l ./"; echo world "
$ ls -l ./"; echo world "
ls: cannot access './; echo world ': No such file or directory
Thanks.
On a side note, why are there two items for the same file in the output of find
command?
since . is a hard link to the current directory, why does find not output about the directly itself but the file under it?
find .
finds.
– steeldriver Jun 09 '18 at 03:02.
is a hard link to the current directory, why doesfind
not output about the directly itself but the file under it? – Tim Jun 09 '18 at 03:04find
doesn't output the listing -ls .
does – steeldriver Jun 09 '18 at 03:08