示例#1
0
    def StopWifiphisher(self):
        """
        外部要求停止功能
        :return:
        """
        if not self.IsRunning:
            return

        self.IsRunning = False
        try:
            if self.__dnsmasq_proc is not None:
                # 启动dnsmasq会出现两个线程
                WWSGC.KillProcByName('dnsmasq')
            if self.__hostapd_proc is not None:
                WWSGC.KillProcByPIDAndName(self.__hostapd_proc.pid, 'hostapd')
            if self.__deauth_proc is not None:
                WWSGC.KillProcByPIDAndName(self.__deauth_proc.pid,
                                           WWSGC.PROG_airreplay(True), 1)

            if self.__webserver_proc.is_alive():
                self.__webserver_proc.StopHTTPServer()

            self.IsException = False
        except:
            logging.debug("%s" % traceback.format_exc())
示例#2
0
def GetTestDataPath():
    """根据称台类型获取系统测试数据路径"""

    datapath = ""
    if GO_VHUtility.SysStat.GetWeighType() == WWSGC.WEIGHTYPE_TRUCK:
        datapath = WWSGC.FILE_WebTruckData()
    else:
        datapath = WWSGC.FILE_WebAxleData()

    return datapath
示例#3
0
    def __StartHostapd(self):
        """
        开启Hostapd功能
        :return: 成功True,失败False
        """
        # 钓鱼AP Hostapd配置
        config = ('interface=%s\n'
                  'driver=nl80211\n'
                  'ssid=%s\n'
                  'hw_mode=g\n'
                  'channel=%s\n'
                  'macaddr_acl=0\n'
                  'ignore_broadcast_ssid=0\n') % (
                      self.__ap_interface, self.__ap_ssid, self.__ap_channel)

        try:
            with open(self.__hostapd_cfg_path, 'w') as hostapd_conf:
                hostapd_conf.write(config.encode(encoding='UTF-8'))

            # 设置网卡up
            Popen(['ifconfig', self.__ap_interface, 'up'], close_fds=True)

            # 启动hostapd进程
            self.__hostapd_proc = Popen(
                [WWSGC.PROG_hostapd(), self.__hostapd_cfg_path],
                close_fds=True)
            time.sleep(5)

            if self.__hostapd_proc.poll() is not None:
                raise KeyboardInterrupt
        except KeyboardInterrupt:
            logging.error('hostapd进程启动错误 : %s' % traceback.format_exc())
            return False
        return True
示例#4
0
    def SetParams(self,
                  ap_interface='',
                  ap_ssid='',
                  ap_channel='',
                  hostapd_cfg_path='',
                  dhcp_cfg_path='',
                  mon_interface='',
                  target_ap_mac='',
                  airreplay_path='',
                  aircrack_path='',
                  wpa_file=''):
        """
        配置钓鱼AP相关参数
        :param ap_interface:        启动钓鱼AP所使用的网卡接口
        :param ap_ssid:             钓鱼AP的ssid
        :param ap_channel:          钓鱼AP的信道
        :param hostapd_cfg_path:    钓鱼AP的hostapd配置文件路径
        :param dhcp_cfg_path:       钓鱼AP的dnsmasq配置文件路径
        :param mon_interface:       阻断目标AP信号所用网卡接口
        :param target_ap_mac:       目标AP的mac地址
        :param airreplay_path:      阻断程序全路径
        :param aircrack_path:       破解程序全路径
        :param wpa_file:            破解文件全路径
        :return: 正确True,错误False
        """
        self.__ap_interface = ap_interface
        self.__ap_ssid = ap_ssid
        self.__ap_channel = ap_channel

        self.__hostapd_cfg_path = hostapd_cfg_path if hostapd_cfg_path else WWSGC.FILE_WifiphisherApCnf(
        )

        WWSGC.KillProcByName('dnsmasq')
        self.__dhcp_cfg_path = dhcp_cfg_path if dhcp_cfg_path else WWSGC.FILE_WifiphisherDHCPCnf(
        )

        self.__mon_interface = mon_interface

        self.__target_ap_mac = target_ap_mac

        self.__aireplay_path = airreplay_path if airreplay_path else WWSGC.PROG_airreplay(
        )
        self.__aircrack_path = aircrack_path if aircrack_path else WWSGC.PROG_aircrack(
        )

        self.__wpa_file_path = wpa_file
示例#5
0
    def __CheckAndRestartThread(self):
        """
        检查相关线程是否正常启动,没有则重启该线程
        """
        try:
            if self.__hostapd_proc.poll() is not None:
                WWSGC.KillProcByPIDAndName(self.__hostapd_proc.pid, 'hostapd')
                self.__StartHostapd()
                time.sleep(5)

            if not self.__webserver_proc.is_alive():
                self.__StartHTTPServer()

            if self.__deauth_proc.poll() is not None:
                WWSGC.KillProcByPIDAndName(self.__deauth_proc.pid,
                                           WWSGC.PROG_airreplay(True), 1)
                self.__StopTargetAP()
                time.sleep(10)
        except:
            logging.error("Wifiphisher检到线程启动失败!")
            raise KeyboardInterrupt
