コード例 #1
0
    def generate_message(self,zeroaccess_nodes,zeroaccess_file_list):
        ret = urllib2.urlopen('https://enabledns.com/ip')
        self.local_ip = ret.read()
        get_local_ip_info = 'Retrieve local ip : '+self.local_ip
        logger.info(get_local_ip_info)

        #faked_ip = self.local_ip
        faked_ip = '96.8.117.251'

        self.getL_message = ZeroAccessUtil.buildZeroAccessGetLMessage()
        self.newL_message = ZeroAccessUtil.buildZeroAccessNewLMessage(faked_ip)

        faked_node_info = ZeroAccessNode()
        faked_node_info.set_ip(struct.unpack("I",socket.inet_aton(faked_ip))[0])
        faked_node_info.set_time(time.time())

        seed_node_size = 15
        seed_node_list = random.sample(zeroaccess_nodes,seed_node_size)
        seed_node_list.append(faked_node_info)

        print 'bootstrap nodes len : ' + str(len(zeroaccess_nodes))
        print 'bootstrap file len : ' + str(len(zeroaccess_file_list))
        file_list = random.sample(zeroaccess_file_list,5)
        self.retL_message = ZeroAccessUtil.buildZeroAccessretLMessage(seed_node_list,file_list)
        print 'retL message length  ' + str(len(self.retL_message))
        print 'retL message :\n' 
        #print ''.join( [ "%02X" % x for x in self.retL_message]).strip()
        print self.retL_message.encode('hex')
コード例 #2
0
    def retL_process(self,original_message,host):
        crc32,command,b_flag,ip_count = struct.unpack('IIII',original_message[:16])

        node_in_info = 'this node ' + str(host) + ' has ' + str(ip_count) + ' descendant ip'  
        logger.debug(node_in_info)
        base_pointer = 16
        if(ip_count > 20):
            return
            #raise Exception(str(host)+ ' IP Count return from P2P Node Two Large : '+str(ip_count),'memory error')
        
        private_ip_count = 0.0
        for i in xrange(ip_count):
            ip =  struct.unpack('I',original_message[base_pointer:(base_pointer+4)])[0]
            times_tamp =  struct.unpack('I',original_message[base_pointer+4:base_pointer+8])[0]
            node = ZeroAccessNode()
            node.set_ip(ip)
            node.set_udpport(self.udp_port)
            node.set_time(times_tamp)
            base_pointer = base_pointer + 8

            z_ip = IP(socket.ntohl(ip))            
            if(z_ip.iptype() == 'PRIVATE'):
                logger.debug('Private IP '+  socket.inet_ntoa(struct.pack('I',ip))+' from '+host[0])
                private_ip_count+=1                
                continue

            if not self.AlreadyQueryed(node):
                self.insertGlobalMap(node)
                self.nonQueryedNodes.put(node)
                self.node_size_count+=1
                if(self.node_size_count % 1000 == 0):
                    info = 'ZeroAccess Nodes Size Mounts to :'+str(self.node_size_count)
                    logger.info(info)
                    print info

        if(private_ip_count > 0):
                self.UpdateFakedRatioInfoOfNode(host[0],(private_ip_count/ip_count))
        

        file_count = struct.unpack('I',original_message[base_pointer:base_pointer+4])[0]
        base_pointer += 4
        for i in range(file_count):
            file_name =  struct.unpack('I',original_message[base_pointer:base_pointer+4])[0]
            file_timestamp =  struct.unpack('I',original_message[base_pointer+4:base_pointer+8])[0]
            file_size =  struct.unpack('I',original_message[base_pointer+8:base_pointer+12])[0]
            file_signature = struct.unpack(str(self.ZEROACCESS_FILE_HEADER_LENGTH)+'B',
                    original_message[base_pointer+12:base_pointer+12+self.ZEROACCESS_FILE_HEADER_LENGTH])

            file_info = ZeroAccessFileInfo()
            #file_info.set_filename(str(hex(file_name)))
            file_info.set_filename(file_name)
            file_info.set_timestamp(file_timestamp)
            file_info.set_filesize(file_size)
            file_info.set_sig(file_signature)

            self.insertFileInfo(file_info,host)

            base_pointer+=12+self.ZEROACCESS_FILE_HEADER_LENGTH
        logger.debug('received file count : '+str(file_count))
        self.sendDatagram()
