Process Filtering with Fiddler - filtering

Is there a way to filter out certain processes in Fiddler? Its very noisy currently, and I don't want it to show just one process.

The built-in Show only traffic from option is useful if your process never exits and always has the same PID. In my case, my HTTP client was starting and exiting frequently, so I added this custom FiddlerScript.
Go to Rules > Customize Rules... to start editing CustomRules.js.
Add this inside the Handlers class
class Handlers
{
RulesString("&Process filter", true)
RulesStringValue(0, "&Chrome", "chrome")
RulesStringValue(1, "&Firefox", "firefox")
RulesStringValue(2, "&Internet Explorer", "iexplore")
RulesStringValue(3, "&Opera", "opera")
RulesStringValue(4, "&PhantomJS", "phantomjs")
RulesStringValue(5, "&Custom...", "%CUSTOM%")
public static var sProcessName: String = null;
// leave the rest of the Handlers class as-is
}
Add this inside the OnBeforeRequest function
static function OnBeforeRequest(oSession: Session) {
if (null != sProcessName) {
var processInfo = oSession["X-PROCESSINFO"];
if(!processInfo || !processInfo.StartsWith(sProcessName + ":")){
oSession["ui-hide"] = "true";
FiddlerObject.StatusText = " Process filter: " + sProcessName;
}
}
// leave the rest of the OnBeforeRequest function as-is
}
Fiddler will apply your changes as soon as you save the CustomRules.js file.
To use, go to Rules > Process Filter and choose a browser, or use Custom and type in your executable's basename (e.g. iexplore).
Filtering applies to requests that start after you choose a process. Previous requests and Fiddler Composer requests are not affected.

Basically a duplicate of Filter Fiddler traffic . Just go to the Filters tab in Fiddler and then the "Client Process" fieldset and then choose "Show only traffic from " and choose the appropriate process.

Related

Blocking a response whose body matches some condition

In Fiddler, is there a way to block a response if its body contains a particular word?
If Fiddler is capable of this (possibly through FiddlerScript?), that'd be awesome. Otherwise, if there is another tool that would be better, I'd love to hear about it.
A similar question was asked at What is the best way to block specific URL for testing?, but in my case I don't want to block a URI entirely, but rather only block certain responses from that URI, so that answer is not applicable.
Possible Leads
In FiddlerScript, there appears to be a function called utilFindInResponse, which might be incorporated into OnBeforeResponse like this:
static function OnBeforeResponse(oSession: Session) {
...
if (oSession.utilFindInResponse("WordToBlock", false) > -1){
oSession.responseCode = "404";
}
}
Is this the right way to go about a response-blocker that searches for a particular word?
Yes, you're on the right track, but you should probably ensure that the response in question is HTML (or whatever text format you're expecting) before trying to search it.
static function OnBeforeResponse(oSession: Session) {
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "text/"))
{
oSession.utilDecodeResponse();
if (oSession.utilFindInResponse("WordToBlock", false) > -1)
{
oSession.responseCode = 404;
oSession.utilSetResponseBody("blocked");
}
}
}
Also, keep in mind that the Streaming option (see Fiddler's toolbar) must be disabled for this code to work as you expect.

Need to update request values in saved fiddler sessions

I need to update the response value of my saved fiddler session.Suppose i have a saved a fiddler session of any service which has 10-20 methods in it.
Now I want to update the request value(e.g hostname) in my saved fiddler session and want to replay it sequentially.
You can easily write script that modifies any aspect of Sessions. Click Rules > Customize Rules. Inside the Handlers class add a new block like e.g.
public static ContextAction("Set MIME...")
function dosetmime(oS: Session[])
{
var s = FiddlerObject.prompt("Enter the Content-Type value", "image/jpeg", "Set MIME");
for (var i: int=0; i<oS.Length; i++)
{
oS[i].oResponse["Content-Type"] = s;
}
}
Save the script and you now have a new Context Menu command "Set MIME" that changes the response Content-Type header of each selected Session.

Fiddler Script - SaveResponseBody()

I want to save all png images that are loaded along with some webpage into a separate folder.
I am using below code with in Fiddler Script [CustomRules.js].
static function OnBeforeResponse(oSession: Session)
{
if(oSession.url.EndsWith(".png"))
{
oSession.SaveResponseBody();
}
//Actual content of OnBeforeResponse function.
}
Problem here is, I was unable to find any image got saved within Program files/Documents.
Where do “SaveResponseBody()” will save the HTTP Response Body?
Can we give our own custom folder?
My Fiddler version is (v4.4.5.6)
The default SaveResponseBody() method saves the files to your \Documents\Fiddler2\Captures\ folder. If you want to use a different name, use the overload that accepts a filename. You should check the Response's status code is 200 to ensure that you're not trying to save off HTTP/304 responses which won't contain a body. Also, rather than looking at the URL, you probably want to check the response's type.
So you end up with something like this:
if ((oSession.responseCode == 200) &&
oSession.oResponse.headers.ExistsAndContains("Content-Type", "image/png"))
{
SaveResponseBody("C:\\temp\\" + oSession.SuggestedFilename);
}
Note: The manual way of doing this would be to go to the QuickExec box below the Web Sessions list, type select png and hit Enter, then click File > Export > Selected Sessions > Raw Files.

Dumping Fiddler sessions automatically

I need to do some data analysis on xml data coming in http responses. Is there a way to set fiddler dump these responses automatically on disk?
(I have filtered the responses, dumping the sessions works too)
In a situation like this one I make a simple edit to the OnBeforeResponse function in the Fiddler rules. Choose Rules | Customize Rules and then add something similar to this::
if (oSession.url.Contains(".xml")) {
var directory: String = "C:\\Temp\\XML";
var path: String = System.IO.Path.Combine(directory, Guid.NewGuid() + ".xml");
oSession.SaveResponseBody(path);
}
The line that I am using to 'filter' the requests may not be appropriate for your situation -- you should attempt to repeat the filter condition that you used in the Fiddler UI.\
Hope that helps.

Is it possible to disconnect a client mid-request?

I'm trying to simulate the situation where a client is sending a large POST request to the server and the server (or a load balancer) terminates the client connection halfway through the request.
Is this possible to do with Fiddler? I'm open to other (Windows) tool suggestions as well.
Thanks!
Click Rules > Customize Rules. Scroll to the OnPeekAtRequestHeaders function. Add code like so:
static function OnPeekAtRequestHeaders(oSession: Session) {
if (oSession.uriContains("myupload.php") &&
oSession.oRequest.headers.Exists("Content-Length") &&
oSession.oRequest.headers["Content-Length"] != "0")
{
oSession.oRequest.pipeClient.EndWithRST();
}
}