Skip to content

Commit

Permalink
Remove msf_print, switch to loguru for logging
Browse files Browse the repository at this point in the history
Replaced custom printing functions from msf_print.py with loguru for consistent logging. Updated all impacted scripts and added loguru to requirements.txt. Removed obsolete msf_print module.
  • Loading branch information
L1ghtn1ng committed Oct 18, 2024
1 parent 32fc265 commit 7ffbbae
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 261 deletions.
290 changes: 141 additions & 149 deletions dnsrecon/cli.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dnsrecon/lib/bingenum.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import time
import urllib.request

__name__ = 'bingenum'

url_opener = urllib.request.FancyURLopener


Expand Down
13 changes: 7 additions & 6 deletions dnsrecon/lib/crtenum.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,43 @@
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen

from loguru import logger
from lxml import etree

from dnsrecon.lib.msf_print import *
__name__ = 'crtenum'


def scrape_crtsh(dom):
"""
Function for enumerating subdomains by scraping crt.sh.
"""
results = []
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0'}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.3'}
url = f'https://crt.sh/?q=%25.{dom}'

req = Request(url=url, headers=headers)
try:
resp = urlopen(req, timeout=30)
data = resp.read()
except HTTPError as e:
print_error(f'Bad http status from crt.sh: "{e.code}"')
logger.error(f'Bad http status from crt.sh: "{e.code}"')
return results
except URLError as e:
print_error(f'Connection with crt.sh failed. Reason: "{e.reason}"')
logger.error(f'Connection with crt.sh failed. Reason: "{e.reason}"')
return results

root = etree.HTML(data)
tbl = root.xpath('//table/tr/td/table/tr/td[5]')
if len(tbl) < 1:
print_error('Certificates for subdomains not found')
logger.error('Certificates for subdomains not found')
return results

for ent in tbl:
sub_dom = ent.text
if not sub_dom.endswith('.' + dom):
continue
if sub_dom.startswith('*.'):
print_status(f'\t {sub_dom} wildcard')
logger.info(f'\t {sub_dom} wildcard')
continue
if sub_dom not in results:
results.append(sub_dom)
Expand Down
99 changes: 49 additions & 50 deletions dnsrecon/lib/dnshelper.py

Large diffs are not rendered by default.

51 changes: 0 additions & 51 deletions dnsrecon/lib/msf_print.py

This file was deleted.

2 changes: 2 additions & 0 deletions dnsrecon/lib/whois.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from netaddr import *

__name__ = 'whois.py'

WHOIS_PORT_NUMBER = 43
WHOIS_RECEIVE_BUFFER_SIZE = 4096

Expand Down
7 changes: 4 additions & 3 deletions dnsrecon/lib/yandexenum.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import urllib
import urllib.request

from dnsrecon.lib.msf_print import *
from loguru import logger

__name__ = 'yandexenum'
url_opener = urllib.request.FancyURLopener


Expand All @@ -45,11 +46,11 @@ def scrape_yandex(dom):
data = sock.read().decode('utf-8')
sock.close()
except Exception as e:
print_error(e)
logger.error(e)
return []

if re.search('enter_captcha_value', data):
print_error("Yandex has detected the search as 'bot activity, stopping search...")
logger.error("Yandex has detected the search as 'bot activity, stopping search...")
return unique(results)

results.extend(re.findall(r'([a-zA-Z0-9\-\.]+' + dom + ')/?', data))
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ target-version = "py311"
show-fixes = true

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I", "UP", "TCH"]
select = ["E4",
"E7",
"E9",
"F",
"I",
"UP",
"TCH",
"RUF",
"PT",
]
ignore = ["E721", "F403", "F405", "UP030"]

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dnspython>=2.6.1
netaddr
lxml
requests
requests
loguru

0 comments on commit 7ffbbae

Please sign in to comment.