コード例 #3
0
    def generate_message(self, zeroaccess_nodes, zeroaccess_file_list):
        ret = urllib2.urlopen('https://enabledns.com/ip')
        self.local_ip = ret.read()
        get_local_ip_info = 'Retrieve local ip : ' + self.local_ip
        logger.info(get_local_ip_info)

        #faked_ip = self.local_ip
        faked_ip = '96.8.117.251'

        self.getL_message = ZeroAccessUtil.buildZeroAccessGetLMessage()
        self.newL_message = ZeroAccessUtil.buildZeroAccessNewLMessage(faked_ip)

        faked_node_info = ZeroAccessNode()
        faked_node_info.set_ip(
            struct.unpack("I", socket.inet_aton(faked_ip))[0])
        faked_node_info.set_time(time.time())

        seed_node_size = 15
        seed_node_list = random.sample(zeroaccess_nodes, seed_node_size)
        seed_node_list.append(faked_node_info)

        print 'bootstrap nodes len : ' + str(len(zeroaccess_nodes))
        print 'bootstrap file len : ' + str(len(zeroaccess_file_list))
        file_list = random.sample(zeroaccess_file_list, 5)
        self.retL_message = ZeroAccessUtil.buildZeroAccessretLMessage(
            seed_node_list, file_list)
        print 'retL message length  ' + str(len(self.retL_message))
        print 'retL message :\n'
        #print ''.join( [ "%02X" % x for x in self.retL_message]).strip()
        print self.retL_message.encode('hex')
コード例 #4
0
def main():
    #logging.Formatter.converter = time.gmtime
    #FORMAT = '%(levelname)s %(asctime)-15s %(message)s'
    #logging.basicConfig(filename = os.path.join(os.getcwd(),'crawl.log'), level = logger.INFO,format = FORMAT)

    SEPARATOR = '/'
    if sys.platform == 'win32':
        SEPARATOR = "\\"

    ZEROACCESS_UDP_PORT = 16471
    silent = False

    zeroaccess_nodes = []

    zeroaccess_file_info_path = "Data" + SEPARATOR + "zeroaccess_file.bin"
    zeroaccess_file_list = ZeroAccessUtil.read_zeroaccess_file_data_from_bin(
        zeroaccess_file_info_path)

    zeroaccess_protocol = ZeroAccessProtocol()

    interactive = False
    crawl_only = False

    # 静默状态,监听
    # -l

    # 使用 getL 查询爬取全网
    # -s

    # 周期性大量发送 getL 查询,同时积极回应,使用newL推送 ip
    # -i

    # 做为客户端,发送查询
    # -c

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hp:lis")
    except getopt.GetoptError as err:
        print str(err)
        sys.exit(2)
    for o, a in opts:
        if o == '-h':
            print 'help'
            sys.exit()
        if o == '-i':
            interactive = True
            zeroaccess_protocol.set_interactive(interactive)
        if o == '-s':
            crawl_only = True
        if o == '-c':
            zeroaccess_nodes = []
            ip_path = "Data" + SEPARATOR + "ip_list.txt"
            ip_file = open(ip_path)
            for ip_line in ip_file:
                print ip_line
                node = ZeroAccessNode()
                ip_int = struct.unpack("I", socket.inet_aton(ip_line))[0]
                node.set_ip(ip_int)
                zeroaccess_nodes.append(node)
        if o == '-l':
            silent = True
            zeroaccess_protocol.set_silent_state(True)
        if o == '-p':
            try:
                ZEROACCESS_UDP_PORT = int(a)
            except ValueError:
                print 'Invalid Value'
            if ZEROACCESS_UDP_PORT not in [16471, 16470, 16464, 16465]:
                port_error_info = 'Crawling Port Not Valid : ' + str(
                    ZEROACCESS_UDP_PORT)
                logger.info(port_error_info)
                sys.exit()
            port_info = 'Crawling Port : ' + str(ZEROACCESS_UDP_PORT)
            logger.info(port_info)
            print port_info

    # get a sample list of zeroaccess nodes map
    #ip_list = random.sample(zeroaccess_nodes,16)
    #print ip_list

    zeroaccess_bootstrap_seeds_path = "Data" + SEPARATOR + "zeroaccess_node_" + str(
        ZEROACCESS_UDP_PORT) + ".dat"

    bootstrap_nodes = ZeroAccessUtil.read_zeroaccess_data_from_file(
        zeroaccess_bootstrap_seeds_path)
    zeroaccess_nodes = zeroaccess_nodes + bootstrap_nodes

    zeroaccess_protocol.set_udp_port(ZEROACCESS_UDP_PORT)
    zeroaccess_protocol.set_bootstrap_node_list(zeroaccess_nodes)
    zeroaccess_protocol.generate_message(zeroaccess_nodes,
                                         zeroaccess_file_list)

    t = reactor.listenUDP(ZEROACCESS_UDP_PORT, zeroaccess_protocol)

    signal.signal(signal.SIGINT, SIGINT_exit)

    if (crawl_only):
        reactor.callLater(40, zeroaccess_protocol.RestartCrawl)
        reactor.callLater(60, ShutdownGracefully, ZEROACCESS_UDP_PORT,
                          zeroaccess_protocol.get_nodes_map(),
                          zeroaccess_protocol.get_files_map())
    if (interactive):
        newL_query_update_loop = task.LoopingCall(
            zeroaccess_protocol.RestartCrawl)
        newL_query_update_loop.start(120)  # call every second

    try:
        reactor.run()
    #except KeyboardInterrupt:
    #    print "Interrupted by keyboard. Exiting."
    #    reactor.stop()
    except:
        print 'Exception caught while interuptting reactor'
        pass
