Skip to content

Commit

Permalink
target can be specified in ip range format
Browse files Browse the repository at this point in the history
  • Loading branch information
nullt3r committed May 14, 2022
1 parent efa708d commit 8fef2a2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 11 deletions.
2 changes: 1 addition & 1 deletion jfscan/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (1, 4, 8)
VERSION = (1, 4, 9)

__version__ = ".".join(map(str, VERSION))
68 changes: 58 additions & 10 deletions jfscan/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,15 @@ def load_targets(self, res, targets_file=None, target=None):
logger.error("no valid targets were specified")
raise SystemExit

target_before = None

for _target in targets:
for _target in list(set(targets)):

# In case the target is URL, we have to extract it first before further checks
_target = _target.strip()

# Domain from URL must be extracted first
if Validator.is_url(_target):
_target = _target.split("/")[2]

# If the next target is same as the one before, we can move onto another one
if _target == target_before:
continue

_target = _target.strip()

if Validator.is_domain(_target):
res.add_domain(_target)

Expand All @@ -222,10 +217,63 @@ def load_targets(self, res, targets_file=None, target=None):

elif Validator.is_ipv4_cidr(_target) or Validator.is_ipv6_cidr(_target):
res.add_cidr(_target)

elif Validator.is_ipv4_range(_target):
cidrs = self.ipv4_range_to_cidrs(_target)

logger.debug("IP range %s was divided into the following CIDRs: %s", _target, ", ".join(cidrs))

for cidr in cidrs:
res.add_cidr(cidr)

elif Validator.is_ipv6_range(_target):
cidrs = self.ipv6_range_to_cidrs(_target)

logger.debug("IP range %s was divided into the following CIDRs: %s", _target, ", ".join(cidrs))

for cidr in cidrs:
res.add_cidr(cidr)

else:
logger.warning("host %s is in unrecognized format, skipping...", _target)

target_before = _target
@staticmethod
def ipv4_range_to_cidrs(ip_range):
"""Converts target specified as IP range (inetnum) to CIDR(s)
Args:
ip_range (str): IP range - 192.168.0.0-192.168.1.255
Returns:
list: list of CIDR(s)
"""
import ipaddress
try:
ip_range = ip_range.split("-")
startip = ipaddress.IPv4Address(ip_range[0])
endip = ipaddress.IPv4Address(ip_range[1])
return [str(ipaddr) for ipaddr in ipaddress.summarize_address_range(startip, endip)]
except:
return None

@staticmethod
def ipv6_range_to_cidrs(ip_range):
"""Converts target specified as IP range (inetnum) to CIDR(s)
Args:
ip_range (str): IP range - 2620:0:2d0:200::7-2620:0:2d0:2df::7
Returns:
list: list of CIDR(s)
"""
import ipaddress
try:
ip_range = ip_range.split("-")
startip = ipaddress.IPv6Address(ip_range[0])
endip = ipaddress.IPv6Address(ip_range[1])
return [str(ipaddr) for ipaddr in ipaddress.summarize_address_range(startip, endip)]
except:
return None

# Oh, just remove it already...
@staticmethod
Expand Down
20 changes: 20 additions & 0 deletions jfscan/core/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ def is_ipv4_cidr(addr):
except:
return False

@staticmethod
def is_ipv4_range(ip_range):
ip_range = ip_range.split("-")
try:
if (type(ipaddress.ip_address(ip_range[0])) is ipaddress.IPv4Address
and type(ipaddress.ip_address(ip_range[1])) is ipaddress.IPv4Address):
return True
except:
return False

@staticmethod
def is_ipv6_range(ip_range):
ip_range = ip_range.split("-")
try:
if (type(ipaddress.ip_address(ip_range[0])) is ipaddress.IPv6Address
and type(ipaddress.ip_address(ip_range[1])) is ipaddress.IPv6Address):
return True
except:
return False

@staticmethod
def is_mac(mac) -> bool:
is_valid_mac = re.match(r'([0-9A-F]{2}[:]){5}[0-9A-F]{2}|'
Expand Down

0 comments on commit 8fef2a2

Please sign in to comment.