Fiddler4.6.20 使用script保存请求或响应数据到本地或post到其它地方保存

来源:赵克立博客 分类: 网络安全 标签:fiddler发布时间:2017-08-11 15:25:37最后更新:2018-08-17 14:29:45浏览:6987
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2018-08-17 14:29:45
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章

可以直接使用下面这个软件实现功能

HttpProxy拦截保存下载


保存请求报文

打开请求前事件函数里

image.png

添加如下代码保存内容到本地D盘

if (oSession.fullUrl.Contains("api.huoshan.com")){
    var fso;
    var file;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    //文件保存路径,可自定义
    file = fso.OpenTextFile("D:\\Sessions.txt",8 ,true, true);
    file.writeLine("Request url: " + oSession.url);
    file.writeLine("Request header:" + "\n" + oSession.oRequest.headers);
    file.writeLine("Request body: " + oSession.GetRequestBodyAsString());
    file.writeLine("\n");
    file.close();
}

保存响应内容到本地

打开响应的事件函数

image.png

添加如下代码

//过滤无关请求,只关注特定请求
if (oSession.fullUrl.Contains("api.huoshan.com"))
{
    oSession.utilDecodeResponse();//消除保存的请求可能存在乱码的情况
    var fso;
    var file;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    //文件保存路径,可自定义
    file = fso.OpenTextFile("D:\\Sessions.txt",8 ,true, true);
    file.writeLine("Response code: " + oSession.responseCode);
    file.writeLine("Response body: " + oSession.GetResponseBodyAsString());
    file.writeLine("\n");
    file.close();
}

把数据POST到其它地方

//把内容通过ajax http发送其它地方
var _xhr = new ActiveXObject('Microsoft.XMLHTTP');
var url = 'http://huoshan.loc/';
//发送的数据参数
var param = {
    a: oSession.GetResponseBodyAsString(),
    b: 'bbbbbbbbb'
};
var par = '';
for (var i in param) {
    var _data = escape(param[i]);
    par += par ? ("&" + i + "=" + _data) : (i + "=" + _data);
}
//不需要返回值所以写啦个空回调
_xhr.onreadystatechange = function() {}
_xhr.open('POST', url, true);
_xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
_xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
_xhr.send(par);

另一种方法直接构造一个原数据请求头

// methods
var method = "POST";
var url = "http://huoshan.loc/?a=responsedata";
var protocol = "HTTP/1.1";
var raw="";
var selected: Session = oSession;
raw += method + " " + url + " " + protocol + "\r\n";
FiddlerApplication.Log.LogString(raw);
// headers
raw +="Host:huoshan.loc\r\n";
raw +="Connection: keep-alive\r\n";
raw +="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n";
raw +="User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36\r\n";
raw +="Accept-Encoding: gzip,deflate,sdch\r\n";
raw +="Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4\r\n";
raw +="Content-Type: application/x-www-form-urlencoded\r\n";
// body
var body= "jsondata="+escape(oSession.GetResponseBodyAsString())+"&url="+escape(oSession.url);
raw += "\r\n" + body;
FiddlerApplication.Log.LogString(raw);
FiddlerObject.utilIssueRequest(raw);




微信号:kelicom QQ群:215861553 紧急求助须知
Win32/PHP/JS/Android/Python