Advertisement
ghost423543

sage_service

Nov 13th, 2021
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. #!/usr/bin/env sage
  2. #encoding=utf-8
  3. from sage.all_cmdline import *
  4. from sage.all import *
  5. import socket
  6. from telnetlib import Telnet
  7. import concurrent.futures
  8. import traceback
  9. DIR = os.path.dirname(os.path.realpath(__file__))
  10.  
  11. HOST,PORT = '127.0.0.1',65535
  12.  
  13. def handle_client(sock):
  14.     global x
  15.     try:
  16.         t = Telnet()
  17.         t.sock=sock
  18.         resp = t.read_until(b'\n');print(resp)
  19.         exec(resp[:-1],globals())
  20.         resp = t.read_until(b'\n');print(resp)  
  21.         t.write(f"{eval(resp[:-1])}\n".encode())
  22.        
  23.     except Exception as E:
  24.         traceback.print_exc()
  25.         print(E)
  26.         sock.send(f"{E}\n".encode())
  27.         pass
  28.     sock.close()
  29.  
  30. if __name__=='__main__':
  31.     # sage -python sage_service.py
  32.     executor = concurrent.futures.ThreadPoolExecutor(max_workers=10)
  33.     with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
  34.         print(f"START server {HOST}:{PORT}")
  35.         s.bind((HOST,PORT))
  36.         s.listen()
  37.         while True:
  38.             conn,addr = s.accept()
  39.             print('Connected from',addr)
  40.             try:
  41.                 set_future = executor.submit(handle_client,(conn))
  42.             except Exception as E:
  43.                 print(f"[-]Error: {E}")
  44.                 pass
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement