cssa

From Mature Owl, 4 Months ago, written in Plain Text, viewed 58 times.
URL https://code.nat.moe/view/8b559e98 Embed
Download Paste or View Raw
  1. #!/usr/bin/env python3
  2. import argparse, requests
  3. from http.server import HTTPServer, BaseHTTPRequestHandler
  4.  
  5. REQUEST = 'POST http://{host}:{port}/mqipt HTTP/1.1\r\nHost: {host}:{port}\r\nUser-Agent: WebSphere-MQ-internet-pass-thru/2.1.0.4\r\nContent-Length: {len}\r\nAccept-Encoding: identity\r\nConnection: Keep-Alive\r\nContent-Type: application/octet-stream\r\nCookie: MQIPTSessionType=FullDuplex-S; MQIPTSessionId=test-{count}\r\nProxy-Connection: Keep-Alive\r\n\r\n'
  6. REPLY = 'HTTP/1.1 200 OK\r\nCache-Control: no-cache, no-transform\r\nConnection: Keep-Alive\r\nContent-Type: application/octet-stream\r\nCookie: MQIPTSessionId=test\r\nProxy-Connection: Keep-Alive\r\nServer: WebSphere-MQ-internet-pass-thru/2.1.0.4\r\nDate: Tue, 22 Feb 2022 22:22:22 GMT\r\nContent-Length: 0\r\n\r\n'
  7.  
  8. CLIENT_HEADERS = {
  9.     'Proxy-Connection': 'Keep-Alive',
  10.     'Content-Type': 'application/octet-stream',
  11. }
  12.  
  13. parser = argparse.ArgumentParser()
  14. parser.add_argument('--client', help = 'client mode', action = 'store_true')
  15. parser.add_argument('--host', type = str, help = 'remote/listen host', required = True)
  16. parser.add_argument('--port', type = int, help = 'remote/listen port', required = True)
  17. parser.add_argument('--size', type = int, help = '(client mode) content length')
  18. parser.add_argument('--count', type = int, help = '(client mode) number of posts (0 = unlimited)')
  19. ns = parser.parse_args()
  20.  
  21. if ns.client and (ns.size is None or ns.count is None):
  22.     parser.error('--client requires --size and --count')
  23.  
  24. class Handler(BaseHTTPRequestHandler):
  25.     protocol_version = 'HTTP/1.1'
  26.     server_version = 'WebSphere-MQ-internet-pass-thru/2.1.0.4'
  27.     sys_version = ''
  28.  
  29.     def do_POST(self):
  30.         self.rfile.read(int(self.headers.get('Content-Length')))
  31.  
  32.         self.send_response(200)
  33.         self.send_header('Connection', 'keep-alive')
  34.         self.send_header('Proxy-Connection', 'keep-alive')
  35.         self.send_header('Content-Type', 'application/octet-stream')
  36.         self.send_header('Content-Length', '0')
  37.         self.end_headers()
  38.         return
  39.  
  40. if ns.client:
  41.     data = bytes(0 for _ in range(1, ns.size))
  42.     client = requests.Session()
  43.     count = 0
  44.  
  45.     while count < ns.count or ns.count == 0:
  46.         client.post(url = 'http://{}:{}/mqipt'.format(ns.host, ns.port), data = data, headers = CLIENT_HEADERS)
  47.         count += 1
  48.         if count % 100 == 0:
  49.                 print('client: {} posts sent'.format(count))
  50. else:
  51.     server = HTTPServer((ns.host, ns.port), Handler)
  52.     server.serve_forever()

Replies to cssa rss

Title Name Language When
Re: cssa Unique Pintail python 4 Months ago.

Reply to "cssa"

Here you can reply to the paste above

captcha