1
1
package top .meethigher .proxy .tcp .tunnel ;
2
2
3
3
import io .vertx .core .Vertx ;
4
+ import io .vertx .core .buffer .Buffer ;
4
5
import io .vertx .core .net .NetClient ;
5
6
import io .vertx .core .net .NetSocket ;
6
7
import org .junit .Before ;
@@ -34,6 +35,24 @@ public void setUp() throws Exception {
34
35
*/
35
36
@ Test
36
37
public void testErrorMsg () {
38
+ // netClient.connect(44444, "127.0.0.1")
39
+ // .onComplete(ar -> {
40
+ // if (ar.succeeded()) {
41
+ // NetSocket socket = ar.result();
42
+ // socket.pause();
43
+ // socket.closeHandler(v -> {
44
+ // log.error("连接被关闭");
45
+ // System.exit(1);
46
+ // });
47
+ // socket.write("hello world");
48
+ // socket.resume();
49
+ // } else {
50
+ // ar.cause().printStackTrace();
51
+ // System.exit(1);
52
+ // }
53
+ // });
54
+
55
+ // 模拟故意制造错误的请求头长度。服务端可以配置闲时超时参数解决。注意要大于客户端心跳的频率
37
56
netClient .connect (44444 , "127.0.0.1" )
38
57
.onComplete (ar -> {
39
58
if (ar .succeeded ()) {
@@ -43,7 +62,34 @@ public void testErrorMsg() {
43
62
log .error ("连接被关闭" );
44
63
System .exit (1 );
45
64
});
46
- socket .write ("hello world" );
65
+
66
+ // 模拟暴力攻击
67
+ vertx .setPeriodic (500 , id -> {
68
+ byte [] byteArray = TunnelMessage .OpenDataPort .newBuilder ()
69
+ .setDataProxyName ("ssh-proxy" )
70
+ .setDataProxyPort (2222 )
71
+ .setSecret ("0123456789" )
72
+ .build ().toByteArray ();
73
+ int totalLength = 4 + 2 + byteArray .length ;
74
+ // 模拟恶意制造消息长度
75
+ totalLength += 100 ;
76
+ Buffer buffer = Buffer .buffer ();
77
+ buffer .appendInt (totalLength );
78
+ buffer .appendShort (TunnelMessageType .OPEN_DATA_PORT .code ());
79
+ buffer .appendBytes (byteArray );
80
+ socket .write (buffer );
81
+ });
82
+
83
+ // socket.write(buffer).onComplete(ar1 -> {
84
+ // // 发送一条正常消息
85
+ // socket.write(new TunnelMessageCodec().encode(TunnelMessageType.OPEN_DATA_PORT.code(),
86
+ // TunnelMessage.OpenDataPort.newBuilder()
87
+ // .setSecret("0123456789")
88
+ // .setDataProxyName("ssh-proxy")
89
+ // .setDataProxyPort(2222)
90
+ // .build().toByteArray()
91
+ // ));
92
+ // });
47
93
socket .resume ();
48
94
} else {
49
95
ar .cause ().printStackTrace ();
@@ -83,7 +129,6 @@ public void client() {
83
129
ReverseTcpProxyTunnelClient .create (vertx , netClient ).connect ("127.0.0.1" , 44444 );
84
130
85
131
86
-
87
132
LockSupport .park ();
88
133
}
89
134
}
0 commit comments