Skip to content

Commit

Permalink
scan summary added
Browse files Browse the repository at this point in the history
  • Loading branch information
nullt3r committed Apr 24, 2022
1 parent 273a1f2 commit 2e6ca15
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 126 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
![logo](screenshots/logo.png)
![GitHub](https://img.shields.io/github/license/nullt3r/jfscan) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/nullt3r/jfscan) ![Rating](https://img.shields.io/github/stars/nullt3r/jfscan?style=social)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# Description
## Killing features
* Perform a large-scale scans using Nmap! Allows you to use Masscan to scan targets and execute Nmap on detected ports with custom settings. Nmap on steroids. *
Expand Down
2 changes: 1 addition & 1 deletion jfscan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3


pass
pass
42 changes: 33 additions & 9 deletions jfscan/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=import-error
#!/usr/bin/env python3
import logging
import time

from jfscan.core.resources import Resources
from jfscan.core.utils import Utils
Expand All @@ -14,6 +15,7 @@

CURRENT_VERSION = __version__.__version__


def main():
try:
logger = logging.getLogger()
Expand All @@ -27,18 +29,20 @@ def main():
logger.level = logging.ERROR
else:
logger.level = logging.INFO
print(f"""\033[38;5;63m
print(
f"""\033[38;5;63m
___,__, _, _,_ , ,
',| '|_,(_, / '|\ |\ |
(_| | _)'\_ |-\ |'\|
' ' `' `' ` \033[0m
\033[97mversion: {CURRENT_VERSION} / author: @nullt3r\033[0m
""")
"""
)

if arguments.resolvers is not None:
user_resolvers = arguments.resolvers.split(",")
logger.info("using custom resolvers: %s", ", ".join(user_resolvers))
utils = Utils(resolvers = user_resolvers)
utils = Utils(resolvers=user_resolvers)
else:
utils = Utils()

Expand Down Expand Up @@ -76,9 +80,12 @@ def main():
utils.check_dependency("nmap", "--version", "Nmap version 7.")
utils.check_dependency("masscan", "--version", "1.3.2")

utils.load_targets(res,
targets_file = arguments.targets,
target = arguments.target.split(",") if arguments.target is not None else None
utils.load_targets(
res,
targets_file=arguments.targets,
target=arguments.target.split(",")
if arguments.target is not None
else None,
)
ip_count = res.count_ips()

Expand All @@ -87,13 +94,20 @@ def main():
raise SystemExit

if arguments.disable_auto_rate is False:
computed_rate = utils.compute_rate(ip_count, ports_count, arguments.max_rate)
logger.info("adjusting packet rate to %s kpps (you can disable this by --disable-auto-rate)", computed_rate)
computed_rate = utils.compute_rate(
ip_count, ports_count, arguments.max_rate
)
logger.info(
"adjusting packet rate to %s kpps (you can disable this by --disable-auto-rate)",
computed_rate,
)
masscan.rate = computed_rate
else:
logger.info("rate adjustment disabled, expect unexpected")
masscan.rate = arguments.max_rate

scanning_start = time.perf_counter()

masscan.run(res)

logger.info("dumping results")
Expand Down Expand Up @@ -123,16 +137,26 @@ def main():

nmap.run(res)

scanning_stop = time.perf_counter()

logger.info(
"scan took %0.2f seconds, discovered %s open ports, %s hosts alive out of %s total",
scanning_stop - scanning_start,
res.count_ports(),
res.count_alive_ips(),
ip_count
)

except KeyboardInterrupt:
logger.fatal("ctrl+c was pressed, cleaning up & exiting...")

import os, glob

for jfscan_file in glob.glob("/tmp/_jfscan_*"):
os.remove(jfscan_file)

raise SystemExit


if __name__ == "__main__":
main()

4 changes: 2 additions & 2 deletions jfscan/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (1, 3, 3)
VERSION = (1, 3, 4)

__version__ = '.'.join(map(str, VERSION))
__version__ = ".".join(map(str, VERSION))
2 changes: 1 addition & 1 deletion jfscan/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python3

pass
pass
27 changes: 15 additions & 12 deletions jfscan/core/arg_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

CURRENT_VERSION = __version__.__version__


class ArgumentHandler:
def __init__(self):
is_tty = bool(sys.stdin.isatty())
Expand All @@ -25,7 +26,7 @@ def __init__(self):
"target",
action="store",
help="a target or targets separated by a comma, accepted form is: domain name, IPv4, IPv6, URL",
nargs='?',
nargs="?",
)
group_targets.add_argument(
"--targets",
Expand Down Expand Up @@ -138,29 +139,31 @@ def __init__(self):
help="path to save output file in XML format (same as nmap option -oX)",
)
group_version.add_argument(
"--version",
action="version",
version=CURRENT_VERSION
"--version", action="version", version=CURRENT_VERSION
)

args = parser.parse_args()

if (args.targets or args.target) is None:
if is_tty is True:
parser.error("the following arguments are required: --targets, positional parameter [target] or stdin, you can also combine all options")
if is_tty is True:
parser.error(
"the following arguments are required: --targets, positional parameter [target] or stdin, you can also combine all options"
)

if args.router_ip is not None:
if validators.ipv4(args.router_ip) is not True:
parser.error("--router-ip has to be an IP addresses")

if args.ports is not None:
port_chars = re.compile(r"^[0-9,\-]+$")
if not re.search(port_chars, args.ports):
parser.error("ports are in a wrong format")

if args.nmap:
if args.nmap_options is not None:
if any(_opt in args.nmap_options for _opt in ["-oN", "-oS", "-oX", "-oG"]):
if any(
_opt in args.nmap_options for _opt in ["-oN", "-oS", "-oX", "-oG"]
):
parser.error(
"output arguments -oNSXG are not permitted, you can use option --nmap-output to save all results to a single xml file (like -oX)"
)
Expand All @@ -170,12 +173,12 @@ def __init__(self):
capture_output=True,
shell=True,
check=False,
)
)

if result.returncode != 0:
error = result.stderr.decode()
parser.error(f"incorrect nmap options: \n{error}")

if args.resolvers is not None:
for resolver in args.resolvers.split(","):
if (validators.ipv4(resolver) or validators.ipv6(resolver)) is not True:
Expand All @@ -198,4 +201,4 @@ def __init__(self):
self.nmap = args.nmap
self.nmap_options = args.nmap_options
self.nmap_threads = args.nmap_threads
self.nmap_output = args.nmap_output
self.nmap_output = args.nmap_output
7 changes: 4 additions & 3 deletions jfscan/core/logging_formatter.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import logging


class CustomFormatter(logging.Formatter):

grey = "\x1b[38;20m"
yellow = "\x1b[33;20m"
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
#format = "[%(asctime)s] [%(levelname)s] [%(module)s.%(funcName)s] - %(message)s"
# format = "[%(asctime)s] [%(levelname)s] [%(module)s.%(funcName)s] - %(message)s"
format = "[%(asctime)s] [%(levelname)s] - %(message)s"

FORMATS = {
logging.DEBUG: grey + format + reset,
logging.INFO: grey + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format + reset
logging.CRITICAL: bold_red + format + reset,
}

def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt, "%Y-%m-%d %H:%M:%S")
return formatter.format(record)
return formatter.format(record)
Loading

0 comments on commit 2e6ca15

Please sign in to comment.