This is my first time using bash and I know that eval have some risks when using it. Can you do a code injection to this ? For example I want to run ls command and see the files.
#!/bin/bash
echo "[*] Please enter the name:"
echo -n "> "
read NAME
echo "[*] Please enter the value:"
echo -n "> "
read VALUE
declare CONFIG_$NAME=$VALUE
for VARIABLE in $(compgen -v CONFIG_)
do
echo "- $VARIABLE: $(eval echo \$$VARIABLE)"
done
If
$VARIABLEcontains;the command after it will be executedThe command executed by
evalisSince
$isn't followed by an identifier, it's simply echoed literally. Thenlsis executed.You could also put a valid identifier at the beginning:
This will execute
so it will echo
123then the output ofls.