dstat is a versatile tool for generating system resource statistics.
It allows users to create a custom plugin and execute by adding option e.g. dstat --myplugin
.
Investigation
If we can execute "dstat" command as root, we can gain access to privileges by using our malicious plugin.
Exploitation
1. Create a New Dstat Plugin
First off, find locate the "dstat" directory.
Assume the location of dstat is “/usr/local/share/dstat”.
Create a plugin called "dstat_exploit.py" under "/usr/local/share/dstat/".
dstat recognizes plugins under "/usr/local/share/dstat/".
Check if the above exploit plugin has been added by executing the following command.
2. Execute Dstat with the Malicious Plugin
Now execute "dstat" with “—exploit” flag (the flag name is determined by the suffix of the file name e.g. "dstat_\<plugin-name>.py").
The exploit plugin executed so we enter bash as root.