Пример #1
0
 def filter_match(self, filt, packet, peer):
     for k,v in filt.items():
         if k == "host":
             try:
                 hosttuple = socket.gethostbyname_ex(v)
                 if peer[0] not in hosttuple[2]:
                     return False
             except:
                 return False
         elif k == "ip":
             if not isinstance(v, list):
                 v = [v]
             peerip = cidr.CIDR(peer[0])
             matches = [peerip in cidr.CIDR(mask) for mask in v]
             if not any(matches):
                 return False
         elif k == "to":
             targets = packet["to"]
             t_filters = v
             if not isinstance(targets, list):
                 targets = [targets]
             if not isinstance(t_filters, list):
                 t_filters = [t_filters]
             for target in targets:
                 for tf in t_filters:
                     if re.match(tf, target):
                         break
                 else:
                     return False
         elif k == "privmsg":
             if not re.match(v, packet["privmsg"]):
                 return False
     return True
Пример #2
0
 def run(self):
     global AC_PORT_LIST
     all_ip_list = []
     for ip in self.scan_list:
         if "/" in ip: ip = cidr.CIDR(ip)
         if not ip: continue
         ip_list = self.get_ip_list(ip)
         for white_ip in self.white_list:
             if white_ip in ip_list:
                 ip_list.remove(white_ip)
         if self.mode == 1:
             self.masscan_path = self.config_ini['Masscan'].split('|')[2]
             self.masscan_rate = self.config_ini['Masscan'].split('|')[1]
             ip_list = self.get_ac_ip(ip_list)
             self.masscan_ac[0] = 1
             AC_PORT_LIST = self.masscan(
                 ip_list)  # 如果安装了Masscan即使用Masscan进行全端口扫描
             if not AC_PORT_LIST: continue
             self.masscan_ac[0] = 0
             for ip_str in AC_PORT_LIST.keys():
                 self.queue.put(ip_str)  # 加入队列
             self.scan_start()  # 开始扫描
         else:
             all_ip_list.extend(ip_list)
     if self.mode == 0:
         if self.icmp: all_ip_list = self.get_ac_ip(all_ip_list)
         for ip_str in all_ip_list:
             self.queue.put(ip_str)  # 加入队列
         self.scan_start()  # TCP探测模式开始扫描
Пример #3
0
 def run(self):
     global AC_PORT_LIST
     all_ip_list = []
     try:
         for ip in self.scan_list:
             if "/" in ip:
                 ip = cidr.CIDR(ip)
             if not ip:
                 continue
             ip_list = self.get_ip_list(ip)
             for white_ip in self.white_list:
                 if white_ip in ip_list:
                     ip_list.remove(white_ip)
             if self.mode == 1:
                 masscan_path = self.config_ini['Masscan'].split('|')[2]
                 masscan_rate = self.config_ini['Masscan'].split('|')[1]
                 # 如果用户在前台关闭了ICMP存活探测则进行全IP段扫描
                 if self.icmp:
                     ip_list = self.get_ac_ip(ip_list)
                 self.masscan_ac[0] = 1
                 # 如果安装了Masscan即使用Masscan进行全端口扫描
                 AC_PORT_LIST = self.masscan(ip_list, masscan_path,
                                             masscan_rate)
                 if not AC_PORT_LIST:
                     continue
                 self.masscan_ac[0] = 0
                 for ip_str in AC_PORT_LIST.keys():
                     self.queue.put(ip_str)  # 加入队列
                 self.scan_start()  # 开始扫描
             else:
                 all_ip_list.extend(ip_list)
         if self.mode == 0:
             if self.icmp:
                 all_ip_list = self.get_ac_ip(all_ip_list)
             for ip_str in all_ip_list:
                 self.queue.put(ip_str)  # 加入队列
             self.scan_start()  # TCP探测模式开始扫描
     except:
         traceback.print_exc()
Пример #4
0
def check_peer(peer):
    address = cidr.CIDR(peer)
    masks = [cidr.CIDR(ip) for ip in CONFIG["ips"]]
    matches = [address in mask for mask in masks]
    return any(matches)