diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..14fac91 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 0931101..495afce 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,14 @@ Tunnels internet traffic through video calling platforms (VK Call, Yandex Telemo ## How it works -Video calling platforms use WebRTC with an SFU (Selective Forwarding Unit). The SFU forwards SCTP data channels between participants without inspecting them. This tool creates a DataChannel alongside the call's built-in channels and uses it as a bidirectional data pipe. +Two tunnel modes are available: **DC** (DataChannel) and **Pion Video** (VP8 data encoding). -- **VK Call**: Uses negotiated DataChannel id:2 (alongside VK's animoji channel id:1) -- **Telemost**: Uses non-negotiated DataChannel labeled "sharing" (matching real screen sharing traffic), with SDP renegotiation via signaling WebSocket +### DC mode + +Browser-based. JavaScript hooks intercept RTCPeerConnection on the call page, create a DataChannel alongside the call's built-in channels, and use it as a bidirectional data pipe. + +- **VK Call** - Negotiated DataChannel id:2 (alongside VK's animoji channel id:1). P2P via TURN relay +- **Telemost** - Non-negotiated DataChannel labeled "sharing" (matching real screen sharing traffic), with SDP renegotiation via signaling WebSocket. SFU architecture ``` Joiner (censored, Android) Creator (free internet, desktop) @@ -24,7 +28,7 @@ WebSocket (:9000) | WebView (call page) Electron (call page) | | -DataChannel <------- SFU -------> DataChannel +DataChannel <--- TURN/SFU ---> DataChannel | WebSocket (:9000) | @@ -33,60 +37,104 @@ DataChannel <------- SFU -------> DataChannel Internet ``` +### Pion Video mode + +Go-based. Pion (Go WebRTC library) connects directly to the platform's TURN/SFU servers, bypassing the browser's WebRTC stack entirely. Data is encoded inside VP8 video frames. + +- **VK Call** - Single PeerConnection, P2P via TURN relay +- **Telemost** - Dual PeerConnection (pub/sub), SFU architecture + +The JS hook replaces `RTCPeerConnection` with a `MockPeerConnection` that forwards all SDP/ICE operations to the local Pion server via WebSocket. Pion creates the real PeerConnection with the platform's TURN servers. + +**VP8 data encoding:** +- Data frames: `[0xFF marker][4B length][payload]` - sent as VP8 video samples +- Keepalive frames: valid VP8 interframes (17 bytes) at 25fps, keyframe every 60th frame. Keeps the video track alive so the SFU/TURN does not disconnect +- The `0xFF` marker byte distinguishes data from real VP8 (keyframe first byte has bit0=0, interframe has bit0=1, so `0xFF` never appears naturally) +- On the receiving side, RTP packets are reassembled into full frames. First byte `0xFF` = extract data, otherwise = keepalive, ignore + +**Multiplexing protocol** over the VP8 tunnel: `[4B frame length][4B connID][1B msgType][payload]` +- Message types: Connect, ConnectOK, ConnectErr, Data, Close, UDP, UDPReply +- Multiple TCP/UDP connections are multiplexed into a single VP8 video stream + +``` +Joiner (censored, Android) Creator (free internet, desktop) + +All apps + | +VpnService (captures all traffic) + | +tun2socks (IP -> TCP) + | +SOCKS5 proxy (Go, :1080) + | +VP8 data tunnel (Pion) VP8 data tunnel (Pion) + | | +MockPC (WebView) MockPC (Electron) + | | +Pion WebRTC <--- TURN/SFU ---> Pion WebRTC + | + Relay bridge + | + Internet +``` + Traffic goes through the platform's TURN servers which are whitelisted. To the network firewall it looks like a normal video call. ## Components -- `hooks/` - JavaScript hooks injected into call pages. Separate hooks per platform and role: - - `joiner-vk.js`, `creator-vk.js` - VK Call hooks - - `joiner-telemost.js`, `creator-telemost.js` - Telemost hooks - - Hooks intercept RTCPeerConnection, create tunnel DataChannel, bridge to local WebSocket +- `hooks/` - JavaScript hooks injected into call pages + - `joiner-vk.js`, `creator-vk.js` - VK Call DC hooks + - `joiner-telemost.js`, `creator-telemost.js` - Telemost DC hooks + - `pion-vk.js`, `pion-telemost.js` - Pion Video hooks (MockPeerConnection mode) + - DC hooks intercept RTCPeerConnection, create tunnel DataChannel, bridge to local WebSocket + - Pion hooks replace RTCPeerConnection with MockPC, forward SDP/ICE to Pion via WebSocket - Telemost hooks include fake media (camera/mic), message chunking (994B payload, 1000B total), and SDP renegotiation - `relay/` - Go relay binary and gomobile library - - SOCKS5 proxy with TCP CONNECT and UDP ASSOCIATE - - WebSocket server for browser-relay communication - - tun2socks (Android only, via build tags) - - Binary framing protocol: `[4B connID][1B msgType][payload]` + - `relay/mobile/` - DC mode: SOCKS5 proxy, WebSocket server, binary framing protocol + - `relay/pion/` - Pion Video mode: VP8 data tunnel, relay bridge, SOCKS5 proxy + - `common.go` - Shared types, WebSocket helper, ICE server parsing, AndroidNet + - `vk.go` - VK Pion client (single PeerConnection, P2P) + - `telemost.go` - Telemost Pion client (dual PeerConnection, pub/sub) + - `vp8tunnel.go` - VP8 frame encoding/decoding, keepalive generation + - `relay.go` - Relay bridge with connection multiplexing, SOCKS5 proxy, UDP ASSOCIATE + - `relay/mobile/tun_android.go` - Android-only: tun2socks + fdsan fix (CGo) + - `relay/mobile/tun_stub.go` - Desktop stub (no tun2socks needed) - `android-app/` - Android joiner app - WebView loading call page with hook injection - VpnService capturing all device traffic - - Go relay as .aar library (gomobile) + - Tunnel mode selector (DC / Pion Video) + - Go relay as .aar library (gomobile) + Pion relay as native binary - `creator-app/` - Electron desktop creator app - Webview with persistent session for login retention - CSP header stripping for localhost WebSocket access - Auto-permission granting (camera/mic) + - Tunnel mode selector (DC / Pion Video) - Go relay spawned as child process - Log panels for relay and hook output -## Prebuilt binaries +## Download -Run `./build-creator.sh` and `./build-app.sh` to produce binaries in `prebuilts/`: - -| File | Platform | -|---|---| -| `WhitelistBypass Creator-*-arm64.dmg` | macOS | -| `WhitelistBypass Creator-*-x64.exe` | Windows x64 | -| `WhitelistBypass Creator-*-ia32.exe` | Windows x86 | -| `WhitelistBypass Creator-*.AppImage` | Linux x64 | -| `whitelist-bypass.apk` | Android | +Prebuilt binaries are available on [GitHub Releases](../../releases). ## Setup ### Creator side (free internet, desktop) -Install and run the Electron app from `prebuilts/`. It bundles the Go relay automatically. +Download and run the Electron app from [GitHub Releases](../../releases). It bundles the Go relay automatically. 1. Open the app -2. Click "VK Call" or "Telemost" -3. Log in, create a call -4. Copy the join link, send it to the joiner +2. Select tunnel mode (DC or Pion Video) +3. Click "VK Call" or "Telemost" +4. Log in, create a call +5. Copy the join link, send it to the joiner ### Joiner side (censored, Android) -1. Install `whitelist-bypass.apk` from `prebuilts/` -2. Paste the call link in the app -3. The app joins the call, establishes the tunnel, starts VPN -4. All device traffic flows through the call +1. Download and install `whitelist-bypass.apk` from [GitHub Releases](../../releases) +2. Select tunnel mode (DC or Pion Video) +3. Paste the call link and tap GO +4. The app joins the call, establishes the tunnel, starts VPN +5. All device traffic flows through the call ## Building from source @@ -102,7 +150,7 @@ Install and run the Electron app from `prebuilts/`. It bundles the Go relay auto ### Build scripts ```sh -# Build Go .aar for Android (includes hooks copy) +# Build Go .aar and Pion relay for Android (includes hooks copy) ./build-go.sh # Build Android APK -> prebuilts/whitelist-bypass.apk @@ -112,7 +160,25 @@ Install and run the Electron app from `prebuilts/`. It bundles the Go relay auto ./build-creator.sh ``` -### Relay cross-compilation +Output in `prebuilts/`: + +| File | Platform | +|---|---| +| `WhitelistBypass Creator-*-arm64.dmg` | macOS | +| `WhitelistBypass Creator-*-x64.exe` | Windows x64 | +| `WhitelistBypass Creator-*-ia32.exe` | Windows x86 | +| `WhitelistBypass Creator-*.AppImage` | Linux x64 | +| `whitelist-bypass.apk` | Android | + +### Relay + +``` +relay --mode [--ws-port 9000] [--socks-port 1080] +``` + +- `--mode` - required: `joiner`, `creator`, `vk-video-joiner`, `vk-video-creator`, `telemost-video-joiner`, `telemost-video-creator` +- `--ws-port` - WebSocket port for browser/hook connection (default 9000) +- `--socks-port` - SOCKS5 proxy port, joiner modes only (default 1080) The Go relay is split into platform-specific files: - `relay/mobile/mobile.go` - Shared networking code (SOCKS5, WebSocket, framing) @@ -120,3 +186,7 @@ The Go relay is split into platform-specific files: - `relay/mobile/tun_stub.go` - Desktop stub (no tun2socks needed) This allows cross-compiling the relay for macOS/Windows/Linux without CGo or Android NDK. + +## License + +[MIT](LICENSE) diff --git a/android-app/app/build.gradle.kts b/android-app/app/build.gradle.kts index e7b7d5d..35db593 100644 --- a/android-app/app/build.gradle.kts +++ b/android-app/app/build.gradle.kts @@ -3,6 +3,11 @@ plugins { alias(libs.plugins.kotlin.android) } +val versionMajor = 0 +val versionMinor = 1 +val versionPatch = 5 +val versionBuild = System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: 0 + android { namespace = "bypass.whitelist" compileSdk { @@ -13,8 +18,8 @@ android { applicationId = "bypass.whitelist" minSdk = 23 targetSdk = 36 - versionCode = 1 - versionName = "0.1" + versionCode = 1_000_000 * versionMajor + 1_000 * versionMinor + versionPatch + versionBuild + versionName = "$versionMajor.$versionMinor.$versionPatch" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/android-app/app/libs/mobile.aar b/android-app/app/libs/mobile.aar index 87d651c..da1b8a0 100644 Binary files a/android-app/app/libs/mobile.aar and b/android-app/app/libs/mobile.aar differ diff --git a/android-app/app/src/main/AndroidManifest.xml b/android-app/app/src/main/AndroidManifest.xml index 000d733..41f74fc 100644 --- a/android-app/app/src/main/AndroidManifest.xml +++ b/android-app/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + @@ -15,7 +16,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.WhitelistBypass" - android:usesCleartextTraffic="true"> + android:usesCleartextTraffic="true" + android:extractNativeLibs="true"> { + 'use strict'; + + var PION_WS_URL = 'ws://127.0.0.1:' + (window.PION_PORT || 9001) + '/signaling'; + var log = function() { + var args = ['[HOOK]'].concat(Array.prototype.slice.call(arguments)); + console.log.apply(console, args); + }; + + var OrigWebSocket = window.WebSocket; + var pionWS = null; + var pionReady = false; + var pendingMessages = []; + var requestId = 0; + var pendingRequests = {}; + var mockPCs = []; + var pcCount = 0; + + function connectPion() { + var ws = new OrigWebSocket(PION_WS_URL); + pionWS = ws; + ws.onopen = function() { + log('Connected to Pion relay'); + pionReady = true; + pendingMessages.forEach(function(m) { ws.send(m); }); + pendingMessages = []; + }; + ws.onclose = function() { + pionReady = false; + pionWS = null; + var hasActive = mockPCs.some(function(pc) { return pc._connectionState !== 'closed'; }); + if (hasActive) { + log('Pion relay disconnected, reconnecting...'); + setTimeout(connectPion, 2000); + } + }; + ws.onerror = function() {}; + ws.onmessage = function(e) { + var msg = JSON.parse(e.data); + handlePionMessage(msg); + }; + } + + function sendToPion(type, data, role) { + var msg = JSON.stringify({ type: type, data: data, role: role || '' }); + if (pionReady && pionWS && pionWS.readyState === 1) { + pionWS.send(msg); + } else { + pendingMessages.push(msg); + } + } + + function requestPion(type, data, role) { + var id = ++requestId; + return new Promise(function(resolve, reject) { + pendingRequests[id] = { resolve: resolve, reject: reject }; + var msg = JSON.stringify({ type: type, data: data, id: id, role: role || '' }); + if (pionReady && pionWS && pionWS.readyState === 1) { + pionWS.send(msg); + } else { + pendingMessages.push(msg); + } + setTimeout(function() { + if (pendingRequests[id]) { + delete pendingRequests[id]; + reject(new Error('Pion request timeout: ' + type)); + } + }, 10000); + }); + } + + function handlePionMessage(msg) { + if (msg.id && pendingRequests[msg.id]) { + pendingRequests[msg.id].resolve(msg.data); + delete pendingRequests[msg.id]; + return; + } + + switch (msg.type) { + case 'ice-candidate': + var targetRole = msg.role || ''; + mockPCs.forEach(function(pc) { + if (pc._connectionState === 'closed') return; + if (targetRole && pc._role !== targetRole) return; + var evt = { candidate: new RTCIceCandidate(msg.data) }; + if (pc._onicecandidate) pc._onicecandidate(evt); + pc._listeners.icecandidate.forEach(function(fn) { fn(evt); }); + }); + break; + case 'remote-track': + log('remote-track received: kind=' + (msg.data && msg.data.kind)); + break; + case 'connection-state': + log('Pion connection state:', msg.data); + mockPCs.forEach(function(pc) { + pc._connectionState = msg.data; + if (msg.data === 'connected') { + if (typeof AndroidBridge !== 'undefined' && AndroidBridge.onTunnelReady) { + AndroidBridge.onTunnelReady(); + } + } + if (pc._onconnectionstatechange) pc._onconnectionstatechange(new Event('connectionstatechange')); + pc._listeners.connectionstatechange.forEach(function(fn) { fn(new Event('connectionstatechange')); }); + }); + break; + } + } + + // MockPC for Telemost GOLOOM SDK + function MockPeerConnection(config) { + this._config = config; + this._connectionState = 'new'; + this._signalingState = 'stable'; + this._iceConnectionState = 'new'; + this._iceGatheringState = 'new'; + this._localDescription = null; + this._remoteDescription = null; + this._senders = []; + this._receivers = []; + this._transceivers = []; + this._onicecandidate = null; + this._onconnectionstatechange = null; + this._ontrack = null; + this._ondatachannel = null; + this._onsignalingstatechange = null; + this._onnegotiationneeded = null; + this._oniceconnectionstatechange = null; + this._pcIdx = pcCount++; + this._listeners = { + connectionstatechange: [], + icecandidate: [], + track: [], + datachannel: [], + iceconnectionstatechange: [], + icegatheringstatechange: [], + signalingstatechange: [], + negotiationneeded: [] + }; + + var existingPub = mockPCs.find(function(pc) { return pc._role === 'pub' && pc._connectionState !== 'closed'; }); + this._role = existingPub ? 'sub' : 'pub'; + + if (config && config.iceServers) { + var servers = config.iceServers.map(function(s) { + var urls = Array.isArray(s.urls) ? s.urls : (s.urls ? [s.urls] : []); + if (typeof AndroidBridge !== 'undefined' && AndroidBridge.resolveHost) { + urls = urls.map(function(url) { + var match = url.match(/^(turn:|stun:)([^:?]+)(.*)/); + if (match) { + var resolved = AndroidBridge.resolveHost(match[2]); + if (resolved) return match[1] + resolved + match[3]; + } + return url; + }); + } + return { + urls: urls, + username: s.username || '', + credential: s.credential || '' + }; + }); + sendToPion('ice-servers', servers, this._role); + } + + mockPCs.push(this); + if (!pionWS) { + if (typeof AndroidBridge !== 'undefined' && AndroidBridge.getLocalIP) { + var ip = AndroidBridge.getLocalIP(); + if (ip) { + log('Local IP from Android: ' + ip); + pendingMessages.push(JSON.stringify({ type: 'local-ip', data: ip })); + } + } + connectPion(); + } + log('MockPC #' + this._pcIdx + ' created (role=' + this._role + ')'); + } + + MockPeerConnection.prototype = { + get connectionState() { return this._connectionState; }, + get signalingState() { return this._signalingState; }, + get iceConnectionState() { return this._iceConnectionState; }, + get iceGatheringState() { return this._iceGatheringState; }, + get localDescription() { return this._localDescription; }, + get remoteDescription() { return this._remoteDescription; }, + get currentLocalDescription() { return this._localDescription; }, + get currentRemoteDescription() { return this._remoteDescription; }, + + set onicecandidate(fn) { this._onicecandidate = fn; }, + get onicecandidate() { return this._onicecandidate; }, + set onconnectionstatechange(fn) { this._onconnectionstatechange = fn; }, + get onconnectionstatechange() { return this._onconnectionstatechange; }, + set ontrack(fn) { log('MockPC #' + this._pcIdx + ' ontrack SET (role=' + this._role + ')'); this._ontrack = fn; }, + get ontrack() { return this._ontrack; }, + set ondatachannel(fn) { this._ondatachannel = fn; }, + get ondatachannel() { return this._ondatachannel; }, + set oniceconnectionstatechange(fn) { this._oniceconnectionstatechange = fn; }, + get oniceconnectionstatechange() { return this._oniceconnectionstatechange; }, + set onicegatheringstatechange(fn) { this._onicegatheringstatechange = fn; }, + get onicegatheringstatechange() { return this._onicegatheringstatechange; }, + set onsignalingstatechange(fn) { this._onsignalingstatechange = fn; }, + get onsignalingstatechange() { return this._onsignalingstatechange; }, + set onnegotiationneeded(fn) { this._onnegotiationneeded = fn; }, + get onnegotiationneeded() { return this._onnegotiationneeded; }, + + addEventListener: function(type, fn) { + if (this._listeners[type]) this._listeners[type].push(fn); + }, + removeEventListener: function(type, fn) { + if (this._listeners[type]) this._listeners[type] = this._listeners[type].filter(function(f) { return f !== fn; }); + }, + dispatchEvent: function(event) { + var type = event.type; + if (this._listeners[type]) this._listeners[type].forEach(function(fn) { fn(event); }); + var handler = this['on' + type]; + if (handler) handler.call(this, event); + }, + + createOffer: function(options) { + log('MockPC #' + this._pcIdx + ' createOffer'); + return requestPion('create-offer', options || {}, this._role).then(function(sdp) { + return new RTCSessionDescription(sdp); + }); + }, + + createAnswer: function(options) { + log('MockPC #' + this._pcIdx + ' createAnswer'); + return requestPion('create-answer', options || {}, this._role).then(function(sdp) { + return new RTCSessionDescription(sdp); + }); + }, + + setLocalDescription: function(desc) { + this._localDescription = desc; + var oldState = this._signalingState; + this._signalingState = desc.type === 'offer' ? 'have-local-offer' : 'stable'; + log('MockPC #' + this._pcIdx + ' setLocalDescription:', desc.type); + sendToPion('set-local-description', { type: desc.type, sdp: desc.sdp }, this._role); + var self = this; + if (oldState !== this._signalingState) { + setTimeout(function() { + if (self._onsignalingstatechange) self._onsignalingstatechange(new Event('signalingstatechange')); + self._listeners.signalingstatechange.forEach(function(fn) { fn(new Event('signalingstatechange')); }); + }, 0); + } + return Promise.resolve(); + }, + + setRemoteDescription: function(desc) { + var oldState = this._signalingState; + this._signalingState = desc.type === 'offer' ? 'have-remote-offer' : 'stable'; + this._remoteDescription = desc; + log('MockPC #' + this._pcIdx + ' setRemoteDescription:', desc.type); + var self = this; + return requestPion('set-remote-description', { type: desc.type, sdp: desc.sdp }, this._role).then(function() { + if (oldState !== self._signalingState) { + if (self._onsignalingstatechange) self._onsignalingstatechange(new Event('signalingstatechange')); + self._listeners.signalingstatechange.forEach(function(fn) { fn(new Event('signalingstatechange')); }); + } + }); + }, + + addIceCandidate: function(candidate) { + if (candidate && candidate.candidate) { + sendToPion('add-ice-candidate', { + candidate: candidate.candidate, + sdpMid: candidate.sdpMid, + sdpMLineIndex: candidate.sdpMLineIndex + }, this._role); + } + return Promise.resolve(); + }, + + addTrack: function(track, stream) { + var sender = { + track: track, + replaceTrack: function(t) { this.track = t; return Promise.resolve(); }, + getParameters: function() { return { encodings: [{}] }; }, + setParameters: function() { return Promise.resolve(); } + }; + this._senders.push(sender); + sendToPion('add-track', { kind: track.kind }, this._role); + return sender; + }, + + addTransceiver: function(trackOrKind, init) { + var kind = typeof trackOrKind === 'string' ? trackOrKind : trackOrKind.kind; + var sender = { + track: typeof trackOrKind === 'string' ? null : trackOrKind, + replaceTrack: function(t) { this.track = t; return Promise.resolve(); }, + getParameters: function() { return { encodings: [{}] }; }, + setParameters: function() { return Promise.resolve(); }, + setStreams: function() {} + }; + var receiver = { + track: { kind: kind, readyState: 'live', enabled: true, muted: true, id: 'mock-' + kind + '-' + this._pcIdx, + addEventListener: function() {}, removeEventListener: function() {}, + getSettings: function() { return {}; } }, + getStats: function() { return Promise.resolve(new Map()); }, + getSynchronizationSources: function() { return []; } + }; + var transceiver = { + sender: sender, receiver: receiver, + direction: (init && init.direction) || 'sendrecv', + setDirection: function(d) { this.direction = d; }, + mid: String(this._transceivers.length), + stopped: false, + stop: function() { this.stopped = true; }, + setCodecPreferences: function() {} + }; + this._senders.push(sender); + this._receivers.push(receiver); + this._transceivers.push(transceiver); + return transceiver; + }, + + removeTrack: function(sender) { + this._senders = this._senders.filter(function(s) { return s !== sender; }); + }, + + getSenders: function() { return this._senders; }, + getReceivers: function() { return this._receivers; }, + getTransceivers: function() { return this._transceivers; }, + getStats: function() { return Promise.resolve(new Map()); }, + getConfiguration: function() { return this._config || {}; }, + + createDataChannel: function(label, opts) { + log('MockPC #' + this._pcIdx + ' createDataChannel:', label); + sendToPion('create-data-channel', { label: label, opts: opts }, this._role); + var dc = { + label: label, + id: opts && opts.id != null ? opts.id : null, + readyState: 'connecting', + binaryType: 'arraybuffer', + bufferedAmount: 0, + bufferedAmountLowThreshold: 0, + onopen: null, onclose: null, onmessage: null, onerror: null, + onbufferedamountlow: null, + send: function() {}, + close: function() { this.readyState = 'closed'; }, + addEventListener: function() {}, + removeEventListener: function() {} + }; + return dc; + }, + + close: function() { + this._connectionState = 'closed'; + this._signalingState = 'closed'; + log('MockPC #' + this._pcIdx + ' close'); + var allClosed = mockPCs.every(function(pc) { return pc._connectionState === 'closed'; }); + if (allClosed) { + sendToPion('close', {}); + log('All MockPCs closed, closing Pion'); + } + }, + + restartIce: function() {}, + setConfiguration: function() {} + }; + + // Hook RTCPeerConnection + var OrigPC = window.RTCPeerConnection; + window.RTCPeerConnection = function(config) { + if (!config || !config.iceServers || config.iceServers.length === 0) { + log('RTCPeerConnection probe (no ICE servers) -> real PC'); + return new OrigPC(config); + } + log('RTCPeerConnection intercepted -> MockPC'); + return new MockPeerConnection(config); + }; + Object.keys(OrigPC).forEach(function(key) { + window.RTCPeerConnection[key] = OrigPC[key]; + }); + window.RTCPeerConnection.prototype = OrigPC.prototype; + window.RTCPeerConnection.generateCertificate = OrigPC.generateCertificate; + + // Intercept signaling via JSON.stringify/parse + var origStringify = JSON.stringify; + JSON.stringify = function(obj) { + var result = origStringify.apply(JSON, arguments); + return result; + }; + + var origParse = JSON.parse; + JSON.parse = function(str) { + var result = origParse.apply(JSON, arguments); + if (result && result.serverHello && result.serverHello.rtcConfiguration) { + var rtcConfig = result.serverHello.rtcConfiguration; + if (rtcConfig.iceServers && rtcConfig.iceServers.length > 0) { + log('ICE servers from serverHello:', rtcConfig.iceServers.length); + } + } + if (result && result.publisherSdpAnswer) { + log('Incoming publisherSdpAnswer, pcSeq=' + result.publisherSdpAnswer.pcSeq); + } + if (result && result.subscriberSdpOffer) { + log('Incoming subscriberSdpOffer, pcSeq=' + result.subscriberSdpOffer.pcSeq); + } + if (result && result.slotsChanged) { + log('Incoming slotsChanged:', JSON.stringify(result.slotsChanged).substring(0, 200)); + } + if (result && result.participantsChanged) { + log('Incoming participantsChanged'); + } + if (result && result.connectionStatusChanged) { + log('Incoming connectionStatusChanged:', JSON.stringify(result.connectionStatusChanged).substring(0, 200)); + } + return result; + }; + + // Fake media - static black canvas + silent audio + navigator.mediaDevices.getUserMedia = function(c) { + log('Intercepting getUserMedia'); + var canvas = document.createElement('canvas'); + canvas.width = 2; canvas.height = 2; + var stream = canvas.captureStream(1); + if (c && c.audio) { + var actx = new AudioContext(); + var dest = actx.createMediaStreamDestination(); + stream.addTrack(dest.stream.getAudioTracks()[0]); + } + return Promise.resolve(stream); + }; + + navigator.mediaDevices.enumerateDevices = function() { + return Promise.resolve([ + {deviceId:'fake-cam',kind:'videoinput',label:'Camera',groupId:'g1',toJSON:function(){return this}}, + {deviceId:'fake-mic',kind:'audioinput',label:'Microphone',groupId:'g2',toJSON:function(){return this}}, + {deviceId:'fake-spk',kind:'audiooutput',label:'Speaker',groupId:'g3',toJSON:function(){return this}} + ]); + }; + + window.__hook = { log: log, mockPCs: mockPCs }; + log('Telemost Pion hook installed (MockPC mode)'); +})(); diff --git a/android-app/app/src/main/assets/pion-vk.js b/android-app/app/src/main/assets/pion-vk.js new file mode 100644 index 0000000..095193a --- /dev/null +++ b/android-app/app/src/main/assets/pion-vk.js @@ -0,0 +1,385 @@ +(() => { + 'use strict'; + + var PION_WS_URL = 'ws://127.0.0.1:' + (window.PION_PORT || 9001) + '/signaling'; + var log = function() { + var args = ['[HOOK]'].concat(Array.prototype.slice.call(arguments)); + console.log.apply(console, args); + }; + + var OrigWebSocket = window.WebSocket; + var pionWS = null; + var pionReady = false; + var pendingMessages = []; + var requestId = 0; + var pendingRequests = {}; + + function connectPion() { + var ws = new OrigWebSocket(PION_WS_URL); + pionWS = ws; + ws.onopen = function() { + log('Connected to Pion relay'); + pionReady = true; + pendingMessages.forEach(function(m) { ws.send(m); }); + pendingMessages = []; + }; + ws.onclose = function() { + pionReady = false; + pionWS = null; + if (mockPC && mockPC._connectionState !== 'closed') { + log('Pion relay disconnected, reconnecting...'); + setTimeout(connectPion, 2000); + } + }; + ws.onerror = function() {}; + ws.onmessage = function(e) { + var msg = JSON.parse(e.data); + handlePionMessage(msg); + }; + } + + function sendToPion(type, data) { + var msg = JSON.stringify({ type: type, data: data }); + if (pionReady && pionWS && pionWS.readyState === 1) { + pionWS.send(msg); + } else { + pendingMessages.push(msg); + } + } + + function requestPion(type, data) { + var id = ++requestId; + return new Promise(function(resolve, reject) { + pendingRequests[id] = { resolve: resolve, reject: reject }; + var msg = JSON.stringify({ type: type, data: data, id: id }); + if (pionReady && pionWS && pionWS.readyState === 1) { + pionWS.send(msg); + } else { + pendingMessages.push(msg); + } + setTimeout(function() { + if (pendingRequests[id]) { + delete pendingRequests[id]; + reject(new Error('Pion request timeout: ' + type)); + } + }, 10000); + }); + } + + var mockPC = null; + function handlePionMessage(msg) { + if (msg.id && pendingRequests[msg.id]) { + pendingRequests[msg.id].resolve(msg.data); + delete pendingRequests[msg.id]; + return; + } + + switch (msg.type) { + case 'ice-candidate': + if (mockPC && mockPC._onicecandidate) { + mockPC._onicecandidate({ candidate: new RTCIceCandidate(msg.data) }); + } + break; + case 'remote-track': + log('remote-track received: kind=' + (msg.data && msg.data.kind) + ' mockPC=' + !!mockPC + ' ontrack=' + !!( mockPC && mockPC._ontrack)); + if (mockPC && mockPC._ontrack) { + var kind = msg.data.kind; + log('Firing ontrack for remote ' + kind); + var canvas = document.createElement('canvas'); + canvas.width = 2; canvas.height = 2; + var fakeStream = canvas.captureStream(1); + var fakeTrack = kind === 'audio' + ? (function() { var a = new AudioContext(); var d = a.createMediaStreamDestination(); return d.stream.getAudioTracks()[0]; })() + : fakeStream.getVideoTracks()[0]; + log('Fake track created: kind=' + fakeTrack.kind + ' readyState=' + fakeTrack.readyState + ' enabled=' + fakeTrack.enabled); + var evt = new Event('track'); + evt.track = fakeTrack; + evt.receiver = { track: fakeTrack }; + evt.transceiver = { receiver: { track: fakeTrack } }; + evt.streams = [kind === 'audio' ? new MediaStream([fakeTrack]) : fakeStream]; + log('Calling mockPC._ontrack with streams[0].getTracks()=' + evt.streams[0].getTracks().length); + mockPC._ontrack(evt); + log('ontrack callback completed'); + } else { + log('WARNING: remote-track but no mockPC or no ontrack handler!'); + } + break; + case 'connection-state': + if (mockPC) { + mockPC._connectionState = msg.data; + log('Pion connection state:', msg.data); + if (msg.data === 'connected') { + if (typeof AndroidBridge !== 'undefined' && AndroidBridge.onTunnelReady) { + AndroidBridge.onTunnelReady(); + } + } + if (mockPC._onconnectionstatechange) { + mockPC._onconnectionstatechange(new Event('connectionstatechange')); + } + mockPC._listeners.connectionstatechange.forEach(function(fn) { + fn(new Event('connectionstatechange')); + }); + } + break; + } + } + + function MockPeerConnection(config) { + this._config = config; + this._connectionState = 'new'; + this._signalingState = 'stable'; + this._iceConnectionState = 'new'; + this._iceGatheringState = 'new'; + this._localDescription = null; + this._remoteDescription = null; + this._senders = []; + this._receivers = []; + this._onicecandidate = null; + this._onconnectionstatechange = null; + this._ontrack = null; + this._ondatachannel = null; + this._listeners = { + connectionstatechange: [], + icecandidate: [], + track: [], + datachannel: [], + iceconnectionstatechange: [], + icegatheringstatechange: [], + signalingstatechange: [], + negotiationneeded: [] + }; + + if (config && config.iceServers) { + var servers = config.iceServers.map(function(s) { + return { + urls: Array.isArray(s.urls) ? s.urls : (s.urls ? [s.urls] : []), + username: s.username || '', + credential: s.credential || '' + }; + }); + sendToPion('ice-servers', servers); + } + + mockPC = this; + if (!pionWS) connectPion(); + log('MockPC created'); + } + + MockPeerConnection.prototype = { + get connectionState() { return this._connectionState; }, + get signalingState() { return this._signalingState; }, + get iceConnectionState() { return this._iceConnectionState; }, + get iceGatheringState() { return this._iceGatheringState; }, + get localDescription() { return this._localDescription; }, + get remoteDescription() { return this._remoteDescription; }, + set onicecandidate(fn) { this._onicecandidate = fn; }, + get onicecandidate() { return this._onicecandidate; }, + set onconnectionstatechange(fn) { this._onconnectionstatechange = fn; }, + get onconnectionstatechange() { return this._onconnectionstatechange; }, + set ontrack(fn) { log('MockPC.ontrack SET by caller'); this._ontrack = fn; }, + get ontrack() { return this._ontrack; }, + set ondatachannel(fn) { this._ondatachannel = fn; }, + get ondatachannel() { return this._ondatachannel; }, + set oniceconnectionstatechange(fn) { this._oniceconnectionstatechange = fn; }, + get oniceconnectionstatechange() { return this._oniceconnectionstatechange; }, + set onicegatheringstatechange(fn) { this._onicegatheringstatechange = fn; }, + get onicegatheringstatechange() { return this._onicegatheringstatechange; }, + set onsignalingstatechange(fn) { this._onsignalingstatechange = fn; }, + get onsignalingstatechange() { return this._onsignalingstatechange; }, + set onnegotiationneeded(fn) { this._onnegotiationneeded = fn; }, + get onnegotiationneeded() { return this._onnegotiationneeded; }, + addEventListener: function(type, fn) { + if (this._listeners[type]) this._listeners[type].push(fn); + }, + removeEventListener: function(type, fn) { + if (this._listeners[type]) this._listeners[type] = this._listeners[type].filter(function(f) { return f !== fn; }); + }, + dispatchEvent: function(event) { + var type = event.type; + if (this._listeners[type]) this._listeners[type].forEach(function(fn) { fn(event); }); + var handler = this['on' + type]; + if (handler) handler(event); + }, + createOffer: function(options) { + log('MockPC.createOffer'); + return requestPion('create-offer', options || {}).then(function(sdp) { + log('MockPC.createOffer resolved'); + return new RTCSessionDescription(sdp); + }); + }, + createAnswer: function(options) { + log('MockPC.createAnswer'); + return requestPion('create-answer', options || {}).then(function(sdp) { + log('MockPC.createAnswer resolved'); + return new RTCSessionDescription(sdp); + }); + }, + setLocalDescription: function(desc) { + this._localDescription = desc; + var oldState = this._signalingState; + this._signalingState = desc.type === 'offer' ? 'have-local-offer' : 'stable'; + log('MockPC.setLocalDescription:', desc.type); + sendToPion('set-local-description', { type: desc.type, sdp: desc.sdp }); + var self = this; + if (oldState !== this._signalingState) { + setTimeout(function() { + if (self._onsignalingstatechange) self._onsignalingstatechange(new Event('signalingstatechange')); + self._listeners.signalingstatechange.forEach(function(fn) { fn(new Event('signalingstatechange')); }); + }, 0); + } + return Promise.resolve(); + }, + setRemoteDescription: function(desc) { + this._remoteDescription = desc; + var oldState = this._signalingState; + this._signalingState = desc.type === 'offer' ? 'have-remote-offer' : 'stable'; + log('MockPC.setRemoteDescription:', desc.type); + var self = this; + return requestPion('set-remote-description', { type: desc.type, sdp: desc.sdp }).then(function() { + if (oldState !== self._signalingState) { + if (self._onsignalingstatechange) self._onsignalingstatechange(new Event('signalingstatechange')); + self._listeners.signalingstatechange.forEach(function(fn) { fn(new Event('signalingstatechange')); }); + } + }); + }, + addIceCandidate: function(candidate) { + if (candidate && candidate.candidate) { + sendToPion('add-ice-candidate', { candidate: candidate.candidate, sdpMid: candidate.sdpMid, sdpMLineIndex: candidate.sdpMLineIndex }); + } + return Promise.resolve(); + }, + addTrack: function(track, stream) { + var sender = { track: track, replaceTrack: function(t) { this.track = t; return Promise.resolve(); }, getParameters: function() { return { encodings: [{}] }; }, setParameters: function() { return Promise.resolve(); } }; + this._senders.push(sender); + sendToPion('add-track', { kind: track.kind }); + return sender; + }, + addTransceiver: function(trackOrKind, init) { + var kind = typeof trackOrKind === 'string' ? trackOrKind : trackOrKind.kind; + var sender = { track: typeof trackOrKind === 'string' ? null : trackOrKind, replaceTrack: function(t) { this.track = t; return Promise.resolve(); }, getParameters: function() { return { encodings: [{}] }; }, setParameters: function() { return Promise.resolve(); } }; + var receiver = { track: { kind: kind, readyState: 'live', enabled: true, muted: true, id: 'mock-' + kind, addEventListener: function() {}, removeEventListener: function() {} } }; + var transceiver = { sender: sender, receiver: receiver, direction: (init && init.direction) || 'sendrecv', setDirection: function(d) { this.direction = d; }, mid: null, stopped: false, stop: function() { this.stopped = true; } }; + this._senders.push(sender); + this._receivers.push(receiver); + return transceiver; + }, + removeTrack: function(sender) { + this._senders = this._senders.filter(function(s) { return s !== sender; }); + }, + getSenders: function() { return this._senders; }, + getReceivers: function() { return this._receivers; }, + getTransceivers: function() { return []; }, + getStats: function() { return Promise.resolve(new Map()); }, + getConfiguration: function() { return this._config || {}; }, + createDataChannel: function(label, opts) { + log('MockPC.createDataChannel:', label); + sendToPion('create-data-channel', { label: label, opts: opts }); + var dc = { + label: label, + id: opts && opts.id != null ? opts.id : null, + readyState: 'connecting', + binaryType: 'arraybuffer', + bufferedAmount: 0, + onopen: null, onclose: null, onmessage: null, onerror: null, + send: function() {}, + close: function() { this.readyState = 'closed'; }, + addEventListener: function() {}, + removeEventListener: function() {} + }; + return dc; + }, + close: function() { + this._connectionState = 'closed'; + this._signalingState = 'closed'; + sendToPion('close', {}); + log('MockPC.close'); + }, + restartIce: function() {} + }; + + var OrigPC = window.RTCPeerConnection; + window.RTCPeerConnection = function(config) { + log('RTCPeerConnection intercepted -> MockPC'); + return new MockPeerConnection(config); + }; + Object.keys(OrigPC).forEach(function(key) { + window.RTCPeerConnection[key] = OrigPC[key]; + }); + window.RTCPeerConnection.prototype = OrigPC.prototype; + window.RTCPeerConnection.generateCertificate = OrigPC.generateCertificate; + + var origStringify = JSON.stringify; + JSON.stringify = function(obj) { + if (obj && obj.command && typeof obj.sequence === 'number') { + if (obj.command === 'change-media-settings' && obj.mediaSettings) { + obj.mediaSettings.isVideoEnabled = true; + log('Forced isVideoEnabled=true in change-media-settings'); + } + try { handleOutgoing(obj); } catch(e) {} + } + var result = origStringify.apply(JSON, arguments); + return result; + }; + + var origParse = JSON.parse; + JSON.parse = function(str) { + var result = origParse.apply(JSON, arguments); + if (result && (result.type === 'notification' || result.type === 'response')) { + try { handleIncoming(result); } catch(e) {} + } + return result; + }; + + function handleOutgoing(msg) { + if (msg.command === 'transmit-data') { + if (msg.data && msg.data.sdp) { + log('VK sending SDP:', msg.data.sdp.type); + } + if (msg.data && msg.data.candidate) { + log('VK sending ICE candidate'); + } + } + if (msg.command === 'change-media-settings') { + log('VK outgoing change-media-settings:', JSON.stringify(msg.mediaSettings)); + } + if (msg.command === 'join-conversation' || msg.command === 'start-conversation') { + log('VK outgoing ' + msg.command + ': mediaSettings=' + JSON.stringify(msg.mediaSettings)); + } + } + + function handleIncoming(msg) { + if (msg.type === 'notification') { + if (msg.notification === 'connection' && msg.conversationParams && msg.conversationParams.turn) { + var turn = msg.conversationParams.turn; + log('TURN servers:', turn.urls.length); + sendToPion('ice-servers', [{ + urls: turn.urls, + username: turn.username, + credential: turn.credential + }]); + } + if (msg.notification === 'transmitted-data' && msg.data) { + if (msg.data.candidate) { + sendToPion('remote-ice-candidate', msg.data.candidate); + } + if (msg.data.sdp) { + log('VK incoming SDP: type=' + msg.data.sdp.type); + } + } + if (msg.notification === 'remote-media-settings' || msg.notification === 'media-settings' || msg.notification === 'media-settings-changed') { + log('VK media-settings notification:', JSON.stringify(msg).substring(0, 300)); + } + if (msg.notification === 'participant-added' || msg.notification === 'participant-removed') { + log('VK participant event: ' + msg.notification); + } + } + if (msg.type === 'response') { + if (msg.data && msg.data.mediaSettings) { + log('VK response mediaSettings: isVideoEnabled=' + msg.data.mediaSettings.isVideoEnabled); + } + } + } + + window.__hook = { log: log }; + log('Signaling proxy hook installed (MockPC mode)'); +})(); diff --git a/android-app/app/src/main/java/bypass/whitelist/MainActivity.kt b/android-app/app/src/main/java/bypass/whitelist/MainActivity.kt index 56b2b10..b8ab998 100644 --- a/android-app/app/src/main/java/bypass/whitelist/MainActivity.kt +++ b/android-app/app/src/main/java/bypass/whitelist/MainActivity.kt @@ -1,16 +1,21 @@ package bypass.whitelist -import android.util.Log import android.annotation.SuppressLint import android.content.ClipData import android.content.ClipboardManager import android.content.Intent +import android.content.pm.PackageManager import android.net.VpnService +import android.os.Build import android.os.Bundle +import android.util.Log import android.webkit.* +import android.widget.AdapterView +import android.widget.ArrayAdapter import android.widget.Button import android.widget.EditText import android.widget.ImageButton +import android.widget.Spinner import android.widget.TextView import android.widget.Toast import androidx.activity.enableEdgeToEdge @@ -18,36 +23,34 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat -import mobile.Mobile import mobile.LogCallback +import mobile.Mobile +import java.io.File class MainActivity : AppCompatActivity() { + private var tunnelMode = TunnelMode.DC + private var pionProcess: Process? = null + private lateinit var webView: WebView private lateinit var logView: TextView private lateinit var urlInput: EditText + private val vpnPrepLauncher = registerForActivityResult( + ActivityResultContracts.StartActivityForResult() + ) {} + private val vpnLauncher = registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> - if (result.resultCode == RESULT_OK) { - startVpnService() - } else { - appendLog("VPN permission denied") - } + if (result.resultCode == RESULT_OK) startVpnService() + else appendLog("VPN permission denied") } - private val hookVk by lazy { - assets.open("joiner-vk.js").bufferedReader().readText() - } - - private val hookTelemost by lazy { - assets.open("joiner-telemost.js").bufferedReader().readText() - } - - private fun hookForUrl(url: String): String { - return if (url.contains("telemost.yandex")) hookTelemost else hookVk - } + private val hookVk by lazy { assets.open("joiner-vk.js").bufferedReader().readText() } + private val hookTelemost by lazy { assets.open("joiner-telemost.js").bufferedReader().readText() } + private val hookPionVk by lazy { assets.open("pion-vk.js").bufferedReader().readText() } + private val hookPionTelemost by lazy { assets.open("pion-telemost.js").bufferedReader().readText() } @SuppressLint("SetJavaScriptEnabled") override fun onCreate(savedInstanceState: Bundle?) { @@ -65,12 +68,14 @@ class MainActivity : AppCompatActivity() { webView = findViewById(R.id.webView) setupWebView() - startRelay() + setupModeSpinner() val goButton = findViewById + Tunnel: +
@@ -49,6 +54,22 @@ body { font-family: -apple-system, sans-serif; background: #1a1a1a; color: #e0e0