Live data from Hacker News

TIL: You can make HTTP requests without curl using Bash /dev/TCP

mareksuppa.com

111–120 of 255 posts

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#112
This was something I learned about 10 years ago when earning my OSCP, useful during penetration tests and CTFs when you get a low-priv shell that's running a minimal OS (No curl, nc, python, etc.) but running a web server listening on localhost.

Using /dev/tcp was also handy in getting that initial low-priv shell.

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#113
post #45

Earlier quoted context omitted.

Why wouldn’t you use curl for the quick test?

Sometimes you want to do something that curl cannot express, e.g. timing, protocol oddities, etc. For example you may want to issue a CONNECT to an echo server through a proxy and observe the bytes flowing back and forth. You may want to see what happens when conflicting hop-by-hop headers are specified without worrying about the client's (curl's) interpretation of them. A simple nc -c (or openssl s_client -crlf) let…

For what it's worth curl can do very detailed timing [1] and it can also do this using a proxy

    export http_proxy=http://your.proxy.server:port/

    export HTTPS_PROXY=https://your.proxy.server:port/

    curl -x http://proxy_server:proxy_port --proxy-user username:password

    or  $socks-wrapper curl # [2]
[1] - https://dev.to/gbhorwood/curl-getting-performance-data-with-...

[2] - torsocks, tsocks, wireproxy, shadowsocks-rust, proxychains-ng, etc...

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#116

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…

I must have tried to write the same "perfect" IRC client from scratch in C a dozen times growing up...

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#117
post #73

Earlier quoted context omitted.

Last century I would read and send personal email from work using telnet to pop3 and smtp respectively.

perhaps you meant "in previous millennium" ?

Presumably the years including 1999 and earlier

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#118
post #95

Once had a coworker tell me to never to use this because "you never know when the customer doesn't have bash installed; use python instead" even though our contract required that the customer had bash. I'm still laughing at that.

FWIW, some distributions (I forget which ones, but I've seen it more than once) compile bash without the network features. Python is ubiquitous, and I've never seen it subsetted this way, so I'd have sided with the coworker.

Eh, looking around, I think you're thinking of Debian. They re-enabled it by-default back in 2009. So, sure, I guess. But if you're dealing with an OS that's from 2009 these days, whether /dev/tcp is enabled in bash or not isn't exactly relevant anymore. And I've seen enough broken python installs (even with stdlib) to put my faith in /dev/tcp working in bash :)

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#119
post #13

Earlier quoted context omitted.

it's not that insane. i've been manually typing http requests in since before http/1.1 and the mandatory host header. it is insane to use it for anything serious (also the opposite, implementing webservers in bash), but for quick testing it's pretty great!

Why wouldn’t you use curl for the quick test?

[dead]

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#120
post #50

Earlier quoted context omitted.

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)

I used telnet to send mail via SMTP once, it's quite literally a good social protocol because it begins with a polite 'HELO'.

Is it the reply to ‘HELO’ that enables things like tarpits?

Like if my server replied with ‘HI PLEASURE TO MEET YOU 127.0.0.1 THAT NAME SOUNDS FAMILIAR ARE YOU BY CHANCE FROM BOSTON MY MOTHER IS FROM BOSTON WELL QUINCY ACTUALLY BUT DO YOU KNOW 127.0.1.1 THEY ARE A REALLY GOOD FRIEND OF MINE YOU SHOULD MEET I HEAR THEIR DAUGHTER IS A DOCTOR DONTYAKNOW AND YOU COULD…”

etc, etc?

Post reply on HN