A shell is a command-line interface that executes commands and manages processes. This project implements a POSIX-compliant shell capable of interpreting shell commands, executing external programs, and running builtin commands.
Learning goals:
- Deepen understanding of C programming and low-level system interactions.
- Explore process management, memory handling, and pointer usage.
- Setting up for extending the shell into penetration testing / offensive security tools.
- Basic REPL loop (
$
prompt) usingfgets
for reading commands.
- Tokenizes input into command and arguments (
argv
array). - Supports up to 64 arguments per command.
exit
– exits the shell.echo
– prints arguments to stdout.type
– identifies whether a command is builtin or external.pwd
– prints current working directory (getcwd
, dynamic allocation).cd
– changes current directory, supports$HOME
and relative paths.
- Finds executables in
PATH
. - Uses
fork()
to create child processes. - Uses
execve()
to execute commands.
gcc shell.c -o shell
./shell
-
Command obfuscation and encoding
- Encode/decode commands to avoid detection.
- Support Base64 or XOR encoding for input/output.
-
Enhanced file system operations
- Commands like
ls
,cat
,download
,upload
. - Recursive file search and enumeration of sensitive directories.
- Commands like
-
Process management
- Spawn and manage background processes.
- Inject scripts or commands into running processes.
-
Networking capabilities
- Reverse shells over TCP/UDP.
- Bind shells and port forwarding.
-
In-memory execution
- Execute binaries directly in memory (Meterpreter style).
- Shellcode execution and dynamic library loading.
-
Persistence and stealth
- Hidden shell sessions.
- Redirection of stdout/stderr to avoid logs.