-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
176 lines (143 loc) · 4.63 KB
/
main.c
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//gcc -lcrypto
#define VERSION "2.4.5"
#define DATE "17 November 2009"
//ppppd.h
#define MAXNAMELEN 256 /* max length of hostname or name for auth */
#define MAXSECRETLEN 256 /* max length of password or secret */
#define PRINTMSG(m, l) { info("Remote message: %0.*v", l, m); }
//Config
#define RADIUS "hebeicncxinli002"
#define PREFIX1 '\n'
#include <stdio.h>
#include "md5.h"
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define PREFIX0 '\r'
typedef unsigned char byte;
//TODO : change the version here
//#define PPPOE_VER 2.4.5
//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);
// printf("-------------------------------------");
//info("timenow(Hex)=%x\n",timenow);
//printf("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");
//printf("Begin : beforeMD5");
memcpy(beforeMD5,timeByte,4);//array_copy
//info("1.<%s>",beforeMD5);
//printf("1.<%s>",beforeMD5);
//locate character "@" in userName
i = strcspn(userName,"@");
memcpy(beforeMD5 + 4 , userName , i);
//info("2.<%s>",beforeMD5);
//printf("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);
//printf("3.<%s>",beforeMD5);
//info("4.length=<%d>",strlen(beforeMD5));
//printf("4.length=<%d>",strlen(beforeMD5));
//info("End : beforeMD5");
//printf("End : beforeMD5");
//afterMD5
//info("Begin : afterMD5");
//printf("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=<%2x>",MD501H[0] );
//printf("1.MD5use_1=<%2x>",MD501H[0] );
//info("2.MD5use_2=<%2x>",MD501H[1] );
//printf("2.MD5use_2=<%2x>",MD501H[1] );
//info("End : afterMD5");
//printf("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 check(){
return 1;
}
//getPIN :The first arg:zhanghao The second number save after
int main()
{
char username[]="tya3350020599@campus";
char saveusername[]="nullnow";
getPIN(username,saveusername);
//printf("%s",saveusername);
//printf("\n");
//printf("%d",sizeof (saveusername));
//printf("\n %d",strlen (saveusername));
char zhuanhuan[33];
zhuanhuan[0]='\\';
zhuanhuan[1]='r';
zhuanhuan[2]='\\';
zhuanhuan[3]='n';
int i=4;
for(;i<=32;i++)
{
int n=i-2;
zhuanhuan[i]=saveusername[n];
}
printf("%s",zhuanhuan);
//cout <<sizeof(saveusername);
/*for (int i=0;;i++)
{
printf("%d,%c",saveusername[i],saveusername[i]);
}*/
}