-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsxplugin.c
More file actions
133 lines (117 loc) · 3.64 KB
/
Copy pathsxplugin.c
File metadata and controls
133 lines (117 loc) · 3.64 KB
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
126
127
128
129
130
131
132
133
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
//TODO : you may obtaion it by git clone https://github.com/squadette/pppd.git
#include "pppd.h"
#include "md5.h"
#define PREFIX0 '\r'
typedef unsigned char byte;
//TODO : change the version here
char pppd_version[] = PPPOE_VER;
static char saveuser[MAXNAMELEN] = {0};
static char savepwd[MAXSECRETLEN] = {0};
static void getPIN(byte *userName, byte *PIN)
{
int i,j;
byte temp[32];
long timedivbyfive;
time_t timenow;//Linux Stamp
byte timeByte[4];//time encryption from Linux Stamp
MD5_CTX md5;//MD5 class from pppd/md5.h
byte afterMD5[16];
byte beforeMD5[128] = {0};
byte MD501H[2];
byte MD501[3];
byte timeHash[4]; //time encryption from timeByte
byte PIN27[6]; //time encryption from timeHash
timenow = time(NULL);
info("-------------------------------------");
info("timenow(Hex)=%x\n",timenow);
timedivbyfive = timenow / 5;
for(i = 0; i < 4; i++) {
timeByte[i] = (byte)(timedivbyfive >> (8 * (3 - i)) & 0xFF);
}
//beforeMD5
info("Begin : beforeMD5");
memcpy(beforeMD5,timeByte,4);//array_copy
info("1.<%s>",beforeMD5);
//locate character "@" in userName
i = strcspn(userName,"@");
memcpy(beforeMD5 + 4 , userName , i);
info("2.<%s>",beforeMD5);
i = i + 4;
//beforeMD5={time encryption(4)}+{user name(11)}+{RADIUS}+'\0';default length in ChongQing is 31
memcpy(beforeMD5 + i , RADIUS, strlen(RADIUS));
info("3.<%s>",beforeMD5);
info("4.length=<%d>",strlen(beforeMD5));
info("beforeMD5[0-3]");
info("%d ",beforeMD5[0]);
info("%d ",beforeMD5[1]);
info("%d ",beforeMD5[2]);
info("%d ",beforeMD5[3]);
info("End : beforeMD5");
//afterMD5
info("Begin : afterMD5");
MD5_Init(&md5);
MD5_Update (&md5, beforeMD5, strlen(beforeMD5));
MD5_Final (afterMD5, &md5);//generate MD5 sum
MD501H[0] = afterMD5[0] >>4& 0xF;//get MD5[0]
MD501H[1] = afterMD5[0] & 0xF;//get MD5[1]
info("1.MD5use_1=<%x>",MD501H[0] );
info("2.MD5use_2=<%x>",MD501H[1] );
info("End : afterMD5");
sprintf(MD501,"%x%x",MD501H[0],MD501H[1]);
//PIN27
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
PIN[0] = PREFIX0;
PIN[1] = PREFIX1;
memcpy(PIN+2, PIN27, 6);
PIN[8] = MD501[0];
PIN[9] = MD501[1];
strcpy(PIN+10, userName);
info("-------------------------------------");
}
static int pap_modifyusername(char *user, char* passwd)
{
byte PIN[MAXSECRETLEN] = {0};
getPIN(saveuser, PIN);
strcpy(user, PIN);
info("sxplugin : user is <%s> ",user);
}
static int check(){
return 1;
}
void plugin_init(void)
{
info("sxplugin : init");
strcpy(saveuser,user);
strcpy(savepwd,passwd);
pap_modifyusername(user, saveuser);
info("sxplugin : passwd loaded");
pap_check_hook=check;
chap_check_hook=check;
}