package nb.
deser;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DeserClient {
public static final int PROTOCOL_HELLO = -268387670;
public static final short PROTOCOL_VERSION = 257;
public void run(String serverAddress, int serverPort) throws Exception {
InetAddress serverAddr = [Link](serverAddress);
[Link]("[+] DeserClient started, connecting to " +
[Link]() + ":" + serverPort);
Socket sock = new Socket(serverAddr, serverPort);
[Link](250);
ObjectOutputStream oos = new ObjectOutputStream([Link]());
ObjectInputStream ois = new ObjectInputStream([Link]());
BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("[+] Connected, reading server hello packet...");
if ([Link]() != -268387670) {
[Link]("[-] Server did not send a valid hello, killing
connection...");
[Link]();
return;
}
[Link]("[+] Hello received, sending hello to server...");
[Link](-268387670);
[Link]();
[Link]("[+] Hello sent, reading server protocol version...");
if ([Link]() > 257) {
[Link]("[-] Server protocol version is greater than client
protocol version, killing connection...");
[Link]();
return;
}
[Link]("[+] Sending supported protocol version to the server...");
[Link](257);
[Link]();
[Link]("[+] Enter a client name to send to the server: ");
[Link]([Link]());
[Link]();
[Link]("[+] Enter a string to hash: ");
HashRequest hr = new HashRequest([Link]());
[Link]("[+] Generating hash of \"" + [Link]() + "\"...");
[Link](hr);
[Link]();
hr = (HashRequest)[Link]();
[Link]("[+] Hash generated: " + [Link]());
}
}
sẻver
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DeserServer {
public static final int PROTOCOL_HELLO = -268387670;
public static final short PROTOCOL_VERSION = 257;
public void run(String listenAddress, int listenPort) throws Exception {
ObjectOutputStream oos = null;
Socket clientSock = null;
InetAddress listenAddr = [Link](listenAddress);
ServerSocket serverSock = new ServerSocket(listenPort, 0, listenAddr);
[Link](250);
[Link]("[+] DeserServer started, listening on " +
[Link]().getHostAddress() + ":" + [Link]());
while (true) {
try {
clientSock = [Link]();
[Link]("[+] Connection accepted from " +
[Link]().getHostAddress() + ":" + [Link]());
oos = new ObjectOutputStream([Link]());
ObjectInputStream ois = new ObjectInputStream([Link]());
[Link]("[+] Sending hello...");
[Link](-268387670);
[Link]();
[Link]("[+] Hello sent, waiting for hello from client...");
if ([Link]() != -268387670) {
[Link]("[-] Client did not send a hello back, killing
connection...");
[Link]();
continue;
}
[Link]("[+] Hello received from client...");
[Link]("[+] Sending protocol version...");
[Link](257);
[Link]();
[Link]("[+] Version sent, waiting for version from client...");
if ([Link]() > 257) {
[Link]("[-] Client protocol version is greater than server
protocol version, killing connection...");
[Link]();
continue;
}
[Link]("[+] Client version is compatible, reading client
name...");
String clientName = [Link]();
[Link]("[+] Client name received: " + clientName);
HashRequest request = (HashRequest)[Link]();
[Link]("[+] Hash request received, hashing: " +
[Link]());
[Link](generateHash([Link]()));
[Link]("[+] Hash generated: " + [Link]());
[Link](request);
[Link]();
[Link]("[+] Done, terminating connection.");
[Link]();
} catch (Exception e) {
try {
if (clientSock != null && [Link]() == true)
[Link](e);
} catch (Exception exception) {}
}
}
}
private String generateHash(String data) throws Exception {
MessageDigest md5 = [Link]("MD5");
[Link]([Link]());
return [Link]("%032x", new Object[] { new BigInteger(1,
[Link]()) });
}
}