php - linux , allow user only one command with changable variable -
i have 2 servers. first web server linux server. on web server write php script connected linux server , run command after user input. , in case command executes on linux server not same. ex.:
<input type="text" name="input">
....
$user_input = $_post["input"]
....
if (!($stream = ssh2_exec($con, "cat $user_input | grep some_text"))) { echo "fail: unable execute command\n"; }
now must allow user 1 command changable variable. user can give ex. "cat" , "grep" commands , "$user_input" changes every time. there way solve situation?
depending on code...
cat $user_input | grep some_text
...you need limit user input 1 specific path file or/and maybe included additional cat
parameters.
in case, have "burn" 1 , command in source code , clean / validate user input avoid injection of other commands, like:
$user_input = "/dev/null; rm -rf /"
in case, should build multi-step-validation check different aspects of user input find out, if path. example regular expressions, check, if typical path syntax. can try pathinfo()
part of validation see, if there valid output. it's hard, 100% secure chack, if user-input contains file name.
Comments
Post a Comment