zap-extensions icon indicating copy to clipboard operation
zap-extensions copied to clipboard

ascanrules: Fix FP in Path Traversal directory browsing checks

Open mikhailevtikhov opened this issue 10 months ago • 4 comments

Overview

This is part of PR 5336. PathTraversal directory browsing detects (Check 3): This check finds a large number of FP in various web applications, because the regular expression that parses the response from the server for the nix architecture will not accurately determine that this is the root directory of the OS. For example, to generate FP on payload "c:" or any other from the LOCAL_DIR_TARGETS array, the words in the response from the server will be enough (etc. , bootstrap.min.js , tabindex) to generate Aletr. The reason for this is a weak pattern check for nix systems implemented in DirNamesContentsMatcher. You can play this FP on Apache Superset.

In this PR checks for windows and nix directories are implemented with different functions and enhanced regex for nix architecture.

Checklist

  • [ ] Update help
  • [x] Update changelog
  • [x] Run ./gradlew spotlessApply for code formatting
  • [x] Write tests
  • [ ] Check code coverage
  • [x] Sign-off commits
  • [ ] Squash commits
  • [x] Use a descriptive title

mikhailevtikhov avatar Apr 04 '24 14:04 mikhailevtikhov

@kingthorin I figured it out in more detail. There are two scenarios in this situation.

  1. It can be directory browsing at the web server level. In this case, you can focus on the examples of the response from the server.
   1.1 "<td><a href=\"/etc/\">etc</a></td>" ...
   1.2 "<li><a href="bin/">bin/</a></li>" ...
  1. It can be directory browsing at the web application level and be given in plain text.
curl http://localhost:4444/ls\?directory\=../../../
sbin
usr
mnt
lib
...
root
srv
opt
home
etc
bin

For this reason, I decided to replace regex. Slightly increase the number of checks to get rid of FP accurately, as well as remove the hardcoded "href" in order to match plain text.

mikhailevtikhov avatar Apr 12 '24 16:04 mikhailevtikhov

@kingthorin What are my next steps?

mikhailevtikhov avatar Apr 16 '24 14:04 mikhailevtikhov

Someone else in the team needs to review and approve (hopefully).

kingthorin avatar Apr 16 '24 15:04 kingthorin

ping

mikhailevtikhov avatar May 02 '24 16:05 mikhailevtikhov

@kingthorin What should I do to get this PR merged?) How do I invite other Reviewers?

mikhailevtikhov avatar Jun 07 '24 09:06 mikhailevtikhov

As mentioned in https://github.com/zaproxy/zap-extensions/pull/5336#issuecomment-2114273656 you should rebase both PRs.

thc202 avatar Jun 07 '24 09:06 thc202

If you need help with the rebases lemme know I can tackle it

kingthorin avatar Jun 07 '24 10:06 kingthorin

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

github-actions[bot] avatar Jun 07 '24 14:06 github-actions[bot]

@kingthorin looks like something went wrong...

mikhailevtikhov avatar Jun 07 '24 15:06 mikhailevtikhov

Okay no problem, I'll have a look 👀 in a few hours

kingthorin avatar Jun 07 '24 15:06 kingthorin

Okay so we have two options:

  1. You turn on "Allow edits by maintainers" (you should see it in the menu on the right). Then I can push a copy in the proper state.
  2. You check this comparison: https://github.com/zaproxy/zap-extensions/compare/main...kingthorin:zap-extensions:pathTraversalDirBased?expand=1
    • Assuming it's correct you add my fork as a git remote git remote add kingthorin https://github.com/kingthorin/zap-extensions.git
    • Fetch my remote git fetch kingthorin
    • Delete your local branch git branch -d pathTraversalDirBased (If it complains that it isn't fully merged you might need to use -D)
    • Checkout the branch on my fork (that's in the proper state) git checkout kingthorin/pathTraversalDirBased
    • Push that back to your fork, replacing the messed up version git push -u origin pathTraversalDirBased

kingthorin avatar Jun 07 '24 21:06 kingthorin

The option 1 will not be present, this PR is from an org's fork.

thc202 avatar Jun 08 '24 06:06 thc202

@kingthorin Please tell me if I can try the following:

  1. Update the fork of the organization;
  2. Create a new branch;
  3. Cheery-pick the necessary commits;
  4. Push a branch into a fork;
  5. Checkout on pathTraversalDirBased from this PR
  6. Rebase pathTraversalDirBased from this PR on new_branch
  7. Push new state of pathTraversalDirBased

mikhailevtikhov avatar Jun 13 '24 09:06 mikhailevtikhov

Discussed this with the team. We think that "should" work, though it actually seems like more effort than my option 2 😉

kingthorin avatar Jun 13 '24 10:06 kingthorin

@kingthorin I am trying your option 2. But I encounter the following error at the last stage.

git push -u origin pathTraversalDirBased     

To https://github.com/vulnspace/zap-extensions.git
 ! [rejected]            pathTraversalDirBased -> pathTraversalDirBased (non-fast-forward)
error: failed to push some refs to 'https://github.com/vulnspace/zap-extensions.git'

mikhailevtikhov avatar Jun 13 '24 11:06 mikhailevtikhov

You probably need to use --force since you're rewriting history

kingthorin avatar Jun 13 '24 11:06 kingthorin

Looks like it worked :D

mikhailevtikhov avatar Jun 13 '24 11:06 mikhailevtikhov

That seems to be back on track. Thanks

kingthorin avatar Jun 13 '24 11:06 kingthorin

Can you address the conflict?

thc202 avatar Jun 21 '24 12:06 thc202

Can you address the conflict?

Done.

mikhailevtikhov avatar Jun 21 '24 13:06 mikhailevtikhov

Thank you!

thc202 avatar Jun 21 '24 14:06 thc202

@mikhailevtikhov thanks for sticking with this and seeing it through!

kingthorin avatar Jun 21 '24 14:06 kingthorin