A Burp Suite request parser, used for aid in assessing application security functionality.
from .burpr import parse_string, parse_file, clone, prepare
from .enums.TransportEnum import TransportEnum as transports
from .enums.ProtocolEnum import ProtocolEnum as protocols
burpr/__init__.py
krystianbajno/burpr
from urllib.parse import urlencode
import json as JSON
from burpr.models.BurpRequest import BurpRequest
from burpr.enums.TransportEnum import TransportEnum

def parse_string(string, json=False) -> BurpRequest:
  data = string.splitlines()
  method = data[0].split(" ")[0]
  path = data[0].split(" ")[1]
  protocol = data[0].split(" ")[2]
  headers = {}
  body = {}

  # headers
  for line in data[1:]:
    if line == "":
      break
    headers[line.split(": ")[0]] = line.split(": ")[1]
    
  # param
  if json:
    body = JSON.loads(data[-1])
  else:
    for param in data[-1].split("&"):
      body[param.split("=")[0]] = param.split("=")[1]
    
  return BurpRequest(
    headers["Host"],
    path,
    protocol,
    method,
    headers,
    body,
    TransportEnum.HTTPS
  )
  
def parse_file(file, json=False):
  with open(file, "r") as f:
    return parse_string(f.read(), json)
  
def clone(req: BurpRequest) -> BurpRequest:
  return BurpRequest(req.host, req.path, req.protocol, req.method, req.headers, req.body, req.transport)

def prepare(req: BurpRequest):
  req.set_header("Content-Length", len(urlencode(req.body)))
burpr/burpr.py
krystianbajno/burpr
from enum import Enum

class ProtocolEnum(str, Enum):
  HTTP2 = "HTTP/2"
  HTTP1_1 = "HTTP/1.1"
  HTTP1_0 = "HTTP/1.0"

  def __str__(self) -> str:
    return self.value
burpr/enums/ProtocolEnum.py
krystianbajno/burpr
from enum import Enum

class TransportEnum(str, Enum):
  HTTP = "http"
  HTTPS = "https"

  def __str__(self) -> str:
    return self.value
  

burpr/enums/TransportEnum.py
krystianbajno/burpr
from burpr.enums.ProtocolEnum import ProtocolEnum

class BurpRequest:
  def __init__(
    self,
    host="",
    path="",
    protocol="",
    method="",
    headers={},
    body={},
    transport=""
  ):
    self.host = host
    self.path = path
    self.protocol = protocol
    self.method = method
    self.headers = headers
    self.body = body
    self.transport = transport

  @property
  def url(self):
    return f'{self.transport}://{self.host}{self.path}'

  @property
  def is_http2(self): 
    return self.protocol == ProtocolEnum.HTTP2

  def set_host(self, host):
    self.host = host

  def set_path(self, path):
    self.path = path

  def set_method(self, method):
    self.method = method

  def get_headers(self):
    return self.headers
  
  def set_headers(self, headers):
    self.headers = headers

  def get_header(self, header_key):
    return self.headers.get(header_key)

  def set_header(self, header_key, header_value):
    self.headers[header_key] = str(header_value)

  def remove_header(self, header_key):
    self.headers.pop(header_key)

  def get_body(self):
    return self.body
  
  def set_body(self, body):
    self.body = body

  def get_parameter(self, parameter_key):
    return self.parameters.get(parameter_key)
  
  def set_parameter(self, param_key, param_value):
    self.body[param_key] = str(param_value)

  def remove_parameter(self, param_key):
    self.body.pop(param_key)
  
  def set_protocol(self, protocol):
    self.protocol = protocol

  def set_transport(self, transport):
    self.transport = transport
burpr/models/BurpRequest.py
krystianbajno/burpr
import os
from setuptools import setup, find_packages

# Utility function to read the README file.
def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name = "burpr",
    version = "0.0.4",
    author = "Krystian Bajno",
    author_email = "krystian.bajno@gmail.com",
    description = ("A Burp Suite request parser, used for aid in assessing application security functionality."),
    license = "MIT",
    long_description_content_type='text/markdown',
    keywords = "burp suite burpsuite request parser",
    url = "https://github.com/krystianbajno/burpr",
    packages=find_packages(),
    install_requires=["urllib3"],
    long_description=read('README.md'),
    classifiers=[
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3',
    ],
)
setup.py
krystianbajno/burpr