Skip to content

Commit 629332f

Browse files
atucomEkultek
authored andcommitted
Cmdline Whitelist Feature (#110)
* Added whitelist arg and modified the Exploiter call * added the whitelist_wash function * added whitelist prompt to terminal * added check for isspace()
1 parent 6dcbb75 commit 629332f

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

lib/cmdline/cmd.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def optparser():
6767
help="pass the path to your framework if it is not in your ENV PATH")
6868
misc.add_argument("--ethics", action="store_true", dest="displayEthics",
6969
help=argparse.SUPPRESS) # easter egg!
70+
misc.add_argument("--whitelist", metavar="PATH", dest="whitelist",
71+
help="only exploit hosts listed in the whitelist file")
7072
opts = parser.parse_args()
7173
return opts
7274

@@ -160,10 +162,13 @@ def single_run_args(opt, keys, loaded_modules):
160162
keys["censys"][1], keys["censys"][0], opt.searchQuery, proxy=headers[0], agent=headers[1]
161163
).censys()
162164
if opt.startExploit:
165+
hosts = open(lib.settings.HOST_FILE).readlines()
166+
if opt.whitelist:
167+
hosts = lib.exploitation.exploiter.whitelist_wash(hosts, whitelist_file=opt.whitelist)
163168
lib.exploitation.exploiter.AutoSploitExploiter(
164169
opt.msfConfig,
165170
loaded_modules,
166-
open(lib.settings.HOST_FILE).readlines(),
171+
hosts,
167172
ruby_exec=opt.rubyExecutableNeeded,
168173
msf_path=opt.pathToFramework
169174
).start_exploit()

lib/exploitation/exploiter.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import lib.settings
22
import lib.output
33

4+
def whitelist_wash(hosts, whitelist_file):
5+
"""
6+
remove IPs from hosts list that do not appear in WHITELIST_FILE
7+
"""
8+
whitelist_hosts = open(whitelist_file).readlines()
9+
lib.output.info('Found {} entries in whitelist.txt, scrubbing'.format(str(len(whitelist_hosts))))
10+
washed_hosts = []
11+
#return supplied hosts if whitelist file is empty
12+
if len(whitelist_hosts) == 0:
13+
return hosts
14+
else:
15+
for host in hosts:
16+
if host in whitelist_hosts:
17+
washed_hosts.append(host)
18+
19+
return washed_hosts
420

521
class AutoSploitExploiter(object):
622

lib/term/terminal.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,19 @@ def exploit_gathered_hosts(self, loaded_mods, hosts=None):
169169
"""
170170
ruby_exec = False
171171
msf_path = None
172+
whitelist_file = lib.output.prompt("specify full path to a whitelist file, otherwise hit enter", lowercase=False)
172173
if hosts is None:
173-
host_file = open(self.host_path).readlines()
174+
if whitelist_file is not "" and not whitelist_file.isspace():
175+
# If whitelist is specified, return a washed hosts list
176+
host_file = lib.exploitation.exploiter.whitelist_wash(open(self.host_path).readlines(), whitelist_file)
177+
else:
178+
host_file = open(self.host_path).readlines()
174179
else:
175-
host_file = open(hosts).readlines()
180+
if whitelist_file is not "" and not whitelist_file.isspace():
181+
# If whitelist is specified, return a washed hosts list
182+
host_file = lib.exploitation.exploiter.whitelist_wash(open(hosts).readlines(), whitelist_file)
183+
else:
184+
host_file = open(hosts).readlines()
176185
if not lib.settings.check_for_msf():
177186
msf_path = lib.output.prompt(
178187
"it appears that MSF is not in your PATH, provide the full path to msfconsole"

0 commit comments

Comments
 (0)