Guest User

Untitled

a guest
Aug 8th, 2014
3,635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.48 KB | None | 0 0
  1. import System;
  2. import System.Windows.Forms;
  3. import Fiddler;
  4.  
  5. // INTRODUCTION
  6. // This is the FiddlerScript Rules file, which creates some of the menu commands and
  7. // other features of Fiddler. You can edit this file to modify or add new commands.
  8. //
  9. // The original version of this file is named SampleRules.js and it is in the
  10. // \Program Files\Fiddler\ folder. When Fiddler first starts, it creates a copy named
  11. // CustomRules.js inside your \Documents\Fiddler2\Scripts folder. If you make a
  12. // mistake in editing this file, simply delete the CustomRules.js file and restart
  13. // Fiddler. A fresh copy of the default rules will be created from the original
  14. // sample rules file.
  15.  
  16. // GLOBALIZATION NOTE:
  17. // Be sure to save this file with UTF-8 Encoding if using any non-ASCII characters
  18. // in strings, etc.
  19.  
  20. // JScript.NET Reference
  21. // http://fiddler2.com/r/?msdnjsnet
  22. //
  23. // FiddlerScript Reference
  24. // http://fiddler2.com/r/?fiddlerscriptcookbook
  25. //
  26. // FiddlerScript Editor:
  27. // http://fiddler2.com/fiddlerscript-editor
  28.  
  29. class Handlers
  30. {
  31. // The following snippet demonstrates a custom-bound column for the Web Sessions list.
  32. // See http://fiddler2.com/r/?fiddlercolumns for more info
  33. /*
  34. public static BindUIColumn("Method", 60)
  35. function FillMethodColumn(oS: Session): String {
  36. return oS.RequestMethod;
  37. }
  38. */
  39.  
  40. // The following snippet demonstrates how to create a custom tab that shows simple text
  41. /*
  42. public BindUITab("Flags")
  43. static function FlagsReport(arrSess: Session[]):String {
  44. var oSB: System.Text.StringBuilder = new System.Text.StringBuilder();
  45. for (var i:int = 0; i<arrSess.Length; i++)
  46. {
  47. oSB.AppendLine("SESSION FLAGS");
  48. oSB.AppendFormat("{0}: {1}\n", arrSess[i].id, arrSess[i].fullUrl);
  49. for(var sFlag in arrSess[i].oFlags)
  50. {
  51. oSB.AppendFormat("\t{0}:\t\t{1}\n", sFlag.Key, sFlag.Value);
  52. }
  53. }
  54. return oSB.ToString();
  55. }
  56. */
  57.  
  58. // You can create a custom menu like so:
  59. /*
  60. QuickLinkMenu("&Links")
  61. QuickLinkItem("IE GeoLoc TestDrive", "http://ie.microsoft.com/testdrive/HTML5/Geolocation/Default.html")
  62. QuickLinkItem("FiddlerCore", "http://fiddler2.com/fiddlercore")
  63. public static function DoLinksMenu(sText: String, sAction: String)
  64. {
  65. Utilities.LaunchHyperlink(sAction);
  66. }
  67. */
  68.  
  69. public static RulesOption("Hide 304s")
  70. BindPref("fiddlerscript.rules.Hide304s")
  71. var m_Hide304s: boolean = false;
  72.  
  73. // Cause Fiddler to override the Accept-Language header with one of the defined values
  74. public static RulesOption("Request &Japanese Content")
  75. var m_Japanese: boolean = false;
  76.  
  77. // Automatic Authentication
  78. public static RulesOption("&Automatically Authenticate")
  79. BindPref("fiddlerscript.rules.AutoAuth")
  80. var m_AutoAuth: boolean = false;
  81.  
  82. // Cause Fiddler to override the User-Agent header with one of the defined values
  83. RulesString("&User-Agents", true)
  84. BindPref("fiddlerscript.ephemeral.UserAgentString")
  85. RulesStringValue(0,"Netscape &3", "Mozilla/3.0 (Win95; I)")
  86. RulesStringValue(1,"WinPhone7", "Mozilla/4.0 (compatible: MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; SAMSUNG; SGH-i917)")
  87. RulesStringValue(2,"WinPhone8.1", "Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; HTC; PM23300) like Gecko")
  88. RulesStringValue(3,"&Safari5 (Win7)", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1")
  89. RulesStringValue(4,"Safari7 (Mac)", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71")
  90. RulesStringValue(5,"iPad", "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25")
  91. RulesStringValue(6,"iPhone6", "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A405 Safari/8536.25")
  92. RulesStringValue(7,"IE &6 (XPSP2)", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)")
  93. RulesStringValue(8,"IE &7 (Vista)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1)")
  94. RulesStringValue(9,"IE 8 (Win2k3 x64)", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; WOW64; Trident/4.0)")
  95. RulesStringValue(10,"IE &8 (Win7)", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)")
  96. RulesStringValue(11,"IE 9 (Win7)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)")
  97. RulesStringValue(12,"IE 10 (Win8)", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)")
  98. RulesStringValue(13,"IE 11 (Surface2)", "Mozilla/5.0 (Windows NT 6.3; ARM; Trident/7.0; Touch; rv:11.0) like Gecko")
  99. RulesStringValue(14,"IE 11 (Win8.1)", "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko")
  100. RulesStringValue(15,"&Opera", "Opera/9.80 (Windows NT 6.2; WOW64) Presto/2.12.388 Version/12.17")
  101. RulesStringValue(16,"&Firefox 3.6", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.7) Gecko/20100625 Firefox/3.6.7")
  102. RulesStringValue(17,"&Firefox 30", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0")
  103. RulesStringValue(18,"&Firefox Phone", "Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0")
  104. RulesStringValue(19,"&Firefox (Mac)", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0")
  105. RulesStringValue(20,"Chrome", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36")
  106. RulesStringValue(21,"ChromeBook", "Mozilla/5.0 (X11; CrOS armv7l 2913.260.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.99 Safari/537.11")
  107. RulesStringValue(22,"GoogleBot Crawler", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
  108. RulesStringValue(23,"Kindle Fire (Silk)", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.22.79_10013310) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true")
  109. RulesStringValue(24,"&Custom...", "%CUSTOM%")
  110. public static var sUA: String = null;
  111.  
  112. // Cause Fiddler to delay HTTP traffic to simulate typical 56k modem conditions
  113. public static RulesOption("Simulate &Modem Speeds", "Per&formance")
  114. var m_SimulateModem: boolean = false;
  115.  
  116. // Removes HTTP-caching related headers and specifies "no-cache" on requests and responses
  117. public static RulesOption("&Disable Caching", "Per&formance")
  118. var m_DisableCaching: boolean = false;
  119.  
  120. public static RulesOption("Cache Always &Fresh", "Per&formance")
  121. var m_AlwaysFresh: boolean = false;
  122.  
  123. // Force a manual reload of the script file. Resets all
  124. // RulesOption variables to their defaults.
  125. public static ToolsAction("Reset Script")
  126. function DoManualReload() {
  127. FiddlerObject.ReloadScript();
  128. }
  129.  
  130. public static ContextAction("Decode Selected Sessions")
  131. function DoRemoveEncoding(oSessions: Session[]) {
  132. for (var x:int = 0; x < oSessions.Length; x++){
  133. oSessions[x].utilDecodeRequest();
  134. oSessions[x].utilDecodeResponse();
  135. }
  136. UI.actUpdateInspector(true,true);
  137. }
  138.  
  139. static function OnBoot() {
  140. // MessageBox.Show("Fiddler has finished booting");
  141. // System.Diagnostics.Process.Start("iexplore.exe");
  142.  
  143. // UI.ActivateRequestInspector("HEADERS");
  144. // UI.ActivateResponseInspector("HEADERS");
  145. }
  146.  
  147. static function OnShutdown() {
  148. // MessageBox.Show("Fiddler has shutdown");
  149. }
  150.  
  151. static function OnAttach() {
  152. // MessageBox.Show("Fiddler is now the system proxy");
  153. }
  154.  
  155. static function OnDetach() {
  156. // MessageBox.Show("Fiddler is no longer the system proxy");
  157. }
  158.  
  159. static function OnBeforeRequest(oSession: Session) {
  160. // Sample Rule: Color ASPX requests in RED
  161. // if (oSession.uriContains(".aspx")) { oSession["ui-color"] = "red"; }
  162.  
  163. // Sample Rule: Flag POSTs to fiddler2.com in italics
  164. // if (oSession.HostnameIs("www.fiddler2.com") && oSession.HTTPMethodIs("POST")) { oSession["ui-italic"] = "yup"; }
  165.  
  166. // Sample Rule: Break requests for URLs containing "/sandbox/"
  167. // if (oSession.uriContains("/sandbox/")) {
  168. // oSession.oFlags["x-breakrequest"] = "yup"; // Existence of the x-breakrequest flag creates a breakpoint; the "yup" value is unimportant.
  169. // }
  170.  
  171. if ((null != gs_ReplaceToken) && (oSession.url.indexOf(gs_ReplaceToken)>-1)) { // Case sensitive
  172. oSession.url = oSession.url.Replace(gs_ReplaceToken, gs_ReplaceTokenWith);
  173. }
  174. if ((null != gs_OverridenHost) && (oSession.host.toLowerCase() == gs_OverridenHost)) {
  175. oSession["x-overridehost"] = gs_OverrideHostWith;
  176. }
  177.  
  178. if ((null!=bpRequestURI) && oSession.uriContains(bpRequestURI)) {
  179. oSession["x-breakrequest"]="uri";
  180. }
  181.  
  182. if ((null!=bpMethod) && (oSession.HTTPMethodIs(bpMethod))) {
  183. oSession["x-breakrequest"]="method";
  184. }
  185.  
  186. if ((null!=uiBoldURI) && oSession.uriContains(uiBoldURI)) {
  187. oSession["ui-bold"]="QuickExec";
  188. }
  189.  
  190. if (m_SimulateModem) {
  191. // Delay sends by 300ms per KB uploaded.
  192. oSession["request-trickle-delay"] = "300";
  193. // Delay receives by 150ms per KB downloaded.
  194. oSession["response-trickle-delay"] = "150";
  195. }
  196.  
  197. if (m_DisableCaching) {
  198. oSession.oRequest.headers.Remove("If-None-Match");
  199. oSession.oRequest.headers.Remove("If-Modified-Since");
  200. oSession.oRequest["Pragma"] = "no-cache";
  201. }
  202.  
  203. // User-Agent Overrides
  204. if (null != sUA) {
  205. oSession.oRequest["User-Agent"] = sUA;
  206. }
  207.  
  208. if (m_Japanese) {
  209. oSession.oRequest["Accept-Language"] = "ja";
  210. }
  211.  
  212. if (m_AutoAuth) {
  213. // Automatically respond to any authentication challenges using the
  214. // current Fiddler user's credentials. You can change (default)
  215. // to a domain\\username:password string if preferred.
  216. //
  217. // WARNING: This setting poses a security risk if remote
  218. // connections are permitted!
  219. oSession["X-AutoAuth"] = "(default)";
  220. }
  221.  
  222. if (m_AlwaysFresh && (oSession.oRequest.headers.Exists("If-Modified-Since") || oSession.oRequest.headers.Exists("If-None-Match")))
  223. {
  224. oSession.utilCreateResponseAndBypassServer();
  225. oSession.responseCode = 304;
  226. oSession["ui-backcolor"] = "Lavender";
  227. }
  228. }
  229.  
  230. // This function is called immediately after a set of request headers has
  231. // been read from the client. This is typically too early to do much useful
  232. // work, since the body hasn't yet been read, but sometimes it may be useful.
  233. //
  234. // For instance, see
  235. // http://blogs.msdn.com/b/fiddler/archive/2011/11/05/http-expect-continue-delays-transmitting-post-bodies-by-up-to-350-milliseconds.aspx
  236. // for one useful thing you can do with this handler.
  237. //
  238. // Note: oSession.requestBodyBytes is not available within this function!
  239. /*
  240. static function OnPeekAtRequestHeaders(oSession: Session) {
  241. }
  242. */
  243.  
  244. //
  245. // If a given session has response streaming enabled, then the OnBeforeResponse function
  246. // is actually called AFTER the response was returned to the client.
  247. //
  248. // In contrast, this OnPeekAtResponseHeaders function is called before the response headers are
  249. // sent to the client (and before the body is read from the server). Hence this is an opportune time
  250. // to disable streaming (oSession.bBufferResponse = true) if there is something in the response headers
  251. // which suggests that tampering with the response body is necessary.
  252. //
  253. // Note: oSession.responseBodyBytes is not available within this function!
  254. //
  255. static function OnPeekAtResponseHeaders(oSession: Session) {
  256. //FiddlerApplication.Log.LogFormat("Session {0}: Response header peek shows status is {1}", oSession.id, oSession.responseCode);
  257. if (m_DisableCaching) {
  258. oSession.oResponse.headers.Remove("Expires");
  259. oSession.oResponse["Cache-Control"] = "no-cache";
  260. }
  261.  
  262. if ((bpStatus>0) && (oSession.responseCode == bpStatus)) {
  263. oSession["x-breakresponse"]="status";
  264. oSession.bBufferResponse = true;
  265. }
  266.  
  267. if ((null!=bpResponseURI) && oSession.uriContains(bpResponseURI)) {
  268. oSession["x-breakresponse"]="uri";
  269. oSession.bBufferResponse = true;
  270. }
  271.  
  272. }
  273.  
  274. static function OnBeforeResponse(oSession: Session) {
  275. if (m_Hide304s && oSession.responseCode == 304) {
  276. oSession["ui-hide"] = "true";
  277.  
  278. }
  279. if (oSession.hostname == "api.twitch.tv") {
  280. if (/^\/api\/videos\/[A-Za-z0-9]+\?as3=t.*$/.test(oSession.PathAndQuery)) {
  281. oSession.utilDecodeResponse();
  282. var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
  283. oBody = oBody.replace(/"upkeep":"fail"/g, '"upkeep":"pass"');
  284. oSession.utilSetResponseBody(oBody);
  285. }
  286. }
  287. }
  288.  
  289. /*
  290. // This function executes just before Fiddler returns an error that it has
  291. // itself generated (e.g. "DNS Lookup failure") to the client application.
  292. // These responses will not run through the OnBeforeResponse function above.
  293. static function OnReturningError(oSession: Session) {
  294. }
  295. */
  296. /*
  297. // This function executes after Fiddler finishes processing a Session, regardless
  298. // of whether it succeeded or failed. Note that this typically runs AFTER the last
  299. // update of the Web Sessions UI listitem, so you must manually refresh the Session's
  300. // UI if you intend to change it.
  301. static function OnDone(oSession: Session) {
  302. }
  303. */
  304.  
  305. // The Main() function runs everytime your FiddlerScript compiles
  306. static function Main() {
  307. var today: Date = new Date();
  308. FiddlerObject.StatusText = " CustomRules.js was loaded at: " + today;
  309.  
  310. // Uncomment to add a "Server" column containing the response "Server" header, if present
  311. // UI.lvSessions.AddBoundColumn("Server", 50, "@response.server");
  312.  
  313. // Uncomment to add a global hotkey (Win+G) that invokes the ExecAction method below...
  314. // UI.RegisterCustomHotkey(HotkeyModifiers.Windows, Keys.G, "screenshot");
  315. }
  316.  
  317. // These static variables are used for simple breakpointing & other QuickExec rules
  318. BindPref("fiddlerscript.ephemeral.bpRequestURI")
  319. public static var bpRequestURI:String = null;
  320.  
  321. BindPref("fiddlerscript.ephemeral.bpResponseURI")
  322. public static var bpResponseURI:String = null;
  323.  
  324. BindPref("fiddlerscript.ephemeral.bpMethod")
  325. public static var bpMethod: String = null;
  326.  
  327. static var bpStatus:int = -1;
  328. static var uiBoldURI: String = null;
  329. static var gs_ReplaceToken: String = null;
  330. static var gs_ReplaceTokenWith: String = null;
  331. static var gs_OverridenHost: String = null;
  332. static var gs_OverrideHostWith: String = null;
  333.  
  334. // The OnExecAction function is called by either the QuickExec box in the Fiddler window,
  335. // or by the ExecAction.exe command line utility.
  336. static function OnExecAction(sParams: String[]): Boolean {
  337.  
  338. FiddlerObject.StatusText = "ExecAction: " + sParams[0];
  339.  
  340. var sAction = sParams[0].toLowerCase();
  341. switch (sAction) {
  342. case "bold":
  343. if (sParams.Length<2) {uiBoldURI=null; FiddlerObject.StatusText="Bolding cleared"; return false;}
  344. uiBoldURI = sParams[1]; FiddlerObject.StatusText="Bolding requests for " + uiBoldURI;
  345. return true;
  346. case "bp":
  347. FiddlerObject.alert("bpu = breakpoint request for uri\nbpm = breakpoint request method\nbps=breakpoint response status\nbpafter = breakpoint response for URI");
  348. return true;
  349. case "bps":
  350. if (sParams.Length<2) {bpStatus=-1; FiddlerObject.StatusText="Response Status breakpoint cleared"; return false;}
  351. bpStatus = parseInt(sParams[1]); FiddlerObject.StatusText="Response status breakpoint for " + sParams[1];
  352. return true;
  353. case "bpv":
  354. case "bpm":
  355. if (sParams.Length<2) {bpMethod=null; FiddlerObject.StatusText="Request Method breakpoint cleared"; return false;}
  356. bpMethod = sParams[1].toUpperCase(); FiddlerObject.StatusText="Request Method breakpoint for " + bpMethod;
  357. return true;
  358. case "bpu":
  359. if (sParams.Length<2) {bpRequestURI=null; FiddlerObject.StatusText="RequestURI breakpoint cleared"; return false;}
  360. bpRequestURI = sParams[1];
  361. FiddlerObject.StatusText="RequestURI breakpoint for "+sParams[1];
  362. return true;
  363. case "bpa":
  364. case "bpafter":
  365. if (sParams.Length<2) {bpResponseURI=null; FiddlerObject.StatusText="ResponseURI breakpoint cleared"; return false;}
  366. bpResponseURI = sParams[1];
  367. FiddlerObject.StatusText="ResponseURI breakpoint for "+sParams[1];
  368. return true;
  369. case "overridehost":
  370. if (sParams.Length<3) {gs_OverridenHost=null; FiddlerObject.StatusText="Host Override cleared"; return false;}
  371. gs_OverridenHost = sParams[1].toLowerCase();
  372. gs_OverrideHostWith = sParams[2];
  373. FiddlerObject.StatusText="Connecting to [" + gs_OverrideHostWith + "] for requests to [" + gs_OverridenHost + "]";
  374. return true;
  375. case "urlreplace":
  376. if (sParams.Length<3) {gs_ReplaceToken=null; FiddlerObject.StatusText="URL Replacement cleared"; return false;}
  377. gs_ReplaceToken = sParams[1];
  378. gs_ReplaceTokenWith = sParams[2].Replace(" ", "%20"); // Simple helper
  379. FiddlerObject.StatusText="Replacing [" + gs_ReplaceToken + "] in URIs with [" + gs_ReplaceTokenWith + "]";
  380. return true;
  381. case "allbut":
  382. case "keeponly":
  383. if (sParams.Length<2) { FiddlerObject.StatusText="Please specify Content-Type to retain during wipe."; return false;}
  384. UI.actSelectSessionsWithResponseHeaderValue("Content-Type", sParams[1]);
  385. UI.actRemoveUnselectedSessions();
  386. UI.lvSessions.SelectedItems.Clear();
  387. FiddlerObject.StatusText="Removed all but Content-Type: " + sParams[1];
  388. return true;
  389. case "stop":
  390. UI.actDetachProxy();
  391. return true;
  392. case "start":
  393. UI.actAttachProxy();
  394. return true;
  395. case "cls":
  396. case "clear":
  397. UI.actRemoveAllSessions();
  398. return true;
  399. case "g":
  400. case "go":
  401. UI.actResumeAllSessions();
  402. return true;
  403. case "goto":
  404. if (sParams.Length != 2) return false;
  405. Utilities.LaunchHyperlink("http://www.google.com/search?hl=en&btnI=I%27m+Feeling+Lucky&q=" + Utilities.UrlEncode(sParams[1]));
  406. return true;
  407. case "help":
  408. Utilities.LaunchHyperlink("http://fiddler2.com/r/?quickexec");
  409. return true;
  410. case "hide":
  411. UI.actMinimizeToTray();
  412. return true;
  413. case "log":
  414. FiddlerApplication.Log.LogString((sParams.Length<2) ? "User couldn't think of anything to say..." : sParams[1]);
  415. return true;
  416. case "nuke":
  417. UI.actClearWinINETCache();
  418. UI.actClearWinINETCookies();
  419. return true;
  420. case "screenshot":
  421. UI.actCaptureScreenshot(false);
  422. return true;
  423. case "show":
  424. UI.actRestoreWindow();
  425. return true;
  426. case "tail":
  427. if (sParams.Length<2) { FiddlerObject.StatusText="Please specify # of sessions to trim the session list to."; return false;}
  428. UI.TrimSessionList(int.Parse(sParams[1]));
  429. return true;
  430. case "quit":
  431. UI.actExit();
  432. return true;
  433. case "dump":
  434. UI.actSelectAll();
  435. UI.actSaveSessionsToZip(CONFIG.GetPath("Captures") + "dump.saz");
  436. UI.actRemoveAllSessions();
  437. FiddlerObject.StatusText = "Dumped all sessions to " + CONFIG.GetPath("Captures") + "dump.saz";
  438. return true;
  439.  
  440. default:
  441. if (sAction.StartsWith("http") || sAction.StartsWith("www")) {
  442. System.Diagnostics.Process.Start(sParams[0]);
  443. return true;
  444. }
  445. else
  446. {
  447. FiddlerObject.StatusText = "Requested ExecAction: '" + sAction + "' not found. Type HELP to learn more.";
  448. return false;
  449. }
  450. }
  451. }
  452. }
Advertisement
Add Comment
Please, Sign In to add comment