123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package de.tudarmstadt.informatik.hostage.protocol;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.IOException;
- import java.net.Socket;
- import java.util.ArrayList;
- import java.util.List;
- import de.tudarmstadt.informatik.hostage.wrapper.Packet;
- /**
- * Ghost Protocol. This protocol mirrors an incoming connection back to the
- * attacker on the same port, that it is running on. It will send all incoming
- * requests back to the attacker on the mirrored connection and will relpy with
- * the responses it get's from this mirrored connection.
- *
- * @author Wulf Pfeiffer
- */
- public class GHOST implements Protocol {
- private boolean isClosed = false;
- private Socket mirroredConnection;
- private BufferedInputStream mirrorInputStream;
- private BufferedOutputStream mirrorOutputStream;
- @Override
- public int getPort() {
- return 5050; // TODO dynamic port / whats the default!? (1433)
- }
- @Override
- public boolean isClosed() {
- return isClosed;
- }
- @Override
- public boolean isSecure() {
- return false;
- }
- @Override
- public List<Packet> processMessage(Packet requestPacket) {
- List<Packet> responsePackets = new ArrayList<Packet>();
- try {
- if (mirroredConnection == null) {
- mirroredConnection = new Socket("192.168.178.86", 5050); // FIXME
- mirrorInputStream = new BufferedInputStream(
- mirroredConnection.getInputStream());
- mirrorOutputStream = new BufferedOutputStream(
- mirroredConnection.getOutputStream());
- }
- if (mirroredConnection.isInputShutdown()
- || mirroredConnection.isOutputShutdown()) {
- mirrorInputStream.close();
- mirrorOutputStream.close();
- mirroredConnection.close();
- isClosed = true;
- }
- mirrorOutputStream.write(requestPacket.getBytes());
- mirrorOutputStream.flush();
- int availableBytes;
- while ((availableBytes = mirrorInputStream.available()) <= 0) {
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- byte[] mirrorResponse = new byte[availableBytes];
- mirrorInputStream.read(mirrorResponse);
- responsePackets.add(new Packet(mirrorResponse));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return responsePackets;
- }
- @Override
- public String toString() {
- return "GhostProtocol";
- }
- @Override
- public TALK_FIRST whoTalksFirst() {
- return TALK_FIRST.CLIENT;
- }
- }
|