Fiddler - 为代理客户端发送请求
Fiddler - send request for proxied client
我将 Fiddler 配置为反向代理,以便充当客户端和服务器之间的中间人。我有一个自定义规则,它会在给定特定响应 uri 的情况下从代理发送请求:
static function OnBeforeResponse(oSession: Session) {
...
if (oSession.uriContains("something.aspx")) {
var request = "..."
FiddlerObject.utilIssueRequest(request);
}
...
}
有什么方法可以将utilIssueRequest 发出的请求路由回客户端机器吗?
可以,但是这样做非常复杂。通常,您要做的只是修改 OnBeforeRequest 处理程序中的请求,以便 URL/Host header 指向新的目标服务器。
抱歉 - 我的问题最终需要比我在提问时意识到的更多的细节。如果有人感兴趣,我用这个奇怪的方法解决了这个问题:
拓扑:Windows 客户端 --> Windows 客户端上的 Fiddler 代理 --> 中间人上的 Fiddler 反向代理 --> Windows 服务器
Windows 客户端中的代码 CustomRules.js:
static function OnBeforeRequest(oSession: Session) {
//detect prefetch response
if (oSession.oRequest.headers.Exists("X-FiddlerPrefetch")) {
//dump response into a variable
oSession.utilDecodeRequest();
prefetchResponse = System.Text.Encoding.UTF8.GetString(oSession.requestBodyBytes);
}
//detect uri that was prefetched
if (oSession.uriContains("/some_uri")) {
//wait for prefetch - cant find any docs for how to 'sleep' here
// while (prefetchResponse === "") {
// Sleep(1);
// }
//use cached response
oSession.utilCreateResponseAndBypassServer();
oSession.utilSetResponseBody(prefetchResponse);
}
//redirect traffic to man-in-the-middle
if (oSession.HostnameIs("some_server")) {
oSession["x-overrideHost"] = "man-in-the-middle:443";
}
...
中间人代码CustomRules.js:
static function OnBeforeResponse(oSession: Session) {
//intercept response containing prefetch material
if (oSession.uriContains("some_response")) {
//parse response body for some prefetch info
...
//compose request
var request = "POST " + uri + " HTTP/1.1" + "\n" +
"X-FiddlerOpt: test\n" +
...
//send off to server
FiddlerObject.utilIssueRequest(request);
}
//detect the prefetch response, send to client
if (oSession.oRequest.headers.Exists("X-FiddlerOpt")) {
oSession.utilDecodeResponse();
var payload = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);;
//compose request
var request = "GET " + "http://windows_client:8888/ HTTP/1.1" + "\n" +
"Content-Length: " + payload.length + "\n" +
"X-FiddlerPrefetch: test\n" +
"\n" +
payload
//send request
FiddlerObject.utilIssueRequest(request);
}
...
我确信有更简单或更好的方法可以做到这一点,欢迎任何反馈。
我将 Fiddler 配置为反向代理,以便充当客户端和服务器之间的中间人。我有一个自定义规则,它会在给定特定响应 uri 的情况下从代理发送请求:
static function OnBeforeResponse(oSession: Session) {
...
if (oSession.uriContains("something.aspx")) {
var request = "..."
FiddlerObject.utilIssueRequest(request);
}
...
}
有什么方法可以将utilIssueRequest 发出的请求路由回客户端机器吗?
可以,但是这样做非常复杂。通常,您要做的只是修改 OnBeforeRequest 处理程序中的请求,以便 URL/Host header 指向新的目标服务器。
抱歉 - 我的问题最终需要比我在提问时意识到的更多的细节。如果有人感兴趣,我用这个奇怪的方法解决了这个问题:
拓扑:Windows 客户端 --> Windows 客户端上的 Fiddler 代理 --> 中间人上的 Fiddler 反向代理 --> Windows 服务器
Windows 客户端中的代码 CustomRules.js:
static function OnBeforeRequest(oSession: Session) {
//detect prefetch response
if (oSession.oRequest.headers.Exists("X-FiddlerPrefetch")) {
//dump response into a variable
oSession.utilDecodeRequest();
prefetchResponse = System.Text.Encoding.UTF8.GetString(oSession.requestBodyBytes);
}
//detect uri that was prefetched
if (oSession.uriContains("/some_uri")) {
//wait for prefetch - cant find any docs for how to 'sleep' here
// while (prefetchResponse === "") {
// Sleep(1);
// }
//use cached response
oSession.utilCreateResponseAndBypassServer();
oSession.utilSetResponseBody(prefetchResponse);
}
//redirect traffic to man-in-the-middle
if (oSession.HostnameIs("some_server")) {
oSession["x-overrideHost"] = "man-in-the-middle:443";
}
...
中间人代码CustomRules.js:
static function OnBeforeResponse(oSession: Session) {
//intercept response containing prefetch material
if (oSession.uriContains("some_response")) {
//parse response body for some prefetch info
...
//compose request
var request = "POST " + uri + " HTTP/1.1" + "\n" +
"X-FiddlerOpt: test\n" +
...
//send off to server
FiddlerObject.utilIssueRequest(request);
}
//detect the prefetch response, send to client
if (oSession.oRequest.headers.Exists("X-FiddlerOpt")) {
oSession.utilDecodeResponse();
var payload = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);;
//compose request
var request = "GET " + "http://windows_client:8888/ HTTP/1.1" + "\n" +
"Content-Length: " + payload.length + "\n" +
"X-FiddlerPrefetch: test\n" +
"\n" +
payload
//send request
FiddlerObject.utilIssueRequest(request);
}
...
我确信有更简单或更好的方法可以做到这一点,欢迎任何反馈。