Skip to content

Commit

Permalink
update plugNHack to use Brk addon
Browse files Browse the repository at this point in the history
Signed-off-by: aryangupta701 <[email protected]>
  • Loading branch information
aryangupta701 committed Feb 15, 2024
1 parent 6bd584f commit a8dcbf9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public class ExtensionPlugNHack extends ExtensionAdaptor
coreBrkDisabled = ExtensionBreak.class.getAnnotation(Deprecated.class) != null;
}

/*
/*
* TODO
* Handle mode
*/
Expand Down Expand Up @@ -226,7 +226,9 @@ public void run() {
try {
sleep(poll);

if (!ctrlInit && Control.getSingleton() != null && !coreBrkDisabled) {
if (!ctrlInit
&& Control.getSingleton() != null
&& !coreBrkDisabled) {
extBreak =
(ExtensionBreak)
Control.getSingleton()
Expand All @@ -237,9 +239,9 @@ public void run() {

if (extBreak != null
&& (extBreak.getBreakpointManagementInterface()
.isBreakRequest()
|| extBreak.getBreakpointManagementInterface()
.isBreakResponse())) {
.isBreakRequest()
|| extBreak.getBreakpointManagementInterface()
.isBreakResponse())) {
// Dont timeout pages while global breakpoints set
// TODO find a solution for custom break points too
continue;
Expand Down Expand Up @@ -298,7 +300,7 @@ public void hook(ExtensionHook extensionHook) {
ExtensionLoader extLoader = Control.getSingleton().getExtensionLoader();

// setup Breakpoints
if(!coreBrkDisabled) {
if (!coreBrkDisabled) {
extBreak = (ExtensionBreak) extLoader.getExtension(ExtensionBreak.NAME);
}

Expand Down Expand Up @@ -349,7 +351,7 @@ public void unload() {
ExtensionLoader extLoader = Control.getSingleton().getExtensionLoader();

// clear up Breakpoints
if(!coreBrkDisabled) {
if (!coreBrkDisabled) {
extBreak = (ExtensionBreak) extLoader.getExtension(ExtensionBreak.NAME);
}
if (extBreak != null) {
Expand Down Expand Up @@ -493,12 +495,12 @@ public boolean onHttpResponseReceive(HttpMessage msg) {
+ SCRIPT_START
+ this.getPnhScript()
+ SCRIPT_END
.replace(REPLACE_ROOT_TOKEN, this.getApiRoot())
.replace(REPLACE_ID_TOKEN, page.getId())
.replace(
REPLACE_NONCE,
API.getInstance()
.getLongLivedNonce(SCRIPT_API))
.replace(REPLACE_ROOT_TOKEN, this.getApiRoot())
.replace(REPLACE_ID_TOKEN, page.getId())
.replace(
REPLACE_NONCE,
API.getInstance()
.getLongLivedNonce(SCRIPT_API))
+ body.substring(endHeadTag);
msg.setResponseBody(body);
msg.getResponseHeader().setContentLength(body.length());
Expand Down Expand Up @@ -919,7 +921,7 @@ protected void messageChanged(ClientMessage msg) {

protected ClientBreakpointsUiManagerInterface getBrkManager() {
if (brkManager == null) {
if(!coreBrkDisabled) {
if (!coreBrkDisabled) {
extBreak =
(ExtensionBreak)
Control.getSingleton()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
/*
* Zed Attack Proxy (ZAP) and its related class files.
*
* ZAP is an HTTP/HTTPS proxy for assessing web application security.
*
* Copyright 2024 The ZAP Development Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.zap.extension.plugnhack.brk;


import java.util.List;
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.control.Control;
Expand Down Expand Up @@ -32,7 +50,8 @@ public List<Class<? extends Extension>> getDependencies() {

@Override
public void hook(ExtensionHook extensionHook) {
getExtension(ExtensionPlugNHack.class).setExtensionBreak(getExtension(ExtensionBreak.class));
getExtension(ExtensionPlugNHack.class)
.setExtensionBreak(getExtension(ExtensionBreak.class));
}

private static <T extends Extension> T getExtension(Class<T> clazz) {
Expand Down

0 comments on commit a8dcbf9

Please sign in to comment.