http请求头回显-创新互联
代码速记:
创新互联建站专注骨干网络服务器租用10余年,服务更有保障!服务器租用,资阳主机托管 成都服务器租用,成都服务器托管,骨干网络带宽,享受低延迟,高速访问。灵活、实现低成本的共享或公网数据中心高速带宽的专属高性能服务器。#encoding: utf-8 #author: walker #date: 2017-07-24 #summary: 回显http头,可用于匿名度检测 #sys.version: '3.5.2 (default, Nov 17 2016, 17:05:23) \n[GCC 5.4.0 20160609]' import argparse from colored import fg, bg, attr from http.server import HTTPServer, BaseHTTPRequestHandler class EchoHTTPHandler(BaseHTTPRequestHandler): #将请求头包装成html,便于返回给http客户端 def text_to_html(self, req_head): html = 'Echo HTTP Header ' html += '' html += '%s - %s - %s' return html #响应get请求,打印http头,并返回给http客户端 def do_GET(self): print('%s - %s - %s' % (self.client_address, self.request_version, self.path)) print(type(self.client_address)) print('### request headers ###') req_head = str(self.headers) for line in req_head.split('\n'): line = line.strip() if line.startswith('Via:') or line.startswith('X-Forwarded-For:'): line = '%s%s%s' % (fg('red'), line, attr('reset')) print(line) self.send_response(200) self.end_headers() self.wfile.write(self.text_to_html(req_head).encode('utf8')) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Echo HTTP server.') parser.add_argument('-a', '--address', help='default: 0.0.0.0') parser.add_argument('-p', '--port', help='default: 8080', type=int) args = parser.parse_args() server = HTTPServer((args.address or '0.0.0.0', args.port or 8080), EchoHTTPHandler) server.serve_forever()
' % (self.client_address, self.request_version, self.path) for line in req_head.split('\n'): line = line.strip() if line.startswith('Via:') or line.startswith('X-Forwarded-For:'): line = '%s
' % line else: line = '%s
' % line html += line html += '
【http json 回显】
以下代码 copy 自:https://gist.github.com/bsingr/a5ef6834524e82270154a9a72950c842,略有改动。
#!/usr/bin/env python3 from http.server import BaseHTTPRequestHandler, HTTPServer from urllib.parse import urlparse import json class RequestHandler(BaseHTTPRequestHandler): def do_GET(self): parsed_path = urlparse(self.path) self.send_response(200) self.end_headers() self.wfile.write(json.dumps({ 'method': self.command, 'path': self.path, 'real_path': parsed_path.query, 'query': parsed_path.query, 'request_version': self.request_version, 'protocol_version': self.protocol_version }).encode()) return def do_POST(self): #content_len = int(self.headers.getheader('content-length')) content_len = int(self.headers['Content-Length']) post_body = self.rfile.read(content_len) data = json.loads(post_body) parsed_path = urlparse(self.path) self.send_response(200) self.end_headers() self.wfile.write(json.dumps({ 'method': self.command, 'path': self.path, 'real_path': parsed_path.query, 'query': parsed_path.query, 'request_version': self.request_version, 'protocol_version': self.protocol_version, 'body': data }).encode()) return if __name__ == '__main__': server = HTTPServer(('localhost', 8000), RequestHandler) print('Starting server at http://localhost:8000') server.serve_forever()
相关阅读:
1、http.server — HTTP servers
2、colored
*** walker ***
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章题目:http请求头回显-创新互联
文章路径:http://azwzsj.com/article/dpehjg.html