Cookie Injector

Inject Cookie String From Wireshark Dump Into Any Webpage

  1. // ==UserScript==
  2. // @name Cookie Injector
  3. // @namespace BearsWithWings
  4. // @description Inject Cookie String From Wireshark Dump Into Any Webpage
  5. // @version 2.0
  6. // @include *
  7. // @exclude https?://gmail.com/*
  8. // @exclude https?://mail.google.com/*
  9. // ==/UserScript==
  10.  
  11. //Anonomyous function wrapper
  12. (function (){
  13. //Ensure that there is only one instance of the cookieInjector Object
  14. if(typeof this["cookieInjector"] == "undefined"){
  15. cookieInjector = {};
  16. }
  17.  
  18. //Make a local refrence to the cookie Injector object to save on typing
  19. var cI = cookieInjector;
  20. //Make the cookieInjector object globally viewable
  21. unsafeWindow['cookieInjector'] = cI;
  22. /**
  23. * Cookie Injector createDiv function
  24. * Sets up the cookie injector dialogue
  25. */
  26. cI.createDiv = function(){
  27. //Create the DIV to contain the Dialog
  28. cI.dialog = document.createElement('div');
  29. cI.dialog.id = "cookieInjectorDiv";
  30. cI.dialog.innerHTML = "<div align='center'>Wireshark Cookie Dump:<br/><input type='text' id='cookieInjectorCookie'/><br/><button onclick='cookieInjector.writeCookie();'>OK</button><button onclick='cookieInjector.hide();'>Cancel</button></div>";
  31. cI.dialog.style.display = "none";
  32. cI.dialog.style.position = "fixed";
  33. cI.dialog.style.opacity = "0.9";
  34. cI.dialog.style.top = "40%";
  35. cI.dialog.style.background= "#DDDDDD";
  36. cI.dialog.style.left = "40%";
  37. cI.dialog.style.width = "20%";
  38. cI.dialog.style.zindex = "99999";
  39. document.body.appendChild(cI.dialog);
  40. cI.visible = false;
  41. }
  42.  
  43. /**
  44. * Show the dialog
  45. */
  46. cI.show = function(){
  47. if(!cI.dialog) {
  48. cI.createDiv();
  49. }
  50. cI.dialog.style.display = "block";
  51. cI.visible = true;
  52. }
  53.  
  54. /**
  55. * Hide the dialog
  56. */
  57. cI.hide = function(){
  58. cI.dialog.style.display = "none";
  59. cI.visible = false;
  60. }
  61.  
  62. /**
  63. * Gets the wireshark dump string and converts it into cookies
  64. */
  65. cI.writeCookie = function(){
  66. //Grab a handle to the text field which contains the string
  67. var cookieNode = document.getElementById('cookieInjectorCookie');
  68. var cookieText = cI.cleanCookie(cookieNode.value);
  69. cookieNode.value = "";
  70. //We have to add the cookies one at a time, so split around the colin
  71. var cookieArray = cookieText.split(";");
  72. for(var x=0; x<cookieArray.length; x++){
  73. //We want the path to be the root, the host is filled in automatically
  74. //since we are on the same webpage that we captured the cookies on
  75. document.cookie = cookieArray[x]+"; path=/";
  76. }
  77.  
  78. alert("All Cookies Have Been Written");
  79. cI.hide();
  80. }
  81.  
  82. /**
  83. * Do a little big of cleanup on the cookie string, Mostly we are looking
  84. * To get rid of the "Cookie: " string that Wireshark prepends to the cookie string
  85. */
  86. cI.cleanCookie = function(cookieText){
  87. var cookie = cookieText.replace("Cookie: ","");
  88. return cookie;
  89. }
  90. /**
  91. * Handle all keypresses, we are looking for an ALT-C key-combo. Since we can't detect
  92. * Two keys being pressed at the same time, we first make sure the ALT key was pressed
  93. * then we wait to see if the C key is pressed next
  94. */
  95. cI.keyPress = function (e){
  96. //Check to see if "C" is pressed after ALT
  97. if(e.keyCode == 67 && cI.ctrlFire){
  98. if(!cI.visible){
  99. cI.show();
  100. }else{
  101. cI.hide();
  102. }
  103. }
  104.  
  105. //Make sure the Alt key was previously depressed
  106. if(e.keyCode == 18){
  107. cI.ctrlFire = true;
  108. }else{
  109. cI.ctrlFire = false;
  110. }
  111. }
  112.  
  113. //Capture all onkeydown events, so we can filter for our key-combo
  114. cI.visible = false;
  115. window.addEventListener('keydown', cI.keyPress,'false');
  116. })();
  117.