Skip to content

Port Knocking UDP with Javascript in Browser

So I am trying to send a port knock sequence from javascript.

The TCP part is simple enough with websockets.

I’ve read that WebRTC is the closest thing the browser offers to sending a UDP packet… but WebRTC is a lot to digest just to attempt to send a UDP “knock”.

Is it even possible to “knock” via UDP using WebRTC? If so, please provide a simple example. I am just looking for a simplistic working example. I.e. to “knock” via TCP you can use the following:

var sock = new WebSocket("ws://"+ host +":"+ port);


It is in fact possible to send UDP packets with the browser.

You could either write a chrome extension (app) which would give you access to ("sockets": {...} in your manifest.json).

Or, as far as WebRTC goes:

var pc = new webkitRTCPeerConnection(
    { "iceServers": [{ "url": "stun:localhost:1234" }] }

pc.createOffer(function (sessionDescription) {

}, function(error) {
}, { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } });

And a quick ruby-script

require ‘socket’

$port = 1234

t = Thread.start do
  server =
  server.bind(nil, $port)
  4.times do
    a = server.recvfrom(12364)
    p a
    p server.send "ping", 0, a[1][2], a[1][1]


[“x00x01x00x00!x12xA4B0PgJcgcqalrO”, [“AF_INET”, 51881, “”, “”]] 4 [“x00x01x00x00!x12xA4Bbmfxf2ABsZws”, [“AF_INET”, 53092, “”, “”]] 4 [“x00x01x00x00!x12xA4B0PgJcgcqalrO”, [“AF_INET”, 51881, “”, “”]] 4 [“x00x01x00x00!x12xA4Bbmfxf2ABsZws”, [“AF_INET”, 53092, “”, “”]]

I’m not sure though if that qualifies as “port knock sequence.”