ignore signals, use our password func/file, handle BFA, pass age

This commit is contained in:
schulze 2022-01-29 15:26:19 +01:00
parent 173511240b
commit 75d8367b25

View File

@ -11,7 +11,6 @@
#include <pwd.h> #include <pwd.h>
#include <sys/types.h> #include <sys/types.h>
#include <crypt.h> #include <crypt.h>
#include <shadow.h>
#include "pwent.h" /* Step 2 */ #include "pwent.h" /* Step 2 */
#define TRUE 1 #define TRUE 1
@ -19,16 +18,20 @@
#define LENGTH 16 #define LENGTH 16
void sighandler() { void sighandler() {
//sigset_t mask;
//sigfillset(&mask);
//sigprocmask(SIG_SETMASK, &mask, NULL);
signal(SIGINT, SIG_IGN); /* This will catch ctrl+c and ignore it*/
//signal(SIGTSTP, SIG_IGN); /* This will catch ctrl+z and ignore it*/
/* add signalhandling routines here */ /* add signalhandling routines here */
/* see 'man 2 signal' */ /* see 'man 2 signal' */
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
struct passwd *passwddata; /* this has to be redefined in step 2 */ //struct passwd *passwddata /* Step 1 */
/* see pwent.h */ mypwent *passwddata; /* Step 2 */
struct spwd *shadowpasswddata; /* this has to be redefined in step 2 */
/* see pwent.h */ /* see pwent.h */
char important1[LENGTH] = "**IMPORTANT 1**"; char important1[LENGTH] = "**IMPORTANT 1**";
@ -54,8 +57,11 @@ int main(int argc, char *argv[]) {
fflush(NULL); /* Flush all output buffers */ fflush(NULL); /* Flush all output buffers */
__fpurge(stdin); /* Purge any data in stdin buffer */ __fpurge(stdin); /* Purge any data in stdin buffer */
if (gets(user) == NULL) /* gets() is vulnerable to buffer */ if (fgets(user,sizeof(user),stdin) == NULL ) {
exit(0); /* overflow attacks. */ clearerr(stdin); //if EOF only, clear error
continue; ///* overflow attacks. */
}
user[strlen(user)-1] = '\0'; //replacing \n with \0
/* check to see if important variable is intact after input of login name - do not remove */ /* check to see if important variable is intact after input of login name - do not remove */
printf("Value of variable 'important 1' after input of login name: %*.*s\n", printf("Value of variable 'important 1' after input of login name: %*.*s\n",
@ -63,30 +69,45 @@ int main(int argc, char *argv[]) {
printf("Value of variable 'important 2' after input of login name: %*.*s\n", printf("Value of variable 'important 2' after input of login name: %*.*s\n",
LENGTH - 1, LENGTH - 1, important2); LENGTH - 1, LENGTH - 1, important2);
// using makepass.c to create hashed password -> saving it manually in passdb
user_pass = getpass(prompt); //enter password using deprecated function :/ user_pass = getpass(prompt); //enter password using deprecated function :/
//passwddata = getpwnam(user); //get user info from /etc/passwd /* Step 1 */ passwddata = mygetpwnam(user); //get user info from passdb
if (passwddata != NULL) { if (passwddata != NULL) {
/* You have to encrypt user_pass for this to work */ /* You have to encrypt user_pass for this to work */
/* Don't forget to include the salt */ /* Don't forget to include the salt */
shadowpasswddata = getspnam(user); //get encrypted password from /etc/shadow
//printf("password in shadow file: %s \n", shadowpasswddata->sp_pwdp);
char *user_pass_encrypted = crypt(user_pass, shadowpasswddata->sp_pwdp);
//printf("encryption of typed pass: %s \n", user_pass_encrypted);
// schulze:
// $6
// $Dvon03J3/yxkUTWF$
// JiIGRAV22.iMUOMPW9MJidTt.aPsKOYK4Bx.Av5EMcVmifp1SkhRELWHLKPWCGmv3nhcFk7tgi7/9.YCO/C
//schulze:$6$Dvon03J3/yxkUTWF$JiIGRAV22.iMUOMPW9MJidTt.aPsKOYK4Bx.Av5EMcVmifp1SkhRELWHLKPWCGmv3nhcFk7tgi7/9.YCO/CnS/:18577:0:99999:7:::
if (!strcmp(user_pass_encrypted, shadowpasswddata->sp_pwdp)) { char *user_pass_encrypted = crypt(user_pass, passwddata->passwd_salt);
if (&user_pass_encrypted == NULL) {
perror("Error");exit(EXIT_FAILURE);
}
printf("encryption of typed pass: %s \n", user_pass_encrypted);
if (passwddata->pwfailed >= 10) {
printf("Too many failed login attempts. Your account has been locked.\nContact and Admin to unlock your account.\n");
} else if (!strcmp(user_pass_encrypted, passwddata->passwd)) {
printf(" You're in !\n"); printf(" You're in !\n");
passwddata->pwfailed = 0;
passwddata->pwage = passwddata->pwage + 1;
mysetpwent(user, passwddata);
if (passwddata->pwage > 100) {
printf(" Your password is OLD!!!!\n");
}
/* check UID, see setuid(2) */ /* check UID, see setuid(2) */
/* start a shell, use execve(2) */
// setuid(passwddata->uid)
/* start a shell, use execve(2) */
execvp("/bin/sh", "");
return 0;
} else {
passwddata->pwfailed = passwddata->pwfailed + 1;
mysetpwent(user, passwddata);
} }
} }
printf("Login Incorrect \n"); printf("Login Incorrect \n");