Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unquoted expression injection bash

I recently read that it is dangerous to use unquoted parameter in bash scripts. my question is:

Is it possible to bypass the condition in order to make it always true?

if test $TOTO -eq ${1} 2>/dev/null; then
    echo "Bypass"
else
    echo "No"
fi

Regards,

R

like image 859
Ravure Avatar asked Mar 01 '23 20:03

Ravure


1 Answers

If you're asking whether you can choose a parameter $1 so that this condition is true for any integer value of $TOTO, then yes:

./yourscript "0 -o foo"

This makes any condition become

test 1234 -eq 0 -o foo

This is the equivalent of 1234 == 0 || "foo" in other languages, with one irrelevant comparison OR'd with the truth value of the string foo.

Since test considers all non-empty strings to be true, this expression is always true.

like image 94
that other guy Avatar answered Mar 05 '23 15:03

that other guy