⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mystar.c

📁 802.1x的客户端实现,相比较2.56版本
💻 C
📖 第 1 页 / 共 2 页
字号:
            }            break;        case 0x03:         //认证成功            if(m_state!=2) continue;            m_state=3;            fputs("@@ Password valid, authentication SUCCESS!!! :)\n",stdout);            if (m_echoInterval<=0) goto done; //user has echo disabled            //uTemp.ulValue = *(((u_long *)(pkt_data+0x9d)));            offset=ntohs( *((u_int16_t*)(pkt_data+0x10)) );            uTemp.ulValue = *((u_int32_t *)(pkt_data+(0x11+offset)-0x08));            m_key.btValue[0] = Alog(uTemp.btValue[3]);            m_key.btValue[1] = Alog(uTemp.btValue[2]);            m_key.btValue[2] = Alog(uTemp.btValue[1]);            m_key.btValue[3] = Alog(uTemp.btValue[0]);            //unblock SIGINT, so we can exit with Ctrl+C            (void)sigemptyset(&sigset_zero);            (void)sigaddset(&sigset_zero,SIGINT);            (void)sigprocmask(SIG_UNBLOCK,&sigset_zero,NULL);            // continue echoing            fputs("Keeping sending echo... \n",stdout);            /*                 while(SendEchoPacket(l,pkt_data)==0) sleep(m_echoInterval);*/            /* v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v      */            if (m_intelligentReconnect == 1)            {                ConnectionMonitor_init(m_intelligentHost, m_DbgInfoLevel);                DbgInfo(20,"Start Connection Monitor!");                SetInterval(6);                StartConnectionMonitor();            }            while(SendEchoPacket(l,pkt_data)==0)            {                MySleep(m_echoInterval);                if (m_intelligentReconnect == 1)                {                    if (IsStillConnected() == 0)                    {                        StopConnectionMonitor();                        //SendEndCertPacket(l);                        goto beginAuthentication;                    }// if IsStillConnected()                } // if m_intelligentReconnect            }            /*  ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^  By 夕霞孤雁 05.10.20   */            goto err2; //this should never happen.            break;        case 0x04:        //认证失败(用户名或密码错误/不在上网时段内/重复上网等)            if((m_state==0)||(m_state==3)) continue;            m_state=0;            msgLen=ntohs( *((u_int16_t*)(pkt_data+0x10)) )-10;            if (msgLen>0)            {                if(msgLen>=(sizeof(msgBuf)-1)) msgLen=sizeof(msgBuf)-1;                memset(msgBuf,'\0',sizeof(msgBuf));                memcpy(msgBuf, pkt_data+0x1c, msgLen);                pmsgBuf=msgBuf;                //remove the leanding "\r\n" which seems alway to exist!                if((msgLen>2)&&(msgBuf[0]==0xd)&&(msgBuf[1]==0xa)) pmsgBuf+=2;            }        else { pmsgBuf=""; } //这个估计是服务器告知静默或确认断网的包            fprintf(stdout,"@@ Authenticaton failed!!! :(%s\n",pmsgBuf);            (void)SendEndCertPacket(l);            goto beginAuthentication;            break; //should never come here        }// end switch    }// end whiledone:    pcap_close(p); libnet_destroy(l);    return 0;err2:    pcap_close(p);err1:    libnet_destroy(l);    return 1;}static void checkAndSetConfig(void){    FILE  *fp;    char   buf[4096];    char  *p;    int   i,len;    static char name[32];    static char password[32];    static char nic[32];    static char fakeAddress[32];    int  intelligentReconnect=-1;    /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */    static char intelligentHost[255];    static unsigned int DbgInfoLevel = 0;    /* +++++++++++++++++++++++++++++++++++++++++++++++++ By 夕霞孤雁 05.10.20   */    int  echoInterval=-1;    int  authenticationMode=-1;    //the check and anylysis against mystar.conf  *don't*  work perfectly.    //this may be improved in the later version.    if( (fp=fopen("mystar.conf","r"))==NULL ) err_quit("cannot open file mystar.conf ! check it.\n");    while(fgets(buf,sizeof(buf),fp)!=NULL)    {        if( (buf[0]=='#') || (buf[0]=='\n') ) continue;        len=strlen(buf); if(buf[len-1]=='\n') buf[len-1]='\0';        if( ( (p=strchr(buf,'=')) == NULL) || (p==buf) )  continue;        //the code above doesn't detect ALL the errors!! it should be improved in future.        *p++='\0';        for(i=0; i<strlen(buf); i++) buf[i]=tolower(buf[i]);        if(strcmp(buf,"name")==0)        {  strncpy(name,p,sizeof(name)-1); name[sizeof(name)-1]=0;  m_name=name; }        else if(strcmp(buf,"password")==0)        {            strncpy(password,p,sizeof(password)-1); password[sizeof(password)-1]=0;            m_password=password;        }        else if(strcmp(buf,"authenticationmode")==0)        { authenticationMode=atoi(p);    m_authenticationMode=authenticationMode; }        else if(strcmp(buf,"nic")==0)        {            for(i=0; i<strlen(p); i++) p[i]=tolower(p[i]);            strncpy(nic,p,sizeof(nic)-1); nic[sizeof(nic)-1]=0; m_nic=nic;        }        else if(strcmp(buf,"echointerval")==0)        { echoInterval=atoi(p);   m_echoInterval=echoInterval;  }        else if(strcmp(buf,"intelligentreconnect")==0)        { intelligentReconnect=atoi(p);  m_intelligentReconnect=intelligentReconnect; }        /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */        else if(strcmp(buf,"intelligenthost")==0)        {            strncpy(intelligentHost,p,sizeof(intelligentHost)-1); intelligentHost[sizeof(intelligentHost)-1]=0;            m_intelligentHost=intelligentHost;        }        else if(strcmp(buf,"dbginfolevel") == 0)        {            DbgInfoLevel=atoi(p);            m_DbgInfoLevel = DbgInfoLevel;        }        /* +++++++++++++++++++++++++++++++++++++++++++++++++++ By 夕霞孤雁 05.10.20  */        else if(strcmp(buf,"fakeaddress")==0)        {            strncpy(fakeAddress,p,sizeof(fakeAddress)-1);            fakeAddress[sizeof(fakeAddress)-1]=0;            if( inet_pton(AF_INET,fakeAddress,m_ip)<=0 )                err_msg("invalid fakeAddress found in mystar.conf, ignored...\n");            else m_fakeAddress=fakeAddress;        }        else continue;    }    if(ferror(fp)) err_quit("cannot read mystar.conf ! check it.\n");    fclose(fp);    if((m_name==NULL)||(m_name[0]==0)) err_quit("invalid name found in mystar.conf!\n");    if((m_password==NULL)||(m_password[0]==0)) err_quit("invalid password found in mystar.conf!\n");    if((m_authenticationMode<0)||(m_authenticationMode>1))        err_quit("invalid authenticationMode found in mystar.conf!\n");    if( (m_nic==NULL) || (strcmp(m_nic,"")==0) ||  (strcmp(m_nic,"any")==0) )        err_quit("invalid nic found in mystar.conf!\n");    if((m_echoInterval<0)||(m_echoInterval>100))        err_quit("invalid echo interval found in mystar.conf!\n" );    if((m_intelligentReconnect<0)||(m_intelligentReconnect>1))        err_quit("invalid intelligentReconnect found in mystar.conf!\n");    /* Used by Test Arguments    printf("m_name=%s\n",m_name);    printf("m_password=%s\n",m_password);    printf("m_nic=%s\n",m_nic);    printf("m_authenticationMode=%d\n",m_authenticationMode);    printf("m_echoInterval=%d\n",m_echoInterval);    printf("m_intelligentReconnect=%d\n",m_intelligentReconnect);//NOT supported now!!    printf("m_fakeAddress=%s\n",m_fakeAddress);     */    //Just set them to zero since they don't seem to be important.    //These will be initlized by libnet's function    memset(m_netgate,0,sizeof(m_netgate));  memset(m_dns1,0,sizeof(m_dns1));}static void sig_intr(int signo){    libnet_t *l=NULL;    char      l_errbuf[LIBNET_ERRBUF_SIZE];    if(m_state==3)    {        if((l=libnet_init(LIBNET_LINK, m_nic,l_errbuf))==NULL) _exit(0);        (void)SendEndCertPacket(l);        libnet_destroy(l);    }    _exit(0); //Different with exit() function}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -