Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JWT Fuzzer #6

Merged
merged 23 commits into from
Sep 3, 2020
Merged

JWT Fuzzer #6

merged 23 commits into from
Sep 3, 2020

Conversation

preetkaran20
Copy link
Member

@preetkaran20 preetkaran20 commented May 30, 2020

This is the part 2 of the JWT Addon where Fuzzer Capabilities are added for Fuzzing JWT token.

ExtensionScript extensionScript =
Control.getSingleton().getExtensionLoader().getExtension(ExtensionScript.class);
HttpPanelManager panelManager = HttpPanelManager.getInstance();
panelManager.addRequestViewFactory(
Copy link
Member Author

@preetkaran20 preetkaran20 Jun 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also adds JWT view to Http Fuzzer. Not sure if there is any way to handle this. Need to look back.
If we don't handle this then in Http Fuzzer it will look similar to JWT Fuzzer but working differs a lot wherein JWT fuzzer does many other things like Signing the token and chaning a field inside the token but http fuzzer just replaces the entire token @kingthorin @thc202 please suggest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point, will check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not be an issue as same menu item is now used for HttpFuzzer and JWT fuzzer

@preetkaran20
Copy link
Member Author

Added PR to reduce JWTFuzzerHandler code that is copied from HttpFuzzer.
zaproxy/zap-extensions#2421

@preetkaran20
Copy link
Member Author

Hi @kingthorin and @thc202 ,

Following is the view of fuzzer:
image
I was in impression that in case of multiple message location each one message location replacer only modifies one http message at a time i.e. say if 2 message locations with one one value is there then 2 http messages will be generated and hence I introduced a field for specifying signature operation which is no signature, generate new signature and use old signature only. But as this is not the case hence this UI becomes invalid so i need to have this field applicable for all the message locations and hence it cannot be represent in message location so i was thinking of adding this field either in Options panel or in fuzzer policy. please suggest.

thanks,
Karan

@preetkaran20
Copy link
Member Author

Hi @kingthorin and @thc202 ,

As i have already mentioned that Http view now contains the JWT view and it looks like this:
image

I am not sure if it is ok or we want to remove it and how can we remove it.

thanks,
Karan

@preetkaran20
Copy link
Member Author

Seems fine to me. Still seems to be plenty if comments to yourself that are un-resolved though. Not sure how important those are/were.

i think they are outdated. However i will look at them once again for confirmation.

@preetkaran20
Copy link
Member Author

Seems fine to me. Still seems to be plenty if comments to yourself that are un-resolved though. Not sure how important those are/were.

Yes i checked and they are outdated. One was regarding testing RSA, I have checked again and it is working fine.
Just waiting for @thc202 's review comments, so shall i merge these changes and track them as bugs (if it takes time) or shall i wait for some more days ? @kingthorin what is your suggestion ?

public void initView(ViewDelegate view) {
super.initView(view);

HttpPanelManager panelManager = HttpPanelManager.getInstance();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Fuzzer add-on now allows to add views to just the the Fuzzer dialogue, through ExtensionFuzz#getClientMessagePanelManager and #getServerMessagePanelManager().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thc202, I am not sure which one to use also i tried using clientMessagePanelManager and i am getting null pointer. I am not sure why. I am thinking that clientMessagePanelManager gets initialized in initview and hence may be that is causing issue.

Copy link
Contributor

@thc202 thc202 Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be the "client" which in HTTP maps to "request". That's right, that would have to be done later in the hook method (if there's view), by then the view of the fuzz extension is already initialised.

try {
extensionHook.addOptionsParamSet(getJWTConfiguration());
extensionHook.getHookView().addOptionPanel(new JWTOptionsPanel());
ExtensionFuzz extensionFuzz =
Control.getSingleton().getExtensionLoader().getExtension(ExtensionFuzz.class);
extensionFuzz.addFuzzerHandler(httpFuzzerHandler);
LOGGER.debug("JWT Extension loaded successfully");
} catch (Exception e) {
LOGGER.error("JWT Extension can't be loaded. Configuration not found or invalid", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed? (Core already catches exceptions that happen when hooking the extensions.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@Override
public void unload() {
super.unload();
HttpPanelManager panelManager = HttpPanelManager.getInstance();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For correctness the views need to be removed as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the views created by the factory ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

jwtComponentJsonKeysComboBox.setSelectedIndex(0);
jwtComponentType.addActionListener(getJWTComponentTypeActionListener(jwtHolder));
} catch (Exception e) {
LOGGER.error("Error Occurred: ", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if the errors were more descriptive, the users will reporting issues with this message. I'd also suggest using a lower level (e.g. warn) if this is expected to happen. Error level should be used just for potential bugs/issues in the code.

@thc202
Copy link
Contributor

thc202 commented Sep 1, 2020

Some comments to build.gradle.kts:

-addOnName.set("JWT Extension")
+addOnName.set("JWT Support") // Or something like that, add-ons are more than just extensions (e.g. this provides scan rules as well).

-implementation("org.zaproxy.addon:fuzz:13.0.0")
+compileOnly("org.zaproxy.addon:fuzz:13.0.0") // Might need testImplementation if you plan to add tests.

The dependencies block needs to have:

register("fuzz") {
    version.set("13.*")
}

JWTI18n.init();
jwtMessageLocationReplacerFactory = new JWTMessageLocationReplacerFactory();
MessageLocationReplacers.getInstance()
.addReplacer(HttpMessage.class, jwtMessageLocationReplacerFactory);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be removed on #unload().

try {
extensionHook.addOptionsParamSet(getJWTConfiguration());
extensionHook.getHookView().addOptionPanel(new JWTOptionsPanel());
ExtensionFuzz extensionFuzz =
Control.getSingleton().getExtensionLoader().getExtension(ExtensionFuzz.class);
extensionFuzz.addFuzzerHandler(httpFuzzerHandler);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@thc202
Copy link
Contributor

thc202 commented Sep 1, 2020

The changelog could be updated to mention the new functionality.

@thc202
Copy link
Contributor

thc202 commented Sep 1, 2020

Another comment for build.gradle.kts, under manifest it could have repo.set("https://github.com/SasanLabs/owasp-zap-jwt-addon/"), that's shown in the marketplace (site and ZAP).

@preetkaran20
Copy link
Member Author

Some comments to build.gradle.kts:

-addOnName.set("JWT Extension")
+addOnName.set("JWT Support") // Or something like that, add-ons are more than just extensions (e.g. this provides scan rules as well).

-implementation("org.zaproxy.addon:fuzz:13.0.0")
+compileOnly("org.zaproxy.addon:fuzz:13.0.0") // Might need testImplementation if you plan to add tests.

The dependencies block needs to have:

register("fuzz") {
    version.set("13.*")
}

what does register doing here ? i didn't got the use ? can you please explain.

@thc202
Copy link
Contributor

thc202 commented Sep 1, 2020

Sorry, that was not clear, that's for the dependencies under the manifest, to declare that the JWT add-on depends on the Fuzzer add-on (and that range version). Like was done for the Common Library.

@thc202
Copy link
Contributor

thc202 commented Sep 2, 2020

The add-on is not filling the "changes" entry of the manifest, since the add-on has a changelog you can add:

changesFile.set(tasks.named<ConvertMarkdownToHtml>("generateManifestChanges").flatMap { it.html })

to the manifest in build.gradle.kts. That's shown to the user to inform about the changes of the version installed or available in the marketplace.

@preetkaran20
Copy link
Member Author

@thc202 while installing and working on new fuzz version i am facing null pointers while saving options panel:

image
image

@kingthorin
Copy link
Collaborator

kingthorin commented Sep 3, 2020

The work around is referenced here: zaproxy/zaproxy#6136

@preetkaran20
Copy link
Member Author

Hi @thc202 ,

I have incorporated changes suggested. Please review.

thanks,
Karan

CHANGELOG.md Outdated
@@ -4,6 +4,7 @@ All notable changes to this add-on will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- First version of JWT Extension.
- Second version of JWT Support.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit misleading, there's no first version (released) yet. Maybe call it iteration? Or just add all under first version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

.getExtensionLoader()
.getExtension(ExtensionFuzz.class)
.getClientMessagePanelManager();
panelManager.addViewFactory(RequestAllComponent.NAME, new JWTFuzzPanelViewFactory(null));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These (and the options panel) should be added only if there's view (there's a hasView() method), to avoid creating unnecessary view components in daemon and command line modes. Same check would apply in unload.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@preetkaran20
Copy link
Member Author

@thc202 done with the changes.

@preetkaran20
Copy link
Member Author

Hi @thc202 @kingthorin ,

please review zaproxy/zaproxy-website#101 also.

thanks,
Karan

@thc202
Copy link
Contributor

thc202 commented Sep 3, 2020

Looks good, thank you (especially for the patience)!

@preetkaran20
Copy link
Member Author

Merging it now. Thanks @thc202 and @kingthorin

@preetkaran20 preetkaran20 merged commit c366816 into master Sep 3, 2020
@preetkaran20 preetkaran20 deleted the FuzzerChanges branch September 3, 2020 12:44
@preetkaran20
Copy link
Member Author

@thc202 @kingthorin what next needs to be done for releasing this Project.

@thc202
Copy link
Contributor

thc202 commented Sep 3, 2020

I think the following steps:

  1. Update the changelog to reflect the new version, e.g.:
-## Unreleased
+## [1.0.0] - 2020-08-03
 
 - First version of JWT Support.
   - Contains scanning rules for basic JWT related vulnerabilities.
   - Contains JWT Fuzzer for fuzzing the JWT's present in the request.
+
+[1.0.0]: https://github.com/SasanLabs/owasp-zap-jwt-addon/releases/tag/v1.0.0
  1. Tag (above example using v1.0.0) and push.
  2. Build the add-on (with Java 8) and create a new release from the tag.

Once that's done we can release to the marketplace.

@preetkaran20
Copy link
Member Author

Hi @thc202 @kingthorin

i have added the release https://github.com/SasanLabs/owasp-zap-jwt-addon/releases/tag/v1.0.0

thanks,
Karan

@kingthorin
Copy link
Collaborator

It doesn't seem to have the actual add-on (*.zap) attached?

@thc202
Copy link
Contributor

thc202 commented Sep 3, 2020

Sorry for the typo in the date.

@preetkaran20
Copy link
Member Author

Added the ".zap" file too.

@thc202
Copy link
Contributor

thc202 commented Sep 3, 2020

The jar can be removed, that will not work in ZAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants