[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: adduser not encrypting password


I wrote a program a long time ago to properly crypt the password,
without fudging a salt. I have included the source and binary{glibc
2.0,kernel 2.2.17,i386} code as 
attachments. Help on using the program is commented in the source, and
generic help 
is available when a mistake is made.

Guy Fraser

"Mike A. Harris" wrote:
> On Fri, 29 Jun 2001, Tim Waugh wrote:
> >Date: Fri, 29 Jun 2001 12:09:58 +0100
> >From: Tim Waugh <twaugh redhat com>
> >To: seawolf-list redhat com
> >Reply-To: seawolf-list redhat com
> >Content-Type: multipart/signed; micalg=pgp-md5;
> >       protocol="application/pgp-signature"; boundary="wxNrNKeE/ptr8Zbn"
> >Subject: Re: adduser not encrypting password
> >
> >On Fri, Jun 29, 2001 at 07:47:50AM -0300, miguel dilaj pharma novartis com wrote:
> >
> >> Of course you must enforce that all users change their password after first
> >> logon.
> >
> >And hope that they don't change the passwords of other users!
> >
> >It seems like mkpasswd(1) can help here.
> No, mkpasswd is terribly insecure.  We have an open bug report in
> bugzilla on this which I have attached a file to which contains
> every last password that mkpasswd can generate.  The number of
> passwords it generates is very low and could easily be brute
> forced.
> mkpasswd should be removed from the distribution entirely because
> it doesn't appear that anyone is fixing it, and a lot of people
> probably use it, and thus anyone suspecting a site is using auto
> generated passwords from mkpasswd, can easily brute force
> accounts.
> There is a total of 32167 unique passwords that mkpasswd will
> generate.  I'm guessing a modern processor could walk through
> that in the bat of an eye.
> http://bugzilla.redhat.com/bugzilla/show_bug?id=9507
> ----------------------------------------------------------------------
>     Mike A. Harris  -  Linux advocate  -  Open Source advocate
>        Opinions and viewpoints expressed are solely my own.
> ----------------------------------------------------------------------
> The key to knowledge is not to rely on people to teach you it.
> _______________________________________________
> Seawolf-list mailing list
> Seawolf-list redhat com
> https://listman.redhat.com/mailman/listinfo/seawolf-list

There is a fine line between genius and lunacy, fear not, walk the
line with pride. Not all things will end up as you wanted, but you
will certainly discover things the meek and timid will miss out on.
genpw.c - Written by : Guy Fraser <guy incentre net>

	genpw -{p|e} password username
		-p password			# clear text password
		-e password			# encrypted password

	An encrypted paswork is send to stdout on success.

To Build type:
	cc -o /usr/bin/genpw -lcrypt genpw.c

	adduser -p `genpw -p Sm0k1n johndoe` johndoe

#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#define UIDMAX 65535
#define UIDMIN 20

char *encrypt_pw(char *clearpw, char *name);

/* crazy conversion for some older OS's. */
/* turns an 8 bit character to 32 bit integer for some poor switch commands. */
/* this is also useful for constructing crypt salts */
typedef union{
  char ch[4];
  int num;

int main(int argv, char *argc[], char *envp[]){

  *set main variables*

  struct passwd *inpass;

  int i = 0 ;

  char *message[1] = {
"\nUsage:\n\tgenpw -{p|e} password username\n\n\
\t-e password\tencrypted password\n\
\t-p password\tclear text password\n\n"

  ctoi x;

  x.num = 0 ;

  if(argv != 4){
    if(argv < 4){
      fprintf(stderr,"Not enough arguments.\n\n");
      fprintf(stderr,"Too many arguments.\n\n");

    for(i = 0;i < argv;i++){

      printf("entry %d = %s\n",i,argc[i]);

    }/*end diag*/

    fprintf(stderr, message[0]);

  }/*end if argv*/

    strcpy(x.ch, argc[1]);	/* crazy conversion for some older OS's. */
    x.ch[0] = x.ch[1];		/* copy command character over the hyphen. */
    x.ch[1] = '\0';		/* clear the copied character. */
    newpass = strdup(argc[2]);
    if (argc[1][0] != '-') {
      fprintf(stderr,"No - found.\n\n");
      fprintf(stderr, message[0]);
    } /* end if */

    switch(x.num){ /* crazy conversion for some older OS's. */

      case 112: newpass = strdup(encrypt_pw(argc[2], argc[3])); /*p*/

      case 101: printf("%s\n",newpass); /*e*/

      default:  fprintf(stderr,"No -p or -e found.\n\n");
      		fprintf(stderr, message[0]);

    }/*end switch*/

  }/*end elseif argv*/


}/*end main*/

char *encrypt_pw(char *clearpw, char *name){

  long now,week,pert1,pert2;
  char salt[3] = "\0\0\0", *newpw,
       saltset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
  ctoi tx;
  tx.num = 0;

  tx.ch[0] = name[0];
  pert1 = tx.num;
  tx.ch[0] = name[1];
  pert2 = tx.num;

  now = time(NULL);
  week = now / (60*60*24*7);

  salt[0] = saltset[((week + pert1 + pert2) % 64)];
  salt[1] = saltset[(now % 64)];

  newpw = (char *)crypt(clearpw, salt);
  return newpw;

Attachment: genpw
Description: Binary data

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]