S
S
Splite2014-08-20 11:58:31
Command line
Splite, 2014-08-20 11:58:31

How to protect yourself from shell injection?

Hello!
The user enters some keyword, which is then substituted into grep
. What characters should be escaped so that nothing extra can be entered?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Misbakh-Soloviev, 2014-08-24
@mva

%  echo '$SHELL:' $SHELL; read i; echo '12\ndw\n3e\n/bin/zsh\n> '|grep "${i}"
$SHELL: /bin/zsh
> $SHELL
%
% echo '$SHELL:' $SHELL; read i; echo '12\ndw\n3e\n/bin/zsh\n> '|grep "${i}"
$SHELL: /bin/zsh
> $(cat /etc/passwd)
%

Symbols are not required. You need to escape the variable that is fed to grep :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question