Created
May 13, 2018 22:52
-
-
Save om26er/e3a3db91bb46fa506cd2426619eaf824 to your computer and use it in GitHub Desktop.
Proof of concept WAMP over RawSocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void doWAMPOverRawSocket() { | |
int jsonSerializerID = 1; | |
int request_max_len_exp = 24; | |
try { | |
Socket socket = SocketFactory.getDefault().createSocket(); | |
socket.connect(new InetSocketAddress("192.168.31.94", 9000)); | |
OutputStream oStream = socket.getOutputStream(); | |
InputStream iStream = socket.getInputStream(); | |
oStream.write(0x7f); | |
oStream.write((request_max_len_exp - 9) << 4 | jsonSerializerID); | |
oStream.write(0x00); | |
oStream.write(0x00); | |
oStream.flush(); | |
byte[] bytes = new byte[4]; | |
while (true) { | |
iStream.read(bytes); | |
byte b = bytes[1]; | |
int serializer = b & 0x0F; | |
int max_length = b >> 4 & 0x0F; | |
if (max_length + 9 == request_max_len_exp && serializer == jsonSerializerID) { | |
System.out.println("MAX " + (long) Math.pow(2, 9 + max_length)); | |
System.out.println("Handshake complete, lets roll"); | |
break; | |
} | |
} | |
Map<String, Map> roles = new HashMap<>(); | |
roles.put("publisher", new HashMap<>()); | |
roles.put("subscriber", new HashMap<>()); | |
roles.put("caller", new HashMap<>()); | |
roles.put("callee", new HashMap<>()); | |
Hello hello = new Hello("realm1", roles); | |
JSONSerializer serializer = new JSONSerializer(); | |
byte[] data = serializer.serialize(hello.marshal()); | |
oStream.write(new byte[] {0x00, 0x00, 0x00, (byte) data.length}); | |
oStream.write(data); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment