{ echo -e "GET / HTTP/1.0\r\nHost: ftp.gnu.org\r\n\r" >&3; cat <&3 ; } 3<> /dev/tcp/ftp.gnu.org/80 { echo -e "GET / HTTP/1.0\r\nHost: ftp.gnu.org\r\n\r" >&3; cat <&3 ; } 3<> /dev/tcp/ftp.gnu.org/80I 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 :)
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.
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-lates... then execute
./xbps-install -S --repository=https://alpha.de.repo.voidlinux.org/current -r / base-system
and call it a day.
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.
That is, that you can find them in an uncompressed form. If you fees adventurous you can probably coax the compressed data somehow through the bootloader decompressor, or the xz or deflate implementation found in the Linux kernel. Unfortunately these days modules tend to be compressed as well, but it should be possible to convice libdl to open a .ko file. If not you can always mmap it PROT_READ|PROT_EXEC and follow the symbols entries through the TLD yourself.
No nc.
https://github.com/kisom/goat/blob/master/goat.go
Well, JK. A simple, braindead, ugly and fast netcat clone (client only) can be done in C in few functions.
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.
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.
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.
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