Re: c

From Tacky Mockingjay, 4 Months ago, written in Plain Text, viewed 57 times. This paste is a reply to c from Scorching Wolf - view diff
URL https://code.nat.moe/view/5a730cdf Embed
Download Paste or View Raw
  1. #!/usr/bin/env python3
  2.  
  3. import socket, argparse, select
  4.  
  5. HEADER = '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.  
  7. parser = argparse.ArgumentParser()
  8. parser.add_argument('--port', type = int, help = 'remote port', required = True)
  9. parser.add_argument('--host', type = str, help = 'remote host', required = True)
  10. parser.add_argument('--size', type = int, help = 'content length', required = True)
  11. parser.add_argument('--count', type = int, help = 'number of posts', required = True)
  12. ns = parser.parse_args()
  13.  
  14. def drain(sock: socket.socket):
  15.     rlist = [sock]
  16.     while True:
  17.         ready, _, _ = select.select(rlist, [], [], .0)
  18.         if len(ready) == 0: break
  19.         sock.recv(65535)
  20.  
  21. def wait(sock: socket.socket):
  22.     rlist = [sock]
  23.     while True:
  24.         ready, _, _ = select.select(rlist, [], [])
  25.         if len(ready) > 0: break
  26.  
  27. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  28.     s.connect((ns.host, ns.port))
  29.     count = 0
  30.     while count < ns.count:
  31.         s.sendall(bytes(HEADER.format(host = ns.host, port = ns.port, len = ns.size, count = count).encode('ascii')))
  32.         s.sendall(bytes(0 for b in range(1, ns.size)))
  33.        
  34.         wait(s)
  35.         drain(s)
  36.  
  37.         count += 1
  38.         if count % 100 == 0:
  39.             print('{} posts sent'.format(count))

Reply to "Re: c"

Here you can reply to the paste above

captcha