Imagine!!! Our campus had actually been breached. Real terrorists, but not the ordinary kind — these knew exactly who they were dealing with. Fearing that students might communicate and coordinate a counter-attack, they seized control of the main server rooms and threw a digital net over the entire campus LAN. Wireshark and Tshark running in promiscuous mode across every Wi-Fi access point, sniffing every single packet. Send anything unencrypted — even a plain "hello" — and they'd intercept it, pinpoint the exact location, and that would be it. Game over. Possibly a lifetime sentence to Windows 11.
No internet. No cellular data. Just one local Wi-Fi router in the corridor, fully monitored by the enemy, and a teammate hiding somewhere else on campus with no safe way to reach them.
So ya to communicate with my teammate, We had to find a solution.
Standard shells leave history files and logs the adversary could trace, so even the shell itself had to be custom-built. This is octo-shell — built up in four levels.
A bare-bones REPL written in pure C. External commands (ls, cat, etc.) run via fork() + execvp(). Built-ins like cd are handled internally with chdir(). Clean memory teardown on exit.
A custom point-to-point file transfer tool over TCP. Every file is preceded by a strict 72-byte header (4-byte verification tag, 64-byte filename, 4-byte payload size) so the receiver knows what's coming and when it ends. Sizes are converted with htonl()/ntohl() to survive cross-architecture byte-order differences.
Hand-rolled encryption, no libraries:
- Key exchange: Diffie-Hellman using modular exponentiation (square-and-multiply) to avoid overflow — both sides derive the same secret
Kwithout ever transmitting it. - Keystream:
Kseeds a custom pseudorandom byte generator. - Cipher: every byte is XOR'd against the keystream before it hits the socket, and XOR'd again on the other end to recover it. To a sniffer, it's just noise.
A passive intrusion detector using a raw socket (SOCK_RAW) to inspect every incoming packet at the IP layer before the OS touches it. Compares each source IP against my teammate's known address — anything else triggers an instant, color-coded alert. My cue to move.
On a network the enemy fully controls, trusting an unaudited library wasn't an option. Every layer — sockets, header parsing, modular exponentiation, the cipher, the packet sniffer — was written and understood by hand.
Sounds Interesting ryt?? Wanna try it out...Its simple just follow this steps i have mentioned in this website. Trust me its gonna be fun!!
Since this project uses POSIX headers (unistd.h, sys/wait.h), it must be compiled inside Linux.
On Windows, launch Ubuntu via WSL:
wsl -d ubuntuMove into the src directory where main.c is located:
cd /mnt/c/Upskilling/Hiba_spider_task2/codecrafters-shell-c/srcUse gcc to compile main.c into an executable named shell:
gcc main.c -o shellIf compilation succeeds, you’ll see a new file called shell in the directory.
Execute the program:
./shellYou should now see your custom shell prompt:
$
Try out the builtins:
echo hello world
cd src
And external programs:
ls -l
cat main.c
grep int main.cType:
exitto quit.
-
Do not compile/run in Git Bash or MinGW
These environments don’t support POSIX headers. Always use WSL Ubuntu. -
Exec format error
If you see this error, it means you tried to run a Linux binary from Windows. Switch back to WSL. -
Codecrafters tests
They will run your program in a Linux environment, so WSL matches the expected setup. -
Compile on Linux
Use Ubuntu (WSL or a VM).
sudo apt update
sudo apt install build-essential
