TIL: provides pseudo devices for TCP and UDP connections:

echo "hello" > /dev/udp/127.0.0.1/1337

or

exec 5<>/dev/tcp/www.google.com/80
echo -e "GET / HTTP/1.0\n" >&5
cat <&5

I'm baffled how I've never discovered that until today.

@fribbledom i've used this for data recovery before

i accidentally overwrote my luks header, lvm header, and a large chunk of my root partition, so i had nearly no chance of recovering my system if i shut it down

so what i was left with was one bash session, in a tty, loaded into memory, and nothing else. no cat, no ls, no cp, no utilities whatsoever aside from bash. my first instinct after digging around was to use /dev/tcp to put a static rsync on this machine, then get my files off (as networking was still functional). but to use /dev/tcp to bring a file over, you need some way to redirect from /dev/tcp as stdin, to a file, and there is no way to do this in pure bash, you need something like cat.

so i wrote a program in asm that piped stdin back to stdout, compiled it, converted it to hex, put it on an arduino micro (atmega 328p, keyboard emulation), which then typed the hexcode of the program into the console. i then put this hex into an executable file i had on my home partition (still mounted), and used it with /dev/tcp and netcat on my laptop to copy a static rsync to my desktop, which i then used to copy my files over

if you're curious, the files i wanted that weren't backed up were my music library.
Follow

@nik

I like the way you're thinking! 😊

· · Web · 1 · 0 · 0
@fribbledom this took 5-6 hours to pull off, i didn't cover all the other things i tried before this...
Sign in to participate in the conversation
Mastodon

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!