Rewrite tcp stream on the fly: how complicated is it? How about dropping a stream?

I am trying to write a tcp stream tunnel (similar to the default SSH descriptors), but with one exception, I have to rewrite certain information as it goes through.

I'm sure there is something similar there, but I could not find it. I have three main questions:

  • Is there an easy way to save tcp stream for monitoring? (for example, using netcat or ssh -r / -l / -D or using some other alltogether utility)
  • How hard is it to rewrite the stream on the fly?

Edit: The rewritten information will only be initial authentication.

+3
source share
4

( ) .

< > socat -v -x tcp-l: 8080, fork, reuseaddr tcp: localhost: 80 2 > log

http://localhost:8080/ http://localhost:80/, log.

TCPreen .

root, , tcpdump tcpflow, , .

socat ,cr ,crnl, // \r.

, & hellip; , Java, , , , .

public class ForwardAndChangeCaseThread extends Thread {
    private Socket in, out;
    public ForwardAndChangeCaseThread(Socket in, Socket out) {
        this.in = in; this.out = out;
    }
    public void run() {
        byte[] buf = new byte[4096];
        InputStream in = this.in.getInputStream();
        OutputStream out = this.out.getOutputStream();
        int count;
        while ((count = in.read(buf)) > 0) {
            for (int i = 0; i < count; i++)
                if (buf[i] >= 0x40) buf[i] ^= 0x20;
            out.write(buf, 0, count);
        }
    }
}
public class TcpForwarder {
    public static void main(String[] args) {
        ServerSocket listen = new ServerSocket(8080, 1);
        for (;;) {
            Socket local = listen.accept();
            Socket remote = new Socket("localhost", 80);
            new ForwardAndChangeCaseThread(local, remote).start();
            new ForwardAndChangeCaseThread(remote, local).start();
        }
    }
}
+11
+2

, , , -. , , . - :

, , , , PortForward, -, TCP, , . - , .

, . , SSL . , / MAC ( , , SSL), .

+1

, , , ...

SSL " ", SSL ... - ( ), SSL. , SSL .

, SSL ( ), , .

0

Source: https://habr.com/ru/post/1730635/


All Articles