Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Ssh bulk login upload execution command download file

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Purpose:

Get the intranet of the linux host, get the general account password, log in in batches, upload the system information collection script, and pull the execution results back locally for analysis.

Disadvantages:

Does not support multi-threaded password must be correct and exactly reachable port hard-coded to 22 if not 22, please modify it yourself

Execution process:

Executing ssh.py root root automatically logs in to ssh, uploads the 1.py file under the local file directory to the linux server tmp directory, executes the / tmp/1.py file, deletes the / tmp/1.py file, and downloads the generated test.txt of the file executed by 1.py back locally. Note: the name of the downloaded file is hard-coded in line 28 of the 1.py file. If the downloaded file is another name, please modify it yourself (both the downloaded file and the generated file need to be changed)

#-*-coding: utf_8-*-# Date: 2015 Unip 5max author:sanrimport paramiko,time,sys Osdef README (): print'+'+'-'* 50 +'+ 'print u'\ t Python ssh bulk login script' print u'\ t ip Please write iplist.txt 'print u'\ t Time:2015-5-15' print u'\ t author: sanr' print'+'-'* 50 +'if len (sys.argv)! = 3: print u'[+] usage:'+ os.path.basename (sys.argv [0]) + "user pass" print u'[+] example:'+ os.path.basename (sys.argv [0]) + "root root" sys.exit () def upload (host) User,pswd): try: ssh = paramiko.Transport ((host,22)) ssh.connect (username = user, password = pswd) sftp = paramiko.SFTPClient.from_transport (ssh) sftp.put (". / 1.py", "/ tmp/1.py") print'[+]'+ host,u'ssh logged in' # call execution command function ssh3 (host,user,pswd) # call create directory function mkdir (host) # download remote host file sftp.get ("/ tmp/test.txt") ". /" + host+ "/ result.txt") print u' information collection result downloaded successfully 'ssh.close () except: passdef ssh3 (host,user Pswd): try: ssh = paramiko.SSHClient () ssh.set_missing_host_key_policy (paramiko.AutoAddPolicy ()) ssh.connect (host,22,user,pswd, timeout=5) # stdin, stdout, stderr = ssh.exec_command ('ifconfig Free') # print stdout.read () # execute command to modify the code permission to upload 1.py to 777. execute 1.py script to delete 1.py script stdin, stdout, stderr = ssh.exec_command ('chmod 777 / tmp/1.py;/usr/bin/python / tmp/1.py Rm-rf / tmp/1.py') ssh.close () except: passdef mkdir (path): # introduction module import os # determines whether the path exists # True # does not exist False isExists=os.path.exists (path) # judgment result if not isExists: # create directory operation As a function os.makedirs (path) # create a directory if it does not exist print u 'created directory successful' Return True else: # do not create a directory if it exists And prompt that the directory already exists print u 'local directory already exists', return Falseif _ _ name__=='__main__': README () start_time = time.time () with open ('. / iplist.txt' 'r') as f: for ip in f: host=ip.strip () user=sys.argv [1] pswd=sys.argv [2] upload (host,user,pswd) print u'[+] report that the information has been collected Time:% d seconds'% (time.time ()-start_time)

Attachment: http://down.51cto.com/data/2365680

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report