示例#6
0
def WR_SYSTEM_Authentication():
    """验证系统合法性"""

    Data = request.files.get('filename')
    if Data.file:
        RawData = Data.file.read()
        FileWrite = open(WWSGC.FILE_Certificate(), 'w+')
        FileWrite.write(RawData)
        FileWrite.close()

        #通知底层去验证
        WWSGC.SendUnixCmd(WWSGC.VERIFY_DEVICE, 0.0, 0.0, 0, 0, 0.0)

        #等待验证结果并返回给用户
        timeout = 5
        while timeout > 0:
            if GO_VHUtility.SysStat.GetDevLegal():
                return WEB_JSON_Suc
            timeout = timeout - 1
            time.sleep(1)

    return WEB_JSON_Err
示例#7
0
def WR_SYSTEM_StartTest():
    """开始系统测试"""

    #先删除存在的数据文件
    datapath = GetTestDataPath()
    if os.path.exists(datapath):
        os.remove(datapath)

    WWSGC.SendUnixCmd(WWSGC.START_SYSTEMTEST, 0.0, 0.0, 0, 0, 0.0)

    GO_VHUtility.SysStat.StartSysTest()

    return WEB_JSON_Suc
示例#8
0
def WR_SYSTEM_SetSysConfig():
    """设置系统配置信息"""

    devid = request.query.get('devid', default='')
    weightype = request.query.get('weightype', default=1, type=int)
    senum = request.query.get('senum', default=1, type=int)

    modify_config = 0
    restart_checkprogram = 0

    #判断是否修改过
    if devid != GO_VHUtility.SysStat.GetDevID():
        GO_VHUtility.SysStat.SetDevID(devid)
        modify_config = 1
    if weightype != GO_VHUtility.SysStat.GetWeighType():
        GO_VHUtility.SysStat.SetWeighType(weightype)
        restart_checkprogram = 1
        modify_config = 1
    if senum != GO_VHUtility.SysStat.GetSenum():
        GO_VHUtility.SysStat.SetSenum(senum)
        restart_checkprogram = 1
        modify_config = 1

    if modify_config == 1:
        sysconfiginfo = {}
        sysconfiginfo["devid"] = devid
        sysconfiginfo["weightype"] = str(weightype)
        sysconfiginfo["senum"] = str(senum)

        #修改配置
        GO_VHUtility.SysConf.ModSysConfig(sysconfiginfo)

        #判断是否有必要重启后台检测程序
        if restart_checkprogram == 1:
            WWSGC.KillProcByName("TruckScale_check")
            Popen([WWSGC.PROG_CheckSensor()], close_fds=True)

    return WEB_JSON_Suc
示例#9
0
def WR_SYSTEM_StopTest():
    """结束系统测试"""

    WWSGC.SendUnixCmd(WWSGC.STOP_SYSTEMTEST, 0.0, 0.0, 0, 0, 0.0)

    GO_VHUtility.SysStat.StopSysTest()

    #等待数据准备好
    timeout = 5
    while timeout > 0:
        if os.path.exists(GetTestDataPath()):
            break
        timeout = timeout - 1
        time.sleep(1)

    retinfo = {}
    retinfo["weightype"] = GO_VHUtility.SysStat.GetWeighType()

    return retinfo
示例#10
0
    def InitUtility(self):
        """初始化系统通用组件对象。
		返回:成功返回True,否则False。"""

        if not self.SysConf.LoadConfig(WWSGC.FILE_SysCnf()):
            logging.error('加载配置文件失败!')
            return False

        if not self.DB.InitDB(self.SysConf.DBHost, self.SysConf.DBPort,
                              self.SysConf.DBUser, self.SysConf.DBPwd,
                              self.SysConf.DBName):
            logging.error('初始化数据库失败!')
            return False

        #创建系统状态的对象
        self.SysStat = SystemStatus.CSystemStatus(self.SysConf.WeighType, self.SysConf.DevId, \
                    self.SysConf.DevLegal, self.SysConf.SensorNum)

        #设置gska、gskb
        self.SysStat.Setgska(1.0)
        self.SysStat.Setgskb(1.0)

        return True
示例#11
0
     default=False, help='Add test function to LocalDevice or RemoteServer')

    # parse_args()返回一个字典,key为add_augument中的dest,value为存储的值。
    args = arg_parser.parse_args()

    return args


def InitLog(file_name, log_level=logging.WARNING):
    """初始化日志为多个文件循环的方式"""

    log_formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s %(thread)d '\
     '[%(filename)s(%(lineno)d)] %(message)s', datefmt='%Y%m%d-%H%M%S')
    my_handler = RotatingFileHandler(file_name, mode='a', maxBytes=5*1024*1024, \
     backupCount=5, encoding=None, delay=0)
    my_handler.setFormatter(log_formatter)
    my_handler.setLevel(log_level)
    app_log = logging.getLogger()
    app_log.setLevel(log_level)
    app_log.addHandler(my_handler)


if __name__ == '__main__':
    args = ParseArgs()
    #设置日志文件名称
    logfile = WWSGC.FILE_OutLogPath()
    loglevel = int(args.loglevel)
    InitLog(logfile, loglevel)
    DaemonObj = CServerVHMain(args.test)
    DaemonObj.Run()