Skip to content

Commit

Permalink
update pocx requests exception error
Browse files Browse the repository at this point in the history
  • Loading branch information
antx-code committed Mar 23, 2022
1 parent 10b45e9 commit 8a47ef2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]

source =
pocx
tests

parallel = True
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 88
select = C,E,F,W,B,B9
ignore = E203, E501, W503
exclude = __init__.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ dmypy.json
dist
.idea
poetry.lock
.coverage
coverage.xml
/tests/
10 changes: 5 additions & 5 deletions pocx/aio_poc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class AioPoc(metaclass=ABCMeta):
def __init__(self) -> None:
self.mode = 'Asynchronous Mode'
self.name = "AioPoc"
self.example = ""
self.cve = ''
self.example = ''
self.session = httpx.AsyncClient(verify=False)
self.session.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"}
logger.info(f'Testing {self.name} with {self.mode}.')

@logger.catch(level='ERROR')
def set_headers(self, headers: dict = None):
Expand All @@ -25,8 +27,8 @@ def set_headers(self, headers: dict = None):
async def aio_request(self, url: str, method: str = 'get', timeout: int = 10, **kwargs) -> httpx.Response:
try:
resp = await self.session.request(method, url, timeout=timeout, **kwargs)
except httpx.RequestError as e:
logger.error(f'[-] Run Poc[{self.name}] => {url} Error:\n\t{e}')
except Exception as e:
logger.error(f'[-] Run Poc [{self.cve} - {self.name}] Connection Error => {url} was not reachable.')
resp = None
return resp

Expand Down Expand Up @@ -57,8 +59,6 @@ async def poc(self, target: str) -> bool:

@logger.catch(level='ERROR')
def run(self, target):
logger.info(f'testing {self.name} with {self.mode}.')

targets = [target] if isinstance(target, str) else target

loop = asyncio.get_event_loop()
Expand Down
10 changes: 5 additions & 5 deletions pocx/basic_poc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ class BasicPoc(metaclass=ABCMeta):
def __init__(self) -> None:
self.mode = 'Synchronous Mode'
self.name = "BasicPoc"
self.example = ""
self.cve = ''
self.example = ''
self.session = httpx.Client(verify=False)
self.session.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"}
logger.info(f'Testing {self.name} with {self.mode}.')

@logger.catch(level='ERROR')
def set_headers(self, headers: dict = None):
Expand All @@ -24,8 +26,8 @@ def set_headers(self, headers: dict = None):
def request(self, url: str, method: str = 'get', timeout: int = 10, **kwargs) -> httpx.Response:
try:
resp = self.session.request(method, url, timeout=timeout, **kwargs)
except httpx.RequestError as e:
logger.error(f'[-] Run Poc[{self.name}] => {url} Error:\n\t{e}')
except Exception as e:
logger.error(f'[-] Run Poc [{self.cve} - {self.name}] Connection Error => {url} was not reachable.')
resp = None
return resp

Expand Down Expand Up @@ -56,8 +58,6 @@ def poc(self, target: str) -> bool:

@logger.catch(level='ERROR')
def run(self, target):
logger.info(f'testing {self.name} with {self.mode}.')

targets = [target] if isinstance(target, str) else target

for target in targets:
Expand Down
2 changes: 1 addition & 1 deletion pocx/funcs/ceye.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def generate_payload_id(self):
return str(self.id_worker.get_id())

@logger.catch(level='ERROR')
def verify(self, pfilter: str, verify_type: str='dns'):
def verify(self, pfilter: str, verify_type: str = 'dns'):
"""
Verify the payload.
Expand Down
3 changes: 3 additions & 0 deletions pocx/funcs/snow_flake.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# coding: utf-8
import time


class InvalidSystemClock(Exception):
"""
时钟回拨异常
"""
pass


# 64位ID的划分
WORKER_ID_BITS = 5
DATACENTER_ID_BITS = 5
Expand All @@ -27,6 +29,7 @@ class InvalidSystemClock(Exception):
# 开始时间截 (1995-03-19)
TWEPOCH = 795542400000


class IdWorker(object):
"""
用于生成IDs
Expand Down

0 comments on commit 8a47ef2

Please sign in to comment.