def _fill_template(self, scan_name, cmd) -> List[str]: """Replace template parameters with values.""" cmd = (cmd.replace('<target>', self.target).replace( '<wordlist>', get_db_value('web-word-list')).replace( '<userlist>', get_db_value('brute-user-list')).replace( '<passlist>', get_db_value('brute-pass-list'))) if '<ports>' in cmd: fout = get_scan_file( self.target, self.name + '.' + '.'.join([str(p) for p in self.ports]) + '.' + scan_name) return [ cmd.replace('<ports>', self.port_str()).replace('<fout>', fout) ] elif '<port>' in cmd: cmds = [] for port in self.ports: fout = get_scan_file( self.target, self.name + '.' + str(port) + '.' + scan_name) cmds.append( cmd.replace('<port>', str(port)).replace('<fout>', fout)) return cmds else: fout = get_scan_file(self.target, self.name + '.' + scan_name) # handling edge-case where a qs-spawned non-port scan could be # overwritten by a ts-spawned non-port scan of the same service i = 0 while file_exists(fout): fout = get_scan_file( self.target, self.name + '.' + str(i) + '.' + scan_name) i += 1 cmd = cmd.replace('<fout>', fout) return [cmd]
async def run_udp_s(target: str) -> Set[ParsedService]: """Run a UDP scan on a target.""" print_i_d2(target, ': beginning UDP scan') udp_config = get_db_value('udp-scan') cmd = udp_config.scan.format( target=target, fout=get_scan_file(target, 'udp.' + udp_config.name)) services = await _parse_port_scan(target, cmd, udp_config.pattern) print_i_d2(target, ': finished UDP scan') return services
async def run_ts(target: str) -> Set[ParsedService]: """Run a thorough TCP scan on a target using the configured method.""" print_i_d2(target, ': beginning TCP thorough scan') ts_config = get_db_value('thorough-scan') cmd = ts_config.scan.format( target=target, fout=get_scan_file(target, 'tcp.thorough.' + ts_config.name)) services = await _parse_port_scan(target, cmd, ts_config.pattern) print_i_d2(target, ': finished TCP thorough scan') return services
async def run_qs(target: str) -> Set[ParsedService]: """Run a quick scan on a target via the configured method.""" print_i_d2(target, ': beginning TCP quick scan') qs_config = get_db_value('quick-scan') cmd = qs_config.scan.format( target=target, fout=get_scan_file(target, 'tcp.quickscan.' + qs_config.name)) services = await _parse_port_scan(target, cmd, qs_config.pattern) print_i_d2(target, ': finished TCP quick scan') return services