CVE-2020-28468
Pwntools < 4.3.1 SSTI allows remote code execution
- CVSS 9.8
- CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
- Input Validation and Sanitization
- Remote
This affects the package pwntools before 4.3.1. The shellcraft generator for affected versions of this module are vulnerable to Server-Side Template Injection (SSTI), which can lead to remote code execution.
- CVSS base score
- 9.8
- Published
- 2021-01-08
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- pwntools
- Fixed by upgrading
- Yes
Solution
Update pwntools to version 4.3.1 or higher.
Vulnerable code sample
from pwntools import shellcraft
# Vulnerable code that uses shellcraft with user input directly
def generate_shellcode(user_input):
# This allows for Server-Side Template Injection (SSTI)
shellcode_template = f"""
{shellcraft.sh()}
{user_input}
"""
return shellcode_template
# Example usage with potentially unsafe user input
user_input = "{{ config }}; echo 'Injected Command'"
output = generate_shellcode(user_input)
print(output)Patched code sample
from jinja2 import Template
def safe_render(template_string, context):
# Use a safe template rendering method to prevent SSTI
template = Template(template_string)
return template.render(context)
# Example usage
template_string = "Hello, {{ user }}!"
context = {"user": "Alice"}
output = safe_render(template_string, context)
print(output)Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Fix pwntools shellcraft SSTI vulnerability (Gallopsled/pwntools)
pwnlib/constants/__init__.py · ConstantsModule.eval,pwnlib/data/syscalls/generate.py,pwnlib/data/syscalls/generate.py · fix_bad_arg_names,pwnlib/data/syscalls/generate.py · generate_one,pwnlib/shellcraft/__init__.py · module.pretty
Cite this entry
@misc{vaitp:cve202028468,
title = {{Pwntools < 4.3.1 SSTI allows remote code execution}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2020-28468},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-28468/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
