5 ms·
If you have bash, you could retrieve wget or CURL and go from there. { echo -e "GET / HTTP/1.0\r\nHost: ftp.gnu.org\r\n\r" >&3; cat <&3 ; } 3<> /dev/tcp/ft
by danieldk 6y ago
If you have bash, you could retrieve wget or CURL and go from there.
{ echo -e "GET / HTTP/1.0\r\nHost: ftp.gnu.org\r\n\r" >&3; cat <&3 ; } 3<> /dev/tcp/ftp.gnu.org/80
- Thorentis 6y agoWoah, that's a cool one liner. Bash always amazes me.
- anthk 6y agoGetting it from a Gopher mirror would be even easier, the protocol is barebones. But bash is cheating, you can write an IRC/FTP/Gopher client in seconds and fetch all the info and documentation from here. You can browse the wikipedia, read an HN mirror, play IF games and even seek Gutenberg from Bash as I can see by just connecting to the port 70 and doing simple Gopher queries. That's too easy then. If the shell is the one from Busybox or ash, the fun begins.
- danieldk 6y agoI guess that the task is really underspecified (maybe intentionally to have different speed runs). It makes a huge difference whether you have a kernel with a TCP/IP stack, a C compiler, a C library with the socket API, etc. The point of the shell example is, that once you have some way to easily open a socket, you can bootstrap a more complete system very quickly. You download a more complete root image from your favorite distribution and override / with that, etc.
- anthk 6y agoTrue. Or as I said, a busybox from a Gopher mirror to an FTP server which mirrors Ibiblio itself. Chmod'ing +x it is dumb easy from C. OpenBSD's netcat without socks and proxy support can be very barebones and understandable and writable in an hour. With that tool you could fetch busybox in a second.
- rootlocus 6y ago> I realized a few years later that this was just an exercise in flexing the fact that I could probably bootstrap my way up from this with the C compiler to write a terrible editor, then write a terrible TCP client, find my way out to ftp.gnu.org, get wget, and keep going from there. I assume by "a terrible TCP client" she means a TCP stack, so you don't have a TCP stack yet, so `/dev/tcp` wouldn't exist. Otherwise just opening a socket and sending the request would do the trick. Or maybe that's what she meant by "TCP client"? But writing an editor for that would be overkill I think. Nice try though :)
- ilaksh 6y agoIt is unclear to me whether the C libs include TCP. If not then that seems like the main part of the work because once you have that then you can download everything else. Unless it was already in BIOS or some network hardware remote admin Intel thing and there was a way to hack into that to use it. Then you would not have to implement TCP IP. To me the question is what is the minimal part of TCP /IP that you would need. I guess also you need ethernet if that's not in the C libs. To cheat maybe your computer has a modem and there is a BBS - simpler protocol.
- datenwolf 6y ago> It is unclear to me whether the C libs include TCP. The exercise states that you have a Linux kernel and there is a network connection. If the kernel does not have TCP, but only offers a raw socket, well, then you have to write down a very simple TCP stack. But if the kernel does have TCP, the exercise boils down to writing a very simple HTTP client, a very simple DNS resolver and a bare bones XZ decompressor and tar reader. From there I'd grab myself https://alpha.de.repo.voidlinux.org/static/xbps-static-latest.x86_64-musl.tar.xz https://alpha.de.repo.voidlinux.org/static/xbps-static-lates... then execute ./xbps-install -S --repository=https://alpha.de.repo.voidlinux.org/current https://alpha.de.repo.voidlinux.org/current -r / base-system and call it a day.
- anthk 6y agoOr just get a static tar and xz static build, they must be somewhere. Better: busybox build. It already has tar, xz and wget. You just need to compile a simple HTTP client, or better: find a gopher mirror. Bare netcat would work against that. gopher://ftp.icm.edu.pl:70/1/vol/rzm6/busybox/binaries With NetCat: echo vol/rzm6/busybox/binaries/1.21.1/ | nc ftp.icm.edu.pl 70 echp vol/rzm6/busybox/binaries/1.21.1/busybox-i586 | nc ftp.icm.edu.pl 70 > busybox Then ln all the binaries. Or run busybox wget. Accesign the rest of the files is the same, just redirect the nc command to a file. If tar is missing, you can just get for sure an static build and compile it. Or try to find an sltar mirror to github ;). But that busybox has ustar, so look how easy it was with just netcat and Gopher, so writting an nc clone (openbsd's netcat portable version is really easy, altough there are another ones many more times dumbed down) would be the easiest win.
- anthk 6y agoBusybox better. With nc(1), IDK about the Bash syntax, so adapt it: echp vol/rzm6/busybox/binaries/1.21.1/busybox-i586 | nc ftp.icm.edu.pl 70 > busybox chmod it with a simple C file: cat > cbox.c << EOF #include <stdio.h> #include <sys/stat.h> int main(){ chmod("/home/crap/busybox", S_IXUSR); return(0); } EOF cc -o cbox cbox.c ./cbox ./busybox | ./busybox more
- shadyabhi 6y ago`cat` is not bash so you should revise that one-liner to use the bash built-in `read`.