Resources
- General
- Compiled vs Interpreted : https://www.freecodecamp.org/news/compiled-versus-interpreted-languages/
- Garbage Collection : https://www.freecodecamp.org/news/a-guide-to-garbage-collection-in-programming/
- Variables
- Arrays
- Geeks4Geeks : https://www.geeksforgeeks.org/c/c-arrays/
- Programiz : https://www.programiz.com/c-programming/c-arrays
- Struct & Unions
- Memory
- Virtual Memory : https://www.geeksforgeeks.org/operating-systems/virtual-memory-in-operating-system/
- Pointers : https://www.cprogramming.com/tutorial/c/lesson6.html || https://boredzo.org/pointers/
- Pointer2Pointer : https://www.reddit.com/r/learnprogramming/comments/ipou54/i_dont_understand_double_pointers_in_c/ || https://www.geeksforgeeks.org/c/c-pointer-to-pointer-double-pointer/ || https://www.youtube.com/watch?v=Ie9ZByxYiG0
- StackOverFlow :
- Difference between LPVOID and void : https://stackoverflow.com/questions/1987957/difference-between-lpvoid-and-void
- abs : https://www.w3schools.com/c/ref_stdlib_abs.php || https://www.reddit.com/r/explainlikeimfive/comments/1b9fb4t/eli5_what_is_the_purpose_of_void_in_c/
- FileDiscreptor : https://www.geeksforgeeks.org/c/input-output-system-calls-c-create-open-close-read-write/ || https://42-cursus.gitbook.io/guide/useful-tools/file-descriptors-fd
- stat&fstat : https://www.emblogic.com/blog/12/diffrence-between-statfstat-and-lstat/
- Multi Module : https://edshare.gcu.ac.uk/4002/2/index.html
- Base64 : https://blog.leonardotamiano.xyz/tech/base64/
- Function Pointer : https://www.w3schools.com/c/c_functions_pointers.php || https://www.upgrad.com/tutorials/software-engineering/c-tutorial/function-pointer-in-c/
- bitwise : https://www.geeksforgeeks.org/c/bitwise-operators-in-c-cpp/
Commands
- Mem Leak
- Vangrind
gcc -g Memory_Leaks.c -o leak_test valgrind --leak-check=full ./leak_test
- Vangrind
- Glibc
ldd ./myprogram - Manuals
man malloc - Tips & Tricks
mkdir -p tiny_implant/{src,include,lib,obj,bin} - Generating
- Manual
- Static
# Object Files gcc -I./include -Wall -c src/crypto.c -o obj/crypto.o gcc -I./include -Wall -c src/Base64.c -o obj/Base64.o # Creating Lib ar rcs lib/libcrypto.a obj/*.o # Making Final Move gcc -I./include -Wall src/main.c -o bin/implant -Llib -lcrypto ./bin/implant - Shared
mkdir -p obj lib bin gcc -I./include -Wall -fPIC -c src/Base64.c -o obj/Base64.o gcc -I./include -Wall -fPIC -c src/Base64.c -o obj/Base64.o gcc -shared -o lib/libcrypto.so obj/*.o gcc -I./include -Wall src/main.c -o bin/implant -Llib -lcrypto export LD_LIBRARY_PATH=./lib:$LD_LIBRARY_PATH ./bin/implant
- Static
- Make
- Tips & Tricks
- For Loop
for file in src/*.c; do if [ "$file" != "src/main.c" ]; then gcc -I./include -Wall -fPIC -c "$file" -o "obj/$(basename "$file" .c).o" fi done - Seeing exported Sympols
nm -D lib/libcrypto.so objdump -T lib/libcrypto.so # List exported Symplos only nm -D lib/libcrypto.so | grep ' T '
- For Loop
- Manual
Tools
- code2flow : https://app.code2flow.com/
- onlinegdb : https://www.onlinegdb.com/
- Valgrind : https://valgrind.org/
Notes
General
- Every variable must be declared before it is used.
- When the array is declared or allocated memory, the elements of the array contain
some garbage value- Arrays must has the
SameTypes of values.- If you run operations like strcpy, which copies data from the src buffer to the dest buffer. It will
ONLY STOP COPYING OR PRINTING IF IT ENCOUNTERS THAT ZERO BYTE.- Virtual memory creates the illusion of a large memory, even if the actual memory (RAM) is small.
- The size of the union will always be equal to the size of the largest member of the union
- Pointers
- Does the line start with int, char, or void? → Declaration (Noun).
- Does the line start with the variable name or logic? → Dereference (Verb).
- malloc only understands one thing:
bytes, If you ask for 100 bytes, and the system has 50 bytes free in one spot and 50 bytes free in another, malloc cannot combine them. It must find 100 bytes sitting right next to each other.
x.id = 10;: From variablex -> id = 10;: from Pointer (The Arrow (→) is only used for Structures)- File Descriptor
- 0: stdin - a file that represents the input to your program from the command line
- 1: stdout - a file that represents the output of your program to the command line
- 2: stderr - a file that represents the output of your program, but containing only errors
- In C, you never actually touch a file. The Linux kernel is fiercely protective of its hardware and memory. It trusts no user-space program. If your code wants to read a file, write to a disk, or open a network port, it must submit a request to the kernel.
- The true power of the file descriptor lies in the core philosophy of Unix: Everything is a file.
strlen: Computes the length of a string (the number of characters before the first null terminator \0).sizeof: Returns the size in bytes of its operand. It can be applied to types, expressions, or variables.- static (.a on Unix-like systems, .lib on Windows) and shared (.so on Linux, .dylib on macOS, .dll on Windows).
- Qoutes
- Single quotes (’ ’) are strictly for a single character. They tell the compiler to generate exactly one byte (e.g., ‘a’). If you put multiple letters inside single quotes, the compiler panics because it tries to crush a whole word into a 1-byte space.
- Double quotes (” ”) are for strings (an array of characters). This tells the compiler to allocate a sequence of bytes in memory and automatically add a null terminator (0x00) at the end.
- double quotes silently add an invisible 0x00 byte to the exact size of your payloads.
- The P (pointer) and LP (long pointer)
The Golden Rule of the Asterisk
To keep it straight in your head, memorize how the C compiler reads the
*symbol:
- Address: If the
*is touching a Data Type (likechar*), it means Memory Address.- Dereference: If the
*is touching a Variable (like*payload), it means Open the Box and get the data inside.- Multiply: If the
*is between Two Variables (likea * b), it means Math.
