mirror of
https://github.com/xen0bit/bitslinger.git
synced 2024-06-27 01:08:42 +00:00
disable ws compression, remove trailing \n from ws protocol, readme
Python example dies with compression enabled. Trailing \n makes no sense in ws protocol, removed so we can use strict == in legnth of segments. Updated readme and examples to reflect change
This commit is contained in:
parent
58de1efd54
commit
080192d12e
@ -73,9 +73,9 @@ An HTTP `POST` request is sent through the proxy and back to the bitslinger HTTP
|
||||
In this mode bitslinger will automatically stand up a WebSocket server in this mode and attempt to send and receive messages containing the packets in the following format to any connected
|
||||
WebSocket client.
|
||||
|
||||
EX: `96f7ba66-d3f2-4b06-b6a0-e5975525d98f\n68656c6c6f0a\n`
|
||||
EX: `96f7ba66-d3f2-4b06-b6a0-e5975525d98f\n68656c6c6f0a`
|
||||
|
||||
Where the UUID and hex encoded payloads segments are terminated with a Line-Feed `\n`.
|
||||
Where the UUID and hex encoded payloads segments are separated with a Line-Feed `\n`.
|
||||
|
||||
### No Proxy
|
||||
|
||||
|
@ -37,7 +37,9 @@ var (
|
||||
httpClient *http.Client
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{} // use default options
|
||||
var upgrader = websocket.Upgrader{
|
||||
EnableCompression: false,
|
||||
}
|
||||
|
||||
// var tcpClient net.Conn
|
||||
var gpq *manager.PacketQueue
|
||||
@ -235,6 +237,8 @@ func receivePayloadWS(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
slog.Info().Str("caller", r.RemoteAddr).Msg("WS Client Connected")
|
||||
// slog.SetOutput(ioutil.Discard)
|
||||
c.EnableWriteCompression(false)
|
||||
c.SetCompressionLevel(0)
|
||||
wsConn = c
|
||||
|
||||
defer func(c *websocket.Conn) {
|
||||
@ -259,7 +263,7 @@ func receivePayloadWS(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Segment Message
|
||||
segments := strings.Split(string(message), "\n")
|
||||
if len(segments) < 2 {
|
||||
if len(segments) != 2 {
|
||||
slog.Warn().Str("message", string(message)).Msg("unexpected message format")
|
||||
continue
|
||||
}
|
||||
@ -311,7 +315,7 @@ func httpModeHandler(pckt manager.Packet) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Warn().Msg("HTTP Proxy communication failed, Default forwarding packet as-is")
|
||||
slog.Warn().Msg("HTTP Proxy communication failed, Default forwarding packet as-is")
|
||||
gpq.AcceptAndRelease(pckt.UUID())
|
||||
}
|
||||
|
||||
@ -320,7 +324,7 @@ func wsModeHandler(pckt manager.Packet) {
|
||||
|
||||
defer slog.Trace().Msg("wsModeHandler done")
|
||||
|
||||
hexEncodedPayload := []byte(pckt.UUID() + "\n" + hex.EncodeToString(pckt.AppLayer().Payload()) + "\n")
|
||||
hexEncodedPayload := []byte(pckt.UUID() + "\n" + hex.EncodeToString(pckt.AppLayer().Payload()))
|
||||
if wsConn != nil {
|
||||
err := wsConn.WriteMessage(websocket.TextMessage, hexEncodedPayload)
|
||||
if err != nil {
|
||||
|
@ -20,7 +20,7 @@ var interrupt chan os.Signal
|
||||
|
||||
func unpackBitSlinger(message []byte) (packetUuid string, packetPayload []byte, err error) {
|
||||
segments := strings.Split(string(message), "\n")
|
||||
if len(segments) >= 2 {
|
||||
if len(segments) == 2 {
|
||||
packetUuid := segments[0]
|
||||
packetPayload, err := hex.DecodeString(segments[1])
|
||||
if err != nil {
|
||||
@ -34,7 +34,7 @@ func unpackBitSlinger(message []byte) (packetUuid string, packetPayload []byte,
|
||||
}
|
||||
|
||||
func packBitSlinger(packetUuid string, packetPayload []byte) (message []byte) {
|
||||
return []byte(packetUuid + "\n" + hex.EncodeToString(packetPayload) + "\n")
|
||||
return []byte(packetUuid + "\n" + hex.EncodeToString(packetPayload))
|
||||
}
|
||||
|
||||
func modifyPayload(payload []byte) []byte {
|
||||
|
@ -4,7 +4,7 @@ const ws = new WebSocket('ws://127.0.0.1:9393/bitslinger');
|
||||
|
||||
function unpackBitSlinger(message) {
|
||||
var segments = message.split('\n');
|
||||
if (segments.length >= 2) {
|
||||
if (segments.length == 2) {
|
||||
var packetUuid = segments[0];
|
||||
var packetPayload = Buffer.from(segments[1], 'hex')
|
||||
return [packetUuid, packetPayload]
|
||||
@ -12,7 +12,7 @@ function unpackBitSlinger(message) {
|
||||
}
|
||||
|
||||
function packBitSlinger(packetUuid, packetPayload) {
|
||||
return packetUuid + '\n' + Buffer.toString('hex') + '\n'
|
||||
return packetUuid + '\n' + Buffer.toString('hex')
|
||||
}
|
||||
|
||||
function modifyPayload(packetPayload) {
|
||||
|
@ -4,13 +4,13 @@ import time
|
||||
|
||||
def unpackBitSlinger(message):
|
||||
segments = message.split("\n")
|
||||
if len(segments) >= 2:
|
||||
if len(segments) == 2:
|
||||
packetUuid = segments[0]
|
||||
packetPayload = bytes.fromhex(segments[1])
|
||||
return packetUuid, packetPayload
|
||||
|
||||
def packBitSlinger(packetUuid, packetPayload):
|
||||
return packetUuid + "\n" + packetPayload.hex() + "\n"
|
||||
return packetUuid + "\n" + packetPayload.hex()
|
||||
|
||||
def modifyPayload(packetPayload):
|
||||
return packetPayload.replace(b'world', b'remy!')
|
||||
|
Loading…
Reference in New Issue
Block a user