I have PHP shell and I want user to be able to call functions directly. I got it done. But then I found out that user can call even pre-defined functions like unlink and more. I think this is security hole so I want to restrict callable functions to only those which I have defined, e.g.:calling unlink wont work.
Asked
Active
Viewed 649 times
4
-
Nice question! You'll need to write a wrapper program to restrict the commands that can be sent to `php`. E.g. using C#, if you're targeting Windows. – Danny Beckett Dec 07 '13 at 23:28
-
3[`get_defined_functions()["user"]`](http://php.net/get_defined_functions) just returns yours. A simple whitelist would make more sense however. – mario Dec 07 '13 at 23:29
-
See http://stackoverflow.com/questions/3115559/exploitable-php-functions – Wayne Whitty Dec 07 '13 at 23:31
-
php shell means `php -a` or a php cli application? – hek2mgl Dec 07 '13 at 23:41
2 Answers
0
You can get the list of define functions with
get_defined_functions();
It will return an assoc array with user defined and internal functions. You can use that information to decide whether a functions is user defined or internal. (manual)

hek2mgl
- 152,036
- 28
- 249
- 266
-
And how would he restrict non-user-functions from being executed by `php`? – Danny Beckett Dec 07 '13 at 23:32
-
Can say only when I know his code. Looks like OP need to wrap function calls – hek2mgl Dec 07 '13 at 23:33
-
-
-
-
A php cli application isn't a *php shell*. If he has a php cli application then he could create a whitelist using information returned by `get_defined_functions()['user']`.. So it should be useful. isn't it? – hek2mgl Dec 07 '13 at 23:38
-
The PHP [manual](http://php.net/manual/en/features.commandline.interactive.php) defines `php -a` as an "interactive shell". I'm curious myself now as to whether this could be done without a wrapper program. Let's see if the OP responds with more info! – Danny Beckett Dec 07 '13 at 23:40
0
You can disable functions using the disable_functions
INI setting (in your php.ini file).
For example:
disable_functions=unlink,fopen,file_get_contents [and so on...]

Sverri M. Olsen
- 13,055
- 3
- 36
- 52