Guest User

Untitled

a guest
Aug 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from OpenSSL import SSL
  4. from twisted.internet import reactor, ssl
  5. from twisted.internet.protocol import ClientFactory
  6. from twisted.protocols.basic import LineReceiver
  7. import socket
  8.  
  9. class ClientTLSContext(ssl.ClientContextFactory):
  10. isClient = 1
  11.  
  12. def get_context(self):
  13. return SSL.Context(SSL.TLSv1_METHOD)
  14.  
  15. class TLSClient(LineReceiver):
  16. def connectionMade(self):
  17. print "Connected\nattempting login"
  18.  
  19. self.send("STARTTLS")
  20.  
  21. def lineReceived(self, line):
  22. print "Received line:", line
  23. if line == "READY":
  24. ctx = ClientTLSContext()
  25. self.transport.startTLS(ctx, self.factory)
  26. print "KEBAB"
  27. self.transport.loseConnection()
  28.  
  29. def send(self, line):
  30. self.sendLine(line)
  31.  
  32.  
  33. class TLSClientFactory(ClientFactory):
  34. protocol = TLSClient
  35.  
  36. def clientConnectionFailed(self, connector, reason):
  37. print "connection failed: ", reason.getErrorMessage()
  38. reactor.stop()
  39.  
  40.  
  41. def clientConnectionLost(self, connector, reason):
  42. print "connection lost: ", reason.getErrorMessage()
  43. reactor.stop()
  44.  
  45. def connectionLost(self):
  46. print "Lost connection"
  47.  
  48. #if __name__ == "__main__":
  49.  
  50. class XClient:
  51. def _connect(self):
  52. factory = TLSClientFactory()
  53. reactor.connectTCP(self.ip, self.port, factory)
  54.  
  55. reactor.run()
  56.  
  57. def login (self, addr="localhost", port=1337, user="x", password="x", **keywords):
  58. try:
  59. self.ip = socket.gethostbyname(addr)
  60. except:
  61. print "Failed to resolve", addr
  62.  
  63. self.port = port
  64.  
  65. self._connect()
Add Comment
Please, Sign In to add comment