コード例 #5
0
def main():
    #logging.Formatter.converter = time.gmtime
    #FORMAT = '%(levelname)s %(asctime)-15s %(message)s'
    #logging.basicConfig(filename = os.path.join(os.getcwd(),'crawl.log'), level = logger.INFO,format = FORMAT)  

    SEPARATOR = '/'
    if sys.platform == 'win32':
        SEPARATOR = "\\"

    ZEROACCESS_UDP_PORT = 16471
    silent = False

    zeroaccess_nodes = []

    zeroaccess_file_info_path = "Data"+SEPARATOR+"zeroaccess_file.bin"
    zeroaccess_file_list = ZeroAccessUtil.read_zeroaccess_file_data_from_bin(zeroaccess_file_info_path)

    zeroaccess_protocol = ZeroAccessProtocol()

    interactive = False
    crawl_only = False

    # 静默状态,监听
    # -l

    # 使用 getL 查询爬取全网
    # -s

    # 周期性大量发送 getL 查询,同时积极回应,使用newL推送 ip
    # -i

    # 做为客户端,发送查询
    # -c

    try:
        opts,args = getopt.getopt(sys.argv[1:],"hp:lis")
    except getopt.GetoptError as err:
        print str(err)
        sys.exit(2)
    for o,a in opts:
        if o=='-h':
            print 'help'
            sys.exit()
        if o=='-i':
            interactive = True
            zeroaccess_protocol.set_interactive(interactive)
        if o=='-s':
            crawl_only = True
        if o=='-c':
            zeroaccess_nodes = []
            ip_path = "Data"+SEPARATOR+"ip_list.txt"
            ip_file = open(ip_path)
            for ip_line in ip_file:
                print ip_line
                node = ZeroAccessNode()
                ip_int = struct.unpack("I",socket.inet_aton(ip_line))[0]
                node.set_ip(ip_int)
                zeroaccess_nodes.append(node)
        if o=='-l':
            silent = True
            zeroaccess_protocol.set_silent_state(True)
        if o=='-p':
            try:
                ZEROACCESS_UDP_PORT = int(a)
            except ValueError:
                print 'Invalid Value'
            if ZEROACCESS_UDP_PORT not in [16471,16470,16464,16465]:
                port_error_info = 'Crawling Port Not Valid : ' + str(ZEROACCESS_UDP_PORT)
                logger.info(port_error_info)
                sys.exit()
            port_info = 'Crawling Port : ' + str(ZEROACCESS_UDP_PORT)
            logger.info(port_info)
            print port_info

    # get a sample list of zeroaccess nodes map
    #ip_list = random.sample(zeroaccess_nodes,16)
    #print ip_list

    zeroaccess_bootstrap_seeds_path = "Data"+SEPARATOR+"zeroaccess_node_"+str(ZEROACCESS_UDP_PORT)+".dat"

    bootstrap_nodes = ZeroAccessUtil.read_zeroaccess_data_from_file(zeroaccess_bootstrap_seeds_path)
    zeroaccess_nodes = zeroaccess_nodes + bootstrap_nodes

    zeroaccess_protocol.set_udp_port(ZEROACCESS_UDP_PORT)
    zeroaccess_protocol.set_bootstrap_node_list(zeroaccess_nodes)
    zeroaccess_protocol.generate_message(zeroaccess_nodes,zeroaccess_file_list)

    t = reactor.listenUDP(ZEROACCESS_UDP_PORT , zeroaccess_protocol)

    signal.signal(signal.SIGINT, SIGINT_exit)

    if(crawl_only):
        reactor.callLater(40,zeroaccess_protocol.RestartCrawl)
        reactor.callLater(60,ShutdownGracefully,ZEROACCESS_UDP_PORT,zeroaccess_protocol.get_nodes_map(),zeroaccess_protocol.get_files_map())
    if(interactive):
        newL_query_update_loop = task.LoopingCall(zeroaccess_protocol.RestartCrawl)
        newL_query_update_loop.start(120) # call every second

    try:
        reactor.run()
    #except KeyboardInterrupt:
    #    print "Interrupted by keyboard. Exiting."
    #    reactor.stop()
    except:
        print 'Exception caught while interuptting reactor'
        pass