We have a Java IRC application where users are allowed to execute arbitrary PHP and get the result. Here is one example of what this is used for:
btc: <php>$btc = json_decode(file_get_contents('https://btc-e.com/api/2/1/ticker'), true); $ticker = $btc['ticker']; echo "Current BTC Ticker: High: $".$ticker['high']." Low: $".$ticker['low']." Average: $" . $ticker['avg'];
We also have a python setup, but we like PHP because PHP does not require newlines in the code anywhere. (Because this is IRC, we cannot give it newlines unless we exec a web-loaded .py file)
The issue is how to prevent people from trying to exploit the system, such as in:
<php>echo readfile("/etc/passwd");
Which would, clearly, read out the passwd file for all to see.
We are also having this problem, after we tried to block readfile():
<php>$rf = readfile; echo $rf("/etc/passwd");
How should we go about securing this system? (The full code is on github, for any interested: https://github.com/clone1018/Shocky)
As an aside, no real sensitive information is being exposed, as the whole thing is in a VM, so it isn't a "timebomb" or anything. We still want to lock it down though.
/etc/passwd
? Lock down your web user for starters. – Puttergill/etc/passwd
is world readable by default on most Linux distributions. Some programs require access to that file in order to function, and it doesn't contain any passwords anyway. – Distracted/etc/passwd
with no 'other' permissions, but that will break or disable functionality in many programs (includingls
). – Distracted/e
modifier does), the pcntl_ functions, and a whole lot of other things as well. plus, you'd want to isolate the user so it can't write to anything that's ever in any user's$PATH
on the VM, you'd want to prevent it from executing anything external, from making remote connections (wheee, free DoS anyone?) and from saving new files/serving files. – Politi