#!/usr/bin/env python3"""Remote python server.Execute Python commands remotely and send output back.WARNING: This version has a gaping security hole -- it accepts requestsfrom any host on the Internet!"""import sysfrom socket import socket, AF_INET, SOCK_STREAMimport ioimport tracebackPORT = 4127BUFSIZE = 1024def main():if len(sys.argv) > 1:port = int(sys.argv[1])else:port = PORTs = socket(AF_INET, SOCK_STREAM)s.bind(('', port))s.listen(1)while True:conn, (remotehost, remoteport) = s.accept()print('connection from', remotehost, remoteport)request = b''while 1:data = conn.recv(BUFSIZE)if not data:breakrequest += datareply = execute(request.decode())conn.send(reply.encode())conn.close()def execute(request):stdout = sys.stdoutstderr = sys.stderrsys.stdout = sys.stderr = fakefile = io.StringIO()try:try:exec(request, {}, {})except:print()traceback.print_exc(100)finally:sys.stderr = stderrsys.stdout = stdoutreturn fakefile.getvalue()try:main()except KeyboardInterrupt:pass
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。