centos 6
buffer weakness #27

5

Weakness Breakdown


Definition:

Buffer overflows are one of the most well-known software vulnerabilities. Even though most developers know what buffer overflows are, attacks against the vulnerabilities are common in both legacy and newer applications. A classic buffer overflow exploit begins with the attacker sending data to a program, which it then stores in an undersized stack buffer. Besides stack buffer overflows, other kinds of buffer overflows include heap overflows, off-by-one errors and many others. Learn more about buffer overflows on OWASP attack index.

Warning code(s):

Does not check for buffer overflows.

File Name:

shadow-4.1.5.1/contrib/adduser-old.c

Context:

The highlighted line of code below is the trigger point of this particular Centos 6 buffer weakness.

 		if (strlen(foo) > 1)
			max_pass = atoi(foo);
		else
			max_pass = DEFAULT_MAX_PASS;
            
		printf("Password Warning Days [%d]: ",DEFAULT_WARN_PASS);
		gets(foo);
		warn_pass = atoi(foo);
		if (warn_pass==0)
			warn_pass = DEFAULT_WARN_PASS;
            
		printf("Days after Password Expiry for Account Locking [%d]: ",DEFAULT_USER_DIE);
		gets(foo);
		user_die = atoi(foo);
		if (user_die == 0)
			user_die = DEFAULT_USER_DIE;
      
		printf("\nInformation for new user [%s] [%s]:\n",uname,person);
		printf("Home directory: [%s] Shell: [%s]\n",dir,shell);
		printf("GID: [%d]\n",group);
		printf("MinPass: [%d] MaxPass: [%d] WarnPass: [%d] UserExpire: [%d]\n",
				min_pass,max_pass,warn_pass,user_die);
		printf("\nIs this correct? [y/N]: ");
		fflush(stdout);
		gets(foo);

		done=bad=correct=(foo[0]=='y'||foo[0]=='Y');

		if(bad!=1)
			printf("\nUser [%s] not added\n",uname);
    }

	bzero(cmd,sizeof(cmd));
	sprintf(cmd,"%s -g %d -d %s -s %s -c \"%s\" -m -k /etc/skel %s",
			USERADD_PATH,group,dir,shell,person,uname);
	printf("Calling useradd to add new user:\n%s\n",cmd);  
	if(system(cmd)){
		printf("User add failed!\n");
		exit(errno);
	};
	bzero(cmd,sizeof(cmd));
	sprintf(cmd,"%s -m %d -M %d -W %d -I %d %s", CHAGE_PATH,
			min_pass,max_pass,warn_pass,user_die,uname);
	printf("%s\n",cmd);
	if(system(cmd)){
		printf("There was an error setting password expire values\n");
		exit(errno);
	};
	bzero(cmd,sizeof(cmd));
	sprintf(cmd,"%s %s",PASSWD_PATH,uname); 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.