Skip to content

Commit

Permalink
adding basic cookies support
Browse files Browse the repository at this point in the history
  • Loading branch information
shmsh9 committed Jan 27, 2021
1 parent d086fe3 commit 04c14ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/_dirbpy/URLBruteforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def __init__(self, host: str,
nb_thread: int = MAX_NUMBER_REQUEST,
status_code: list = VALID_STATUS_CODE,
proxy: dict = PROXY_DEFAULT_DICT,
cookies: dict = {},
directories_to_ignore: list = [],
logger: Logger = logging.getLogger(__name__),
duplicate_log: bool = True):


self.cookies = cookies
self.host = host
if 'https' in urlparse(self.host).scheme:
disable_https_warnings()
Expand All @@ -47,7 +49,6 @@ def __init__(self, host: str,
self.proxy = self.PROXY_DEFAULT_DICT
self.proxy[self.HTTPS_STR] = self._url_to_https(proxy)
self.proxy[self.HTTP_STR] = self._url_to_http(proxy)

self.directories_to_ignore = directories_to_ignore
self.logger = logger
if not duplicate_log:
Expand Down Expand Up @@ -94,7 +95,7 @@ def _remove_invalid_url_from_directory_found(self, directories_found: list, url:

def _request_thread(self, complete_url: str) -> list:
try:
response = requests.get(complete_url, proxies=self.proxy, verify=False)
response = requests.get(complete_url, proxies=self.proxy, verify=False, cookies=self.cookies)
except Exception as e:
self.logger.error(str(e) + '. URL: {}'.format(complete_url), exc_info=True)
return []
Expand Down
20 changes: 19 additions & 1 deletion src/_dirbpy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
def remove_none_value_in_kwargs(params_dict: dict) -> dict:
return {k: v for k, v in params_dict.items() if v is not None}

def parse_cookies(cookies_list):
cookies_dict = dict()
try:
for cookie in cookies_list:
pair = cookie.split("=")
cookies_dict[pair[0]] = pair[1]
return cookies_dict
except:
print("Cannot parse cookies {}.".format(cookies_list))
return None

def do_request_with_online_file(dict_url: str, host: str, **kwargs) -> None:
data = requests.get(dict_url)
Expand Down Expand Up @@ -93,6 +103,10 @@ def get_parser():
nargs='*',
type=str,
help='Specify the url of the proxy if you want to use one. (Ex: localhost:8080)')
parser.add_argument('-C', '--cookies',
nargs='*',
type=str,
help='Specify the cookies separated by a space if you want to use them. (Ex: cookie1=value cookie2=othervalue)')
parser.add_argument('-i', '--ignore',
nargs='*',
type=str,
Expand Down Expand Up @@ -138,7 +152,10 @@ def main():
print(f'Using proxy: {proxy}\n')
else:
proxy = None

if args.cookies:
cookies = parse_cookies(args.cookies)
else:
cookies = None
status_code = None
if args.status_code:
status_code = args.status_code
Expand All @@ -154,6 +171,7 @@ def main():
"nb_thread": args.thread,
"status_code": status_code,
"proxy": proxy,
"cookies": cookies,
"directories_to_ignore": directories_to_ignore,
"duplicate_log": args.no_duplicate
}
Expand Down

0 comments on commit 04c14ab

Please sign in to comment.