def add_bot(iface): global BOT_NUM s = init_socket(iface, TIMEOUT) if s: communicate(s, dbg=DBG, print_cmd=PRINT_CMD, timeout=TIMEOUT) s.close() with lock: BOT_NUM -= 1 # Bot disconnected
def main(): print "Bot counter v2.2\n" # Initialize bot_rheader structure bot_rheader = init_bot_rheader(bid=0, size=0) # Initialize socket s = init_socket(IFACE, TIMEOUT) # Send data (BOT_RHEADER packed binary) s.sendall(buffer(bot_rheader)[:]) # Get BID upper bound upper_bound = get_bid(s) if not upper_bound: cprint("[-] Error: Failed to get BID upper bound", "red") sys.exit(-1) else: cprint("[+] Got BID upper bound: " + str(upper_bound), "green") # Give the user chance to see the upper bound time.sleep(3) cprint("\n[*] Starting bot counter...", "cyan") bot_count = 0 # Bot entry count bid_registered = [] # BID of bots registered bid_not_registered = [] # BID of bots not registered # Note: Max size of Python list is 536,870,912 elements (on a 32bit system). # Warning: The larger the list is the slower the operations will be. # Show progress bar pbar = ProgressBar() # Search And Destroy for bid in pbar(list(range(upper_bound - 1, 0, -1))): # Spoof BID bot_rheader.bid = bid s = init_socket(IFACE, TIMEOUT) # Re-initiate socket connection s.sendall(buffer(bot_rheader)[:]) # Send data # Check return BID if bid == get_bid(s): bot_count += 1 bid_registered.append(bid) #cprint("[BID: " + str(bid) + "]" + " Bot found\t\tTotal: " \ # + str(bot_count), "cyan") else: bid_not_registered.append(bid) #cprint("[BID: " + str(bid) + "]" + " Bot not registered", "red") # Print statistics cprint("\n[+] Statistics:", "yellow") cprint("Total bot count: " + str(bot_count), "yellow") cprint("\nBID registered:", "yellow") print "[%s]" % ", ".join(map(str, bid_registered)) cprint("\nBID not registered:", "yellow") print "[%s]" % ", ".join(map(str, bid_not_registered)) # Close socket s.close()