Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 209079 | Differences between
and this patch

Collapse All | Expand All

(-)a/libcli/auth/smbencrypt.c (-1 / +73 lines)
Lines 45-50 void SMBencrypt_hash(const uint8_t lm_hash[16], const uint8_t *c8, uint8_t p24[2 Link Here
45
#endif
45
#endif
46
}
46
}
47
47
48
#define SMB_HASH_LM 1
49
#define SMB_HASH_NTLM 2
50
48
/*
51
/*
49
   This implements the X/Open SMB password encryption
52
   This implements the X/Open SMB password encryption
50
   It takes a password ('unix' string), a 8 byte "crypt key"
53
   It takes a password ('unix' string), a 8 byte "crypt key"
Lines 63-68 bool SMBencrypt(const char *passwd, const uint8_t *c8, uint8_t p24[24]) Link Here
63
	return ret;
66
	return ret;
64
}
67
}
65
68
69
/*
70
   Support for using LM/NTLM hashes -- jmk@foofus.net 10/2006 
71
   Greets: Foofus, Phenfen, Omi, Fizzgig, pMonkey
72
*/
73
void E_set_hash(int type, unsigned char hash[16])
74
{
75
       uint l;
76
       char p[1024];
77
       int i, j;
78
       char HexChar;
79
       int HexValue;
80
81
       if ( (getenv("SMBHASH")) && (strlen(getenv("SMBHASH")) == 65) )
82
       {
83
    memset(p, 0, 1024);
84
               strncpy(p, getenv("SMBHASH"), 1024);
85
86
    /* Replace "NO PASSWORD*********************" */
87
    if ((type == SMB_HASH_LM) && (strncmp(p, "N", 1) == 0))
88
      strncpy(p, "AAD3B435B51404EEAAD3B435B51404EE", 32);
89
    else if ((type == SMB_HASH_NTLM) && (strncmp(p+33, "N", 1) == 0))
90
      strncpy(p+33, "31D6CFE0D16AE931B73C59D7E0C089C0", 32);
91
    
92
               for (i=0; i<16; i++) {
93
                       HexValue = 0x0;
94
                       for (j=0; j<2; j++) {
95
                               if (type == SMB_HASH_LM)
96
                                       HexChar = (char)p[2*i+j];
97
                               else
98
                                       HexChar = (char)p[2*i+j+33];
99
100
                               if (HexChar > 0x39)
101
                                       HexChar = HexChar | 0x20;  /* convert upper case to lower */
102
103
                               if (!(((HexChar >= 0x30) && (HexChar <= 0x39))||   /* 0 - 9 */
104
                                        ((HexChar >= 0x61) && (HexChar <= 0x66)))) {    /* a - f */
105
                                       fprintf(stderr, "Error invalid char (%c) for hash.\n", HexChar);
106
                                       exit(1);
107
                               }
108
109
                               HexChar -= 0x30;
110
                               if (HexChar > 0x09)  /* HexChar is "a" - "f" */
111
                                       HexChar -= 0x27;
112
113
                               HexValue = (HexValue << 4) | (char)HexChar;
114
                       }
115
                       hash[i] = (unsigned char)HexValue;
116
               }
117
       }
118
       else
119
       {
120
               fprintf(stderr, "Error reading SMB HASH.\n");
121
               fprintf(stderr, "\tEx: export SMBHASH=\"_LM_HASH_:_NTLM_HASH_\"\n");
122
               exit(1);
123
       }
124
}
125
/* jmk */
126
66
/**
127
/**
67
 * Creates the MD4 Hash of the users password in NT UNICODE.
128
 * Creates the MD4 Hash of the users password in NT UNICODE.
68
 * @param passwd password in 'unix' charset.
129
 * @param passwd password in 'unix' charset.
Lines 75-80 bool E_md4hash(const char *passwd, uint8_t p16[16]) Link Here
75
	smb_ucs2_t *wpwd;
136
	smb_ucs2_t *wpwd;
76
	bool ret;
137
	bool ret;
77
138
139
        /* Support for using NTLM hashes -- jmk@foofus.net 10/2006 */
140
        if ( getenv("SMBHASH") ) {
141
                fprintf(stderr, "HASH PASS: Substituting user supplied NTLM HASH...\n");
142
                E_set_hash(SMB_HASH_NTLM, p16);
143
        } else { 
78
	ret = push_ucs2_talloc(NULL, &wpwd, passwd, &len);
144
	ret = push_ucs2_talloc(NULL, &wpwd, passwd, &len);
79
	if (!ret || len < 2) {
145
	if (!ret || len < 2) {
80
		/* We don't want to return fixed data, as most callers
146
		/* We don't want to return fixed data, as most callers
Lines 88-93 bool E_md4hash(const char *passwd, uint8_t p16[16]) Link Here
88
154
89
	talloc_free(wpwd);
155
	talloc_free(wpwd);
90
	return true;
156
	return true;
157
	}
91
}
158
}
92
159
93
/**
160
/**
Lines 123-128 bool E_deshash(const char *passwd, uint8_t p16[16]) Link Here
123
	bool ret = true;
190
	bool ret = true;
124
	char dospwd[256];
191
	char dospwd[256];
125
	ZERO_STRUCT(dospwd);
192
	ZERO_STRUCT(dospwd);
193
        /* Support for using LM hashes -- jmk@foofus.net 10/2006 */
194
        if ( getenv("SMBHASH") ) {
195
                fprintf(stderr, "HASH PASS: Substituting user supplied LM HASH...\n");
196
                E_set_hash(SMB_HASH_LM, p16);
197
        } else {
126
198
127
	/* Password must be converted to DOS charset - null terminated, uppercase. */
199
	/* Password must be converted to DOS charset - null terminated, uppercase. */
128
	push_string(dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE);
200
	push_string(dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE);
Lines 135-141 bool E_deshash(const char *passwd, uint8_t p16[16]) Link Here
135
	}
207
	}
136
208
137
	ZERO_STRUCT(dospwd);
209
	ZERO_STRUCT(dospwd);
138
210
	}
139
	return ret;
211
	return ret;
140
}
212
}
141
213

Return to bug 209079