Skip to content

Commit

Permalink
Fix lfi with open redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkiros authored and bretfourbe committed Nov 9, 2023
1 parent 8ef13d6 commit 9614398
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/attack/test_mod_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ async def test_inclusion_detection():
assert ["f", "/etc/services"] in persister.add_payload.call_args_list[0][1]["request"].get_params


@pytest.mark.asyncio
async def test_open_redirect():
persister = AsyncMock()
request = Request("http://127.0.0.1:65085/open_redirect.php?url=toto")
#request.path_id = 42

crawler_configuration = CrawlerConfiguration(Request("http://127.0.0.1:65085/"))
async with AsyncCrawler.with_configuration(crawler_configuration) as crawler:
options = {"timeout": 10, "level": 2}

module = ModuleFile(crawler, persister, options, Event(), crawler_configuration)
module.do_post = False
await module.attack(request)

assert pytest.raises(httpx.InvalidURL)


@pytest.mark.asyncio
async def test_loknop_lfi_to_rce():
# https://gist.github.com/loknop/b27422d355ea1fd0d90d6dbc1e278d4d
Expand Down
5 changes: 4 additions & 1 deletion wapitiCore/attack/mod_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from time import monotonic
from typing import Optional, Iterator

from httpx import ReadTimeout, RequestError
from httpx import ReadTimeout, RequestError, InvalidURL

from wapitiCore.main.log import log_red, log_orange, log_verbose, logging
from wapitiCore.attack.attack import Attack
Expand Down Expand Up @@ -200,6 +200,9 @@ async def attack(self, request: Request, response: Optional[Response] = None):
except RequestError:
self.network_errors += 1
continue
except InvalidURL:
logging.warning(f"Invalid URL: {mutated_request.url} potentially vulnerable to open redirect")
continue
else:
file_warning = None
for i, rule in enumerate(payload_info.rules):
Expand Down

0 comments on commit 9614398

Please sign in to comment.