Discuss this help topic in SecureBlackbox Forum
Intercept the data being tunneled
Certain tasks may require you to intercept and/or modify application layer data tunneled over a simple forwarding object. For example, you might need that if you are building a proxy with NAT features, or if you are an NSA branch secretly building a secure worldwide surveillance solution.
Intercepting functionality is offered with TElSSHForwardingIntercept component. The Intercept object is attached to the host simple forwarding component (e.g. TElSSHLocalPortForwarding) via its Intercept property; once attached, the forwarding component will direct all its data flows through it.
The TElSSHForwardingIntercept object is abstract and is supposed to be overridden by the component user as per their interception requirements. Essentially, you need to override the following protected methods:
void ChannelRead(TElSSHForwardedConnection conn, byte[] buffer) { Logger.Log(conn, "RemoteToLocal", buffer); // logging data to some file WriteToSocket(buffer, 0, buffer.Length) // writing data unchanged to socket } void SocketRead(TElSSHForwardedConnection conn, byte[] buffer) { Logger.Log(conn, "LocalToRemote", buffer); // logging data to some file WriteToChannel(buffer, 0, buffer.Length); }Example 2. Implementing (very nasty) active interception
void ChannelRead(TElSSHForwardedConnection conn, byte[] buffer) { For (int I = 0; I < buffer.Length; i++) { If (buffer[i] == 0x41) buffer[i] = 0x42; // replacing all 'A's with 'B's. } WriteToSocket(buffer, 0, buffer.Length) } void SocketRead(TElSSHForwardedConnection conn, byte[] buffer) { Byte[] buf = SBUtils.Unit.CloneArray(buffer, 0, buffer.Length - 1); // truncating the last byte of the original buffer WriteToChannel(buf, 0, buf.Length); }Not overriding a particular method preserves its default behavior. For example, Accept() will let accept all incoming connections, and ChannelRead() and SocketRead() will opaquely direct all provided data to the destination point with WriteToSocket() and WriteToChannel() calls.