1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <pppd/pppd.h> #include <pppd/md5.h>
typedef unsigned char byte;
char pppd_version[] = VERSION;
static char saveuser[MAXNAMELEN] = {0}; static char savepwd[MAXSECRETLEN] = {0};
static void getPIN(byte *userName, byte *PIN) { int i,j; long timedivbyfive; time_t timenow; byte RADIUS[16]; byte timeByte[4]; byte beforeMD5[32]; MD5_CTX md5; byte afterMD5[16]; byte MD501H[2]; byte MD501[3]; byte timeHash[4]; byte temp[32]; byte PIN27[6];
info("sxplugin : using zjxinlisx01"); strcpy(RADIUS, "zjxinlisx01"); timenow = time(NULL); timedivbyfive = timenow / 5;
for(i = 0; i < 4; i++) { timeByte[i] = (byte)(timedivbyfive >> (8 * (3 - i)) & 0xFF); } for(i = 0; i < 4; i++) { beforeMD5[i]= timeByte[i]; } for(i = 4; i < 16 && userName[i-4]!='@' ; i++) { beforeMD5[i] = userName[i-4]; } j=0; while(RADIUS[j]!='\0') beforeMD5[i++] = RADIUS[j++];
MD5_Init(&md5); MD5_Update (&md5, beforeMD5, i); printf("%d %s\n",i,beforeMD5); MD5_Final (afterMD5, &md5);
MD501H[0] = afterMD5[0] >> 4 & 0xF; MD501H[1] = afterMD5[0] & 0xF;
sprintf(MD501,"%x%x",MD501H[0],MD501H[1]);
for(i = 0; i < 32; i++) { temp[i] = timeByte[(31 - i) / 8] & 1; timeByte[(31 - i) / 8] = timeByte[(31 - i) / 8] >> 1; }
for (i = 0; i < 4; i++) { timeHash[i] = temp[i] * 128 + temp[4 + i] * 64 + temp[8 + i] * 32 + temp[12 + i] * 16 + temp[16 + i] * 8 + temp[20 + i] * 4 + temp[24 + i] * 2 + temp[28 + i]; }
temp[1] = (timeHash[0] & 3) << 4; temp[0] = (timeHash[0] >> 2) & 0x3F; temp[2] = (timeHash[1] & 0xF) << 2; temp[1] = (timeHash[1] >> 4 & 0xF) + temp[1]; temp[3] = timeHash[2] & 0x3F; temp[2] = ((timeHash[2] >> 6) & 0x3) + temp[2]; temp[5] = (timeHash[3] & 3) << 4; temp[4] = (timeHash[3] >> 2) & 0x3F;
for (i = 0; i < 6; i++) { PIN27[i] = temp[i] + 0x020; if(PIN27[i]>=0x40) { PIN27[i]++; } }
PIN[0] = '\r'; PIN[1] = '\n';
memcpy(PIN+2, PIN27, 6);
PIN[8] = MD501[0]; PIN[9] = MD501[1];
strcpy(PIN+10, userName); }
static int pap_modifyusername(char *user, char* passwd) { byte PIN[MAXSECRETLEN] = {0}; getPIN(saveuser, PIN); strcpy(user, PIN); info("sxplugin : username %s",user); if(passwd!=0){ info("sxplugin : load passwd "); strcpy(passwd,savepwd); } return 1; }
static int check(){ return 1; }
void plugin_init(void) { info("sxplugin init"); strcpy(saveuser,user); strcpy(savepwd,passwd); passwd[0]=0; pap_passwd_hook=pap_modifyusername; chap_passwd_hook=pap_modifyusername; pap_check_hook=check; chap_check_hook=check; }
|