[fix] 修复位置问题

This commit is contained in:
wujiawei 2024-09-24 19:38:53 +08:00
parent bc1c2b008b
commit 576498afc7
35 changed files with 221 additions and 172 deletions

View File

@ -75,8 +75,8 @@ public class HeartbeatClientConfiguration {
}
@Bean
public ClientHandleDistributeClientTransferClientResponseTypeAdvanced clientHandleDistributeClientTransferClientResponseTypeAdvanced() {
return new ClientHandleDistributeClientTransferClientResponseTypeAdvanced();
public ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced clientHandleDistributeClientTransferClientResponseTypeAdvanced() {
return new ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced();
}
@Bean
public ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced handleDistributeSingleClientRealCloseVisitorTypeAdvanced() {
@ -84,8 +84,8 @@ public class HeartbeatClientConfiguration {
}
@Bean
public ClientReportHandleChannelTransferTypeAdvancedHandleDistribute handleChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
return new ClientReportHandleChannelTransferTypeAdvancedHandleDistribute(nettyClientProperties);
public ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute handleChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
return new ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute(nettyClientProperties);
}
@Bean
@ -153,9 +153,13 @@ public class HeartbeatClientConfiguration {
@Bean
public ClientHandleDistributeSingleClientRealConnectTypeAdvanced clientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties,
public ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced clientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties,
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
return new ClientHandleDistributeSingleClientRealConnectTypeAdvanced(nettyClientProperties, handleChannelTypeAdvancedList);
return new ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced(nettyClientProperties, handleChannelTypeAdvancedList);
}
@Bean
public ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced clientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced() {
return new ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced();
}
}

View File

@ -43,9 +43,4 @@ public class InternalNetworkPermeateServerVisitor implements InternalNetworkPerm
*/
private List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
/**
* 访客ID
*/
private String visitorId;
}

View File

