HTTP static server one-liners
gist.github.com
gist.github.com
gawk '@load "filefuncs";func send(s,e,d,t,b) {;print "HTTP/1.0 "s" "e|&S;print "Content-Length: "b|&S;print"Content-Type: "t|&S;print d|&S;close(S);}func mt(f) {;c = "file -b --mime-type " f;r="";while ((c|getline z)>0) {;r=r z;} ;close(c);return r;} ;BEGIN {RS=ORS="\r\n";while(1){;S="/inet/tcp/8080/0/0";while((S|&getline l)>0) {;split(l,f," ");if(f[1]=="GET"){p=substr(f[2],2)}if(p==""){p="index.html"}stat(p,s);if (s["type"]=="file") {;m=mt(p);while ((getline i <p)>0){o=o i}send(200,"OK",o,m,s["size"]);break;} ;n="<html>Not Found</html>";send(404,"Not Found",n,"text/html",length(n));break;}}}'
edit: Added better mime-type detection and 404s. It actually sorta works well now. gawk '@load"filefuncs";@load"readfile";func send(s,e,d,t,b){print"HTTP/1.0 "s" "e|&S;print"Content-Length: "b|&S;print"Content-Type: "t|&S;print d|&S;close(S);}func cf(x){split(x,y,"/");for(z in y){print "FOUND "y[z];if(y[z]==".."){return 0;}}return 1;}func mt(f){c="file -b --mime-type "f;r="";while((c|getline z)>0){r=r z;}close(c);return r;}BEGIN{if(ARGV[1]!=""){if(chdir(ARGV[1])){print "Failed to chdir to "ARGV[1];exit;}ARGC=1;}RS=ORS="\r\n";while(1){S="/inet/tcp/8080/0/0";while((S|&getline l)>0){split(l,f," ");if(f[1]=="GET"){p=substr(f[2],2)}if(p==""){p="index.html"}stat(p,s);if(cf(p)&&s["type"]=="file"){m=mt(p);o=readfile(p);send(200,"OK",o,m,s["size"]);break;}n="<html>Not Found</html>";send(404,"Not Found",n,"text/html"RS,length(n));break;}}}' rclone serve http .
You can replace . with any of your other cloud storage backends too (s3, google drive, dropbox, etc), or http with sftp, webdav, ftp, dlna. It works on Windos/macOS/Linux.(Rclone author ;-)
ruby -r webrick/https -e '
WEBrick::HTTPServer.new(
Port: 8000, DocumentRoot: ".",
SSLEnable: true, SSLCertName: [%w[CN localhost]]).start'
https://stackoverflow.com/a/37986354/59325 caddy file-server --domain example.com
And similarly for HTTPS reverse proxy: caddy reverse-proxy --from example.com --to localhost:9000
[1]: https://caddyserver.com/This plus hosts file can be a quick way to test secure cookies, secure headers, etc.
openssl req -x509 -newkey rsa:4096 -keyout /tmp/key.pem -out /tmp/cert.pem -nodes && openssl s_server -WWW -port 8443 -cert /tmp/cert.pem -key /tmp/key.pemThe same thing, in `batch` for Windows: https://github.com/rahuldottech/netcat-http-server-for-windo...
It's similar to the others mentioned here, with the nice extras that there's optional basic auth, optional HTTPS with automatic creation and use of a self-signed certificate, there are installers for most popular OS's package managers (snap, homebrew, scoop, chocolatey), tiny 2-5 MB zero-dependency binary and some other features.
I've had plans to add automatic Let's Encrypt certs, Onion service creation and reverse SSH functionality (either using one's own SSH server or one of the public ones) for a while and hope I'll get to them soon. Does anyone have any specific preferences for one of those or another feature specifically for the use case of serving files to another person as quickly as possible?
Edit: Didn't know there was an `eval` flag for Node, so that will do the job:
node --eval "var fs = require('fs'), http = require('http'); http.createServer(function (req, res) { fs.readFile(__dirname + req.url, function (err,data) { if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return;}res.writeHead(200);res.end(data); });}).listen(8080);"
ngrok http file:///Users/alan/share
Just wanted to chime in and say I love ngrok too, not allow allows you to easily create proxies, it allows you to create proxies that also works on the public internet (ngrok assigns you a x.ngrok.io address) and with tcp connections. Great work on it inconshreveable!
devd -ol .
[1]: https://github.com/cortesi/devd npx serve
(This is a node.js thing.)I guess I would normally just start with ‘path/to/dir/‘ or ‘/path/to/dir/index.html’
When -U is specified, it provides an upload form, allowing file uploads.
php -S localhost:8000 lwan -r /path/to/files/to/serveOr tcpserver from djb
.
while TRUE; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat /path/to/thing; } | nc -l 8000; done
From: https://krypted.com/https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c...
You don't need to fully install globally
Instructions for how to do that would be a helpful addition to this page.
crystal eval 'require "http/server"; server = HTTP::Server.new([HTTP::LogHandler.new, HTTP::StaticFileHandler.new(".")]); server.bind_tcp(8080); server.listen' rarun2 listen=80 program=/usr/bin/printf arg1="HTTP/1.1 200 OK\r\nContent-type=text/html\r\nConnection: close\r\n\r\n" apt install nginx
Why settle for less.curl https://patchbay.pub/abcd1234.html --data-binary @index.html
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
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.
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.
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
Did the directory you were serving contain any symbolic links to folders outside of that directory?
There have been bugs though, like https://bugs.python.org/issue26657
I think my localhost is different from your localhost.