Fillder Script语法

官方的Fiddler Script使用文档

http://docs.telerik.com/fiddler/KnowledgeBase/FiddlerScript/ModifyRequestOrResponse

打开fiddler后在右边找到下面选项来编辑脚本

blob.png

打开go to 下拉框我看看下

blob.png

这里是一些http经过代理时的事件,看名字应该就可以明白是什么意思啦,

没有上面这个选项卡的就打开菜单里的customize rules会自动打开一个页面让你下载一个扩展,安装后重启软件就可以看到啦

blob.png

下面介绍两个常用的事件请求和响应

OnBeforeRequest 在把请求发送给服务器之前调用

监测请求

我们把要监测的请求链接给加成红色方便我们查看

在这个函数里添加下面代码,里面主机名改成你的就可以

复制代码

1
2
3
4
5
 
 
 
static function OnBeforeRequest(oSession: Session) {
if (oSession.HostnameIs("www.zhaokeli.com")) {
oSession["ui-color"] = "red";
}
}
 
 

如下图,颜色已经为红色

blob.png

修改cookie和header头信息

cookie是请求头里的一个字段,并不是像我们写程序设置cookies时的一个键对应一个值,直接就是一个cookies的字符串,因此我们可以把cookie清除掉重新添加

复制代码

1
2
3
4
5
6
 
 
 
static function OnBeforeRequest(oSession: Session) {
// 的cookie
oSession.oRequest.headers.Remove("Cookie");
// 的cookie
oSession.oRequest.headers.Add("Cookie", "uuid=asdfasdfasdf;key=asdfasdf");
}
 
 

也可以使用替换字符串的方法对单个的cookie值进行修改

复制代码

1
2
3
4
5
6
7
8
9
10
11
 
 
 
static function OnBeforeRequest(oSession: Session) {
//果url含username含cookie改cookie
if(oSession.uriContains('username') &&oSession.oRequest.headers.Contains("Cookie")){
//出cookie
var sCookie = oSession.oRequest["Cookie"];
//用replace作cookie的string
sCookie = sCookie.Replace("strname", "replacename");
//置cookie
oSession.oRequest["Cookie"] = sCookie;
}
}
 
 

修改post时的body里面的值(注意里面的值是&分隔的键值参数字符串)

复制代码

1
2
3
4
5
6
7
8
9
10
11
12
13
 
 
 
static function OnBeforeRequest(oSession: Session) {
//法,
// 取Request 的body
var strBody=oSession.GetRequestBodyAsString();
// 者replace改string
strBody=strBody.replace("1111","2222");
// 的body
FiddlerObject.alert(strBody);
// 的body回Request
oSession.utilSetRequestBody(strBody);
//
oSession.utilReplaceInRequest("1111", "2222");
}
 
 

禁止css请求

复制代码

1
2
3
4
5
 
 
 
if (oSession.uriContains(".css")){
oSession["ui-color"]="orange";
oSession["ui-bold"]="true";
oSession.oRequest.FailSession(404, "Blocked", "Fiddler blocked CSS file");
}
 
 

伪装user-agent头

复制代码

1
 
 
 
oSession.oRequest["User-Agent"]="Googlebot/2.X (+http://www.googlebot.com/bot.html)";
 
 

OnBeforeResponse从服务器收到响应然后返回给浏览器之前调用

查找并且替换html

复制代码

1
2
3
4
5
6
 
 
 
static function OnBeforeResponse(oSession: Session) {
if (oSession.HostnameIs("www.zhaokeli.com") && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){
oSession.utilDecodeResponse();
oSession.utilReplaceInResponse('<b>','<u>');
}
}
 
 

在response返回的html中查找出指定字符串时把当前链接显示成红色(查找时不区分大小写)

复制代码

1
2
3
 
 
 
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "text/html") && oSession.utilFindInResponse("searchfor", false)>-1){
oSession["ui-color"] = "red";
}
 
 

移除响应内容中的所有div标签

复制代码

1
2
3
4
5
6
7
8
9
10
11
 
 
 
// 为 HTML, 的div
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
//
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
// 使有div
var oRegEx = /<div[^>]*>|</div>/gi;
oBody = oBody.replace(oRegEx, "");
//
oSession.utilSetResponseBody(oBody);
}
 
 

使用脚本控制断点功能

暂停所有post请求(断下后可以修改post的数据)

复制代码

1
2
3
 
 
 
if (oSession.HTTPMethodIs("POST")){
oSession["x-breakrequest"]="breaking for POST";
}
 
 

暂停所有包含指定关键字的post请求

复制代码

1
2
3
 
 
 
if (oSession.HTTPMethodIs("POST") && (oSession.utilFindInRequest("thekeyword", true) > -1)){
oSession["x-breakrequest"] = "keyword";
}
 
 

暂停url中请求类型是xml的请求

复制代码

1
2
3
 
 
 
if (oSession.url.toLowerCase().indexOf(".xml")>-1){
oSession["x-breakrequest"]="reason_XML";
}
 
 

暂停响应头是javascript类型的请求(一般用在修改响应数据的时候)

复制代码

1
2
3
 
 
 
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "javascript")){
oSession["x-breakresponse"]="reason is JScript";
}
 
 

还有很多功能请查看官方文档,都带的有示例

有不懂的,或者更好的见解可以随时交流!每天都会看的。
原文地址:https://www.cnblogs.com/java-xz/p/7527609.html