Skip to content

Commit

Permalink
Merge branch 'main' of github.com:tristanlatr/burpa
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlatr committed Mar 27, 2024
2 parents c89c15a + d54f92c commit 8752ef0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion burpa/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__author__ = 'Adel "0x4d31" Karimi, and other contributors'
__version__ = '0.3.10'
__version__ = '0.3.12'
4 changes: 2 additions & 2 deletions burpa/_burp_rest_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def proxy_uri(self) -> str:
return f"{self.proxy_url}:{self.api_port}"

@property
def rest_api_version(self) -> Tuple[int,int,int]:
def rest_api_version(self) -> Tuple[int,...]:
"""The version of the burp-rest-api Extension"""
try:
r = self.request('versions')
Expand All @@ -144,7 +144,7 @@ def rest_api_version(self) -> Tuple[int,int,int]:
return get_version(r.json()['extensionVersion'])

@property
def burp_version(self) -> Tuple[int,int,int]:
def burp_version(self) -> Tuple[int,...]:
"""The version of Burp"""
try:
r = self.request('versions')
Expand Down
4 changes: 2 additions & 2 deletions burpa/_burpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from ._burp_commander import BurpCommander
from ._error import BurpaError
from ._utils import (get_valid_filename, parse_commas_separated_str, ensure_scheme,
parse_targets, setup_logger, perform, is_timenow_between, strip_tags)
parse_targets, setup_logger, perform, is_timenow_between, strip_tags, read_text)
from .__version__ import __version__, __author__

###################################################
Expand Down Expand Up @@ -670,7 +670,7 @@ def generate_csv(io: TextIO, issues: List[Dict[str, Any]], report_datetime:str)
return

# Add CWE information
jsondata = json.loads(importlib_resources.read_text('burpa', 'issue_defs.json'))
jsondata = json.loads(read_text('burpa', 'issue_defs.json'))

for i in issues:
# Discard request/response data.
Expand Down
46 changes: 37 additions & 9 deletions burpa/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import sys
import concurrent.futures
from datetime import datetime, time
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, TextIO, Tuple
from importlib_resources import files

def get_valid_filename(s: str) -> str:
'''Return the given string converted to a string that can be used for a clean filename. Stolen from Django, I think.'''
Expand Down Expand Up @@ -123,40 +124,67 @@ def is_timenow_between(begin_time: time, end_time: time) -> bool:
else: # When the time crosses midnight
return check_time >= begin_time or check_time <= end_time

def get_version(s:str) -> Tuple[int, int, int]:
def get_version(s:str) -> Tuple[int, ...]:
"""
Parse a version string like <major>.<minor>.<micro> into a tuple of ints.
"""
parts = s.strip().split('.')
intparts = []
intparts: 'list[int]' = []

for p in parts:
try:
v = int(p)
except:
v = 0
if intparts:
v = 0
else:
continue
intparts.append(v)


if 3-len(intparts)>0:
for _ in range(3-len(intparts)):
intparts.append(0)
elif len(intparts)>3:
for _ in range(len(intparts)-3):
intparts.pop(0)

assert len(intparts)==3

return tuple(intparts) # type: ignore

_tag = re.compile('<[^<]+?>')

def strip_tags(html:str) -> str:
return _tag.sub('', html)

def open_text(
package: str,
resource: str,
encoding: str = 'utf-8',
errors: str = 'strict',
) -> TextIO:
"""Return a file-like object opened for text reading of the resource."""
return (files(package) / resource).open( # type:ignore
'r', encoding=encoding, errors=errors
)


def read_text(
package: str,
resource: str,
encoding: str = 'utf-8',
errors: str = 'strict',
) -> str:
"""Return the decoded string of the resource.
The decoding-related arguments have the same semantics as those of
bytes.decode().
"""
with open_text(package, resource, encoding, errors) as fp:
return fp.read()

if __name__ == "__main__":

assert get_version("2.2.0") == (2,2,0)
assert get_version("2") == (2,0,0)
assert get_version("Burp Suite Professional.2022.6.1") == (2022,6,1)
assert get_version("Burp Suite Professional.2022.6.1.1") == (2022,6,1,1)
assert get_version("Burp Suite Professional.2022.thing.1") == (2022,0,1)
assert get_version("0.2022.6.1") == (2022,6,1)
assert get_version("0.2022.6.1") == (0, 2022,6,1)

0 comments on commit 8752ef0

Please sign in to comment.