private void responseToChallenge(ByteBuffer buf, Link link) { // Challenge is exactly 16 bytes long if (!cap(buf, 16, 16, link, true)) return; ByteBuffer challenge = buf.slice(buf.cursor, 16, true); buf.unref(); // Encode challenge with password ByteBuffer response; try { response = encodePassword(challenge, password); challenge.unref(); } catch (Exception e) { throw new RuntimeException( "Cannot encrypt client password to send to server: " + e.getMessage()); } if (verbose) { response.putMetadata("sender", this); } // Send encoded challenge nextStage(); pushDataToOTOut(response); }
private void handleCredSSP(ByteBuffer buf, Link link) { if (verbose) System.out.println("[" + this + "] INFO: CredSSP data received: " + buf + "."); // Store header position: will parse whole header later in BER format parser int headerPosition = buf.cursor - 1; long payloadLength = buf.readBerLength(); if (payloadLength > 10 * 1024) throw new RuntimeException( "[" + this + "] ERROR: CredSSP packets seems to be too long: " + payloadLength + "bytes. Data: " + buf + "."); // Length is the size of payload, so we need to append size of header int headerLength = buf.cursor - headerPosition; int packetLength = (int) payloadLength + headerLength; if (!cap(buf, packetLength, packetLength, link, false)) // Wait for full packet to arrive return; // Extract payload (with header) ByteBuffer outBuf = buf.slice(headerPosition, packetLength, true); buf.unref(); if (verbose) { outBuf.putMetadata("source", this); } pushDataToPad(CREDSSP_PAD, outBuf); }
private void handleTpkt(ByteBuffer buf, Link link) { // Reserved buf.skipBytes(1); // Read TPKT length int length = buf.readUnsignedShort(); if (!cap(buf, length, length, link, false)) // Wait for full packet to arrive return; int payloadLength = length - buf.cursor; // Extract payload ByteBuffer outBuf = buf.slice(buf.cursor, payloadLength, true); buf.unref(); if (verbose) { outBuf.putMetadata("source", this); } pushDataToPad(TPKT_PAD, outBuf); }
private void handleFastPath(ByteBuffer buf, Link link, int typeAndFlags) { // Number of bytes in updateData field (including header (1+1 or 2 // bytes)) int length = buf.readVariableUnsignedShort(); if (!cap(buf, length, length, link, false)) // Wait for full packet to arrive return; int type = typeAndFlags & 0x3; int securityFlags = (typeAndFlags >> 6) & 0x3; // Assertions { if (type != PROTOCOL_FASTPATH) throw new RuntimeException( "Unknown protocol. Expected protocol: 0 (FastPath). Actual protocol: " + type + ", data: " + buf + "."); switch (securityFlags) { case FASTPATH_OUTPUT_SECURE_CHECKSUM: // TODO throw new RuntimeException("Secure checksum is not supported in FastPath packets."); case FASTPATH_OUTPUT_ENCRYPTED: // TODO throw new RuntimeException("Encryption is not supported in FastPath packets."); } } // TODO: optional FIPS information, when FIPS is selected // TODO: optional data signature (checksum), when checksum or FIPS is // selected // Array of FastPath update fields while (buf.cursor < buf.length) { int updateHeader = buf.readUnsignedByte(); int size = buf.readUnsignedShortLE(); int updateCode = updateHeader & 0xf; int fragmentation = (updateHeader >> 4) & 0x3; int compression = (updateHeader >> 6) & 0x3; if (verbose) System.out.println( "[" + this + "] INFO: FastPath update received. UpdateCode: " + updateCode + ", fragmentation: " + fragmentation + ", compression: " + compression + ", size: " + size + "."); ByteBuffer data = buf.readBytes(size); buf.putMetadata("fragmentation", fragmentation); buf.putMetadata("compression", compression); switch (updateCode) { case FASTPATH_UPDATETYPE_ORDERS: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_ORDERS."); pushDataToPad(ORDERS_PAD, data); break; case FASTPATH_UPDATETYPE_BITMAP: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_BITMAP."); pushDataToPad(BITMAP_PAD, data); break; case FASTPATH_UPDATETYPE_PALETTE: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_PALETTE."); pushDataToPad(PALETTE_PAD, data); break; case FASTPATH_UPDATETYPE_SYNCHRONIZE: // @see http://msdn.microsoft.com/en-us/library/cc240625.aspx if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_SYNCHRONIZE."); data.unref(); if (size != 0) throw new RuntimeException( "Size of FastPath synchronize packet must be 0. UpdateCode: " + updateCode + ", fragmentation: " + fragmentation + ", compression: " + compression + ", size: " + size + ", data: " + data + "."); break; case FASTPATH_UPDATETYPE_SURFCMDS: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_SURFCMDS."); break; case FASTPATH_UPDATETYPE_PTR_NULL: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_PTR_NULL."); break; case FASTPATH_UPDATETYPE_PTR_DEFAULT: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_PTR_DEFAULT."); break; case FASTPATH_UPDATETYPE_PTR_POSITION: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_PTR_POSITION."); break; case FASTPATH_UPDATETYPE_COLOR: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_COLOR."); break; case FASTPATH_UPDATETYPE_CACHED: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_CACHED."); break; case FASTPATH_UPDATETYPE_POINTER: if (verbose) System.out.println("[" + this + "] INFO: FASTPATH_UPDATETYPE_POINTER."); break; default: throw new RuntimeException( "Unknown FastPath update. UpdateCode: " + updateCode + ", fragmentation: " + fragmentation + ", compression: " + compression + ", size: " + size + ", data: " + data + "."); } buf.unref(); } }