Web Sockets: Using wsrepl
wsrepl, a tool developed by Doyensec, aims to simplify the auditing of websocket-based apps. It offers an interactive REPL interface that is user-friendly and easy to automate. The tool was developed during an engagement with a client whose web application heavily relied on WebSockets for soft real-time communication.
wsrepl is designed to provide a balance between an interactive REPL experience and automation. It is built with Python’s TUI framework Textual, and it interoperates with curl’s arguments, making it easy to transition from the Upgrade request in Burp to wsrepl. It also provides full transparency of WebSocket opcodes as per RFC 6455 and has an automatic reconnection feature in case of disconnects.
pip install wsrepl
wsrepl -u URL -P auth_plugin.pyMoreover, wsrepl simplifies the process of transitioning into WebSocket automation. Users just need to write a Python plugin. The plugin system is designed to be flexible, allowing users to define hooks that are executed at various stages of the WebSocket lifecycle (init, on_message_sent, on_message_received, ...).
from wsrepl import Plugin
from wsrepl.WSMessage import WSMessage
import json
import requests
class Demo(Plugin):
def init(self):
token = requests.get("https://example.com/uuid").json()["uuid"]
self.messages = [
json.dumps({
"auth": "session",
"sessionId": token
})
]
async def on_message_sent(self, message: WSMessage) -> None:
original = message.msg
message.msg = json.dumps({
"type": "message",
"data": {
"text": original
}
})
message.short = original
message.long = message.msg
async def on_message_received(self, message: WSMessage) -> None:
original = message.msg
try:
message.short = json.loads(original)["data"]["text"]
except:
message.short = "Error: could not parse message"
message.long = original
Comments
No comments yet.