Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Remove compatibility code that provided the singletons (`control` and `model`) in JavaScript scripts, they can now be accessed directly always.
- Use provided singletons (`control` and `model`) in Python scripts.
- Use non-deprecated `HttpSender` constructor.
- extender/Simple Reverse Proxy.js - replace usage of deprecated core classes.
- Remove statements that return the message in HTTP Sender scripts, the message passed as parameter is used/sent always.

## [16] - 2023-03-29
Expand Down
55 changes: 19 additions & 36 deletions extender/Simple Reverse Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,31 @@ var remotePort = 80
var proxyAddress = "127.0.0.1"
var proxyPort = 8081

var ProxyServer = Java.type("org.parosproxy.paros.core.proxy.ProxyServer")
var ProxyListener = Java.type("org.parosproxy.paros.core.proxy.ProxyListener")
var ZapXmlConfiguration = Java.type("org.zaproxy.zap.utils.ZapXmlConfiguration")
var HttpSender = Java.type("org.parosproxy.paros.network.HttpSender")
var URI = Java.type("org.apache.commons.httpclient.URI")

var extLoader = control.getExtensionLoader()
var extensionNetwork = control.getExtensionLoader().getExtension("ExtensionNetwork")
var proxy

function messageHandler(ctx, msg) {
if (!ctx.isFromClient()) {
return
}

var requestUri = msg.getRequestHeader().getURI()
requestUri = new URI(requestUri.getScheme(),
requestUri.getUserinfo(),
remoteAddress,
remotePort,
requestUri.getPath())
msg.getRequestHeader().setURI(requestUri)
}

function install(helper) {
proxy = new ProxyServer("Proxy");
proxy.getProxyParam().load(new ZapXmlConfiguration());
var proxyParam = proxy.getProxyParam();
proxyParam.setAlwaysDecodeGzip("false");
proxyParam.setBehindNat(false);
proxyParam.setRemoveUnsupportedEncodings(true);

proxy.setConnectionParam(model.getOptionsParam().getConnectionParam());
proxy.setEnableApi(false);

extLoader.addProxyServer(proxy)

proxy.addProxyListener(new ProxyListener() {

onHttpRequestSend: function(msg) {
var requestUri = msg.getRequestHeader().getURI()
requestUri = new URI(requestUri.getScheme(),
requestUri.getUserinfo(),
remoteAddress,
remotePort,
requestUri.getPath())
msg.getRequestHeader().setURI(requestUri)
return true
},

onHttpResponseReceive: function(msg) { return true },
getArrangeableListenerOrder: function() { return 0 }
})

proxy.startServer(proxyAddress, proxyPort, false);
proxy = extensionNetwork.createHttpProxy(HttpSender.PROXY_INITIATOR, messageHandler)
proxy.start(proxyAddress, proxyPort)
}

function uninstall(helper) {
proxy.stopServer()
extLoader.removeProxyServer(proxy)
proxy.stop()
}