Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. It’s a freeware application and can debug traffic from any application, including Internet Explorer, Mozilla Firefox, Opera, alot more.
Click here for more information
Click here for more information FiddlerCore shows a couple of examples of how you can program against FiddlerCore. Lets see how we can do it using Windows PowerShell. First, we need to install FiddlerCore. You can download FiddlerCore here. Next, click on FiddlerCoreAPISetup.exe to start the installation.
After the installation is completed you’ll see FiddlerCore.ddl in the folder where you installed FiddlerCore.
Time for some PowerShell. Download the Fiddler.psm1 module and start PowerShell. Use Import-Module to add the module to your current scope. In the example below the location of the module is C:\FiddlerCore\Fiddler.psm1
PS > Import-Module C:\FiddlerCore\Fiddler.psm1When the module is added to your current scope you cab use Get-Command to display the commands (actually functions) avaialable from the module.
Note that the module currently includes three commands: Start-Fiddler, Receive-Fiddler and Stop-Fiddler. You can also use Get-Help to display information about each command. Here’s an example.
PS > Get-Help Start-Fiddler -Full
NAME
Start-Fiddler
SYNOPSIS
Uses FiddlerCore to listen on a specified port.
SYNTAX
Start-Fiddler [-Path] [-ListenPort] [-RegisterAsSystemProxy] [-WhatIf] [-Confirm]
[]
DESCRIPTION
Start-Fiddler loads the FiddlerCore DLL and uses Fiddler.FiddlerApplication to listen on a specified port.
When http(s) traffic is generated Fiddler logs the traffic. The result is exposed through a job interface.
Start-Fiddler requires FiddlerCore which allows you to integrate HTTP/HTTPS traffic viewing and modification
capabilities into your .NET application.
PARAMETERS
-Path
Specifies the path to the assembly DLL file that contain the types (FiddlerCore.dll).
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters?
-ListenPort
Specifies the Port that Fiddler listens to.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters?
-RegisterAsSystemProxy []
Registers as the system proxy, default set to False.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters?
-WhatIf []
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters?
-Confirm []
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters?
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".
INPUTS
OUTPUTS
NOTES
Start-Fiddler requires FiddlerCore which allows you to integrate HTTP/HTTPS traffic viewing and
modification capabilities into your .NET application.
-------------------------- EXAMPLE 1 --------------------------
C:\PS>Start-Fiddler -Path C:\FiddlerCoreAPI\FiddlerCore.dll -ListenPort 8877 -RegisterAsSystemProxy
Starts Fiddler and listens to Port 8877, registers as the system proxy.
-------------------------- EXAMPLE 2 --------------------------
C:\PS>Start-Fiddler -Path C:\FiddlerCoreAPI\FiddlerCore.dll -ListenPort 8877 -RegisterAsSystemProxy -Whatif
Displays what would happen if you run Start-Fiddler.
RELATED LINKS
https://www.fiddler2.com/fiddler/core/
Let’s go ahead and start Fiddler and do some monitoring. As you might have guessed, the Start-Fiddler command uses Fiddler.FiddlerApplication to listen on a specified port. In the example below the -RegisterAsSystemProxy parameter is used. Internet Explorer and many other applications use the system proxy by default and are notified when it changes. When Start-Fiddler is used with the -RegisterAsSystemProxy parameter the Proxy Server checkbox in Local Area Network (LAN) Settings is checked.
PS > Start-Fiddler -Path C:\FiddlerCoreAPI\FiddlerCore.dll -ListenPort 8877 -RegisterAsSystemProxy
Here’s what happens to the Local Area Network (LAN) Setting in Internet Explorer when the RegisterAsSystemProxy parameter is used.
In the resource monitor you’ll also notice that PowerShell is Listening to the Port you specified as input to ListenPort.
The Start-Fiddler function actually loads the FiddlerCore DLL and uses Fiddler.FiddlerApplication to listen on a specified port. When starting Fiddler.FiddlerApplication the Startup() method is used, here’s a reference post. In this version the function only allows two inputs, ListenPort and RegisterAsSystemProxy. As soon as I get some time off, i’ll update the function (and module) to support even more cool fiddler stuff. Next, the function subscribes to an event using Register-ObjectEvent. In this version the arguments are simply outputted in the Action. Finally, two script variables are created. These are used to keep track of the Event and background job.
Now we can generate some traffic. Start up Internet Explorer and surf the web for a while. In this example I’m checking out www.bing.com.
When your done, type Receive-Fiddler in powershell.
Notice how the traffic generated from Internet Explorer is returned in PowerSHell. Pretty Cool.
The Receive-Fiddler function uses Receive-Job to get the result from the background job created by the event. The function also supports the -Keep parameter which allows you to save the results so that you can receive them again.
Let’s do some more fiddling. In this example I use Internet Explorer and navigate to www.powershell.nu. Back in PowerShell, I use Receive-Fiddler, but this time i store the result in a variable
PS > $result = Receive-FiddlerCalling the variable displays the logged traffic.
PS > $result | Select-Object -First 1
BitFlags : None
isHTTPS : False
isFTP : False
LocalProcessID : 1040
SuggestedFilename : 190.txt
bypassGateway : False
clientPort : 49407
state : ReadingResponse
PathAndQuery : /
fullUrl : http://www.powershell.nu/
url : www.powershell.nu/
host : www.powershell.nu
hostname : www.powershell.nu
port : 80
id : 190
clientIP : ::ffff:127.0.0.1
responseCode : 0
bHasResponse : False
bBufferResponse : False
Timers : ClientConnected: 21:14:29.027, ClientBeginRe
ateway Determination: 0ms, DNS Lookup: 13ms,
ected: 21:14:29.074,FiddlerBeginRequest: 21:
esponse: 21:14:30.715,ServerDoneResponse: 21
neResponse: 21:14:31.199, Overall Elapsed: 0
ViewItem :
isTunnel : False
oResponse : Fiddler.ServerChatter
oRequest : Fiddler.ClientChatter
oFlags : {x-clientport, x-responsebodytransferlength,
requestBodyBytes : {}
responseBodyBytes :
m_clientIP : ::ffff:127.0.0.1
m_clientPort : 49407
m_hostIP : 217.25.34.124
There are a couple of properties available that contain logged information such as: fullUrl, hostnam, port and so on. Some properties contain simple string values and others contain objects with even more information. As an example, let’s see what oResponse contains.
PS > $result[0].oResponse
MIMEType : text/html
iTTFB : 1640
iTTLB : 2125
bWasForwarded : False
bServerSocketReused : False
headers : HTTP/1.1 200 OK
Date: Tue, 15 Mar 2011 20:14:29 GMT
Server: Apache
X-Powered-By: PHP/5.2.16
X-Pingback: http://www.powershell.nu/xmlrpc.php
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
pipeServer :
When your done, use Stop-Fiddler to proparly remove the event, background job and Shut Down Fiddler. Here’s an example:
PS > Stop-FiddlerRemember to use Stop-Fiddler to close the Fiddler connection. This is important, if you do not use Stop-Fiddler and simply shut down PowerShell the Local Area Network (LAN) Settings will not be unchecked and Internet Explorer may not work proparly.
What if i forgot to use Stop-Fiddler and closed my PowerShell session? Start Internet Explorer, Click on Internet Options/Connections/Local Area Network (LAN) Settings and uncheck “Use a proxy server for your LAN”..
Note that the Fiddler.psm1 module is not fully tested (or fully completed) and should be used in a test-envirnment only. With that said:Click here to download Fiddler.psm1
[?]
Snyggt jobbat Nicklas!
Jag satt och meckade med [System.Reflection.Assembly], men fick inte riktigt till allt som du visade. Detta ger lite mer klarhet i det hela.
mvh
Dick
Gött
Hey Nicklas,
A useful module, I’ve tweaked the module a bit for my own use as well – http://amonkeysden.tumblr.com/post/5127684898/powershell-and-fiddler
Thanks,
Matt
maby im a bit stupid but i cant import Fiddler.psm1 becurse its not there, but i can import the fiddlercore.dll but that dont do me any good… what am i doing wrong ?
Pingback: PowerShell: Cool Stuff, Error Handling, Remoting, Jobs, AD, SQL « MS Tech BLOG