Browse Source

GHOST protocol is now able to run on specific ports with the attackers
ip

Wulf Pfeiffer 10 years ago
parent
commit
2870e26acf

+ 5 - 0
src/de/tudarmstadt/informatik/hostage/HoneyHandler.java

@@ -17,6 +17,7 @@ import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
 import de.tudarmstadt.informatik.hostage.nio.Reader;
 import de.tudarmstadt.informatik.hostage.nio.Writer;
+import de.tudarmstadt.informatik.hostage.protocol.GHOST;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol.TALK_FIRST;
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
@@ -63,6 +64,10 @@ public class HoneyHandler implements Runnable {
 		this.service = service;
 		this.listener = listener;
 		this.protocol = protocol;
+		if (protocol.toString().equals("GHOST")) {
+			((GHOST) protocol).setAttackerIP(client.getInetAddress());
+			((GHOST) protocol).setCurrentPort(listener.getPort());
+		}
 		this.client = client;
 		this.thread = new Thread(this);
 		SharedPreferences pref = PreferenceManager

+ 19 - 8
src/de/tudarmstadt/informatik/hostage/protocol/GHOST.java

@@ -3,6 +3,7 @@ package de.tudarmstadt.informatik.hostage.protocol;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.List;
@@ -26,10 +27,23 @@ public class GHOST implements Protocol {
 	private BufferedInputStream mirrorInputStream;
 
 	private BufferedOutputStream mirrorOutputStream;
+	
+	private int currentPort;
+	
+	private InetAddress attackerIP;
+	
+
+	public void setCurrentPort(int currentPort) {
+		this.currentPort = currentPort;
+	}
+
+	public void setAttackerIP(InetAddress attackerIP) {
+		this.attackerIP = attackerIP;
+	}
 
 	@Override
 	public int getPort() {
-		return 5050; // TODO dynamic port / whats the default!? (1433)
+		return 5050; // TODO whats the default!? (1433)
 	}
 
 	@Override
@@ -47,7 +61,7 @@ public class GHOST implements Protocol {
 		List<Packet> responsePackets = new ArrayList<Packet>();
 		try {
 			if (mirroredConnection == null) {
-				mirroredConnection = new Socket("192.168.178.86", 5050); // FIXME
+				mirroredConnection = new Socket(attackerIP, currentPort);
 				mirrorInputStream = new BufferedInputStream(
 						mirroredConnection.getInputStream());
 				mirrorOutputStream = new BufferedOutputStream(
@@ -66,24 +80,21 @@ public class GHOST implements Protocol {
 
 			int availableBytes;
 			while ((availableBytes = mirrorInputStream.available()) <= 0) {
-				try {
-					Thread.sleep(1);
-				} catch (InterruptedException e) {
-					e.printStackTrace();
-				}
+				Thread.yield();
 			}
 			byte[] mirrorResponse = new byte[availableBytes];
 			mirrorInputStream.read(mirrorResponse);
 			responsePackets.add(new Packet(mirrorResponse));
 		} catch (IOException e) {
 			e.printStackTrace();
+			responsePackets.add(requestPacket);
 		}
 		return responsePackets;
 	}
 
 	@Override
 	public String toString() {
-		return "GhostProtocol";
+		return "GHOST";
 	}
 
 	@Override