Skip to content

Commit

Permalink
Bump v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
snovvcrash committed Jul 23, 2023
1 parent 02d5142 commit 0185692
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</p>

<p align="center">
<a href="https://github.com/snovvcrash/DivideAndScan/blob/main/pyproject.toml#L3"><img src="https://img.shields.io/badge/version-1.0.0-success" alt="version" /></a>
<a href="https://github.com/snovvcrash/DivideAndScan/blob/main/pyproject.toml#L3"><img src="https://img.shields.io/badge/version-1.0.1-success" alt="version" /></a>
<a href="https://github.com/snovvcrash/DivideAndScan/search?l=python"><img src="https://img.shields.io/badge/python-3.9-blue?logo=python&logoColor=white" alt="python" /></a>
<a href="https://www.codacy.com/gh/snovvcrash/DivideAndScan/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=snovvcrash/DivideAndScan&amp;utm_campaign=Badge_Grade"><img src="https://app.codacy.com/project/badge/Grade/35f0bdfece9846d7aab3888b01642813" alt="codacy" /></a>
<a href="https://github.com/snovvcrash/DivideAndScan/actions/workflows/publish-to-pypi.yml"><img src="https://github.com/snovvcrash/DivideAndScan/actions/workflows/publish-to-pypi.yml/badge.svg" alt="pypi" /></a>
Expand Down
2 changes: 1 addition & 1 deletion das/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = '@snovvcrash'
__site__ = 'https://github.com/snovvcrash/DivideAndScan'
__version__ = '1.0.0'
__version__ = '1.0.1'

import time
import shlex
Expand Down
69 changes: 69 additions & 0 deletions das/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python3

import os
import tempfile
from pathlib import Path
from collections import defaultdict

from tinydb import TinyDB

from das.common import Logger, run_command


class DB:
"""Class for utilities that serve for manual DB manipulations."""

def __init__(self, db_path):
"""
Constructor.
:param db_path: a TinyDB database file path
:type db_path: str
"""
self.db = TinyDB(db_path)

def create_generic(self, scan_path, domains_path=None):
"""Create TinyDB from a generic scan output and a list of domain names (projectdiscovery/dnsx must be in PATH).
:param scan_path: an input file path with newline-separated scan output
:type scan_path: pathlib.PosixPath
:param domains_path: an input file path with newline-separated domain names
:type domains_path: pathlib.PosixPath
:return: number of hosts added to DB
:rtype: int
"""
with open(scan_path) as f:
# fmt -> 127.0.0.1:1337
scan = f.read().splitlines()

if domains_path:
with open(domains_path) as f:
domains = set(f.read().splitlines())

with tempfile.NamedTemporaryFile('w', suffix='.txt') as tmp:
dnsx_path = Path(tempfile.gettempdir()) / 'dnsx.txt'
domains_punycode = [domain.encode('idna').decode() + '\n' for domain in domains]
tmp.writelines(domains_punycode)
run_command(f'dnsx -l {tmp.name} -re -silent -o {dnsx_path}')

with open(dnsx_path) as f:
dnsx = f.read().splitlines()

Logger.print_info(f'Resolved {len(dnsx)} DNS records')
os.remove(dnsx_path)

domains = defaultdict(set)
for line in dnsx:
domain, ip = line.split()
domain = domain.encode().decode('idna')
ip = ip.replace('[', '').replace(']', '')
domains[ip].add(domain)

items = [{'ip': ip, 'port': int(port), 'domains': list(domains[ip])} for ip, port in (line.split(':') for line in scan)]
else:
items = [{'ip': ip, 'port': int(port), 'domains': []} for ip, port in (line.split(':') for line in scan)]

self.db.truncate()
self.db.insert_multiple(items)

return len(set([i['ip'] for i in items]))
28 changes: 28 additions & 0 deletions das/parsers/masscan_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from das.parsers import IAddPortscanOutput


class AddPortscanOutput(IAddPortscanOutput):
"""Child class for processing Masscan output (import)."""

def parse(self):
"""
Masscan (import) raw output parser.
:return: a pair of values (portscan raw output filename, number of hosts added to DB)
:rtype: tuple
"""
items, hosts = [], set()
for line in self.portscan_raw:
try:
ip = line.split()[3]
port, _, proto = line.split()[-1].split('/')[0:3]
except Exception:
pass
else:
if proto == 'tcp':
items.append({'ip': ip, 'port': int(port), 'domains': []})
hosts.add(ip)

self.db.insert_multiple(items)

return (self.portscan_out, len(hosts))
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "divideandscan"
version = "1.0.0"
version = "1.0.1"
description = "Divide full port scan results and use it for targeted Nmap runs"
authors = ["Sam Freeside <snovvcrash@protonmail.ch>"]
license = "BSD-2-Clause"
Expand Down Expand Up @@ -42,5 +42,5 @@ pylint = "^2.12.2"
twine = "^3.8.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core>=1.0.1"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 0185692

Please sign in to comment.