Skip to content

Commit

Permalink
Fix directory redirection (Issue #6)
Browse files Browse the repository at this point in the history
Handle the verification of (is_directory_redirection) in the must_attack function
  • Loading branch information
OussamaBeng authored and fwininger committed May 1, 2024
1 parent ea135d1 commit 2f2dd00
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions wapitiCore/attack/attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ async def must_attack(
request: Request, # pylint: disable=unused-argument
response: Optional[Response] = None, # pylint: disable=unused-argument
):
if response.is_directory_redirection:
return False

return not self.finished

@property
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
page = request.path
headers = response.headers

if response.is_directory_redirection:
return False

if page in self.attacked_get:
return False

Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_brute_login_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if "Letm3in_" not in request.encoded_data + request.encoded_params:
return False

if response.is_directory_redirection:
return False

# We may want to remove this but if not available fallback to target URL
if not request.referer:
return False
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_cookieflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if self.finished:
return False

if response.is_directory_redirection:
return False

if request.method == "POST":
return False

Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if self.finished:
return False

if response.is_directory_redirection:
return False

if request.method == "POST":
return False

Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if request.method != "POST":
return False

if response.is_directory_redirection:
return False

# JSON requests can only be sent using JS with same-origin policy in place
# so, it is unlikely that a CSRF is possible. Let's filter those requests to prevent false positives
if request.is_json:
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_htaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if request.path in self.attacked_get:
return False

if response.is_directory_redirection:
return False

return response.status in (401, 402, 403, 407)

async def attack(self, request: Request, response: Optional[Response] = None):
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_http_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if request.method == "POST":
return False

if response.is_directory_redirection:
return False

if request.is_root and not request.parameters_count:
return True

Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_https_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if self.finished:
return False

if response.is_directory_redirection:
return False

url = urlparse(request.url)
if not test_port(url.hostname, url.port or 80, self.crawler_configuration.timeout):
log_orange(f"Port {url.port or 80} appears to be closed on {url.hostname}")
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ async def query_method(self, path: str, method: str) -> Response:
return await self.crawler.async_send(request)

async def must_attack(self, request: Request, response: Optional[Response] = None):

if response.is_directory_redirection:
return False
return request.path not in self.excluded_path

async def attack(self, request: Request, response: Optional[Response] = None):
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_network_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if self.finished:
return False

if response.is_directory_redirection:
return False

if request.method == "POST":
return False

Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_nikto.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if self.finished:
return False

if response.is_directory_redirection:
return False

return request.url == await self.persister.get_root_url()

async def is_false_positive(self, evil_request: Request, expected_status_codes: List[int]) -> bool:
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_permanentxss.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
# Same goes for redirections
return False

if response.is_directory_redirection:
return False

return True

async def attack(self, request: Request, response: Optional[Response] = None):
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_shellshock.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def __init__(self, crawler, persister, attack_options, stop_event, crawler_confi
}

async def must_attack(self, request: Request, response: Optional[Response] = None):
if response.is_directory_redirection:
return False

# We attempt to attach each script once whatever the method
return request.path not in self.attacked_get

Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
if request.scheme != "https":
return False

if response.is_directory_redirection:
return False

if request.hostname in self.tested_targets:
return False

Expand Down
2 changes: 2 additions & 0 deletions wapitiCore/attack/mod_takeover.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ async def must_attack(self, request: Request, response: Optional[Response] = Non
except (TldDomainNotFound, TldBadUrl):
# If the hostname part is an IP or is invalid we can't do subdomain enumeration obviously
return False
if response.is_directory_redirection:
return False

if root_domain in self.processed_domains:
return False
Expand Down
3 changes: 3 additions & 0 deletions wapitiCore/attack/mod_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def is_excluded(self, url: str):
return False

async def must_attack(self, request: Request, response: Optional[Response] = None):
if response.is_directory_redirection:
return False

return request.is_multipart

async def attack(self, request: Request, response: Optional[Response] = None):
Expand Down
2 changes: 0 additions & 2 deletions wapitiCore/net/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ async def _async_analyze(self, request) -> Tuple[bool, List, Optional[Response]]
await asyncio.sleep(0)
resources = self.extract_links(response, request)
# TODO: there's more situations where we would not want to attack the resource... must check this
if response.is_directory_redirection:
return False, resources, response

return True, resources, response

Expand Down

0 comments on commit 2f2dd00

Please sign in to comment.