1、新建一个C文件:snplugin.c
- #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 int is_name_modified = 0;
- static char pwd[MAXSECRETLEN] = {0};
- static option_t options[] = {
- { "pwd", o_string, pwd,
- "pwd",
- OPT_STATIC, NULL, MAXSECRETLEN-1 },
- { NULL }
- };
- void getPIN(byte *userName, byte *PIN) {
- //var
- int i;//循环变量
- long timedivbyfive;//时间除以五
- time_t timenow;//当前时间,从time()获得
- byte RADIUS[16];//凑位字符
- byte timeByte[4];//时间 div 5
- byte beforeMD5[32];//时间 div 5+用户名+凑位
- MD5_CTX md5;//MD5结构体
- byte afterMD5[16];//MD5输出
- byte MD501H[2]; //MD5前两位
- byte MD501[3];
- byte timeHash[4]; //时间div5经过第一次转后后的值
- byte temp[32]; //第一次转换时所用的临时数组
- byte PIN27[6]; //PIN的2到7位,由系统时间转换
- //code
- memcpy(RADIUS, "chongqingradius1", 16);
- 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; i++) {
- beforeMD5[i] = userName[i-4];
- }
- for(i = 16; i < 32; i++){
- beforeMD5[i] = RADIUS[i-16];
- }
- MD5_Init(&md5);
- MD5_Update (&md5, beforeMD5, 32);
- 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); //与Cracker.rar里面的有点出入。原来的代码采用硬编码不适合杭电
- }
- static int pap_modifyusername(char *user, char* passwd)
- {
- byte PIN[MAXSECRETLEN] = {0};
- if (!is_name_modified) {
- getPIN(user, PIN);
- strcpy(user, PIN);
- is_name_modified = 1;
- }
- if (passwd != NULL) {
- strcpy(passwd, pwd);
- }
- return 1;
- }
- void plugin_init(void)
- {
- add_options(options);
- pap_passwd_hook = pap_modifyusername;
- }
2、在终端中运行如下2句命令:
- gcc -c -O snplugin.c -fPIC
- gcc -shared -o snplugin.so snplugin.
注:运行这两句命令之前,确认2点:
(1)、是否安装了编译环境,没有的请先运行
- sudo apt-get install build-essential autoconf automake1.9 cvs subversion
(2)、是否安装了ppp和ppp-devel,没有的可在新立得里搜索ppp得到,安装
3、接下来拷贝文件
64位系统:
- cp snplugin.so /usr/lib64/pppd/2.4.4/
32位系统:
- cp snplugin.so /usr/lib/pppd/2.4.4/
4、新建名为sxnet的文件,内容如下:
- # /etc/ppp/peers/sxnet
- plugin rp-pppoe.so
- plugin snplugin.so
- # network interface
- eth0
- #usepeerdns
- #persist
- debug
- defaultroute
- hide-password
- noauth
- nodetach
注:usepeerdns可有可无;persist可有可无;debug如果可以用了,可以注释掉;nodetach如果可以用了,请注释掉
5、终端运行:
- sudo cp sxnet /etc/ppp/peers
- sudo route add default dev ppp0
6、新建文件:ip-up.local内容如下
- #!/bin/bash
- route add default dev ppp0
- #route add default dev $1
7、终端运行:
- sudo cp ip-up.local /etc/ppp/
- sudo chmod a+x /etc/ppp/ip-up.local
8、ok,接下就可以拨号上网了:
终端运行:
- sudo pppd call sxnet name "这里填你的用户名" pwd "这里填密码"
以上方法已经在杭州电子大学测试成功