I'm playing with wget
, and I basically do a script that download a page, grep some information on this page, and then wget
another page depending on these informations. So basically, my code looks like
defautltCommand="wget -v"
formValue=$(cat myfileA.html | get_field_value )
command="${defaultCommand} --post-data=\"myfield=${formValue}\""
echo "Command 3: ${command}"
echo "${command}" | bash
However, this solution has several problems, the main one is that if the html file has some evil values (like " google.com; <evil command>; ls "
), then it could do code injection. And because my script should be run as root as a NetworkManager script... I'd like to be sure that it's not possible to inject code. However, I like the idea to write the command that will be used, it's quite useful to debug when an error occurs.
Do you have a nice way to be sure that I can't get any code injection? Or maybe you have a still better way to proceed? The first idea I got was to replace all quote like this: ... | sed 's/"/\\/g"'
, but I'm not sure that I capture all the possible ways to inject code.
Thank you!