Created
January 13, 2016 14:02
-
-
Save sneakybeaky/eba26e585ac1f83301cc to your computer and use it in GitHub Desktop.
Filters Gor capture files and removes any requests bigger than 64KiB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
from bitstring import ConstBitStream | |
import sys | |
import argparse | |
# Requests in gor file are demarked by \n<U+1F435><U+1F648><U+1F649>\n | |
boundary = "0x0af09f90b5f09f9988f09f99890a" | |
# Max payload gor can read from a file is currently 64Kb | |
max_size = 64 * 1024 * 8 | |
def verbose(*objs): | |
print(*objs, file=sys.stderr) | |
def do_filter(instream, outstream): | |
s = ConstBitStream(instream) | |
discarded = 0 | |
try: | |
while s.pos < s.len: | |
bs = s.readto(boundary, bytealigned=True) | |
if bs.length > max_size: | |
discarded += 1 | |
else: | |
outstream.write(bs.tobytes()) | |
finally: | |
outstream.close() | |
verbose("Discarded {} payloads".format(discarded)) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description="Filters a gor capture file and removes any requests larger than 64Kb") | |
parser.add_argument('-i', '--input-file', type=argparse.FileType('rb'), default='-', dest='instream') | |
parser.add_argument('-o', '--output-file', type=argparse.FileType('wb'), default='-', dest='outstream') | |
args = parser.parse_args() | |
do_filter(args.instream, args.outstream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment