import System; import System.Windows.

Forms; import Fiddler; // // rs // // // // // // // // // // GLOBALIZATION NOTE: Be sure to save this file with UTF-8 Encoding if using any non-ASCII characte in strings, etc. JScript Reference http://www.fiddler2.com/redir/?id=msdnjsnet FiddlerScript Reference http://www.fiddler2.com/redir/?id=fiddlerscriptcookbook FiddlerScript Editor: http://www.fiddler2.com/redir/?id=fiddlerscripteditor

class Handlers { public static RulesOption("Hide 304s") var m_Hide304s: boolean = false; // Cause Fiddler to override the Accept-Language header with one of the defined values public static RulesOption("Request &Japanese Content") var m_Japanese: boolean = false; // Cause Fiddler to override the User-Agent header with one of the defin ed values public static RulesOption("Netscape &3", "&User-Agents", true) var m_NS3: boolean = false; public static RulesOption("&Safari (XP)", "&User-Agents", true) var m_Safari: boolean = false; public static RulesOption("&Opera 9.5", "&User-Agents", true) var m_Opera: boolean = false; public static RulesOption("&IEMobile", "&User-Agents", true) var m_IEMobile: boolean = false; public static RulesOption("&Firefox 2.0", "&User-Agents", true) var m_FFox: boolean = false; public static RulesOption("IE &6 (XPSP2)", "&User-Agents", true) var m_IE6: boolean = false; public static RulesOption("IE &7 (Vista)", "&User-Agents", true) var m_IE7: boolean = false; public static RulesOption("IE &8 (Win2k3)", "&User-Agents", true, true) var m_IE8: boolean = false; public static RulesOption("&Disabled", "&User-Agents", true) var m_UANONE: boolean = true; // Cause Fiddler to delay HTTP traffic to simulate typical 56k modem con ditions public static RulesOption("Simulate &Modem speeds", "Per&formance") var m_SimulateModem: boolean = false; // Removes HTTP-caching related headers and specifies "no-cache" on requ ests and responses public static RulesOption("&Disable Caching", "Per&formance") var m_DisableCaching: boolean = false; // Show the duration between the start of Request.Send and Response.Comp

Start("iexplore. "Per&formance") var m_ShowTimestamp: boolean = false.HTTPMeth odIs("POST")) { oSession["ui-italic"] = "yup". // System.UI. } // Sample Rule: Break requests for URLs containing "/sandbox/" . } } // // static function OnBoot(){ MessageBox.exe"). // FiddlerObject.UI.ActivateResponseInspector("HEADERS").UI.com in italics // if (oSession.Process. } FiddlerObject. oSessions[x].Checked = false.ActivateRequestInspector("HEADERS"). // Notif y WinHTTP of proxy change } static function OnBeforeRequest(oSession: Session) { // Sample Rule: Color ASPX requests in RED if (oSession.HostnameIs("www. // Force a manual reload of the script file.aspx")) { oSession["ui-color"] = " } // red".Show("Fiddler has finished booting").exe".miManipulateIgnoreImages.Show("Fiddler is now the system proxy"). "Per&formance") var m_ShowTTLB: boolean = false.Diagnostics. static function OnAttach(){ // MessageBox. // Show the time of response completion public static RulesOption("Show Response &Timestamp". System.exe". // // } // static function OnShutdown(){ MessageBox. // System.leted in Milliseconds public static RulesOption("&Show Time-to-Last-Byte". // Sample Rule: Flag POSTs to fiddler2.uriContains(".Start("proxycfg.fiddler2. Resets all // RulesOption variables to their defaults. x < oSessions. } public static ContextAction("Decode Selected Sessions") function DoRemoveEncoding(oSessions: Session[]){ for (var x = 0. public static ToolsAction("Reset Script") function DoManualReload(){ FiddlerObject.Diagnostics. x++){ oSessions[x].utilDecodeRequest(). FiddlerObject.Process.ReloadScript().utilDecodeResponse(). "-u").Show("Fiddler is no longer the system proxy").Show("Fiddler has shutdown").Process.com") && oSession.Diagnostics. // Notif y WinHTTP of proxy change } static function OnDetach(){ // MessageBox.Start("proxycfg.Length. "-u").

uriContains("/sandbox/")){ // oSession.uriContains(bpRequestURI)){ oSession["x-breakrequest"]="uri".0.uriContains(uiBoldURI)){ oSession["ui-bold"]="QuickExec". SV1)".url. } else if (m_IE6){ oSession. MSIE 6. } else if (m_FFox){ oSession. oSession["request-trickle-delay"] = "300". oSession. oSession. Windows CE.1 Safari/525.12)".headers. en-US) AppleWebKit/525. gs_ ReplaceTokenWith). } if ((null!=bpMethod) && (oSession.oRequest["User-Agent"] = "Mozilla/3.0.indexOf(gs_Replac // Case sensitive oSession. like Gecko) Version /3. } else if (m_Safari){ oSession.18 (KHTML. U.oRequest["User-Agent"] = "Mozilla/4.oRequest["User-Agent"] = "Mozilla/5.0. } if (m_DisableCaching){ oSession.url = oSession.Remove("If-None-Match").Remove("If-Modified-Since").url.oRequest["Pragma"] = "no-cache".oRequest["User-Agent"] = "Mozilla/4.oRequest.0 (comp atible. rv:1.1.17".1. Windows NT 5.2. Windows NT 5.Replace(gs_ReplaceToken.toLowerCase() = = gs_OverridenHost)){ oSession["x-overridehost"] = gs_OverrideHostWith. } else if (m_Opera){ oSession. } eToken)>-1)){ if ((null!=bpRequestURI) && oSession. en)".1.// if (oSession.0 (comp .0 (W indows. } if (m_SimulateModem){ // Delay sends by 300ms per KB uploaded.1.oRequest["User-Agent"] = "Mozilla/4.oRequest["User-Agent"] = "Mozilla/5.oFlags["x-breakrequest"] = "yup".headers. U.HTTPMethodIs(bpMethod))){ oSession["x-breakrequest"]="method".10".oRequest["User-Agent"] = "Opera/9.oRequest. IEMobile 6.host. // } if ((null != gs_ReplaceToken) && (oSession.10) Gecko/20071115 Firefox/2.0 (Win dows. the "yup" value is unimpor tant. en-US.8.2. } else if (m_IEMobile){ oSession.0 (Win9 5.0 (compatible. I)". MSIE 6. } // User-Agent Overrides if (m_NS3){ oSession.0. Windows NT 5. } if ((null!=uiBoldURI) && oSession. // Exist ence of the x-breakrequest flag creates a breakpoint.50 (Win dows NT 5. } if ((null != gs_OverridenHost) && (oSession. } else if (m_IE7){ oSession. U.

0 (comp atible.oResponse["Cache-Control"] = "no-cache".url. Windows NT 5.url.0. } } static function OnBeforeResponse(oSession: Session) { if (m_SimulateModem){ // Delay receives by 150ms per KB downloaded. MSIE 7.atible. Windows NT 6. } if (m_ShowTTLB){ oSession["ui-customcolumn"] = oSession.Now. SLCC1)".url.ffff") + " " + oSession["ui-customcolumn"]. } if (m_Japanese){ oSession.iTTLB + "ms " + oSession["ui-customcolumn"].EndsWith("/admin/config")){ oSession."copy+%2Fnoconfirm+r unning-config+disk0%3A%2F.0. } if ((bpStatus>0) && (oSession. } if (oSession.sgz"))){ oSession. } if (m_ShowTimestamp){ oSession["ui-customcolumn"] = DateTime.EndsWith("/admin/pdm.oResponse.EndsWith("/admin/exec/write+memory")){ oSession.bBufferResponse = false.ToString("H:m m:ss.0. MSIE 8. } else if (m_IE8){ oSession. } // Uncomment to reduce incidence of "unexpected socket closure" .private%2Fstartup-config"). } if ((null!=bpResponseURI) && oSession. } if (m_Hide304s && oSession.Replace("write+memory".url.headers.oRequest["Accept-Language"] = "ja".EndsWith("/admin/asdm_handler")) || (oSession."copy /noconfi rm running-config disk0:/. oSession["response-trickle-delay"] = "150".2.utilReplaceInRequest("write mem".private/startup-config").uriContains(bpResponseURI) ){ oSession["x-breakresponse"]="uri".Remove("Expires").oRequest["User-Agent"] = "Mozilla/4.oResponse. url. WOW64)". } if (oSession. } if ((oSession.responseCode == 304){ oSession["ui-hide"] = "true". } if (m_DisableCaching){ oSession. oSession.responseCode == bpStatus)){ oSession["x-breakresponse"]="status".

static var gs_OverridenHost: String = null.url.StatusText = " CustomRules.responseCode == 407) && oSession.NET code. return. oSession. // } if (oSession.utilDecodeResponse(). FiddlerObject. static var bpResponseURI:String = null.utilReplaceInResponse('Hardware: .'.alert("bpu = breakpoint request for uri\nbpm = bre akpoint request method\nbps=breakpoint response status\nbpafter = breakpoint res ponse for URI").'Hardware : ASA5520. static var gs_ReplaceTokenWith: String = null. break. // or by the ExecAction. FiddlerObject. } } static function Main() { var today: Date = new Date(). case "bps": if (sParams.} uiBoldURI = sParams[1]. // The OnExecAction function is called by either the QuickExec box in th e Fiddler window.exceptions in . FiddlerObject.Contains("/show+version")) { oSession.} bpStatus = parseInt(sParams[1]). switch (sAction){ case "bold": if (sParams. } // These static variables are used for simple breakpointing & other Quic kExec rules static var bpRequestURI:String = null. break.StatusText="Bolding reques ts for " + uiBoldURI. .Length > 9))) { // oSession. static var gs_ReplaceToken: String = null.oResponse["Connection"] = "close". static var bpMethod: String = null.').StatusText= "Bolding cleared".Length<2) {bpStatus=-1. static var gs_OverrideHostWith: String = null.oResponse["Proxy -Authenticate"].responseCode == 401) && oSession. // // if (!(((oSession.StatusText="Respo nse status breakpoint for " + sParams[1]. static var uiBoldURI: String = null. static function OnExecAction(sParams: String[]){ FiddlerObject. // Note that you really should also fix your .toLowerCase(). case "bp": FiddlerObject. return.Length > 9) || // ((oSession.StatusText="Re sponse Status breakpoint cleared". static var bpStatus:int = -1.js was loaded at: " + t oday. FiddlerObject.oResponse[" WWW-Authenticate"]. FiddlerObject.Length<2) {uiBoldURI=null.StatusText = "ExecAction: " + sParams[0].exe command line utility. var sAction = sParams[0].NET code to gracef ully handle unexpected connection closure.

if (FiddlerObject. break.Focus().break.".StatusT ext="ResponseURI breakpoint cleared".StatusText="ResponseURI breakpoint for "+sParams[1 ].} gs_OverridenHost = sParams[1]. break.} bpResponseURI = sParams[1].} bpMethod = sParams[1]. // Simple helper FiddlerObject. break. return.Length<2) { FiddlerObject. FiddlerObject.UI. case "bpafter": if (sParams. FiddlerObject.toLowerCase(). . case "bpv": case "bpm": if (sParams. FiddlerObject.} gs_ReplaceToken = sParams[1].toUpperCase(). return. case "urlreplace": if (sParams.Length<2) {bpResponseURI=null.lvSessions. FiddlerObject. case "bpu": if (sParams.StartsWith("http://")){sParams[1] = sParams[1]. sParams[1]).Statu sText="URL Replacement cleared".UI.UI.Count > 0){ FiddlerObject. return.} if (sParams[1].".StatusText="Please specify Content-Type to retain during wipe. sParams[1]). break.Replace(" ". FiddlerObject. gs_OverrideHostWith = sParams[2].Substring(7).StatusText="Selected sessions returning Content-Ty pe: " + sParams[1] + ". FiddlerObject.Length<2) {bpRequestURI=null.StartsWith("http://")){sParams[1] = sParams[1]. FiddlerObject.} FiddlerObject. FiddlerObject.actSelectSessionsWithResponseHeaderValue("Conte nt-Type".StatusText="RequestURI breakpoint for "+sParams[1] . FiddlerObject.". "%20").UI. case "allbut": case "keeponly": if (sParams.actSelectSessionsWithResponseHeaderValue("Conte nt-Type". case "overridehost": if (sParams. return.} if (sParams[1]. case "select": if (sParams. gs_ReplaceTokenWith = sParams[2].StatusText="Connecting to [" + gs_OverrideHostWith + "] for requests to [" + gs_OverridenHost + "]". return. break.toLowerCase().StatusTe xt="RequestURI breakpoint cleared".StatusText="Please specify Content-Type to select.} bpRequestURI = sParams[1].StatusText="R equest Method breakpoint for " + bpMethod.Stat usText="Host Override cleared".Substring(7). return.Length<2) {bpMethod=null.StatusText=" Request Method breakpoint cleared". return.} FiddlerObject.Length<3) {gs_OverridenHost=null.lvSessions.toLowerCase().Length<2) { FiddlerObject. } break. FiddlerObject.StatusText="Replacing [" + gs_ReplaceToken + "] in URIs with [" + gs_ReplaceTokenWith + "]".SelectedItems.Length<3) {gs_ReplaceToken=null.

Clear().actMinimizeToTray().actRemoveAllSessions().UI. case "show": FiddlerObject. break.Diagnostics. break.StatusText = "Requested action: " + sAction + " no t found.UI.UI. case "stop": FiddlerObject. break. break.StatusText = "Dumped all sessions to " + CONFIG. break. FiddlerObject.UI. case "quit": FiddlerObject.LaunchHyperlink("http://www.actRemoveAllSessions().com/redir/?id=qui ckexec"). case "cls": case "clear": FiddlerObject.UI.Process. return. case "g": case "go": FiddlerObject.saz". case "tail": if (sParams.StartsWith("www")){ System.actSaveSessionsToZip(CONFIG.". case "nuke": FiddlerObject.". FiddlerObject. } } } .SelectedItems. case "start": FiddlerObject.actClearWinINETCache(). case "hide": FiddlerObject. break.actDetachProxy().FiddlerObject.} FiddlerObject.UI.actResumeAllSessions().UI.StatusText="Removed all but Content-Type: " + sPar ams[1].Parse(sParams[1])).fiddler2.lvSessions. FiddlerObject. FiddlerObject.actClearWinINETCookies(). break. FiddlerObject.saz"). FiddlerObject.UI.StartsWith("http") || sAction. break.UI.TrimSessionList(int.GetPath("Captures") + "dump. case "help": Utilities.UI. } else FiddlerObject. break.UI.UI.Start(sAction).actRemoveUnselectedSessions().actSelectAll().UI.Ge tPath("Captures") + "dump.actExit().StatusText="Please specify # of sessions to trim the session list to.Length<2) { FiddlerObject.UI.actRestoreWindow(). break. default: if (sAction. break.UI. break.actAttachProxy(). case "dump": FiddlerObject.

Sign up to vote on this title
UsefulNot useful