5 ms·
Lots of people use these one liners for Dev/test environments. Most of those people aren't aware how insecure they are. For example, with the python SimpleHTT
by londons_explore 7y ago
Lots of people use these one liners for Dev/test environments.
Most of those people aren't aware how insecure they are.
For example, with the python SimpleHTTPServer I can simply request http://localhost/../../.ssh/id_rsa http://localhost/../../.ssh/id_rsa
All your SSH private keys are now mine. I can steal your browser cookie database and get into your email/Facebook/Twitter in the same way.
Any web page can request that, or any software on any machine on your local network.
- Thorrez 7y agoHuh? When I use SimpleHTTPServer with .. it just ignores the .. and keeps me in the same directory. Is the behavior different on different versions of python or something? Is there some special technique I don't know? I tried with '.' and with '%2e' .
- tyingq 7y agoI noticed that browsers and curl were doing something with .. on the client side. Try telnet to the port and typing the GET by hand.
- Thorrez 7y agoYou're partially right that curl is blocking '..'. But it's not blocking '%2e%2e'. I got it to avoid blocking '..' with the --path-as-is flag. I redid the tests, with curl's --path-as-is flag, as well as with raw TCP (via netcat), and SimpleHTTPServer is still not vulnerable.
- guessmyname 7y ago> For example, with the python SimpleHTTPServer I can simply request http://localhost/../../.ssh/id_rsa http://localhost/../../.ssh/id_rsa Eh! That’s not true. I just tried and both Python 2.7.16 and Python 3.7.6 return a "404 Not Found” when I try to download and existing file that is located one or more levels up from the directory where the HTTP server was started. Here is a screenshot showing both results: https://i.imgur.com/uizp7zV.png https://i.imgur.com/uizp7zV.png
- londons_explore 7y agoMaybe behaviour has changed recently? In a past version someone has demonstrated this attack on me...
- reificator 7y agoWere you perhaps running from your home directory? Did the directory you were serving contain any symbolic links to folders outside of that directory?
- tveita 7y agoAFAICT SimpleHTTPServer has been protected against basic traversal attacks for a very long time. There have been bugs though, like https://bugs.python.org/issue26657 https://bugs.python.org/issue26657
- _pmf_ 7y ago> For example, with the python SimpleHTTPServer I can simply request http://localhost/../../.ssh/id_rsa http://localhost/../../.ssh/id_rsa I think my localhost is different from your localhost.
- allendoerfer 7y agoOP was suggesting that a website you were visiting was accessing this URL via JavaScript and posting it to OP's server.
- minitech 7y agoSame-origin policy prevents that specific attack, although the same idea exists if you’re not protected from DNS rebinding on localhost, and `--bind 127.0.0.1` (or some other way to block the port) is necessary – but the Pythons’ built-in HTTP servers aren’t vulnerable to path traversal anyway.
- deleted 7y ago[deleted]
- lixtra 7y ago[1] https://python-security.readthedocs.io/vuln/http-server-directory-traversal.html https://python-security.readthedocs.io/vuln/http-server-dire...