Search code examples
phplinuxbashshprocfs

PHP calls to system vs Bash scripts Security


Heey all,

I have made a platform to show CPU, RAM and swap data. This data is entered in a database for analysing reasons. At this moment it's written in a bash script using the proc filesystem.

The platform is written in PHP using Symfony framework. Should i consider moving the bash scripts to my PHP project and make use of the functions system(), exec(), shellExec() Or shall i stay with the bash scripts?

I'd to know this in security point of view. With sources for more info.

For now the bash scripts post data to an url (which comes from the symfony project)

The servers are running Debian.


Solution

  • Your solution is a good starting point.

    • Php dangerous functions like system(), exec() and others should be disabled due to security reasons. So you shouldn't consider to moving your bash scripts to your symfony projects
    • You can connect your bash scripts which generates data and your php-application in different ways:

      1. Through api calls (your approach). bash script --> api calls --> php application. In this case you need to save data in your app synchronously with its generating (sometimes you want to smooth out the peaks)
      2. Through log files bash script --> write log files && php application --> read log files. In this case your bash scripts don't need to know about your php application. You only need to agree on the format of the log files. In this case you can process your data in your app asynchronously.