Skip to content

Commit

Permalink
Merge pull request #270 from branchvincent/pyproject
Browse files Browse the repository at this point in the history
  • Loading branch information
L1ghtn1ng authored Apr 6, 2024
2 parents c5bdfcc + 524ff4d commit 9d26542
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/DNSrecon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements-dev.txt
pip install .[dev]
- name: Lint with ruff
run: |
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
*.pyc
*.pyo
venv/
*.pytest_cache/
*.pytest_cache/
*.egg-info
build/
dist/
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM python:alpine3
FROM python:alpine
WORKDIR /app
COPY . /app
RUN apk add --no-cache build-base libffi-dev libxml2-dev libxslt-dev
RUN /usr/local/bin/python -m pip install --upgrade pip
RUN /usr/local/bin/python --version
RUN pip3 install --no-cache-dir -r requirements.txt
RUN chmod +x *.py
ENTRYPOINT ["/app/dnsrecon.py"]
RUN pip3 install --no-cache-dir .
ENTRYPOINT ["dnsrecon"]
104 changes: 50 additions & 54 deletions dnsrecon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import sqlite3
from argparse import ArgumentParser, RawTextHelpFormatter
from concurrent import futures
from pathlib import Path
from random import SystemRandom
from string import ascii_letters, digits
from xml.dom import minidom
Expand Down Expand Up @@ -60,6 +61,7 @@
brtdata = []

CONFIG = {'disable_check_recursion': False, 'disable_check_bindversion': False}
DATA_DIR = Path(__file__).parent / 'data'


def process_range(arg):
Expand Down Expand Up @@ -207,12 +209,12 @@ def check_nxdomain_hijack(nameserver):
try:
answers = res.resolve(testname, record_type, tcp=True)
except (
dns.resolver.NoNameservers,
dns.resolver.NXDOMAIN,
dns.exception.Timeout,
dns.resolver.NoAnswer,
socket.error,
dns.query.BadResponse,
dns.resolver.NoNameservers,
dns.resolver.NXDOMAIN,
dns.exception.Timeout,
dns.resolver.NoAnswer,
socket.error,
dns.query.BadResponse,
):
continue

Expand Down Expand Up @@ -285,8 +287,7 @@ def brute_tlds(res, domain, verbose=False, thread_num=None):
future_results = {
**{executor.submit(res.get_ip, f'{domain_main}.{tld}'): tld for tld in total_tlds},
**{executor.submit(res.get_ip, f'{domain_main}.{cc}'): cc for cc in cctld},
**{executor.submit(res.get_ip, f'{domain_main}.{cc}.{tld}'): (cc, tld) for (cc, tld) in
zip(cctld, total_tlds)},
**{executor.submit(res.get_ip, f'{domain_main}.{cc}.{tld}'): (cc, tld) for (cc, tld) in zip(cctld, total_tlds)},
}

# Display logs as soon as a thread is finished
Expand Down Expand Up @@ -433,7 +434,7 @@ def brute_reverse(res, ip_list, verbose=False, thread_num=None):

ip_range = range(len(ip_list[i]) - 1)
ip_group_size = 255
for ip_group in [ip_range[j: j + ip_group_size] for j in range(0, len(ip_range), ip_group_size)]:
for ip_group in [ip_range[j : j + ip_group_size] for j in range(0, len(ip_range), ip_group_size)]:
try:
if verbose:
for x in ip_group:
Expand All @@ -457,13 +458,13 @@ def brute_reverse(res, ip_list, verbose=False, thread_num=None):


