I'm working on a BASH CGI Binary that reads a string a user would type from an HTML form, then appends that string to a log file on my Linux server. I'm using BASH.cgi as seen on (http://oinkzwurgl.org/bash_cgi) to transfer all the POST/GET input user strings automatically into variables. Everything is working perfectly fine, however I found a major security flaw:
HTML Form...
<form action="?" method="POST">
Feedback:<textarea name="comments"></textarea>
<input type="submit" value="Submit">
</form>
BASH CGI...
echo "$comments" >> ./logs/log.txt
Suppose a malicious user would submit the following into the comments text area of the form:
$( rm -rf / )
BASH.cgi would then create a new variable called "comments" that returns the executed value of everything in between the $( and the ). This would in result compromise the server by executing anything a malicious user would please. There must be a way to directly and safely pass the string of a variable without executing what's inside. Any help would be greatly appreciated!
-- Egoscio