Skip to content

Instantly share code, notes, and snippets.

@RPHAELLA
Last active January 7, 2021 09:07
Show Gist options
  • Save RPHAELLA/879c0cc3d40bf9ccbe44e581c485908f to your computer and use it in GitHub Desktop.
Save RPHAELLA/879c0cc3d40bf9ccbe44e581c485908f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# Spawn Multiple Connection Per User for SSH File Transfer Protocol
# Copyright (C) 2017
#
# This program can be redistributed and/or modified under the terms of the
# GNU General Public License, either version 3 of the License, or (at your
# option) any later version.
#
import paramiko, sys, os, socket, subprocess
global line, host, username, key, input_file
line = "-------------------------------------------------------------------------------"
def sftp_connect(code=0):
sftp_key = paramiko.RSAKey.from_private_key_file(key, password='P@ssw0rd')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(host, port=22, username=username, pkey=sftp_key)
sftp = ssh.open_sftp()
sftp.sshclient = ssh
return sftp
except paramiko.AuthenticationException:
print("[!] Incorrect Login - User: %s [*]" % (username))
ssh.close()
except socket.error, e:
print("[*] Connection Could Not Be Established To Address: %s " % (host))
ssh.close()
return
try:
response = {}
host = raw_input("[*] Enter Target Host Address: ")
username = raw_input("[*] Enter SFTP Username: ")
key = raw_input("[*] Enter Private Key: ")
if os.path.exists(key) == False:
print "\n[*] File Path Does Not Exist"
sys.exit(4)
session_no = int(raw_input("[*] Enter Number of Session to Spawn: "))
for i in range(0, session_no):
try:
response[i] = sftp_connect()
directory_list = response[i].listdir('.')
directory_list = ", ".join(directory_list)
print("[*] Session %s: Connection Established - User: %s" % (i, username))
print("[*] Session %s: Directory - %s" % (i, directory_list))
except Exception, e:
print e
pass
close = False
while(close == False):
user_input = raw_input("[*] Do You Want To Close All Session? [Y/N]:")
close = True if user_input == "Y" else False
if close:
for i in range(0, session_no):
try:
response[i].close()
print("[*] Connection Closed for Session %s - User: %s" % (i, username))
except Exception, e:
print e
pass
except KeyboardInterrupt:
print "\n\n[*] User Requested An Interrupt"
sys.exit(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment