Guest User

Untitled

a guest
Jul 15th, 2016
1,499
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #/usr/bin/env python
  2. from Crypto.Cipher.AES import AESCipher
  3.  
  4. import SocketServer,threading,os,time
  5. import signal
  6.  
  7. from secret2 import FLAG, KEY
  8.  
  9. PORT = 7765
  10.  
  11. def pad(s):
  12.   l = len(s)
  13.   needed = 16 - (l % 16)
  14.   return s + (chr(needed) * needed)
  15.  
  16. def encrypt(s):
  17.   return AESCipher(KEY).encrypt(pad('ENCRYPT:' + s.decode('hex') + FLAG))
  18.  
  19. class incoming(SocketServer.BaseRequestHandler):
  20.     def handle(self):
  21.         atfork()
  22.         req = self.request
  23.  
  24.         def recvline():
  25.             buf = ""
  26.             while not buf.endswith("\n"):
  27.                 buf += req.recv(1)
  28.             return buf
  29.         signal.alarm(5)
  30.  
  31.         req.sendall("Send me some hex-encoded data to encrypt:\n")
  32.         data = recvline()
  33.         req.sendall("Here you go:")
  34.         req.sendall(encrypt(data).encode('hex') + '\n')
  35.         req.close()
  36.  
  37. class ReusableTCPServer(SocketServer.ForkingMixIn, SocketServer.TCPServer):
  38.   pass
  39.  
  40. SocketServer.TCPServer.allow_reuse_address = True
  41. server = ReusableTCPServer(("0.0.0.0", PORT), incoming)
  42.  
  43. print "Server listening on port %d" % PORT
  44. server.serve_forever()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×