• Stars
    star
    244
  • Rank 165,885 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easily intercept and modify WebSocket requests and message events.

wsHook

Easily intercept and modify WebSocket requests and message events.

ToDo

Figure out if we still need immutable MessageEvent

Usage

1. Download and include wsHook.js in your WebSocket client

<script src='wsHook.js'></script>

2. Define the before and after hooks

Define your custom before and after hooks on the globally exposed wsHook object.

wsHook.before = function(data, url, wsObject) {
    console.log("Sending message to " + url + " : " + data);
}

// Make sure your program calls `wsClient.onmessage` event handler somewhere.
wsHook.after = function(messageEvent, url, wsObject) {
    console.log("Received message from " + url + " : " + messageEvent.data);
    return messageEvent;
}

// if you do not want to propagate the MessageEvent further down, just return null
wsHook.after = function(messageEvent, url, wsObject) {
 console.log("Received message from " + url + " : " + messageEvent.data);
 // This example can ping-pong forever, so maybe use some conditions
 wsObject.send("Intercepted and sent again")
 return null;
}

3. Let your program play with WebSockets

var wsClient = new WebSocket("wss://echo.websocket.org");

wsClient.onopen = function() {
    wsClient.send("Echo this");
}

wsClient.onmessage = function(e){
  console.log(e);
}

API

wsHook.before - function(data, url, wsObject):

Invoked just before calling the actual WebSocket's send() method.

This method must return data which can be modified as well.

wsHook.after - function(event, url, wsObject):

Invoked just after receiving the MessageEvent from the WebSocket server and before calling the WebSocket's onmessage Event Handler.

This method must return event whose properties can be modified as well. You might be interested in modiying, event.data or event.origin usually.

The wsObject refers to the corresponding WebSocket object used. You can use this to send a message to the server. This allows one to fully hijack the WebSocket connection programatically.

If you do not want the user's original onmessage event handler to be called, just return null.

Overview

Example

// Load wsHook.js
// Define the 'before' and 'after' hooks as you wish.

wsHook.before = function(data, url, wsObject){
  data += "_modified";
  console.log("Modifying data to " + data);
  return data;
}

var wsClient = new WebSocket("wss://echo.websocket.org");
wsClient.onopen = function() {
  wsClient.send("Echo this");
}
wsClient.onmessage = function(e){
  console.log(e);
}

Used by

  • Hookish: Hooks in to interesting functions and helps reverse the web app faster.

TODO

  • Test cases for common WebSocket libraries.

License

The MIT License (MIT)

Copyright (c) 2015 Ahamed Nafeez

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.

More Repositories

1

hookish

Hooks in to interesting functions and helps reverse the web app faster.
JavaScript
162
star
2

arpjs

Send ARP packets and read ARP tables using Javascript
JavaScript
85
star
3

damnvulnerable.me

A deliberately vulnerable modern day app with lots of DOM related bugs
HTML
36
star
4

domstorm

A dashboard for interesting DOM tricks/techniques.
JavaScript
36
star
5

subquest

Fast, Elegant subdomain scanner using nodejs
JavaScript
33
star
6

tlsjack

A simple TLS forwarder that lets you intercept traffic and play with them.
JavaScript
30
star
7

fuzzcat

Fuzzing web services in style with nodejs
JavaScript
12
star
8

voracle

Compression Oracle Attack on OpenVPN
JavaScript
11
star
9

mitmjs

Be a Man-In-The-Middle between two hosts
JavaScript
11
star
10

node-radamsa

A simple, synchronous, pipe to Radamsa tool from your nodejs programs.
JavaScript
7
star
11

tlsscan

Testing TLS servers for weakness
JavaScript
6
star
12

seclint

A javascript dom security linter
JavaScript
6
star
13

git-watchdog

I collect post-receive from GitHub and alert you on security errors
JavaScript
4
star
14

dosa

A Javascript transpiler for instrumentation
JavaScript
3
star
15

symtable.js

An imperative symbol table library in JavaScript
JavaScript
2
star
16

esflow

Elegant, Fast JavaScript static security analyzer for finding issues like DOM XSS.
JavaScript
2
star
17

node-xstream

Duplex streams that can do operations
JavaScript
2
star
18

PoC-Stack-for-TCP-Simultaneous-Connection

Acts as a TCP Stack which handles SYN , SYN-ACK and responds with a New SYN . Part of the research work on the concept of mitigating DoS attacks using simultaneous connection initiation.
C
2
star
19

uglify-ast

All about the UglifyJS AST
2
star
20

insecure-commits-test

A test repo which frequently commits insecure code patterns.
1
star
21

tlsecho

A simple TLS echo server
JavaScript
1
star
22

temp-travis-test

A temporary repo to test Travis with custom binaries
JavaScript
1
star
23

mask

Tiny text masking utility
Go
1
star
24

domato-fuzzer.skepticfx.com

The Domato Fuzzer but as an HTTP endpoint
Python
1
star
25

dotfiles

Lua
1
star