Skip to content

Commit 7466ff6

Browse files
authored
Merge pull request #333 from thc202/update-proxy-script
Update Simple Reverse Proxy
2 parents 787502d + 99b0258 commit 7466ff6

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
- Remove compatibility code that provided the singletons (`control` and `model`) in JavaScript scripts, they can now be accessed directly always.
1010
- Use provided singletons (`control` and `model`) in Python scripts.
1111
- Use non-deprecated `HttpSender` constructor.
12+
- extender/Simple Reverse Proxy.js - replace usage of deprecated core classes.
1213
- Remove statements that return the message in HTTP Sender scripts, the message passed as parameter is used/sent always.
1314

1415
## [16] - 2023-03-29

extender/Simple Reverse Proxy.js

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,31 @@ var remotePort = 80
88
var proxyAddress = "127.0.0.1"
99
var proxyPort = 8081
1010

11-
var ProxyServer = Java.type("org.parosproxy.paros.core.proxy.ProxyServer")
12-
var ProxyListener = Java.type("org.parosproxy.paros.core.proxy.ProxyListener")
13-
var ZapXmlConfiguration = Java.type("org.zaproxy.zap.utils.ZapXmlConfiguration")
11+
var HttpSender = Java.type("org.parosproxy.paros.network.HttpSender")
1412
var URI = Java.type("org.apache.commons.httpclient.URI")
1513

16-
var extLoader = control.getExtensionLoader()
14+
var extensionNetwork = control.getExtensionLoader().getExtension("ExtensionNetwork")
1715
var proxy
1816

17+
function messageHandler(ctx, msg) {
18+
if (!ctx.isFromClient()) {
19+
return
20+
}
21+
22+
var requestUri = msg.getRequestHeader().getURI()
23+
requestUri = new URI(requestUri.getScheme(),
24+
requestUri.getUserinfo(),
25+
remoteAddress,
26+
remotePort,
27+
requestUri.getPath())
28+
msg.getRequestHeader().setURI(requestUri)
29+
}
30+
1931
function install(helper) {
20-
proxy = new ProxyServer("Proxy");
21-
proxy.getProxyParam().load(new ZapXmlConfiguration());
22-
var proxyParam = proxy.getProxyParam();
23-
proxyParam.setAlwaysDecodeGzip("false");
24-
proxyParam.setBehindNat(false);
25-
proxyParam.setRemoveUnsupportedEncodings(true);
26-
27-
proxy.setConnectionParam(model.getOptionsParam().getConnectionParam());
28-
proxy.setEnableApi(false);
29-
30-
extLoader.addProxyServer(proxy)
31-
32-
proxy.addProxyListener(new ProxyListener() {
33-
34-
onHttpRequestSend: function(msg) {
35-
var requestUri = msg.getRequestHeader().getURI()
36-
requestUri = new URI(requestUri.getScheme(),
37-
requestUri.getUserinfo(),
38-
remoteAddress,
39-
remotePort,
40-
requestUri.getPath())
41-
msg.getRequestHeader().setURI(requestUri)
42-
return true
43-
},
44-
45-
onHttpResponseReceive: function(msg) { return true },
46-
getArrangeableListenerOrder: function() { return 0 }
47-
})
48-
49-
proxy.startServer(proxyAddress, proxyPort, false);
32+
proxy = extensionNetwork.createHttpProxy(HttpSender.PROXY_INITIATOR, messageHandler)
33+
proxy.start(proxyAddress, proxyPort)
5034
}
5135

5236
function uninstall(helper) {
53-
proxy.stopServer()
54-
extLoader.removeProxyServer(proxy)
37+
proxy.stop()
5538
}

0 commit comments

Comments
 (0)