| 4 | import os |
| 5 | |
| 6 | class DirBuster(ServiceScan): |
| 7 | |
| 8 | def __init__(self): |
| 9 | super().__init__() |
| 10 | self.name = "Directory Buster" |
| 11 | self.slug = 'dirbuster' |
| 12 | self.priority = 0 |
| 13 | self.tags = ['default', 'safe', 'long', 'http'] |
| 14 | |
| 15 | def configure(self): |
| 16 | self.add_choice_option('tool', default='feroxbuster', choices=['feroxbuster', 'gobuster', 'dirsearch', 'ffuf', 'dirb'], help='The tool to use for directory busting. Default: %(default)s') |
| 17 | self.add_list_option('wordlist', default=[os.path.join(config['data_dir'], 'wordlists', 'dirbuster.txt')], help='The wordlist(s) to use when directory busting. Separate multiple wordlists with spaces. Default: %(default)s') |
| 18 | self.add_option('threads', default=10, help='The number of threads to use when directory busting. Default: %(default)s') |
| 19 | self.add_option('ext', default='txt,html,php,asp,aspx,jsp', help='The extensions you wish to fuzz (no dot, comma separated). Default: %(default)s') |
| 20 | self.add_true_option('recursive', help='Enables recursive searching (where available). Warning: This may cause significant increases to scan times. Default: %(default)s') |
| 21 | self.add_option('extras', default='', help='Any extra options you wish to pass to the tool when it runs. e.g. --dirbuster.extras=\'-s 200,301 --discover-backup\'') |
| 22 | self.match_service_name('^http') |
| 23 | self.match_service_name('^nacn_http$', negative_match=True) |
| 24 | |
| 25 | def check(self): |
| 26 | tool = self.get_option('tool') |
| 27 | if tool == 'feroxbuster' and which('feroxbuster') is None: |
| 28 | self.error('The feroxbuster program could not be found. Make sure it is installed. (On Kali, run: sudo apt install feroxbuster)') |
| 29 | return False |
| 30 | elif tool == 'gobuster' and which('gobuster') is None: |
| 31 | self.error('The gobuster program could not be found. Make sure it is installed. (On Kali, run: sudo apt install gobuster)') |
| 32 | return False |
| 33 | elif tool == 'dirsearch' and which('dirsearch') is None: |
| 34 | self.error('The dirsearch program could not be found. Make sure it is installed. (On Kali, run: sudo apt install dirsearch)') |
| 35 | return False |
| 36 | elif tool == 'ffuf' and which('ffuf') is None: |
| 37 | self.error('The ffuf program could not be found. Make sure it is installed. (On Kali, run: sudo apt install ffuf)') |
| 38 | return False |
| 39 | elif tool == 'dirb' and which('dirb') is None: |
| 40 | self.error('The dirb program could not be found. Make sure it is installed. (On Kali, run: sudo apt install dirb)') |
| 41 | return False |
| 42 | |
| 43 | async def run(self, service): |
| 44 | dot_extensions = ','.join(['.' + x for x in self.get_option('ext').split(',')]) |
| 45 | for wordlist in self.get_option('wordlist'): |
| 46 | name = os.path.splitext(os.path.basename(wordlist))[0] |
| 47 | if self.get_option('tool') == 'feroxbuster': |
| 48 | await service.execute('feroxbuster -u {http_scheme}://{addressv6}:{port}/ -t ' + str(self.get_option('threads')) + ' -w ' + wordlist + ' -x "' + self.get_option('ext') + '" -v -k ' + ('' if self.get_option('recursive') else '-n ') + '-q -e -r -o "{scandir}/{protocol}_{port}_{http_scheme}_feroxbuster_' + name + '.txt"' + (' ' + self.get_option('extras') if self.get_option('extras') else '')) |
| 49 | |
| 50 | elif self.get_option('tool') == 'gobuster': |
| 51 | await service.execute('gobuster dir -u {http_scheme}://{addressv6}:{port}/ -t ' + str(self.get_option('threads')) + ' -w ' + wordlist + ' -e -k -x "' + self.get_option('ext') + '" -z -r -o "{scandir}/{protocol}_{port}_{http_scheme}_gobuster_' + name + '.txt"' + (' ' + self.get_option('extras') if self.get_option('extras') else '')) |
| 52 | |
| 53 | elif self.get_option('tool') == 'dirsearch': |
| 54 | if service.target.ipversion == 'IPv6': |
| 55 | service.error('dirsearch does not support IPv6.') |
| 56 | else: |
| 57 | await service.execute('dirsearch -u {http_scheme}://{address}:{port}/ -t ' + str(self.get_option('threads')) + ' -e "' + self.get_option('ext') + '" -f -q -F ' + ('-r ' if self.get_option('recursive') else '') + '-w ' + wordlist + ' --format=plain -o "{scandir}/{protocol}_{port}_{http_scheme}_dirsearch_' + name + '.txt"' + (' ' + self.get_option('extras') if self.get_option('extras') else '')) |
| 58 | |
| 59 | elif self.get_option('tool') == 'ffuf': |
| 60 | await service.execute('ffuf -u {http_scheme}://{addressv6}:{port}/FUZZ -t ' + str(self.get_option('threads')) + ' -w ' + wordlist + ' -e "' + dot_extensions + '" -v -r ' + ('-recursion ' if self.get_option('recursive') else '') + '-noninteractive' + (' ' + self.get_option('extras') if self.get_option('extras') else '') + ' | tee {scandir}/{protocol}_{port}_{http_scheme}_ffuf_' + name + '.txt') |
| 61 | |
| 62 | elif self.get_option('tool') == 'dirb': |
| 63 | await service.execute('dirb {http_scheme}://{addressv6}:{port}/ ' + wordlist + ' -l ' + ('' if self.get_option('recursive') else '-r ') + '-S -X ",' + dot_extensions + '" -f -o "{scandir}/{protocol}_{port}_{http_scheme}_dirb_' + name + '.txt"' + (' ' + self.get_option('extras') if self.get_option('extras') else '')) |
nothing calls this directly
no outgoing calls
no test coverage detected