@ -6,8 +6,7 @@ import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeChannelTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
@ -18,11 +17,11 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
*/
@Slf4j
public class ClientReportHandleChannelTransferTypeAdvancedHandleDistribute extends AbstractHandleDistributeChannelTransferTypeAdvanced<NettyProxyMsg> {
public class ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute extends AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced<NettyProxyMsg> {
private final NettyClientProperties nettyClientProperties;
public ClientReportHandleChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
public ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute(NettyClientProperties nettyClientProperties) {
this.nettyClientProperties = nettyClientProperties;
}

View File

@ -47,16 +47,13 @@ public class ClientHandleDistributeClientPermeateServerInitTypeAdvanced extends
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
// ChannelFlowAdapter channelFlowAdapter = SpringContextHolder.getBean(ChannelFlowAdapter.class);
NettyClientPermeateServerVisitorSocket nettyClientPermeateServerVisitorSocket = NettyClientPermeateServerVisitorSocket.NettyVisitorSocketBuilder.builder()
.builderClientId(new String(clientIdBytes))
.builderClientTargetIp(new String(clientTargetIp))
.builderClientTargetPort(Integer.parseInt(new String(clientTargetPort)))
.builderVisitorPort(Integer.parseInt(new String(visitorPort)))
.builderNettyClientProperties(nettyClientProperties)
// .builderChannelFlowAdapter(channelFlowAdapter)
.builderHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList)
.build();
try {
nettyClientPermeateServerVisitorSocket.start();

View File

@ -28,16 +28,15 @@ public class ClientHandleDistributeClientTransferServerPermeateChannelConnection
/**
* 处理当前数据
*
* @param channel 当前通道
* @param transferChannel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
public void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
// 连接成功 开启自动读取写
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
String visitorId = new String(msgVisitorId);
Channel visitor = NettyRealIdContext.getReal(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(transferChannel);
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
}

View File

@ -7,7 +7,7 @@ import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyServe
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPenetrationRealClient;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientRealConnectTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced;
import java.util.List;
@ -15,12 +15,12 @@ import java.util.List;
* 客户端创建真实代理同奥
*/
@Slf4j
public class ClientHandleDistributeSingleClientRealConnectTypeAdvanced extends AbstractHandleDistributeSingleClientRealConnectTypeAdvanced<NettyProxyMsg> {
public class ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced extends AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced<NettyProxyMsg> {
private final NettyClientProperties nettyClientProperties;// 服务端地址信息
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
public ClientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
public ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
this.nettyClientProperties = nettyClientProperties;
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
}

View File

@ -5,7 +5,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientResponseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
@ -17,7 +17,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
*/
@Slf4j
public class ClientHandleDistributeClientTransferClientResponseTypeAdvanced extends AbstractHandleDistributeClientTransferClientResponseTypeAdvanced<NettyProxyMsg> {
public class ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced extends AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced<NettyProxyMsg> {

View File

@ -0,0 +1,35 @@
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
/**
* 下发 客户端渗透服务端通信通道关闭
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
*/
@Slf4j
public class ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
// 关闭本地通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
channel.close();
nextChannel.close();
}
}

View File

@ -4,7 +4,6 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientRealHandler;
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyServerPermeateClientRealHandler;
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
import org.framework.lazy.cloud.network.heartbeat.common.encoder.TransferEncoder;
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;

View File

@ -12,11 +12,8 @@ import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPe
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.wu.framework.core.utils.ObjectUtils;
import java.util.UUID;
@ -44,13 +41,14 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
// 生成访客ID
String visitorId = UUID.randomUUID().toString();
log.info("this channel{} use visitorId:{}", visitorChannel.id().asLongText(), visitorId);
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
internalNetworkPermeateServerVisitor.setVisitorId(visitorId);
// 判断是否有可用的通道 如果没有创建新的通道
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
// 创建访客连接服务端通道
NettyClientPermeateServerVisitorTransferSocket.buildTransferServer(internalNetworkPermeateServerVisitor,visitorChannel);
log.debug("客户端渗透服务端访客端口连接成功了");
log.info("客户端渗透服务端访客端口连接成功了,访客ID:{}", visitorId);
super.channelActive(ctx);
}
@ -65,7 +63,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
// 获取客户端通道而后进行数据下发
log.debug("【客户端渗透服务端】访客端口成功接收数据:{}", new String(bytes));
log.info("【客户端渗透服务端】访客端口成功接收数据:{}", new String(bytes));
// 使用访客的通信通道
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
@ -78,14 +76,14 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
nettyProxyMsg.setData(bytes);
nextChannel.writeAndFlush(nettyProxyMsg);
// 处理访客流量
log.debug("【客户端渗透服务端】访客端口成功发送数据了");
log.info("【客户端渗透服务端】访客端口成功发送数据了 访客ID:{}", visitorId);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
Channel channel = ctx.channel();
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
String clientId = ChannelAttributeKeyUtils.getClientId(channel);
log.info("channel inactive:{}", visitorId);
if (StringUtil.isNullOrEmpty(visitorId)) {
super.channelInactive(ctx);
return;
@ -102,7 +100,12 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
myMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
myMsg.setVisitorId(visitorId);
nextChannel.writeAndFlush(myMsg);
//通信通道
nextChannel.close();
}
// 访客通道关闭
channel.close();
log.warn("【客户端渗透服务端】访客端口断开连接");
super.channelInactive(ctx);
}
@ -111,10 +114,10 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
if (ctx.channel().isWritable()) {
log.debug("Channel is writable again");
log.info("Channel is writable again");
// 恢复之前暂停的操作如写入数据
} else {
log.debug("Channel is not writable");
log.info("Channel is not writable");
// 暂停写入操作等待可写状态
}
log.info("channelWritabilityChanged!");
@ -128,7 +131,6 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
String clientId = ChannelAttributeKeyUtils.getClientId(channel);
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
// 使用通信通道 下发关闭访客
Channel visitorChannel = NettyCommunicationIdContext.getVisitor(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
if (nextChannel != null) {
// 下发关闭访客

View File

@ -30,7 +30,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
Integer visitorPort = ChannelAttributeKeyUtils.getVisitorPort(ctx.channel());
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
// 访客通信通道 上报服务端代理完成
Channel visitorChannel = NettyCommunicationIdContext.getVisitor(visitorId);
Channel visitor = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
NettyProxyMsg returnMessage = new NettyProxyMsg();
returnMessage.setType(MessageType.REPORT_CLIENT_TRANSFER);
returnMessage.setVisitorId(visitorId);
@ -38,7 +38,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
returnMessage.setVisitorPort(visitorPort);
returnMessage.setData(bytes);
visitorChannel.writeAndFlush(returnMessage);
visitor.writeAndFlush(returnMessage);
}
@ -52,7 +52,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
// 客户端真实通信通道
Channel visitor = NettyCommunicationIdContext.getVisitor(visitorId);
Channel visitor = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
if (visitor != null) {
// 上报关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
@ -79,11 +79,12 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
// 获取访客的传输通道
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
if(ObjectUtils.isEmpty(visitorId)) {
super.channelWritabilityChanged(ctx);
return;
}
Channel visitorCommunicationChannel = NettyCommunicationIdContext.getVisitor(visitorId);
Channel visitorCommunicationChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
if (visitorCommunicationChannel != null) {
log.debug("visitorId:{} transfer AUTO_READ:{} ",visitorId,ctx.channel().isWritable());
visitorCommunicationChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());

View File

@ -15,6 +15,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelT
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 客户端连接真实服务
@ -131,7 +132,7 @@ public class NettyClientPermeateClientRealSocket {
// 使用的客户端ID:{}
log.info("Client ID used: {}", clientId);
future.addListener((ChannelFutureListener) futureListener -> {
Channel visitorChannel = futureListener.channel();
Channel transferChannel = futureListener.channel();
if (futureListener.isSuccess()) {
realChannel.config().setOption(ChannelOption.AUTO_READ, true);
// 通知服务端访客连接成功
@ -142,20 +143,30 @@ public class NettyClientPermeateClientRealSocket {
nettyProxyMsg.setClientTargetPort(clientTargetPort);
nettyProxyMsg.setVisitorPort(visitorPort);
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL);
visitorChannel.writeAndFlush(nettyProxyMsg);
transferChannel.writeAndFlush(nettyProxyMsg);
ChannelAttributeKeyUtils.buildNextChannel(visitorChannel, realChannel);
ChannelAttributeKeyUtils.buildNextChannel(realChannel, visitorChannel);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);
ChannelAttributeKeyUtils.buildNextChannel(realChannel, transferChannel);
// 绑定客户端真实通信通道
NettyCommunicationIdContext.pushVisitor(visitorChannel, visitorId);
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(visitorChannel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
} else {
log.info("无法连接到服务端....");
transferChannel.eventLoop().schedule(() -> {
try {
newVisitorConnect2Server(clientId,
clientTargetIp,
clientTargetPort,
visitorPort,
visitorId,realChannel, nettyClientProperties, handleChannelTypeAdvancedList);
} catch (Exception e) {
e.printStackTrace();
}
}, 2, TimeUnit.SECONDS);
}
});
}

View File

@ -16,6 +16,8 @@ import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.concurrent.TimeUnit;
/**
* 客户端渗透服务端传输通道
*/
@ -75,7 +77,7 @@ public class NettyClientPermeateClientVisitorTransferSocket {
// 使用的客户端ID:{}
log.info("Client ID used: {}", clientId);
future.addListener((ChannelFutureListener) futureListener -> {
Channel channel = futureListener.channel();
Channel transferChannel = futureListener.channel();
if (futureListener.isSuccess()) {
NettyProxyMsg myMsg = new NettyProxyMsg();
@ -87,20 +89,26 @@ public class NettyClientPermeateClientVisitorTransferSocket {
myMsg.setClientTargetPort(targetPort);
myMsg.setVisitorId(visitorId);
channel.writeAndFlush(myMsg);
transferChannel.writeAndFlush(myMsg);
// 绑定客户端真实通信通道
NettyCommunicationIdContext.pushVisitor(channel, visitorId);
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
// 传输通道打开后自动读取
Channel visitor = NettyRealIdContext.getReal(visitorId);
ChannelAttributeKeyUtils.buildNextChannel(visitor, channel);
ChannelAttributeKeyUtils.buildNextChannel(channel, visitor);
ChannelAttributeKeyUtils.buildNextChannel(visitor, transferChannel);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, visitor);
} else {
log.info("无法连接到服务端....");
transferChannel.eventLoop().schedule(() -> {
try {
buildTransferServer(internalNetworkClientPermeateClientVisitor);
} catch (Exception e) {
e.printStackTrace();
}
}, 2, TimeUnit.SECONDS);
}
});
}

View File

@ -263,8 +263,8 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
internalNetworkPermeateServerVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
NettyClientPermeateServerVisitorFilter visitorFilter = new NettyClientPermeateServerVisitorFilter(internalNetworkPermeateServerVisitor);
return new NettyClientPermeateServerVisitorSocket(visitorFilter, clientId, visitorPort);
NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter = new NettyClientPermeateServerVisitorFilter(internalNetworkPermeateServerVisitor);
return new NettyClientPermeateServerVisitorSocket(nettyClientPermeateServerVisitorFilter, clientId, visitorPort);
}

View File

@ -14,6 +14,8 @@ import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.util.concurrent.TimeUnit;
/**
* 客户端渗透服务端传输通道
*/
@ -21,20 +23,12 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
public class NettyClientPermeateServerVisitorTransferSocket {
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
/**
* 连接服务端通信通道
*/
public static void buildTransferServer(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor, Channel visitorChannel) {
newTransferConnect2Server(internalNetworkPermeateServerVisitor,visitorChannel);
}
/**
* 连接服务端通信通道
* <p>
* internalNetworkPermeateServerVisitor
*/
protected static void newTransferConnect2Server(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor, Channel visitorChannel) {
public static void buildTransferServer(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor, Channel visitorChannel) {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup)
@ -63,7 +57,7 @@ public class NettyClientPermeateServerVisitorTransferSocket {
String targetIp = internalNetworkPermeateServerVisitor.getTargetIp();
Integer targetPort = internalNetworkPermeateServerVisitor.getTargetPort();
String visitorId = internalNetworkPermeateServerVisitor.getVisitorId();
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
@ -73,7 +67,7 @@ public class NettyClientPermeateServerVisitorTransferSocket {
// 使用的客户端ID:{}
log.info("Client ID used: {}", clientId);
future.addListener((ChannelFutureListener) futureListener -> {
Channel channel = futureListener.channel();
Channel transferChannel = futureListener.channel();
if (futureListener.isSuccess()) {
NettyProxyMsg myMsg = new NettyProxyMsg();
@ -82,18 +76,24 @@ public class NettyClientPermeateServerVisitorTransferSocket {
myMsg.setVisitorPort(visitorPort);
myMsg.setClientTargetIp(targetIp);
myMsg.setClientTargetPort(targetPort);
myMsg.setVisitorId(visitorId);
channel.writeAndFlush(myMsg);
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
// 传输通道打开后自动读取
ChannelAttributeKeyUtils.buildNextChannel(visitorChannel, transferChannel);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, visitorChannel);
transferChannel.writeAndFlush(myMsg);
ChannelAttributeKeyUtils.buildNextChannel(visitorChannel, channel);
ChannelAttributeKeyUtils.buildNextChannel(channel, visitorChannel);
} else {
log.info("客户端渗透服务端通信通道中断....");
transferChannel.eventLoop().schedule(() -> {
try {
buildTransferServer(internalNetworkPermeateServerVisitor, visitorChannel);
} catch (Exception e) {
e.printStackTrace();
}
}, 2, TimeUnit.SECONDS);
}
});
}

View File

@ -75,7 +75,7 @@ public class NettyServerPermeateClientRealSocket {
log.info("访客通过 客户端:【{}】,绑定本地服务,IP:{},端口:{} 新建通道成功", clientId, clientTargetIp, clientTargetPort);
// 客户端真实通道
NettyRealIdContext.pushReal(realChannel, visitorId);
// NettyRealIdContext.pushReal(realChannel, visitorId);
// 绑定访客ID到当前真实通道属性
ChannelAttributeKeyUtils.buildVisitorId(realChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(realChannel, clientId);
@ -84,7 +84,7 @@ public class NettyServerPermeateClientRealSocket {
// 新建一个通道处理
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList,realChannel);
// 是否等 服务端相应访客通道已经可以自动读写
// realChannel.config().setOption(ChannelOption.AUTO_READ, true);
@ -132,7 +132,8 @@ public class NettyServerPermeateClientRealSocket {
*/
protected static void newVisitorConnect2Server(InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient,
NettyClientProperties nettyClientProperties,
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) throws InterruptedException {
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList,
Channel realChannel) throws InterruptedException {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup)
.channel(NioSocketChannel.class)
@ -171,7 +172,7 @@ public class NettyServerPermeateClientRealSocket {
// 使用的客户端ID:{}
log.info("Client ID used: {}" , visitorClientId);
future.addListener((ChannelFutureListener) futureListener -> {
Channel channel = futureListener.channel();
Channel transferChannel = futureListener.channel();
if (futureListener.isSuccess()) {
NettyProxyMsg myMsg = new NettyProxyMsg();
@ -182,17 +183,17 @@ public class NettyServerPermeateClientRealSocket {
myMsg.setClientTargetPort(clientTargetPort);
myMsg.setVisitorId(visitorId);
channel.writeAndFlush(myMsg);
transferChannel.writeAndFlush(myMsg);
// 绑定客户端真实通信通道
NettyCommunicationIdContext.pushVisitor(channel, visitorId);
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
ChannelAttributeKeyUtils.buildClientId(channel, visitorClientId);
NettyCommunicationIdContext.pushVisitor(transferChannel, visitorId);
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(transferChannel, visitorClientId);
// 客户端真实通道自动读写打开
Channel visitor = NettyRealIdContext.getReal(visitorId);
visitor.config().setOption(ChannelOption.AUTO_READ, true);
ChannelAttributeKeyUtils.buildNextChannel(visitor, channel);
ChannelAttributeKeyUtils.buildNextChannel(channel, visitor);
realChannel.config().setOption(ChannelOption.AUTO_READ, true);
ChannelAttributeKeyUtils.buildNextChannel(realChannel, transferChannel);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);
@ -200,9 +201,9 @@ public class NettyServerPermeateClientRealSocket {
} else {
log.info("每隔2s重连....");
// 离线
channel.eventLoop().schedule(() -> {
transferChannel.eventLoop().schedule(() -> {
try {
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList,realChannel);
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@ -2,6 +2,8 @@ package org.framework.lazy.cloud.network.heartbeat.common;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelHeartbeatTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.*;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.*;
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
@ -52,7 +54,7 @@ public class MessageType {
* 上报 客户端数据传输内网穿透数据回传
*
* @see MessageTypeEnums#REPORT_CLIENT_TRANSFER
* @see AbstractHandleReportHandleChannelTransferTypeAdvanced
* @see AbstractHandleReportServicePermeateClientTransferTypeAdvanced
*/
public static final byte REPORT_CLIENT_TRANSFER = 0X05;
@ -61,14 +63,14 @@ public class MessageType {
* 上报 客户端创建需要代理的真实端口成功
*
* @see MessageTypeEnums#REPORT_SINGLE_CLIENT_REAL_CONNECT
* @see AbstractHandleReportSingleClientRealConnectTypeAdvanced
* @see AbstractHandleReportServicePermeateClientRealConnectTypeAdvanced
*/
public static final byte REPORT_SINGLE_CLIENT_REAL_CONNECT = 0X06;
/**
* 上报 客户端关闭一个访客通道
*
* @see MessageTypeEnums#REPORT_SINGLE_CLIENT_CLOSE_VISITOR
* @see AbstractHandleReportSingleClientCloseVisitorTypeAdvanced
* @see AbstractHandleReportServicePermeateClientCloseVisitorTypeAdvanced
*/
public static final byte REPORT_SINGLE_CLIENT_CLOSE_VISITOR = 0X08;
@ -83,7 +85,7 @@ public class MessageType {
* 服务端通道 is active
*
* @see MessageTypeEnums#SERVER_CHANNEL_ACTIVE
* @see AbstractHandleServerChannelActiveTypeAdvanced
* @see AbstractHandleReportServerChannelActiveTypeAdvanced
*/
public static final byte SERVER_CHANNEL_ACTIVE = 0X10;
@ -207,6 +209,9 @@ public class MessageType {
*/
public static final byte REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE = 0X25;
/**
* 下发 客户端接收连接成功通知
*
@ -240,14 +245,14 @@ public class MessageType {
* 下发 客户端数据传输(内网穿透数据发送)
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
* @see AbstractHandleDistributeChannelTransferTypeAdvanced
* @see AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced
*/
public static final byte DISTRIBUTE_CLIENT_TRANSFER = -0X05;
/**
* 下发 客户端创建需要代理的真实端口
*
* @see MessageTypeEnums#DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT
* @see AbstractHandleDistributeSingleClientRealConnectTypeAdvanced
* @see AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced
*/
public static final byte DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT = -0X06;
@ -381,7 +386,7 @@ public class MessageType {
* 下发客户端渗透客户端数据传输响应
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
* @see AbstractHandleDistributeClientTransferClientResponseTypeAdvanced
* @see AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced
* @see MessageType#REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE
*/
public static final byte DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE = -0X24;

View File

@ -10,7 +10,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
* 下发 客户端 创建真实连接
*/
public abstract class AbstractHandleDistributeSingleClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
public abstract class AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**
* 是否支持当前类型

View File

@ -12,7 +12,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
*
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
*/
public abstract class AbstractHandleDistributeClientTransferClientResponseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
public abstract class AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
* 客户端处理服务端下发数据
* DISTRIBUTE_CLIENT_TRANSFER
*/
public abstract class AbstractHandleDistributeChannelTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
public abstract class AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
* 服务端通道 is active
* SERVER_CHANNEL_ACTIVE
*/
public abstract class AbstractHandleServerChannelActiveTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
public abstract class AbstractHandleReportServerChannelActiveTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
* 服务端处理客户端 关闭一个访客
* REPORT_SINGLE_CLIENT_CLOSE_VISITOR
*/
public abstract class AbstractHandleReportSingleClientCloseVisitorTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
public abstract class AbstractHandleReportServicePermeateClientCloseVisitorTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
* 服务端处理客户端绑定真实服务成功
* REPORT_SINGLE_CLIENT_REAL_CONNECT
*/
public abstract class AbstractHandleReportSingleClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
public abstract class AbstractHandleReportServicePermeateClientRealConnectTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -11,7 +11,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
* 服务端处理客户端上报数据
* REPORT_CLIENT_STAGING_CLOSED
*/
public abstract class AbstractHandleReportHandleChannelTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
public abstract class AbstractHandleReportServicePermeateClientTransferTypeAdvanced<MSG> extends AbstractHandleChannelTypeAdvanced<NettyProxyMsg> implements HandleChannelTypeAdvanced {
/**

View File

@ -5,6 +5,8 @@ import lombok.Getter;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelHeartbeatTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.*;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.*;
/**
@ -34,16 +36,16 @@ public enum MessageTypeEnums {
*/
REPORT_CLIENT_STAGING_CLOSED(MessageType.REPORT_CLIENT_STAGING_CLOSED, "上报 客户端暂存关闭"),
/**
* @see AbstractHandleReportHandleChannelTransferTypeAdvanced
* @see AbstractHandleReportServicePermeateClientTransferTypeAdvanced
*/
REPORT_CLIENT_TRANSFER(MessageType.REPORT_CLIENT_TRANSFER, "上报 客户端数据传输(内网穿透数据回传)"),
/**
* @see AbstractHandleReportSingleClientRealConnectTypeAdvanced
* @see AbstractHandleReportServicePermeateClientRealConnectTypeAdvanced
*/
REPORT_SINGLE_CLIENT_REAL_CONNECT(MessageType.REPORT_SINGLE_CLIENT_REAL_CONNECT, "上报 客户端创建需要代理的真实端口成功"),
/**
* @see AbstractHandleReportSingleClientCloseVisitorTypeAdvanced
* @see AbstractHandleReportServicePermeateClientCloseVisitorTypeAdvanced
*/
REPORT_SINGLE_CLIENT_CLOSE_VISITOR(MessageType.REPORT_SINGLE_CLIENT_CLOSE_VISITOR, "上报 客户端关闭一个访客通道"),
/**
@ -51,7 +53,7 @@ public enum MessageTypeEnums {
*/
REPORT_SINGLE_CLIENT_MESSAGE(MessageType.REPORT_SINGLE_CLIENT_MESSAGE, "上报 客户端消息到另一个客户端"),
/**
* @see AbstractHandleServerChannelActiveTypeAdvanced
* @see AbstractHandleReportServerChannelActiveTypeAdvanced
*/
SERVER_CHANNEL_ACTIVE(MessageType.SERVER_CHANNEL_ACTIVE, "服务端通道 is active"),
/**
@ -140,11 +142,11 @@ public enum MessageTypeEnums {
*/
DISTRIBUTE_CLIENT_STAGING_CLOSED_NOTIFICATION(MessageType.DISTRIBUTE_CLIENT_STAGING_CLOSED_NOTIFICATION, "下发 客户端暂存关闭通知"),
/**
* @see AbstractHandleDistributeChannelTransferTypeAdvanced
* @see AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced
*/
DISTRIBUTE_CLIENT_TRANSFER(MessageType.DISTRIBUTE_CLIENT_TRANSFER, "下发 客户端数据传输(内网穿透数据发送)"),
/**
* @see AbstractHandleDistributeSingleClientRealConnectTypeAdvanced
* @see AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced
*/
DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT, "下发 客户端创建需要代理的真实端口"),
/**
@ -216,7 +218,7 @@ public enum MessageTypeEnums {
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST, "下发客户端渗透客户端数据传输"),
/**
* 下发客户端渗透客户端数据传输
* @see AbstractHandleDistributeClientTransferClientResponseTypeAdvanced
* @see AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced
*/
DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE(MessageType.DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE, "下发客户端渗透客户端数据传输"),
/**

View File

@ -26,12 +26,12 @@ public class HeartbeatServerConfiguration {
/**
* 处理 服务端处理客户端数据传输
*
* @return ServerHandleReportHandleChannelTransferTypeAdvanced
* @return ServerHandleReportServicePermeateClientTransferTypeAdvanced
*/
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Bean
public ServerHandleReportHandleChannelTransferTypeAdvanced serverReportChannelTransferTypeAdvanced(ChannelFlowAdapter channelFlowAdapter) {
return new ServerHandleReportHandleChannelTransferTypeAdvanced(channelFlowAdapter);
public ServerHandleReportServicePermeateClientTransferTypeAdvanced serverReportChannelTransferTypeAdvanced(ChannelFlowAdapter channelFlowAdapter) {
return new ServerHandleReportServicePermeateClientTransferTypeAdvanced(channelFlowAdapter);
}
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@ -69,14 +69,14 @@ public class HeartbeatServerConfiguration {
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Bean
public ServerHandleReportSingleClientCloseVisitorTypeAdvanced serverReportSingleClientCloseVisitorTypeAdvanced() {
return new ServerHandleReportSingleClientCloseVisitorTypeAdvanced();
public ServerHandleReportServicePermeateClientCloseVisitorTypeAdvanced serverReportSingleClientCloseVisitorTypeAdvanced() {
return new ServerHandleReportServicePermeateClientCloseVisitorTypeAdvanced();
}
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Bean
public ServerHandleReportSingleClientRealConnectTypeAdvanced serverReportSingleClientRealConnectTypeAdvanced() {
return new ServerHandleReportSingleClientRealConnectTypeAdvanced();
public ServerHandleReportServicePermeateClientRealConnectTypeAdvanced serverReportSingleClientRealConnectTypeAdvanced() {
return new ServerHandleReportServicePermeateClientRealConnectTypeAdvanced();
}
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)

View File

@ -5,7 +5,6 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportClientPermeateServerTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ChannelFlowEnum;
@ -37,10 +36,10 @@ public class ServerHandleReportClientPermeateServerTransferTypeAdvanced extends
String clientId = new String(msg.getClientId());
Integer visitorPort = Integer.valueOf(new String(msg.getVisitorPort()));
byte[] visitorId = msg.getVisitorId();
// log.info("访客ID:【{}】 访客端口:[{}] 接收到客户端:[{}]", new String(visitorId), visitorPort, clientId);
// log.debug("访客ID:【{}】接收到客户端:[{}] 返回数据大小:[{}] 内网穿透返回的数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
log.info("【客户端渗透服务端】访客ID:【{}】 访客端口:[{}] 接收到客户端:[{}] 接收服务端数据大小:[{}]", new String(visitorId), visitorPort, clientId, msg.getData().length);
log.debug("【客户端渗透服务端】访客ID:【{}】接收到客户端:[{}] 接收服务端数据大小:[{}] 接收服务端数据:[{}]", new String(visitorId), clientId, msg.getData().length, new String(msg.getData()));
// 将数据转发访客通道
Channel visitor = NettyRealIdContext.getReal(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
if (nextChannel != null) {
ByteBuf buf = nextChannel.config().getAllocator().buffer(msg.getData().length);
@ -58,6 +57,6 @@ public class ServerHandleReportClientPermeateServerTransferTypeAdvanced extends
.build();
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
}
log.debug("访客ID:【{}】接收到客户端:[{}] 发送真实数据成功", new String(visitorId), clientId);
log.debug("客户端渗透服务端】访客ID:【{}】接收到客户端:[{}] 传输真实数据成功", new String(visitorId), clientId);
}
}

View File

@ -14,11 +14,11 @@ public class ServerHandleReportClientTransferServerPermeateChannelConnectionSucc
/**
* 处理当前数据
*
* @param channel 当前通道
* @param transferChannel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
// 创建目标地址连接
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
@ -28,7 +28,7 @@ public class ServerHandleReportClientTransferServerPermeateChannelConnectionSucc
Integer.parseInt(new String(msgVisitorPort)),
new String(msgClientTargetIp),
Integer.parseInt(new String(msgClientTargetPort)),
channel
transferChannel
);

View File

@ -6,14 +6,14 @@ import org.springframework.stereotype.Component;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportSingleClientCloseVisitorTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportServicePermeateClientCloseVisitorTypeAdvanced;
/**
* 服务端处理客户端 关闭一个访客
*/
@Slf4j
@Component
public class ServerHandleReportSingleClientCloseVisitorTypeAdvanced extends AbstractHandleReportSingleClientCloseVisitorTypeAdvanced<NettyProxyMsg> {
public class ServerHandleReportServicePermeateClientCloseVisitorTypeAdvanced extends AbstractHandleReportServicePermeateClientCloseVisitorTypeAdvanced<NettyProxyMsg> {
/**

View File

@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportSingleClientRealConnectTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportServicePermeateClientRealConnectTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
/**
@ -15,16 +15,16 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
*/
@Slf4j
@Component
public class ServerHandleReportSingleClientRealConnectTypeAdvanced extends AbstractHandleReportSingleClientRealConnectTypeAdvanced<NettyProxyMsg> {
public class ServerHandleReportServicePermeateClientRealConnectTypeAdvanced extends AbstractHandleReportServicePermeateClientRealConnectTypeAdvanced<NettyProxyMsg> {
/**
* 处理当前数据
*
* @param channel 当前通道
* @param transferChannel 当前通道
* @param nettyProxyMsg 通道数据
*/
@Override
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
protected void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
// 客户端绑定端口成功
byte[] clientId = nettyProxyMsg.getClientId();
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
@ -33,16 +33,16 @@ public class ServerHandleReportSingleClientRealConnectTypeAdvanced extends Abstr
byte[] visitorId = nettyProxyMsg.getVisitorId();
log.info("客户端:{},绑定真实服务ip:{},port:{},成功", new String(clientId), new String(clientTargetIp), new String(clientTargetPort));
// 绑定服务端访客通信通道
NettyCommunicationIdContext.pushVisitor(channel, new String(visitorId));
ChannelAttributeKeyUtils.buildVisitorId(channel, visitorId);
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(channel, Integer.valueOf(new String(visitorPort)));
NettyCommunicationIdContext.pushVisitor(transferChannel, new String(visitorId));
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
ChannelAttributeKeyUtils.buildVisitorPort(transferChannel, Integer.valueOf(new String(visitorPort)));
// 访客通道开启自动读取
Channel visitorRealChannel = NettyRealIdContext.getReal(new String(visitorId));
Channel visitorRealChannel = NettyRealIdContext.getReal(visitorId);
visitorRealChannel.config().setOption(ChannelOption.AUTO_READ, true);
ChannelAttributeKeyUtils.buildNextChannel(channel, visitorRealChannel);
ChannelAttributeKeyUtils.buildNextChannel(visitorRealChannel, channel);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, visitorRealChannel);
ChannelAttributeKeyUtils.buildNextChannel(visitorRealChannel, transferChannel);
// 或许此处还应该通知服务端 这个访客绑定的客户端真实通道打开

View File

@ -8,14 +8,12 @@ import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportHandleChannelTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportServicePermeateClientTransferTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ChannelFlowEnum;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.server.netty.flow.ServerChannelFlow;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
/**
* 服务端处理客户端数据传输
@ -23,11 +21,11 @@ import java.nio.charset.StandardCharsets;
*/
@Slf4j
@Component
public class ServerHandleReportHandleChannelTransferTypeAdvanced extends AbstractHandleReportHandleChannelTransferTypeAdvanced<NettyProxyMsg> {
public class ServerHandleReportServicePermeateClientTransferTypeAdvanced extends AbstractHandleReportServicePermeateClientTransferTypeAdvanced<NettyProxyMsg> {
private final ChannelFlowAdapter channelFlowAdapter;
public ServerHandleReportHandleChannelTransferTypeAdvanced(ChannelFlowAdapter channelFlowAdapter) {
public ServerHandleReportServicePermeateClientTransferTypeAdvanced(ChannelFlowAdapter channelFlowAdapter) {
this.channelFlowAdapter = channelFlowAdapter;
}

View File

@ -45,14 +45,6 @@ public class NettyClientPermeateServerRealHandler extends SimpleChannelInboundHa
nextChannel.writeAndFlush(nettyMsg);
// 记录出口数据
// ServerChannelFlow serverChannelFlow = ServerChannelFlow
// .builder()
// .channelFlowEnum(ChannelFlowEnum.OUT_FLOW)
// .port(visitorPort)
// .clientId(clientId)
// .flow(msg.getData().length)
// .build();
// channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
}
@ -62,8 +54,11 @@ public class NettyClientPermeateServerRealHandler extends SimpleChannelInboundHa
// 客户端真实通信通道
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
if (nextChannel != null) {
// 上报关闭这个客户端的访客通道
nextChannel.close();
log.info("【客户端渗透服务端】服务端真实连接断开");
// 下发关闭这个客户端的访客通道
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
closeVisitorMsg.setType(MessageType.DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
nextChannel.writeAndFlush(closeVisitorMsg);
}
super.channelInactive(ctx);
@ -71,12 +66,13 @@ public class NettyClientPermeateServerRealHandler extends SimpleChannelInboundHa
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
log.info("channelWritabilityChanged");
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
log.info("exceptionCaught:{}", cause.getMessage());
super.exceptionCaught(ctx, cause);
}
}

View File

@ -96,7 +96,6 @@ public class NettyServerPermeateClientVisitorHandler extends SimpleChannelInboun
log.debug("【服务端】访客端口成功接收数据:{}", new String(bytes));
// 使用访客的通信通道
Channel visitorCommunicationChannel = NettyCommunicationIdContext.getVisitor(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(visitorChannel);
// 绑定数据流量
ChannelAttributeKeyUtils.buildInFlow(nextChannel, bytes.length);
@ -159,7 +158,6 @@ public class NettyServerPermeateClientVisitorHandler extends SimpleChannelInboun
return;
}
Channel visitorCommunicationChannel = NettyCommunicationIdContext.getVisitor(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
if (nextChannel != null) {
log.debug("visitorId:{} transfer AUTO_READ:{} ",visitorId,ctx.channel().isWritable());
@ -193,7 +191,6 @@ public class NettyServerPermeateClientVisitorHandler extends SimpleChannelInboun
String clientId = ChannelAttributeKeyUtils.getClientId(channel);
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
// 使用通信通道 下发关闭访客
Channel visitorChannel = NettyCommunicationIdContext.getVisitor(visitorId);
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
if (nextChannel != null) {
// 下发关闭访客

View File

@ -6,12 +6,12 @@ import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPermeateRealServer;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.server.netty.filter.ClientPermeateServerRealFilter;
import org.framework.lazy.cloud.network.heartbeat.server.netty.filter.PermeateClientRealFilter;
import java.util.concurrent.TimeUnit;
/**
* 客户端渗透服务端 连接真实通道
@ -25,7 +25,7 @@ public class NettyClientPermeateServerConnectRealSocket {
* 连接真实服务
*/
public static void buildNewRealServer(
String visitorId,int visitorPort,String targetIp,int targetPort, Channel visitorChannel) {
String visitorId, int visitorPort, String targetIp, int targetPort, Channel transferChannel) {
try {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class)
@ -54,8 +54,8 @@ public class NettyClientPermeateServerConnectRealSocket {
log.info("服务端内网渗透通过,绑定本地服务,IP:{},端口:{} channelID:{} 新建通道成功", targetIp, targetPort,realChannel.id().asLongText());
ChannelAttributeKeyUtils.buildVisitorPort(realChannel, visitorPort);
// 缓存当前端口对应的通道通道池
ChannelAttributeKeyUtils.buildNextChannel(realChannel, visitorChannel);
ChannelAttributeKeyUtils.buildNextChannel(visitorChannel, realChannel);
ChannelAttributeKeyUtils.buildNextChannel(realChannel, transferChannel);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);
ChannelAttributeKeyUtils.buildVisitorId(realChannel, visitorId);
@ -66,15 +66,14 @@ public class NettyClientPermeateServerConnectRealSocket {
myMsg.setClientTargetIp(targetIp);
myMsg.setClientTargetPort(targetPort);
myMsg.setVisitorId(visitorId);
visitorChannel.writeAndFlush(myMsg);
transferChannel.writeAndFlush(myMsg);
} else {
log.error("服务端内网渗透 无法连接当前网络内的目标IP【{}】,目标端口:【{}】", targetIp, targetPort);
// future.channel().eventLoop().schedule(() -> {
// buildNewRealServer(internalNetworkPermeateRealServer);
// }, 2, TimeUnit.SECONDS);
channelFuture.channel().eventLoop().schedule(() -> {
buildNewRealServer(visitorId, visitorPort, targetIp, targetPort, transferChannel);
}, 2, TimeUnit.SECONDS);
}
});

View File

@ -10,6 +10,8 @@ import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPermeate
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.server.netty.filter.PermeateClientRealFilter;
import java.util.concurrent.TimeUnit;
/**
* 服务端渗透服务端 连接真实通道
*/
@ -74,9 +76,9 @@ public class NettyServerPermeateServerConnectRealSocket {
} else {
log.error("服务端内网渗透 无法连接当前网络内的目标IP【{}】,目标端口:【{}】", clientTargetIp, clientTargetPort);
// future.channel().eventLoop().schedule(() -> {
// buildNewRealServer(internalNetworkPermeateRealServer);
// }, 2, TimeUnit.SECONDS);
channelFuture.channel().eventLoop().schedule(() -> {
buildNewRealServer(internalNetworkPermeateRealServer, visitorChannel, visitorId);
}, 2, TimeUnit.SECONDS);
}
});