def brute_domain(
res,
dictfile,
dom,
filter_=None,
verbose=False,
ignore_wildcard=False,
thread_num=None,
res,
dictfile,
dom,
filter_=None,
verbose=False,
ignore_wildcard=False,
thread_num=None,
):
"""
Main Function for domain brute forcing
Expand Down Expand Up @@ -660,8 +661,7 @@ def whois_ips(res, ip_list):

if 'a' in answer:
for i in range(len(list_whois)):
print_status(
'Performing Reverse Lookup of range {0}-{1}'.format(list_whois[i]['start'], list_whois[i]['end']))
print_status('Performing Reverse Lookup of range {0}-{1}'.format(list_whois[i]['start'], list_whois[i]['end']))
found_records.append(brute_reverse(res, expand_range(list_whois[i]['start'], list_whois[i]['end'])))

elif 'n' in answer:
Expand All @@ -670,8 +670,7 @@ def whois_ips(res, ip_list):
for a in answer:
net_selected = list_whois[int(a)]
print_status(net_selected['orgname'])
print_status(
'Performing Reverse Lookup of range {0}-{1}'.format(net_selected['start'], net_selected['end']))
print_status('Performing Reverse Lookup of range {0}-{1}'.format(net_selected['start'], net_selected['end']))
found_records.append(brute_reverse(res, expand_range(net_selected['start'], net_selected['end'])))
else:
print_error('No IP Ranges were found in the Whois query results')
Expand Down Expand Up @@ -843,26 +842,26 @@ def write_db(db, data):
for n in data:
if re.match(r'PTR|^[A]$|AAAA', n['type']):
query = (
'insert into data( domain, type, name, address ) '
+ 'values( "{domain}", "{type}", "{name}","{address}" )'.format(**n)
'insert into data( domain, type, name, address ) '
+ 'values( "{domain}", "{type}", "{name}","{address}" )'.format(**n)
)

elif re.match(r'NS$', n['type']):
query = (
'insert into data( domain, type, name, address ) '
+ 'values( "{domain}", "{type}", "{target}", "{address}" )'.format(**n)
'insert into data( domain, type, name, address ) '
+ 'values( "{domain}", "{type}", "{target}", "{address}" )'.format(**n)
)

elif re.match(r'SOA', n['type']):
query = (
'insert into data( domain, type, name, address ) '
+ 'values( "{domain}", "{type}", "{mname}", "{address}" )'.format(**n)
'insert into data( domain, type, name, address ) '
+ 'values( "{domain}", "{type}", "{mname}", "{address}" )'.format(**n)
)

elif re.match(r'MX', n['type']):
query = (
'insert into data( domain, type, name, address ) '
+ 'values( "{domain}", "{type}", "{exchange}", "{address}" )'.format(**n)
'insert into data( domain, type, name, address ) '
+ 'values( "{domain}", "{type}", "{exchange}", "{address}" )'.format(**n)
)

elif re.match(r'TXT', n['type']):
Expand All @@ -873,14 +872,14 @@ def write_db(db, data):

elif re.match(r'SRV', n['type']):
query = (
'insert into data( domain, type, name, target, address, port ) '
+ 'values( "{domain}", "{type}", "{name}" , "{target}", "{address}" ,"{port}" )'.format(**n)
'insert into data( domain, type, name, target, address, port ) '
+ 'values( "{domain}", "{type}", "{name}" , "{target}", "{address}" ,"{port}" )'.format(**n)
)

elif re.match(r'CNAME', n['type']):
query = (
'insert into data( domain, type, name, target ) '
+ 'values( "{domain}", "{type}", "{name}" , "{target}" )'.format(**n)
'insert into data( domain, type, name, target ) '
+ 'values( "{domain}", "{type}", "{name}" , "{target}" )'.format(**n)
)

else:
Expand All @@ -889,8 +888,7 @@ def write_db(db, data):
del n['type']
record_data = ''.join([f'{key}={value},' for key, value in n.items()])
records = [t, record_data]
query = 'insert into data(domain,type,text) values ("%(domain)", \'' + records[0] + "','" + records[
1] + "')"
query = 'insert into data(domain,type,text) values ("%(domain)", \'' + records[0] + "','" + records[1] + "')"

# Execute Query and commit
cur.execute(query)
Expand Down Expand Up @@ -935,8 +933,7 @@ def dns_sec_check(domain, res):

except dns.exception.Timeout:
print_error('A timeout error occurred please make sure you can reach the target DNS Servers')
print_error(
f'directly and requests are not being filtered. Increase the timeout from {res._res.timeout} second')
print_error(f'directly and requests are not being filtered. Increase the timeout from {res._res.timeout} second')
print_error('to a higher number with --lifetime <time> option.')
sys.exit(1)
except dns.resolver.NoAnswer:
Expand All @@ -958,11 +955,11 @@ def check_bindversion(res, ns_server, timeout):
print_status(f'\t Bind Version for {ns_server} {version}')

except (
dns.resolver.NXDOMAIN,
dns.exception.Timeout,
dns.resolver.NoAnswer,
socket.error,
dns.query.BadResponse,
dns.resolver.NXDOMAIN,
dns.exception.Timeout,
dns.resolver.NoAnswer,
socket.error,
dns.query.BadResponse,
):
pass

Expand Down Expand Up @@ -992,17 +989,17 @@ def check_recursive(res, ns_server, timeout):


def general_enum(
res,
domain,
do_axfr,
do_bing,
do_yandex,
do_spf,
do_whois,
do_crt,
zw,
request_timeout,
thread_num=None,
res,
domain,
do_axfr,
do_bing,
do_yandex,
do_spf,
do_whois,
do_crt,
zw,
request_timeout,
thread_num=None,
):
"""
Function for performing general enumeration of a domain. It gets SOA, NS, MX
Expand Down Expand Up @@ -1810,8 +1807,7 @@ def main():
dictionary = ''
if any(dictionary_required):
# we generate a list of possible dictionary files
script_dir = os.path.dirname(os.path.realpath(__file__)) + os.sep
dictionaries = ['/etc/dnsrecon/namelist.txt', script_dir + 'namelist.txt']
dictionaries = ['/etc/dnsrecon/namelist.txt', DATA_DIR / 'namelist.txt']

# if the user has provided a custom dictionary file,
# we insert it as the first entry of the list
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 37 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
[project]
name = "dnsrecon"
description = "DNS Enumeration Script"
readme = "README.md"
authors = [{ name = "Carlos Perez", email = "[email protected]" }]
requires-python = ">=3.9"
urls.Homepage = "https://github.com/darkoperator/dnsrecon"
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Operating System :: OS Independent",
]
dynamic = ["dependencies", "optional-dependencies", "version"]

[project.scripts]
dnsrecon = "dnsrecon.__main__:main"

[tool.setuptools.dynamic]
version = { attr = "dnsrecon.cli.__version__" }
dependencies = { file = "requirements.txt" }
optional-dependencies.dev = { file = "requirements-dev.txt" }

[tool.setuptools.packages.find]
include = ["dnsrecon*"]

[tool.setuptools.package-data]
"*" = ["*.txt"]

[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
minversion = "8.0.0"
addopts = "--no-header"
Expand Down Expand Up @@ -54,4 +90,4 @@ indent-style = "space"
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
line-ending = "auto"
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
-r requirements.txt
pytest==8.1.1
ruff==0.3.5
41 changes: 0 additions & 41 deletions setup.py

This file was deleted.

0 comments on commit 9d26542

Please sign in to comment.