Re: cssa

From Unique Pintail, 5 Months ago, written in Python, viewed 69 times. This paste is a reply to cssa from Mature Owl - go back
URL https://code.nat.moe/view/b0679c1b/diff Embed
Viewing differences between cssa and Re: cssa
#!/usr/bin/env python3
import argparse, requests
from http.server import HTTPServer, BaseHTTPRequestHandler

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'
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'

CLIENT_HEADERS = {
    'Proxy-Connection': 'Connection': 'Keep-Alive',
    'Content-Type': 'application/octet-stream',
}

class Handler(BaseHTTPRequestHandler):
    protocol_version = 'HTTP/1.1'

    def do_POST(self):
        self.rfile.read(int(self.headers.get('Content-Length')))

        self.send_response(200)
        self.send_header('Connection', 'keep-alive')
        self.send_header('Content-Type', 'application/octet-stream')
        self.send_header('Content-Length', '0')
        self.end_headers()
        
        return

parser = argparse.ArgumentParser()
parser.add_argument('--client', help = 'client mode', action = 'store_true')
parser.add_argument('--host', type = str, help = 'remote/listen host', required = True)
parser.add_argument('--port', type = int, help = 'remote/listen port', required = True)
parser.add_argument('--size', type = int, help = '(client mode) content length')
parser.add_argument('--count', type = int, help = '(client mode) number of posts (0 = unlimited)')
ns = parser.parse_args()

if ns.client and (ns.size is None or ns.count is None):
    parser.error('--client requires --size and --count')

class Handler(BaseHTTPRequestHandler):
    protocol_version = 'HTTP/1.1'
    server_version = 'WebSphere-MQ-internet-pass-thru/2.1.0.4'
    sys_version = ''

    def do_POST(self):
        self.rfile.read(int(self.headers.get('Content-Length')))

        self.send_response(200)
        self.send_header('Connection', 'keep-alive')
        self.send_header('Proxy-Connection', 'keep-alive')
        self.send_header('Content-Type', 'application/octet-stream')
        self.send_header('Content-Length', '0')
        self.end_headers()
        return

if ns.client:
    data = bytes(0 for _ in range(1, ns.size))
    client = requests.Session()
    count = 0

0
    
    while count < ns.count or ns.count == 0:
        client.post(url = 'http://{}:{}/mqipt'.format(ns.host, ns.port), data = data, headers = CLIENT_HEADERS)
        count += 1
        if count % 100 == 0:
                            print('client: {} posts sent'.format(count))
else:
    server = HTTPServer((ns.host, ns.port), Handler)
    server.serve_forever()

Reply to "Re: cssa"

Here you can reply to the paste above

captcha