Skip to content

Commit 21f3924

Browse files
committed
added the --show-ips option to show all ips in a cidr range
1 parent feafe63 commit 21f3924

File tree

3 files changed

+72
-20
lines changed

3 files changed

+72
-20
lines changed

in_scope.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
1.1.1.1 # this is a comments after an addy
22
8.8.8.8
33
1.2.3.4
4-
192.168.1.0/24
5-
172.16.0.0/16
4+
192.168.1.0/28
5+
# 172.16.0.0/16
66
12.34.13.37
77
# this is a comment
88
#vuln.target.com
99
1.2.3.4
1010
shyft.us
11+

indascope.py

+36-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
import typer
13+
og_print = print
1314
from rich import print
1415

1516
__VERSION__ = '' # this is updated with make release which rebuilds
@@ -37,7 +38,7 @@ def get_ip(host:str, verbose=True, loading_scope=False) -> ipaddress.IPv4Address
3738

3839

3940

40-
def build_targets(scope_file) -> set:
41+
def build_scope(scope_file, showing:bool=False) -> set:
4142
targets = set()
4243
try:
4344
f = open(scope_file)
@@ -69,29 +70,32 @@ def build_targets(scope_file) -> set:
6970
print('is an ip ', line)
7071
targets.add(ipaddress.IPv4Address(line))
7172
elif re.search(r'\d\/\d*$', line): # for cidr networks e.g. 10.0.0.0/8
72-
if VERBOSE:
73-
print('is a cidr', line)
74-
ip_net = ipaddress.ip_network(line)
73+
74+
ip_net = ipaddress.ip_network(line, strict=False)
75+
7576
net = [ip for ip in ip_net] # add all the ips to the set...
77+
if VERBOSE:
78+
print(f'is a cidr {line} with {len(net)} IPs starting at {net[0]} and ending at {net[-1]}')
7679
targets.update(net)
7780
elif re.search(r'\w', line): # is a hostname... we need the ip
81+
82+
ip = get_ip(line, loading_scope=True)
7883
if VERBOSE:
79-
print('is a hostname', line)
80-
ip = get_ip(line, loading_scope=True)
84+
print(f'is a hostname "{line}" with ip {ip}')
8185
targets.add(ip) # add the ip to the set
8286
targets.add(line) # and the hostname...
8387
try:
8488
targets.remove(None) # remove erroneous entries to the set
8589
except KeyError as e:
8690
pass
8791

88-
if VERBOSE:
89-
num_targets = len(targets)
90-
if num_targets < 512:
91-
print(targets) # rich.print is slow on large collections.
92-
print(f'Total in scope IPS: {num_targets}')
93-
print('-'*30)
94-
92+
# if VERBOSE and showing == False:
93+
# num_targets = len(targets)
94+
# if num_targets < 512:
95+
# print(targets) # rich.print is slow on large collections.
96+
# print(f'Total in scope IPS: {num_targets}')
97+
# print('-'*30)
98+
9599
return targets
96100

97101
def check(in_scope_targets, potential_targets, verbose=False):
@@ -120,18 +124,32 @@ def check(in_scope_targets, potential_targets, verbose=False):
120124

121125

122126
@app.command()
123-
def in_scope(targets:List[str]=typer.Argument(None), target_file:Path=None, scope_file:Path=f'./in_scope.txt', verbose:bool=typer.Option(False, '-v'), version:bool=typer.Option(False, '--version')):
127+
def in_scope(targets:List[str]=typer.Argument(None), target_file:Path=None, scope_file:Path=f'./in_scope.txt', verbose:bool=typer.Option(False, '-v'), show:bool=typer.Option(False, '--show-ips', '-s'), version:bool=typer.Option(False, '--version')):
124128
"""Checks to see if one or more host IPs are in the scope file; """
125129
if version:
126130
print(__VERSION__)
127131
sys.exit()
128-
129132
if verbose == True:
130133
global VERBOSE
131134
VERBOSE = True
132135

133-
in_scope_ips = build_targets(scope_file)
134-
136+
in_scope_targets = build_scope(scope_file, showing=show)
137+
138+
if show:
139+
in_scope_host : ipaddress.IPv4Address
140+
# for in_scope_host in in_scope_targets: # 10 seconds for example scope; 65k ips
141+
# if type(in_scope_host) == ipaddress.IPv4Address:
142+
143+
# print(str(in_scope_host))
144+
145+
ips=[str(x) for x in in_scope_targets]
146+
print(sorted(ips)) # 5 seconds ; 65k ips
147+
if VERBOSE:
148+
print(f'Total in scope hosts (IPs and hostnames): {len(in_scope_targets)}')
149+
sys.exit()
150+
151+
152+
135153
if len(targets) == 0 and target_file == None:
136154
# print('using stdin')
137155
targets = sys.stdin.read().splitlines(keepends=False)
@@ -140,7 +158,7 @@ def in_scope(targets:List[str]=typer.Argument(None), target_file:Path=None, scop
140158
targets = f.read().splitlines(keepends=False)
141159

142160

143-
with WorkerPool(shared_objects=in_scope_ips) as pool:
161+
with WorkerPool(shared_objects=in_scope_targets) as pool:
144162
# https://slimmer-ai.github.io/mpire/v2.1.0/usage/worker_pool.html#shared-objects
145163
# pool.set_shared_objects(in_scope_ips) # another way to do this inside of
146164
pool.map(check, targets)

readme.md

+33
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,39 @@ OR
4343
```bash
4444
indascope -f list_of_potenttial_targets.txt
4545
```
46+
47+
OR
48+
49+
```bash
50+
indascope --show-ips
51+
[
52+
'1.1.1.1',
53+
'1.2.3.4',
54+
'12.34.13.37',
55+
'192.168.1.0',
56+
'192.168.1.1',
57+
'192.168.1.10',
58+
'192.168.1.11',
59+
'192.168.1.12',
60+
'192.168.1.13',
61+
'192.168.1.14',
62+
'192.168.1.15',
63+
'192.168.1.2',
64+
'192.168.1.3',
65+
'192.168.1.4',
66+
'192.168.1.5',
67+
'192.168.1.6',
68+
'192.168.1.7',
69+
'192.168.1.8',
70+
'192.168.1.9',
71+
'3.224.74.192',
72+
'8.8.8.8',
73+
'shyft.us'
74+
]
75+
```
76+
77+
78+
4679
## Scope files (in_scope.txt)
4780
scope files are just lines of IP addresses, CIDR ranges, and/or domain/hostnames
4881

0 commit comments

Comments
 (0)