As a kid in the late 90s my mind was blown when I realized I could telnet to port 80, 25, or 110 and interact with the servers manually. Simple get: GET / HTTP/1.1 Content-Type: text/html User-Agent: l33t hax0rs lol X-Funny-Monkey: farts For sending a mail message on port 25: HELO mail-from: whoever@whatever.com mail-to: sysadmin@yaya.com Body of the message yay. POP3 was so long ago I forgot but you could list the m…
TIL: You can make HTTP requests without curl using Bash /dev/TCP
211–220 of 255 posts
Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#212This is pretty neat if all you need is to ping a local server but please use curl (or something equivalent) for contacting remote services. HTTP1.1 seems like such a simple protocol but in the real world you need to deal with proxies, different encodings, and redirects. Curl takes care of that (and a host of other annoying stuff) for you.
Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#213Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#214Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#215Earlier quoted context omitted.
> No, it can not. Bash lets you open TCP sockets. Very fair pushback -- I did get carried away and will update the article to be more precise. Thanks for raising it! > For less insane, non-bash shells there is always nc which is usually probably the wiser choice. For completeness, `nc` or any netcat equvialent I could think of was not available in the image I was trying this with. It would certainly be a better optio…
This is the most Claude pilled comment I've seen here.
Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#216Earlier quoted context omitted.
Last century I would read and send personal email from work using telnet to pop3 and smtp respectively.
I also have a tendency to say "Last century", thinking it comedically suggests "a long time ago" without it actually being that long ago. But as time goes by it obviously becomes legitimately a long time ago, and I suspect young people wouldn't see the attempted irony at all.
Probably get confusing again when people start referring to 'the 20s' not as the 1920s.
Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#217> As it turns out, bash can speak HTTP by itself. No, it can not. Bash lets you open TCP sockets. What you are doing here is trying to speak HTTP yourself, which is fine for testing and debugging, and hella cool for fun to do by hand, but you will shoot yourself in the foot if you try to use this pseudo http client unattended in reality. This toy code does not parse HTTP properly and will break. You could of course w…
Need to be clear that "full http server in pure bash" is incorrect. Bash cannot listen on a TCP/UDP socket for incoming connections. bash-web-server project builds a C language socket listener [0] that is dynamically loaded at run-time as a "built-in" module that makes the functionality available. [0] https://github.com/bahamas10/bash-web-server/tree/main/loada...
cd src/bash-5.3/examples/loadables
make accept
enable -f ./accept accept
(accept -r RHOST -v SOCKETFD -b 127.0.0.1 8000;
read -u $SOCKETFD SOCKETDATA;
printf "%s: %s\n" "$RHOST" "$SOCKETDATA";
printf "goodbye, world\n" 1>&${SOCKETFD} ) &
nc 127.0.0.1 8000
For real use you may need to add "exec {SOCKETFD}Edit: https://news.ycombinator.com/item?id=39369749 (2024)Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#218Zsh has its own zsh/net/tcp and zsh/zftp modules.
https://zsh.sourceforge.io/Doc/Release/TCP-Function-System.h...
https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-...
https://zsh.sourceforge.io/Doc/Release/Zftp-Function-System....
Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#219Earlier quoted context omitted.
Why wouldn’t you use curl for the quick test?
because in those days there was no curl, or wget. and then when there was, there was no guarantee they'd be installed. telnet was always there though. it also worked for speaking all the other plaintext internet protocols. (imap, pop, smtp, etc)
Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP
#220Earlier quoted context omitted.
The magic for me, to this day in fact, is knowing that mail is essentially anyone on the internet being allowed to write to a mail servers disk. There are rules now, but the concept is still almost intact, random people writing to the servers disk - to be later read by someone
It used to be even more literally so - network mail started off as using FTP to SNDMSG onto a remote system instead of your own. In RFC475, FTP has MAIL and MLFL (mailfile) commands to support this. I think it's neat that you can still find echoes of this. MAIL worked by just appending to MLFL, separating records with CRLF.CRLF - which is still how Data segments are terminated in SMTP.