Hi Emmanuel,
I am using a simple telnet client command to send the data. I have attached
the code below for Server and of the messageReceived Method. I don't think
there is much change to be done to fix this server side but I noticed that
if I use the filterchain with TextLineCodecFactory I don't see the issue. I
also checked the Network Traffic with Wireshark on the port and found that
only the data I was sending was getting transferred not the null Padded
bytes.
Server Code::
try {
IoAcceptor acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("logger", new
LoggingFilter());
acceptor.setHandler(this);
acceptor.getSessionConfig().setReadBufferSize(2048);
// acceptor.getSessionConfig().setIdleTime(
IdleStatus.BOTH_IDLE, 10
// );//NO IDLE Time for our case
PORT =4000;
acceptor.bind(new InetSocketAddress(PORT));
} catch (Exception e) {
e.printStackTrace();
System.err.println("Shutting down");
}
Acceptor Method::
@Override
public void messageReceived(IoSession session, Object message)
throws Exception {
if (message instanceof IoBuffer) {
IoBuffer buffer = (IoBuffer) message;
SocketAddress remoteAddress =
session.getRemoteAddress();
byte[] bufferArray = buffer.array();
// System.out.println(new String(bufferArray));
logger.info("Writing Byte Request from {}. Data is:
'{}'", "", new String(bufferArray));
StringBuffer strBuffer = new StringBuffer();
strBuffer.append("Bytes from PDM : ");
StringBuffer strBuffer2 = new StringBuffer("BYTE
DATA IN {");
for (int i = 0; i < bufferArray.length; i++) {
strBuffer.append(" [" + i + ":" +
bufferArray[i] + " ] , ");
strBuffer2.append("," + bufferArray[i]);
}
strBuffer2.append("}");
logger.info(strBuffer2.toString());
logger.info(strBuffer.toString());
logger.info("Machine Address is : " +
remoteAddress);
}
}
Thanks & Regards
Abhishek Chavan
Member Architecture Group
Nagarro Software Pvt. Ltd.
PH: +919953541323
DISCLAIMER:
This communication, along with any documents, files or attachments, is
intended only for the use of the addressee and may contain legally
privileged and confidential information. If you are not the intended
recipient, you are hereby notified that any dissemination, distribution or
copying of any information contained in or attached to this communication is
strictly prohibited. This communication does not form any contractual
obligation on behalf of the sender or, the sender's employer, or the
employer's parent company, affiliates or subsidiaries.
-----Original Message-----
From: Emmanuel Lecharny [mailto:[email protected]]
Sent: Monday, June 13, 2011 6:22 PM
To: [email protected]
Subject: Re: TCP Null Packets
Hi,
On Mon, Jun 13, 2011 at 9:53 AM, Abhishek Chavan <
[email protected]> wrote:
> Dear All,
>
> I have created a simple TCP Server using Apache Mina with only "logging"
as
> a filterchain. I am trying to read data sent by clients to my server. I
am
> receiving the data however I am also getting a lot of Null byte data in
the
> packet. I searched the Forums and found that this is a sign of Malicious
> Acticity. I am using TCP test Tool as my client as well as Telnet. How can
> I
> fix this problem?
>
First, it has to be a problem. It's difficult to tell with the information
you are providing.
However, if you consider that the received null bytes are malicious, then
close the asociated session when you detect such an activity. It should do
the trick
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com