Browse Source

-Added a new Wrapper: Packet
-Changed io classes to use Packet
-Removed type specific handler
-Changed Protocols to use Packet
-Moved several classes into other packages
-Minor changes

Wulf Pfeiffer 10 years ago
parent
commit
28ab077dad
29 changed files with 385 additions and 432 deletions
  1. 1 1
      AndroidManifest.xml
  2. 45 11
      src/de/tudarmstadt/informatik/hostage/HoneyHandler.java
  3. 16 26
      src/de/tudarmstadt/informatik/hostage/HoneyListener.java
  4. 5 5
      src/de/tudarmstadt/informatik/hostage/HoneyService.java
  5. 0 69
      src/de/tudarmstadt/informatik/hostage/handler/ByteArrayHandler.java
  6. 0 59
      src/de/tudarmstadt/informatik/hostage/handler/StringHandler.java
  7. 8 7
      src/de/tudarmstadt/informatik/hostage/io/ByteArrayReaderWriter.java
  8. 6 5
      src/de/tudarmstadt/informatik/hostage/io/ReaderWriter.java
  9. 9 6
      src/de/tudarmstadt/informatik/hostage/io/StringReaderWriter.java
  10. 2 2
      src/de/tudarmstadt/informatik/hostage/logging/DatabaseHandler.java
  11. 0 1
      src/de/tudarmstadt/informatik/hostage/logging/MyLocationManager.java
  12. 7 7
      src/de/tudarmstadt/informatik/hostage/protocol/ECHO.java
  13. 27 21
      src/de/tudarmstadt/informatik/hostage/protocol/FTP.java
  14. 21 15
      src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java
  15. 1 1
      src/de/tudarmstadt/informatik/hostage/protocol/HTTPS.java
  16. 20 15
      src/de/tudarmstadt/informatik/hostage/protocol/MySQL.java
  17. 6 3
      src/de/tudarmstadt/informatik/hostage/protocol/Protocol.java
  18. 5 5
      src/de/tudarmstadt/informatik/hostage/protocol/SIP.java
  19. 50 49
      src/de/tudarmstadt/informatik/hostage/protocol/SMB.java
  20. 20 17
      src/de/tudarmstadt/informatik/hostage/protocol/SSH.java
  21. 1 1
      src/de/tudarmstadt/informatik/hostage/protocol/SSLProtocol.java
  22. 29 30
      src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java
  23. 2 4
      src/de/tudarmstadt/informatik/hostage/sync/BluetoothSync.java
  24. 0 2
      src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java
  25. 5 4
      src/de/tudarmstadt/informatik/hostage/ui/PlayGroundActivity.java
  26. 6 8
      src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java
  27. 2 3
      src/de/tudarmstadt/informatik/hostage/ui/ViewLogTable.java
  28. 0 55
      src/de/tudarmstadt/informatik/hostage/wrapper/ByteArray.java
  29. 91 0
      src/de/tudarmstadt/informatik/hostage/wrapper/Packet.java

+ 1 - 1
AndroidManifest.xml

@@ -55,7 +55,7 @@
         </activity>
        
        	<activity
-            android:name="de.tudarmstadt.informatik.hostage.PlayGroundActivity"
+            android:name="de.tudarmstadt.informatik.hostage.ui.PlayGroundActivity"
             android:label="@string/playground" >
             <intent-filter>
   				<action android:name="android.nfc.action.NDEF_DISCOVERED" />

+ 45 - 11
src/de/tudarmstadt/informatik/hostage/handler/AbstractHandler.java → src/de/tudarmstadt/informatik/hostage/HoneyHandler.java

@@ -1,32 +1,37 @@
-package de.tudarmstadt.informatik.hostage.handler;
+package de.tudarmstadt.informatik.hostage;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.Socket;
+import java.util.List;
 
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.preference.PreferenceManager;
-import de.tudarmstadt.informatik.hostage.HoneyListener;
-import de.tudarmstadt.informatik.hostage.HoneyService;
+import de.tudarmstadt.informatik.hostage.io.ByteArrayReaderWriter;
+import de.tudarmstadt.informatik.hostage.io.ReaderWriter;
+import de.tudarmstadt.informatik.hostage.io.StringReaderWriter;
 import de.tudarmstadt.informatik.hostage.logging.Logger;
 import de.tudarmstadt.informatik.hostage.logging.MyLocationManager;
 import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
+import de.tudarmstadt.informatik.hostage.protocol.Protocol.TALK_FIRST;
 import de.tudarmstadt.informatik.hostage.ui.MainActivity;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 /**
  * Abstract class for a connection handler using a given protocol.
  * @author Mihai Plasoianu 
+ * @author Wulf Pfeiffer
  */
-public abstract class AbstractHandler implements Runnable {
+public class HoneyHandler implements Runnable {
 
-	/**
-	 * Time until the socket throws a time out. The time is in milliseconds.
-	 */
+	/** Time until the socket throws a time out. The time is in milliseconds. */
 	private int TIMEOUT;
+	/** Time that a inputstream waits if no content is available to read again from stream. */
+	private int SLEEPTIME;
 
 	protected Protocol protocol;
 	private Socket client;
@@ -40,7 +45,7 @@ public abstract class AbstractHandler implements Runnable {
 
 	private HoneyListener listener;
 	protected Logger log;
-
+	
 	/**
 	 * Constructor of the class.
 	 * Initializes class variables for communication and logging.
@@ -50,7 +55,7 @@ public abstract class AbstractHandler implements Runnable {
 	 * @param protocol The protocol on which the handler is running.
 	 * @param client A Socket for the communication with a remote client.
 	 */
-	public AbstractHandler(HoneyService service, HoneyListener listener,
+	public HoneyHandler(HoneyService service, HoneyListener listener,
 			Protocol protocol, Socket client) {
 		this.listener = listener;
 		this.log = service.getLog();
@@ -58,6 +63,7 @@ public abstract class AbstractHandler implements Runnable {
 		this.client = client;
 		this.thread = new Thread(this);
 		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(service);
+		SLEEPTIME = pref.getInt("sleeptime", 500);
 		TIMEOUT = pref.getInt("timeout", 30) * 1000;
 		//TODO ThreadSicher?
 		attack_id = getAndIncrementAttackID(pref);
@@ -129,8 +135,36 @@ public abstract class AbstractHandler implements Runnable {
 	 * @param out OutputStream of the socket.
 	 * @throws IOException
 	 */
-	abstract protected void talkToClient(InputStream in, OutputStream out)
-			throws IOException;
+	protected void talkToClient(InputStream in, OutputStream out) throws IOException {
+		ReaderWriter stream;
+		if(protocol.getType().equals(byte[].class)) {
+			stream = new ByteArrayReaderWriter(in, out, SLEEPTIME);
+		} else {
+			stream = new StringReaderWriter(in, out);
+		}
+		Packet inputLine;
+		List<Packet> outputLine;
+		if (protocol.whoTalksFirst() == TALK_FIRST.SERVER) {
+			outputLine = protocol.processMessage(null);
+			stream.write(outputLine);
+			for (Packet o : outputLine) {
+				log.write(createRecord(TYPE.SEND, o.toString()));
+			}
+		}
+		while (!thread.isInterrupted() && (inputLine = stream.read()) != null) {
+			outputLine = protocol.processMessage(inputLine);
+			log.write(createRecord(TYPE.RECEIVE, inputLine.toString()));
+			if (outputLine != null) {
+				stream.write(outputLine);
+				for (Packet o : outputLine) {
+					log.write(createRecord(TYPE.SEND, o.toString()));
+				}
+			}
+			if (protocol.isClosed()) {
+				break;
+			}
+		}
+	}
 
 	/**
 	 * Creates a Record for a message exchanged with a client.

+ 16 - 26
src/de/tudarmstadt/informatik/hostage/HoneyListener.java

@@ -12,28 +12,24 @@ import javax.net.ssl.SSLSocketFactory;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
-import de.tudarmstadt.informatik.hostage.handler.AbstractHandler;
-import de.tudarmstadt.informatik.hostage.handler.ByteArrayHandler;
-import de.tudarmstadt.informatik.hostage.handler.StringHandler;
 import de.tudarmstadt.informatik.hostage.net.MyServerSocketFactory;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
 import de.tudarmstadt.informatik.hostage.ui.MainActivity;
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
 
 /**
  * Protocol listener class:<br>
  * Creates a Socket on the port of a given protocol and listens for incoming
  * connections.<br>
  * For each connection creates a Socket and instantiate an
- * {@link AbstractHandler}.
+ * {@link HoneyHandler}.
  * 
  * @author Mihai Plasoianu
  * 
  */
 public class HoneyListener implements Runnable {
 
-	private ArrayList<AbstractHandler> handlers = new ArrayList<AbstractHandler>();
+	private ArrayList<HoneyHandler> handlers = new ArrayList<HoneyHandler>();
 
 	/**
 	 * Determines the amount of active handlers.
@@ -44,7 +40,7 @@ public class HoneyListener implements Runnable {
 		return handlers.size();
 	}
 
-	private Protocol<?> protocol;
+	private Protocol protocol;
 	private ServerSocket server;
 	private Thread thread;
 
@@ -75,7 +71,7 @@ public class HoneyListener implements Runnable {
 	 * @param protocol
 	 *            The Protocol on which the listener is running.
 	 */
-	public HoneyListener(HoneyService service, Protocol<?> protocol) {
+	public HoneyListener(HoneyService service, Protocol protocol) {
 		this.service = service;
 		this.protocol = protocol;
 		pref = service.getApplicationContext().getSharedPreferences(
@@ -88,7 +84,7 @@ public class HoneyListener implements Runnable {
 		while (!thread.isInterrupted()) {
 			addHandler();
 		}
-		for (AbstractHandler handler : handlers) {
+		for (HoneyHandler handler : handlers) {
 			handler.kill();
 		}
 	}
@@ -141,9 +137,9 @@ public class HoneyListener implements Runnable {
 	 * Remove all terminated handlers from its internal ArrayList.
 	 */
 	public void refreshHandlers() {
-		for (Iterator<AbstractHandler> iterator = handlers.iterator(); iterator
+		for (Iterator<HoneyHandler> iterator = handlers.iterator(); iterator
 				.hasNext();) {
-			AbstractHandler handler = iterator.next();
+			HoneyHandler handler = iterator.next();
 			if (handler.isTerminated()) {
 				conReg.closeConnection();
 				iterator.remove();
@@ -153,7 +149,7 @@ public class HoneyListener implements Runnable {
 
 	/**
 	 * Waits for an incoming connection, accepts it and starts a
-	 * {@link AbstractHandler}
+	 * {@link HoneyHandler}
 	 */
 	private void addHandler() {
 		if (conReg.isConnectionFree()) {
@@ -180,14 +176,14 @@ public class HoneyListener implements Runnable {
 
 	/**
 	 * Creates a SSLSocket out of the given socket and starts a
-	 * {@link AbstractHandler}.
+	 * {@link HoneyHandler}.
 	 * 
 	 * @param client
 	 *            The socket with the accepted connection.
 	 * @throws Exception
 	 */
 	private void startSecureHandler(Socket client) throws Exception {
-		SSLContext sslContext = ((SSLProtocol<?>) protocol).getSSLContext();
+		SSLContext sslContext = ((SSLProtocol) protocol).getSSLContext();
 		SSLSocketFactory factory = sslContext.getSocketFactory();
 		SSLSocket sslClient = (SSLSocket) factory.createSocket(client, null,
 				client.getPort(), false);
@@ -197,7 +193,7 @@ public class HoneyListener implements Runnable {
 	}
 
 	/**
-	 * Starts a {@link AbstractHandler} with the given socket.
+	 * Starts a {@link HoneyHandler} with the given socket.
 	 * 
 	 * @param client
 	 *            The socket with the accepted connection.
@@ -209,7 +205,7 @@ public class HoneyListener implements Runnable {
 	}
 
 	/**
-	 * Creates a new instance of an {@link AbstractHandler}.
+	 * Creates a new instance of an {@link HoneyHandler}.
 	 * 
 	 * @param service
 	 *            The background service
@@ -219,17 +215,11 @@ public class HoneyListener implements Runnable {
 	 *            The Protocol the handler will run on
 	 * @param client
 	 *            The Socket the handler uses
-	 * @return A Instance of a {@link AbstractHandler} with the specified
+	 * @return A Instance of a {@link HoneyHandler} with the specified
 	 *         parameter.
 	 */
-	private AbstractHandler newInstance(HoneyService service,
-			HoneyListener listener, Protocol<?> protocol, Socket client) {
-		if (protocol.getType().equals(String.class)) {
-			return new StringHandler(service, listener, protocol, client);
-		} else if (protocol.getType().equals(ByteArray.class)) {
-			return new ByteArrayHandler(service, listener, protocol, client);
-		} else {
-			return null;
-		}
+	private HoneyHandler newInstance(HoneyService service,
+			HoneyListener listener, Protocol protocol, Socket client) {
+		return new HoneyHandler(service, listener, protocol, client);
 	}
 }

+ 5 - 5
src/de/tudarmstadt/informatik/hostage/HoneyService.java

@@ -81,7 +81,7 @@ public class HoneyService extends Service {
 		sessionPref = getSharedPreferences(MainActivity.SESSION_DATA, Context.MODE_PRIVATE);
 		editor = sessionPref.edit();
 		createNotification();
-		for (Protocol<?> protocol : getProtocolArray()) {
+		for (Protocol protocol : getProtocolArray()) {
 			listeners.add(new HoneyListener(this, protocol));
 		}
 		registerNetReceiver();
@@ -240,14 +240,14 @@ public class HoneyService extends Service {
 	 * Creates a instance of each protocol defined in /res/values/protocols.xml and puts it in a List
 	 * @return ArrayList of {@link de.tudarmstadt.informatik.hostage.protocol.Protocol Protocol}
 	 */
-	private ArrayList<Protocol<?>> getProtocolArray() {
+	private ArrayList<Protocol> getProtocolArray() {
 		String[] protocols = getResources().getStringArray(R.array.protocols);
 		String packageName = Protocol.class.getPackage().getName();
-		ArrayList<Protocol<?>> protocolArray = new ArrayList<Protocol<?>>();
+		ArrayList<Protocol> protocolArray = new ArrayList<Protocol>();
 
 		for (String protocol : protocols) {
 			try {
-				protocolArray.add((Protocol<?>) Class.forName(
+				protocolArray.add((Protocol) Class.forName(
 						String.format("%s.%s", packageName, protocol))
 						.newInstance());
 			} catch (Exception e) {
@@ -360,7 +360,7 @@ public class HoneyService extends Service {
 	}
 	
 	/**
-	 * Task for accuiring a qotd from one of four possible servers
+	 * Task for accuiring a qotd from one of four possible servers.
 	 * @author Wulf Pfeiffer
 	 */
 	private class QotdTask extends AsyncTask<String, Void, String>{	

+ 0 - 69
src/de/tudarmstadt/informatik/hostage/handler/ByteArrayHandler.java

@@ -1,69 +0,0 @@
-package de.tudarmstadt.informatik.hostage.handler;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.util.List;
-
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
-
-import de.tudarmstadt.informatik.hostage.HoneyListener;
-import de.tudarmstadt.informatik.hostage.HoneyService;
-import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.io.ByteArrayReaderWriter;
-import de.tudarmstadt.informatik.hostage.io.ReaderWriter;
-import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
-import de.tudarmstadt.informatik.hostage.protocol.Protocol;
-import de.tudarmstadt.informatik.hostage.protocol.Protocol.TALK_FIRST;
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
-
-/**
- * Handles the socket connections for byte arrays.
- * @author Mihai Plasoianu
- */
-public class ByteArrayHandler extends AbstractHandler {
-
-	/** Defined time until timeout */
-	private int SLEEPTIME;
-	
-	public ByteArrayHandler(HoneyService service, HoneyListener listener,
-			Protocol<?> protocol, Socket client) {
-		super(service, listener, protocol, client);
-		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(service);
-		SLEEPTIME = pref.getInt("sleeptime", 500);
-	}
-
-	@Override
-	protected void talkToClient(InputStream in, OutputStream out)
-			throws IOException {
-		ReaderWriter<ByteArray> stream = new ByteArrayReaderWriter(in, out, SLEEPTIME);
-
-		ByteArray inputLine;
-		List<ByteArray> outputLine;
-
-		if (protocol.whoTalksFirst() == TALK_FIRST.SERVER) {
-			outputLine = protocol.processMessage(null);
-			stream.write(outputLine);
-			for (ByteArray s : outputLine) {
-				log.write(createRecord(TYPE.SEND, HelperUtils.bytesToHexString(s.get())));
-			}
-		}
-
-		while (!thread.isInterrupted() && (inputLine = stream.read()) != null) {
-			outputLine = protocol.processMessage(inputLine);
-			log.write(createRecord(TYPE.RECEIVE, HelperUtils.bytesToHexString(inputLine.get())));
-			if (outputLine != null) {
-				stream.write(outputLine);
-				for (ByteArray s : outputLine) {
-					log.write(createRecord(TYPE.SEND, HelperUtils.bytesToHexString(s.get())));
-				}
-			}
-			if (protocol.isClosed()) {
-				break;
-			}
-		}
-	}
-
-}

+ 0 - 59
src/de/tudarmstadt/informatik/hostage/handler/StringHandler.java

@@ -1,59 +0,0 @@
-package de.tudarmstadt.informatik.hostage.handler;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.util.List;
-
-import de.tudarmstadt.informatik.hostage.HoneyListener;
-import de.tudarmstadt.informatik.hostage.HoneyService;
-import de.tudarmstadt.informatik.hostage.io.ReaderWriter;
-import de.tudarmstadt.informatik.hostage.io.StringReaderWriter;
-import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
-import de.tudarmstadt.informatik.hostage.protocol.Protocol;
-import de.tudarmstadt.informatik.hostage.protocol.Protocol.TALK_FIRST;
-
-/**
- * Handles the socket connections for byte Strings.
- * @author Mihai Plasoianu
- */
-public class StringHandler extends AbstractHandler {
-
-	public StringHandler(HoneyService service, HoneyListener listener,
-			Protocol<?> protocol, Socket client) {
-		super(service, listener, protocol, client);
-	}
-
-	@Override
-	protected void talkToClient(InputStream in, OutputStream out)
-			throws IOException {
-		ReaderWriter<String> stream = new StringReaderWriter(in, out);
-
-		String inputLine;
-		List<String> outputLine;
-
-		if (protocol.whoTalksFirst() == TALK_FIRST.SERVER) {
-			outputLine = protocol.processMessage(null);
-			stream.write(outputLine);
-			for (String s : outputLine) {
-				log.write(createRecord(TYPE.SEND, s));
-			}
-		}
-
-		while (!thread.isInterrupted() && (inputLine = stream.read()) != null) {
-			log.write(createRecord(TYPE.RECEIVE, inputLine));
-			outputLine = protocol.processMessage(inputLine);
-			if (outputLine != null) {
-				stream.write(outputLine);
-				for (String s : outputLine) {
-					log.write(createRecord(TYPE.SEND, s));
-				}
-			}
-			if (protocol.isClosed()) {
-				break;
-			}
-		}
-	}
-
-}

+ 8 - 7
src/de/tudarmstadt/informatik/hostage/io/ByteArrayReaderWriter.java

@@ -7,13 +7,14 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.List;
 
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
  * Handles the reading and writing of the socket in- and outputstream for byte arrays
  * @author Mihai Plasoianu
+ * @author Wulf Pfeiffer
  */
-public class ByteArrayReaderWriter implements ReaderWriter<ByteArray> {
+public class ByteArrayReaderWriter implements ReaderWriter {
 
 	private BufferedInputStream in;
 	private BufferedOutputStream out;
@@ -32,7 +33,7 @@ public class ByteArrayReaderWriter implements ReaderWriter<ByteArray> {
 	}
 
 	
-	public ByteArray read() throws IOException {
+	public Packet read() throws IOException {
 		int availableBytes;
 		while((availableBytes = in.available()) <= 0) {
 			try {
@@ -43,13 +44,13 @@ public class ByteArrayReaderWriter implements ReaderWriter<ByteArray> {
 		}
 		byte[] buffer = new byte[availableBytes];
 		in.read(buffer);
-		return new ByteArray(buffer);
+		return new Packet(buffer);
 	}
 
 	
-	public void write(List<ByteArray> message) throws IOException {
-		for (ByteArray m : message) {
-			out.write(m.get());
+	public void write(List<Packet> outputLine) throws IOException {
+		for (Packet o : outputLine) {
+			out.write(o.getMessage());
 			out.flush();
 		}
 	}

+ 6 - 5
src/de/tudarmstadt/informatik/hostage/io/ReaderWriter.java

@@ -2,26 +2,27 @@ package de.tudarmstadt.informatik.hostage.io;
 
 import java.io.IOException;
 import java.util.List;
+
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 /**
  * Interface for a generic class that offers methods for read and write.
  * Is used to abstract the implementation details for String and Byte protocols.
  * @author Mihai Plasoianu 
- *
- * @param <T>
+ * @author Wulf Pfeiffer
  */
-public interface ReaderWriter<T> {
+public interface ReaderWriter {
 	/**
 	 * Method to read from a medium.
 	 * @return Returns the output.
 	 * @throws IOException
 	 */
-	T read() throws IOException;
+	Packet read() throws IOException;
 
 	/**
 	 * Method to write to a medium.
 	 * @param outputLine The input to write.
 	 * @throws IOException
 	 */
-	void write(List<T> outputLine) throws IOException;
+	void write(List<Packet> outputLine) throws IOException;
 
 }

+ 9 - 6
src/de/tudarmstadt/informatik/hostage/io/StringReaderWriter.java

@@ -9,11 +9,14 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.util.List;
 
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
+
 /**
  * Handles the reading and writing of the socket in- and outputstream for strings
  * @author Mihai Plasoianu
+ * @author Wulf Pfeiffer
  */
-public class StringReaderWriter implements ReaderWriter<String> {
+public class StringReaderWriter implements ReaderWriter {
 
 	private BufferedReader in;
 	private BufferedWriter out;
@@ -30,14 +33,14 @@ public class StringReaderWriter implements ReaderWriter<String> {
 	}
 
 	
-	public String read() throws IOException {
-		return in.readLine();
+	public Packet read() throws IOException {
+		return new Packet(in.readLine());
 	}
 
 	
-	public void write(List<String> message) throws IOException {
-		for (String m : message) {
-			out.write(m + "\n");
+	public void write(List<Packet> outputLine) throws IOException {
+		for (Packet o : outputLine) {
+			out.write(o + "\n");
 			out.flush();
 		}
 	}

+ 2 - 2
src/de/tudarmstadt/informatik/hostage/logging/DatabaseHandler.java

@@ -104,7 +104,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 		//Initialize Port Table
 		for (String protocol : protocols) {
 			try {				
-				int port = ((Protocol<?>) Class.forName(String.format("%s.%s", packageName, protocol)).newInstance()).getPort();
+				int port = ((Protocol) Class.forName(String.format("%s.%s", packageName, protocol)).newInstance()).getPort();
 		        db.execSQL("INSERT INTO " + TABLE_PORTS + " VALUES ( '" + protocol + "'," + port + ")");
 			} catch (Exception e) {
 				e.printStackTrace();
@@ -571,7 +571,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
     public void updateNetworkInformation(HashMap<String, Object> networkInformation){ 
         SQLiteDatabase db = this.getReadableDatabase();
 		String bssid = (String) networkInformation.get(KEY_BSSID);
-		Log.i("DatabaseHandler", "Füge " + bssid + " hinzu");
+		Log.i("DatabaseHandler", "F�ge " + bssid + " hinzu");
 		String bssidQuery = "SELECT  * FROM " + TABLE_BSSIDS + " WHERE "  + KEY_BSSID + " = " + "'" + bssid + "'";
         Cursor cursor = db.rawQuery(bssidQuery, null);
         int result = cursor.getCount();

+ 0 - 1
src/de/tudarmstadt/informatik/hostage/logging/MyLocationManager.java

@@ -9,7 +9,6 @@ import android.location.LocationListener;
 import android.location.LocationManager;
 import android.os.Bundle;
 import android.util.Log;
-import android.widget.Toast;
 
 public class MyLocationManager {
 	

+ 7 - 7
src/de/tudarmstadt/informatik/hostage/protocol/ECHO.java

@@ -3,13 +3,13 @@ package de.tudarmstadt.informatik.hostage.protocol;
 import java.util.ArrayList;
 import java.util.List;
 
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
  * ECHO protocol
  * @author Wulf Pfeiffer
  */
-public class ECHO implements Protocol<ByteArray>{
+public class ECHO implements Protocol{
 
 	
 	public int getPort() {
@@ -22,9 +22,9 @@ public class ECHO implements Protocol<ByteArray>{
 	}
 	
 	
-	public List<ByteArray> processMessage(ByteArray message) {
-		List<ByteArray> response = new ArrayList<ByteArray>();
-		response.add(message);
+	public List<Packet> processMessage(Packet packet) {
+		List<Packet> response = new ArrayList<Packet>();
+		response.add(packet);
 		return response;
 	}
 
@@ -39,8 +39,8 @@ public class ECHO implements Protocol<ByteArray>{
 	}
 
 	
-	public Class<ByteArray> getType() {
-		return ByteArray.class;
+	public Class<byte[]> getType() {
+		return byte[].class;
 	}
 	
 	

+ 27 - 21
src/de/tudarmstadt/informatik/hostage/protocol/FTP.java

@@ -3,11 +3,13 @@ package de.tudarmstadt.informatik.hostage.protocol;
 import java.util.ArrayList;
 import java.util.List;
 
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
+
 /**
  * FTP protocol
  * @author Wulf Pfeiffer
  */
-public class FTP implements Protocol<String> {
+public class FTP implements Protocol {
 	/**
 	 * Represents the states of the protocol
 	 */
@@ -31,54 +33,58 @@ public class FTP implements Protocol<String> {
 	}
 
 	
-	public List<String> processMessage(String message) {
-		List<String> response = new ArrayList<String>();
+	public List<Packet> processMessage(Packet packet) {
+		String request = null;
+		if (packet != null) {
+			request = packet.toString();
+		}
+		List<Packet> response = new ArrayList<Packet>();
 		switch (state) {
 		case NONE:
-			if (message == null) {
+			if (request == null) {
 				state = STATE.OPEN;
-				response.add(c220);
+				response.add(new Packet(c220));
 			} else {
 				state = STATE.CLOSED;
-				response.add(c421);
+				response.add(new Packet(c421));
 			}
 			break;
 		case OPEN:
-			if (message.contains("QUIT")) {
+			if (request.contains("QUIT")) {
 				state = STATE.CLOSED;
 				return null;
-			} else if (message.equals("USER \r\n")) {
-				response.add(c501);
-			} else if (message.contains("USER")) {
+			} else if (request.equals("USER \r\n")) {
+				response.add(new Packet(c501));
+			} else if (request.contains("USER")) {
 				state = STATE.USER;
-				response.add(c331);
+				response.add(new Packet(c331));
 			} else {
-				response.add(c332);
+				response.add(new Packet(c332));
 			}
 			break;
 		case USER:
-			if (message.equals("PASS \r\n")) {
+			if (request.equals("PASS \r\n")) {
 				state = STATE.OPEN;
-				response.add(c501);
-			} else if (message.contains("PASS")) {
+				response.add(new Packet(c501));
+			} else if (request.contains("PASS")) {
 				state = STATE.LOGGED_IN;
-				response.add(c230);
+				response.add(new Packet(c230));
 			} else {
 				state = STATE.CLOSED;
-				response.add(c221);
+				response.add(new Packet(c221));
 			}
 			break;
 		case LOGGED_IN:
-			if (message != null && !message.contains("QUIT")) {
-				response.add(c500);
+			if (request != null && !request.contains("QUIT")) {
+				response.add(new Packet(c500));
 			} else {
 				state = STATE.CLOSED;
-				response.add(c221);
+				response.add(new Packet(c221));
 			}
 			break;
 		default:
 			state = STATE.CLOSED;
-			response.add(c421);
+			response.add(new Packet(c421));
 		}
 		return response;
 	}

+ 21 - 15
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -7,12 +7,14 @@ import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
 
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
+
 
 /**
  * HTTP protocol
  * @author Wulf Pfeiffer
  */
-public class HTTP implements Protocol<String> {
+public class HTTP implements Protocol {
 	
 	
 	public int getPort() {
@@ -25,27 +27,31 @@ public class HTTP implements Protocol<String> {
 	}
 	
 	
-	public List<String> processMessage(String message) {
-		List<String> response = new ArrayList<String>();
-		request = message + request;
+	public List<Packet> processMessage(Packet packet) {
+		String request = null;
+		if (packet != null) {
+			request = packet.toString();
+		}
+		List<Packet> response = new ArrayList<Packet>();
+		this.request = request;
 
-		if(!message.contains(version)){
+		if(!request.contains(version)){
 			response.add(buildPacket(c505, ""));
-		} else if(message.contains(get)) {
+		} else if(request.contains(get)) {
 			response.add(buildPacket(c200, get));
-		} else if(message.contains(head)) {
+		} else if(request.contains(head)) {
 			response.add(buildPacket(c200, head));
-		} else if(message.contains(trace)){
+		} else if(request.contains(trace)){
 			response.add(buildPacket(c200, trace));
-		} else if(message.contains(options)){
+		} else if(request.contains(options)){
 			response.add(buildPacket(c400, options));
-		} else if(message.contains(post)){
+		} else if(request.contains(post)){
 			response.add(buildPacket(c200, post));
-		} else if(message.contains(put)){
+		} else if(request.contains(put)){
 			response.add(buildPacket(c400, put));
-		} else if(message.contains(delete)){
+		} else if(request.contains(delete)){
 			response.add(buildPacket(c200, delete));
-		} else if(message.contains(connect)){
+		} else if(request.contains(connect)){
 			response.add(buildPacket(c400, connect));
 		} else {
 			response.add(buildPacket(c400, ""));
@@ -79,14 +85,14 @@ public class HTTP implements Protocol<String> {
 	 * @param type request type that was sent by the client
 	 * @return the html response
 	 */
-	private String buildPacket(String code, String type) {
+	private Packet buildPacket(String code, String type) {
 		String doc = "";
 		if(type.equals(get)) doc = htmlDoc;
 		else if(type.equals(head) || type.equals(delete)) doc = "";
 		else if(type.equals(trace)) doc = request;
 		else doc = errorHtmlPrefix + " " + code + errorHtmlSuffix;
 
-		return version + " " + code + headerPrefix + doc.length() + headerSuffix + doc;
+		return new Packet(version + " " + code + headerPrefix + doc.length() + headerSuffix + doc);
 	}
 	
 	/**

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/protocol/HTTPS.java

@@ -10,7 +10,7 @@ import de.tudarmstadt.informatik.hostage.ui.MainActivity;
  * HTTPS protocol
  * @author Wulf Pfeiffer
  */
-public class HTTPS extends HTTP implements SSLProtocol<String> {
+public class HTTPS extends HTTP implements SSLProtocol {
 
 	@Override
 	public int getPort() {

+ 20 - 15
src/de/tudarmstadt/informatik/hostage/protocol/MySQL.java

@@ -3,14 +3,15 @@ package de.tudarmstadt.informatik.hostage.protocol;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
+
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
  * MySQL protocol
  * @author Wulf Pfeiffer
  */
-public class MySQL implements Protocol<ByteArray>{
+public class MySQL implements Protocol {
 	/**
 	 * Represents the states of the protocol
 	 */
@@ -27,25 +28,29 @@ public class MySQL implements Protocol<ByteArray>{
 	private byte[] lastMessage;
 	
 	
-	public List<ByteArray> processMessage(ByteArray request) {
-		List<ByteArray> response = new ArrayList<ByteArray>();
+	public List<Packet> processMessage(Packet packet) {
+		byte[] request = null;
+		if (packet != null) {
+			request = packet.getMessage();
+		}
+		List<Packet> response = new ArrayList<Packet>();
 		if(request != null)
-			lastMessage = request.get();
+			lastMessage = request;
 				
 		switch(state) {
 		case NONE:
-			response.add(new ByteArray(greeting()));
+			response.add(greeting());
 			state = STATE.CONNECTED;
 			break;
 		case CONNECTED:
-			response.add(new ByteArray(responseOK()));
+			response.add(responseOK());
 			state = STATE.LOGIN_INFO;
 			break;
 		case LOGIN_INFO:
 			if(this.lastMessage[4] == 0x01) {
 				state = STATE.CLOSED;
 			} else {
-				response.add(new ByteArray(responseError()));
+				response.add(responseError());
 			}
 			break;
 		default:
@@ -80,8 +85,8 @@ public class MySQL implements Protocol<ByteArray>{
 		return false;
 	}
 
-	public Class<ByteArray> getType() {
-		return ByteArray.class;
+	public Class<byte[]> getType() {
+		return byte[].class;
 	}
 
 	/**
@@ -89,7 +94,7 @@ public class MySQL implements Protocol<ByteArray>{
 	 * @param packet that is wrapped
 	 * @return wrapped packet
 	 */
-	private byte[] wrapPacket(byte[] packet) {
+	private Packet wrapPacket(byte[] packet) {
 		byte[] buffer = ByteBuffer.allocate(4).putInt(packet.length).array();
 		byte[] packetLength = {buffer[3], buffer[2], buffer[1]};
 		byte[] packetNumber = new byte[1];
@@ -97,14 +102,14 @@ public class MySQL implements Protocol<ByteArray>{
 		else packetNumber[0] = 0x00;
 		
 		byte[] response = HelperUtils.concat(packetLength, packetNumber, packet);
-		return response;
+		return new Packet(response);
 	}
 	
 	/**
 	 * Builds the greeting packet that the server sends as first packet
 	 * @return greeting packet
 	 */
-	private byte[] greeting() {
+	private Packet greeting() {
 		byte[] protocol = {0x0a};
 		byte[] version = serverVersion.getBytes();
 		byte[] versionFin = {0x00};
@@ -126,7 +131,7 @@ public class MySQL implements Protocol<ByteArray>{
 	 * Builds the ok-response packet
 	 * @return ok-response packet
 	 */
-	private byte[] responseOK() {
+	private Packet responseOK() {
 		byte[] affectedRows = {0x00, 0x00, 0x00};
 		byte[] status = {0x02, 0x00};
 		byte[] warnings = {0x00, 0x00};
@@ -139,7 +144,7 @@ public class MySQL implements Protocol<ByteArray>{
 	 * Builds the error-response packet
 	 * @return error-response packet
 	 */
-	private byte[] responseError() {
+	private Packet responseError() {
 		byte[] fill1 = {(byte) 0xff};
 		byte[] code = {0x17, 0x04};
 		byte[] fill2 = {0x23};

+ 6 - 3
src/de/tudarmstadt/informatik/hostage/protocol/Protocol.java

@@ -2,12 +2,15 @@ package de.tudarmstadt.informatik.hostage.protocol;
 
 import java.util.List;
 
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
+
 /**
  * Interface for protocols that are used by the application.
  * @param <T> Denotes if the protocol is using Strings or ByteArrays.
  * @author Mihai Plasoianu
+ * @author Wulf Pfeiffer
  */
-public interface Protocol<T> {
+public interface Protocol {
 
 	/**
 	 * Represents who starts the communication once the connection is established.
@@ -33,7 +36,7 @@ public interface Protocol<T> {
 	 * @param message last message that was sent by the client.
 	 * @return next message that will be sent.
 	 */
-	List<T> processMessage(T message);
+	List<Packet> processMessage(Packet packet);
 
 	/**
 	 * Returns whether the communication is ended and the connection should be closed or not.
@@ -51,7 +54,7 @@ public interface Protocol<T> {
 	 * Returns what type the protocol is using, Strings or ByteArrays.
 	 * @return the class that the protocol is using.
 	 */
-	Class<T> getType();
+	Class<? extends Object> getType();
 	
 	/**
 	 * Returns the name of the protocol.

+ 5 - 5
src/de/tudarmstadt/informatik/hostage/protocol/SIP.java

@@ -2,9 +2,9 @@ package de.tudarmstadt.informatik.hostage.protocol;
 
 import java.util.List;
 
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
-public class SIP implements Protocol<ByteArray> {
+public class SIP implements Protocol {
 
 	public int getPort() {
 		return 5060;
@@ -14,7 +14,7 @@ public class SIP implements Protocol<ByteArray> {
 		return TALK_FIRST.CLIENT;
 	}
 
-	public List<ByteArray> processMessage(ByteArray message) {
+	public List<Packet> processMessage(Packet packet) {
 		// TODO Auto-generated method stub
 		return null;
 	}
@@ -28,8 +28,8 @@ public class SIP implements Protocol<ByteArray> {
 		return false;
 	}
 
-	public Class<ByteArray> getType() {
-		return ByteArray.class;
+	public Class<byte[]> getType() {
+		return byte[].class;
 	}
 
 }

+ 50 - 49
src/de/tudarmstadt/informatik/hostage/protocol/SMB.java

@@ -9,13 +9,13 @@ import java.util.List;
 import java.util.TimeZone;
 
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
  * SMB protocol
  * @author Wulf Pfeiffer
  */
-public class SMB implements Protocol<ByteArray> {
+public class SMB implements Protocol {
 	/**
 	 * Represents the states of the protocol
 	 */
@@ -40,78 +40,78 @@ public class SMB implements Protocol<ByteArray> {
 		return TALK_FIRST.CLIENT;
 	}
 	
-	private SMBPacket packet = new SMBPacket();
+	private SMBPacket smbPacket = new SMBPacket();
 
 	
-	public List<ByteArray> processMessage(ByteArray message) {
-		if(message != null)
-			lastMessage = message.get();
-		packet.newMsg(lastMessage);
-		byte smbCommand = packet.getSmbCommand();
-		List<ByteArray> response = new ArrayList<ByteArray>();
+	public List<Packet> processMessage(Packet packet) {
+		if(packet != null)
+			lastMessage = packet.getMessage();
+		smbPacket.newMsg(lastMessage);
+		byte smbCommand = smbPacket.getSmbCommand();
+		List<Packet> response = new ArrayList<Packet>();
 
 		switch (state) {
 		case NONE:
 			if (smbCommand == 0x72) {
 				state = STATE.CONNECTED;
-				response.add(new ByteArray(packet.getNego()));
+				response.add(smbPacket.getNego());
 			} else {
 				state = STATE.DISCONNECTED;
-				response.add(new ByteArray(packet.getTreeDisc()));
+				response.add(smbPacket.getTreeDisc());
 			}
 			break;
 		case CONNECTED:
 			if (smbCommand == 0x73) {
-				response.add(new ByteArray(packet.getSessSetup()));
+				response.add(smbPacket.getSessSetup());
 			} else if (smbCommand == 0x75) {
 				state = STATE.AUTHENTICATED;
-				response.add(new ByteArray(packet.getTreeCon()));
+				response.add(smbPacket.getTreeCon());
 			} else {
 				state = STATE.DISCONNECTED;
-				response.add(new ByteArray(packet.getTreeDisc()));
+				response.add(smbPacket.getTreeDisc());
 			}
 			break;
 		case AUTHENTICATED:
 			if (smbCommand == (byte) 0xa2) {
 				state = STATE.LISTING;
-				response.add(new ByteArray(packet.getNTCreate()));
+				response.add(smbPacket.getNTCreate());
 			} else if (smbCommand == 0x2b) {
-				response.add(new ByteArray(packet.getEcho()));
+				response.add(smbPacket.getEcho());
 			} else if (smbCommand == 0x32) {
-				response.add(new ByteArray(packet.getTrans2()));
+				response.add(smbPacket.getTrans2());
 			} else if (smbCommand == 0x04) {
-				response.add(new ByteArray(packet.getClose()));
+				response.add(smbPacket.getClose());
 			} else if (smbCommand == 0x71) {
 				state = STATE.CLOSED;
-				response.add(new ByteArray(packet.getTreeDisc()));
+				response.add(smbPacket.getTreeDisc());
 			} else {
 				state = STATE.DISCONNECTED;
-				response.add(new ByteArray(packet.getTreeDisc()));
+				response.add(smbPacket.getTreeDisc());
 			}
 			break;
 		case LISTING:
 			if (smbCommand == 0x25) {
-				response.add(new ByteArray(packet.getTrans()));
+				response.add(smbPacket.getTrans());
 			} else if (smbCommand == 0x04) {
-				response.add(new ByteArray(packet.getClose()));
+				response.add(smbPacket.getClose());
 			} else if (smbCommand == 0x71) {
 				state = STATE.CLOSED;
-				response.add(new ByteArray(packet.getTreeDisc()));
+				response.add(smbPacket.getTreeDisc());
 			} else if (smbCommand == 0x72) {
 				state = STATE.CONNECTED;
-				response.add(new ByteArray(packet.getNego()));
+				response.add(smbPacket.getNego());
 			} else {
 				state = STATE.DISCONNECTED;
-				response.add(new ByteArray(packet.getTreeDisc()));
+				response.add(smbPacket.getTreeDisc());
 			}
 			break;
 		case DISCONNECTED:
 			state = STATE.CLOSED;
-			response.add(new ByteArray(packet.getTreeDisc()));
+			response.add(smbPacket.getTreeDisc());
 			break;
 		default:
 			state = STATE.CLOSED;
-			response.add(new ByteArray(packet.getTreeDisc()));
+			response.add(smbPacket.getTreeDisc());
 		}
 		return response;
 	}
@@ -127,8 +127,8 @@ public class SMB implements Protocol<ByteArray> {
 	}
 
 	
-	public Class<ByteArray> getType() {
-		return ByteArray.class;
+	public Class<byte[]> getType() {
+		return byte[].class;
 	}
 
 	
@@ -274,7 +274,7 @@ public class SMB implements Protocol<ByteArray> {
 		 * Builds the negotiate packet
 		 * @return negotiate packet
 		 */
-		private byte[] getNego() {
+		private Packet getNego() {
 			byte[] wordCount	= {0x11};
 			byte[] dialect		= evaluateDialect();		
 			byte[] secMode		= {0x03};
@@ -299,7 +299,7 @@ public class SMB implements Protocol<ByteArray> {
 			byte[] response = HelperUtils.concat(wordCount, dialect, secMode, maxMpxC, maxVcs, maxBufSize, maxRawBuf,
 							sessionKey, capabilities, sysTime, timeZone, keyLength, byteCount, guid, secBlob, oid,
 							protectNeg, negToken, mechType, mechType2);
-			return wrapNetbios(wrapHeader(response));
+			return new Packet(wrapNetbios(wrapHeader(response)));
 		}
 		
 		/**
@@ -328,11 +328,12 @@ public class SMB implements Protocol<ByteArray> {
 		 * Builds the session setup packet
 		 * @return session setup packet
 		 */
-		private byte[] getSessSetup() {
-			if(authenticateNext) return getSetupAuth();
-			else {
+		private Packet getSessSetup() {
+			if(authenticateNext) {
+				return new Packet(getSetupAuth());
+			} else {
 				authenticateNext = true;
-				return getSetupChal();
+				return new Packet(getSetupChal());
 			}
 		}
 		
@@ -439,7 +440,7 @@ public class SMB implements Protocol<ByteArray> {
 		 * Builds the tree connect packet
 		 * @return tree connect packet
 		 */
-		private byte[] getTreeCon() {
+		private Packet getTreeCon() {
 			String str 			= toString();
 			byte[] wordCount	= {0x00};
 			byte[] andXCommand	= {0x00, 0x00};
@@ -469,14 +470,14 @@ public class SMB implements Protocol<ByteArray> {
 				response = HelperUtils.concat(wordCount, andXCommand);
 			}
 			
-			return wrapNetbios(wrapHeader(response));
+			return new Packet(wrapNetbios(wrapHeader(response)));
 		}
 		
 		/**
 		 * Builds the nt create packet
 		 * @return nt create packet
 		 */
-		private byte[] getNTCreate() {
+		private Packet getNTCreate() {
 			byte[] wordCount		= {0x22};
 			byte[] andXCommand		= {(byte) 0xff};
 			byte[] reserved			= {0x00};
@@ -499,14 +500,14 @@ public class SMB implements Protocol<ByteArray> {
 			byte[] response = HelperUtils.concat(wordCount, andXCommand, reserved, andXOffset, oplockLevel, fid,
 												createAction, created, lastAccess, lastWrite, change, fileAttributes, allocationSize,
 												endOfFile, fileType, ipcState, isDirectory, byteCount);
-			return wrapNetbios(wrapHeader(response));
+			return new Packet(wrapNetbios(wrapHeader(response)));
 		}
 		
 		/**
 		 * Builds the trans packet
 		 * @return trans packet
 		 */
-		private byte[] getTrans() {
+		private Packet getTrans() {
 			byte[] transSub	= getTransSub();
 			byte[] response = null;
 			if(transSub[0] == 0x00 && transSub[1] == 0x0b) { //bind_ack
@@ -584,7 +585,7 @@ public class SMB implements Protocol<ByteArray> {
 				
 			}
 			
-			return wrapNetbios(wrapHeader(response));		
+			return new Packet(wrapNetbios(wrapHeader(response)));		
 		}
 		
 		/**
@@ -637,7 +638,7 @@ public class SMB implements Protocol<ByteArray> {
 		 * Builds the close packet
 		 * @return close packet
 		 */
-		private byte[] getClose() {
+		private Packet getClose() {
 			byte[] wordCount	= {0x00};
 			byte[] byteCount	= {0x00, 0x00};
 			
@@ -645,14 +646,14 @@ public class SMB implements Protocol<ByteArray> {
 			
 			byte[] response = HelperUtils.concat(wordCount, byteCount);
 			
-			return wrapNetbios(wrapHeader(response));
+			return new Packet(wrapNetbios(wrapHeader(response)));
 		}
 		
 		/**
 		 * Builds the tree disconnect packet
 		 * @return tree disconnect packet
 		 */
-		private byte[] getTreeDisc() {
+		private Packet getTreeDisc() {
 			byte[] wordCount	= {0x00};
 			byte[] byteCount	= {0x00, 0x00};
 			
@@ -660,21 +661,21 @@ public class SMB implements Protocol<ByteArray> {
 			
 			byte[] response = HelperUtils.concat(wordCount, byteCount);
 			
-			return wrapNetbios(wrapHeader(response));
+			return new Packet(wrapNetbios(wrapHeader(response)));
 		}
 		
 		/**
 		 * Builds the echo packet
 		 * @return echo packet
 		 */
-		private byte[] getEcho() {
+		private Packet getEcho() {
 			byte[] wordCount	= {0x01};
 			byte[] echoSeq		= {0x01, 0x00};
 			byte[] byteCount	= {0x10, 0x00};
 			byte[] echoData		= {(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0,
 									(byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0, (byte) 0xf0}; 
 			byte[] response = HelperUtils.concat(wordCount, echoSeq, byteCount, echoData);
-			return wrapNetbios(wrapHeader(response));
+			return new Packet(wrapNetbios(wrapHeader(response)));
 
 		}
 		
@@ -682,13 +683,13 @@ public class SMB implements Protocol<ByteArray> {
 		 * Builds the trans2 packet
 		 * @return trans2 packet
 		 */
-		private byte[] getTrans2() {
+		private Packet getTrans2() {
 			byte[] response = null;		
 			byte[] wordCount	= {0x00};
 			byte[] andXCommand	= {0x00, 0x00};
 			ntStat = new byte[] {0x22, 0x00, 0x00, (byte) 0xc0};
 			response = HelperUtils.concat(wordCount, andXCommand);
-			return wrapNetbios(wrapHeader(response));
+			return new Packet(wrapNetbios(wrapHeader(response)));
 		}
 		
 		/**

+ 20 - 17
src/de/tudarmstadt/informatik/hostage/protocol/SSH.java

@@ -7,24 +7,25 @@ import java.security.KeyPair;
 import java.security.KeyPairGenerator;
 import java.security.MessageDigest;
 import java.security.PublicKey;
+import java.security.SecureRandom;
 import java.security.Signature;
 import java.security.interfaces.DSAPublicKey;
 import java.util.ArrayList;
 import java.util.List;
-import java.security.SecureRandom;
 
 import javax.crypto.KeyAgreement;
 import javax.crypto.interfaces.DHPublicKey;
 import javax.crypto.spec.DHParameterSpec;
 import javax.crypto.spec.DHPublicKeySpec;
+
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
  * SSH protocol.
  * @author Wulf Pfeiffer
  */
-public class SSH implements Protocol<ByteArray> {
+public class SSH implements Protocol {
 	/**
 	 * Represents the states of the protocol.
 	 */
@@ -55,27 +56,29 @@ public class SSH implements Protocol<ByteArray> {
 	}
 
 	
-	public List<ByteArray> processMessage(ByteArray message) {
-		List<ByteArray> response = new ArrayList<ByteArray>();
+	public List<Packet> processMessage(Packet packet) {
+		List<Packet> response = new ArrayList<Packet>();
 		byte[] request = null;
-		if(message != null) request = message.get();
+		if(packet != null) {
+			request = packet.getMessage();
+		}
 		
 		switch(connectionState) {
 		case NONE:			
-			response.add(new ByteArray(serverVersion + serverType + "\r\n"));
+			response.add(new Packet(serverVersion + serverType + "\r\n"));
 			connectionState = STATE.SERVER_VERSION;
 			break;
 		case SERVER_VERSION:
 			extractType(request);
 			extractCookie(request);
-			response.add(new ByteArray(kexInit()));
+			response.add(kexInit());
 			connectionState = STATE.CLIENT_VERSION;
 			break;
 		case CLIENT_VERSION:
 			extractPubKey(request);
-			response.add(new ByteArray(dhKexReply()));
+			response.add(dhKexReply());
 			//FIXME signature in dhKexReply seems to be wrong
-			response.add(new ByteArray(newKeys()));
+			response.add(newKeys());
 			connectionState = STATE.KEX_INIT;
 			break;
 		case KEX_INIT:
@@ -102,8 +105,8 @@ public class SSH implements Protocol<ByteArray> {
 	}
 
 	
-	public Class<ByteArray> getType() {
-		return ByteArray.class;
+	public Class<byte[]> getType() {
+		return byte[].class;
 	}
 
 	
@@ -116,7 +119,7 @@ public class SSH implements Protocol<ByteArray> {
 	 * @param packet content that is wrapped.
 	 * @return wrapped packet.
 	 */
-	private byte[] wrapPacket(byte[] packet) {
+	private Packet wrapPacket(byte[] packet) {
 		int packetLength = 5 + packet.length; 	//4 byte packet length, 1 byte padding length, payload length
 		int paddingLengthCBS = cipherBlockSize - (packetLength % cipherBlockSize);
 		int paddingLength8 = 8 - (packetLength % 8);
@@ -131,14 +134,14 @@ public class SSH implements Protocol<ByteArray> {
 			SecureRandom rndm = new SecureRandom();
 			paddingString[i] = (byte) rndm.nextInt(255);
 		}
-		return HelperUtils.concat(packetLen, paddingLen, packet, paddingString);
+		return new Packet(HelperUtils.concat(packetLen, paddingLen, packet, paddingString));
 	}
 	
 	/**
 	 * Builds the Kex Init packet that contains all the allowed algorithms by the server.
 	 * @return Kex Init packet.
 	 */
-	private byte[] kexInit() {
+	private Packet kexInit() {
 		byte[] msgCode = {0x14};
 		I_S = randomBytes(16);
 		byte[] kexLength = ByteBuffer.allocate(4).putInt(kex_alg.getBytes().length).array();
@@ -165,7 +168,7 @@ public class SSH implements Protocol<ByteArray> {
 	 * Builds the Diffie-Hellman Kex Reply, containing the host key,f and the signature.
 	 * @return Diffie-Hellman Kex Reply packet.
 	 */
-	private byte[] dhKexReply() {
+	private Packet dhKexReply() {
 		generateDHKeys();
 		generateHostKey();
 		generateSha1Hash();
@@ -185,7 +188,7 @@ public class SSH implements Protocol<ByteArray> {
 	 * New Keys response.
 	 * @return New Keys response.
 	 */
-	private byte[] newKeys() {
+	private Packet newKeys() {
 		byte[] msgCode = {0x15};
 		return wrapPacket(msgCode);
 	}

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/protocol/SSLProtocol.java

@@ -6,7 +6,7 @@ import javax.net.ssl.SSLContext;
  * @author Wulf Pfeiffer
  * @param <T> Denotes if the protocol is using Strings or ByteArrays
  */
-public interface SSLProtocol<T> extends Protocol<T> {
+public interface SSLProtocol extends Protocol {
 
 	/**
 	 * Returns the initialized SSL Context with the KeyManager and TrustManager that will be used

+ 29 - 30
src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java

@@ -4,13 +4,13 @@ import java.util.ArrayList;
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
  * TELNET protocol
  * @author Wulf Pfeiffer
  */
-public class TELNET implements Protocol<ByteArray> {
+public class TELNET implements Protocol {
 	/**
 	 * Represents the states of the protocol
 	 */
@@ -33,23 +33,22 @@ public class TELNET implements Protocol<ByteArray> {
 	}
 
 	
-	public List<ByteArray> processMessage(ByteArray message) {
+	public List<Packet> processMessage(Packet packet) {
 		byte[] request = null;
-		if(message != null) {
-			message.get();
-			request = message.get();
+		if(packet != null) {
+			request = packet.getMessage();
 		}
-		List<ByteArray> response = new ArrayList<ByteArray>();
+		List<Packet> response = new ArrayList<Packet>();
 		
 		switch (state) {
 		case NONE:
-			response.add(new ByteArray(optionRequest));
+			response.add(new Packet(optionRequest));
 			state = STATE.OPEN;
 			break;
 		case OPEN:
 			if(request != null) {
-				response.add(new ByteArray(getOptionResponse(request)));
-				response.add(new ByteArray(serverName + " login: "));
+				response.add(new Packet(getOptionResponse(request)));
+				response.add(new Packet(serverName + " login: "));
 				state = STATE.LOGIN;
 			}
 			break;
@@ -60,10 +59,10 @@ public class TELNET implements Protocol<ByteArray> {
 					byte[] buffer = new byte[request.length - 2]; 
 					System.arraycopy(request, 0, buffer, 0, request.length - 2); 
 					user = HelperUtils.concat(user, buffer);
-					response.add(new ByteArray(buffer));
+					response.add(new Packet(buffer));
 				}
-				response.add(new ByteArray("\r\n"));
-				response.add(new ByteArray("Password: "));
+				response.add(new Packet("\r\n"));
+				response.add(new Packet("Password: "));
 				state = STATE.AUTHENTICATE;
 				sessionToken = HelperUtils.concat(sessionPrefix, user, "@".getBytes(), serverName.getBytes(), sessionMiddle, user, "@".getBytes(), serverName.getBytes(), sessionSuffix);
 				break;
@@ -71,24 +70,24 @@ public class TELNET implements Protocol<ByteArray> {
 				byte[] tmp = new byte[user.length - 1];
 				System.arraycopy(user, 0, tmp, 0, user.length - 1);
 				user = tmp;
-				response.add(new ByteArray("\b \b"));
+				response.add(new Packet("\b \b"));
 				break;
 			} else if (!checkForByte(request, (byte) 0xff)){
 				if(user == null)
 					user = request;
 				else
 					user = HelperUtils.concat(user, request);
-				response.add(message);
+				response.add(packet);
 			}
 			break;
 		case AUTHENTICATE:
 			if(request == null) break;
 			else if(checkForByte(request, (byte) 0x0d)) {
-				response.add(new ByteArray("\r\n"));
-				response.add(new ByteArray(sessionToken));
+				response.add(new Packet("\r\n"));
+				response.add(new Packet(sessionToken));
 				state = STATE.LOGGED_IN;
 			} else if (checkForByte(request, (byte) 0x7f)) {
-				response.add(new ByteArray("\b \b"));
+				response.add(new Packet("\b \b"));
 			}			
 			break;
 		case LOGGED_IN:
@@ -98,37 +97,37 @@ public class TELNET implements Protocol<ByteArray> {
 					byte[] buffer = new byte[request.length - 2]; 
 					System.arraycopy(request, 0, buffer, 0, request.length - 2); 
 					command = HelperUtils.concat(command, buffer);
-					response.add(new ByteArray(buffer));
+					response.add(new Packet(buffer));
 				}
 				if(command == null) {
-					response.add(new ByteArray("\r\n"));
-					response.add(new ByteArray(sessionToken));
+					response.add(new Packet("\r\n"));
+					response.add(new Packet(sessionToken));
 				} else if (new String(command).contains("exit")) {
-					response.add(new ByteArray("\r\nlogout\r\n"));
+					response.add(new Packet("\r\nlogout\r\n"));
 					state = STATE.CLOSED;
 				} else {
 					String bash = "\r\n-bash: " + new String(command)+ ": command not found";
-					response.add(new ByteArray(bash));
-					response.add(new ByteArray("\r\n"));
-					response.add(new ByteArray(sessionToken));
+					response.add(new Packet(bash));
+					response.add(new Packet("\r\n"));
+					response.add(new Packet(sessionToken));
 					command = null;
 				}
 			} else if (checkForByte(request, (byte) 0x7f) && command != null && command.length != 0) {
 				byte[] tmp = new byte[command.length - 1];
 				System.arraycopy(command, 0, tmp, 0, command.length - 1);
 				command = tmp;
-				response.add(new ByteArray("\b \b"));
+				response.add(new Packet("\b \b"));
 				break;
 			} else if (!checkForByte(request, (byte) 0xff)){
 				if(command == null)
 					command = request;
 				else
 					command = HelperUtils.concat(command, request);
-				response.add(message);
+				response.add(packet);
 			}
 			break;
 		default:
-			response.add(new ByteArray("\r\nlogout\r\n"));
+			response.add(new Packet("\r\nlogout\r\n"));
 			state = STATE.CLOSED;
 			break;
 		}
@@ -150,8 +149,8 @@ public class TELNET implements Protocol<ByteArray> {
 	}
 	
 	
-	public Class<ByteArray> getType() {
-		return ByteArray.class;
+	public Class<byte[]> getType() {
+		return byte[].class;
 	}
 	
 	/**

+ 2 - 4
src/de/tudarmstadt/informatik/hostage/sync/BluetoothSync.java

@@ -7,9 +7,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.UUID;
 
-import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
-
 import android.app.AlertDialog;
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
@@ -20,8 +17,9 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.util.Log;
 import android.widget.ArrayAdapter;
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
 
 public class BluetoothSync{
 	

+ 0 - 2
src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java

@@ -42,12 +42,10 @@ import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
-import android.widget.Toast;
 import android.widget.ToggleButton;
 import android.widget.ViewAnimator;
 import de.tudarmstadt.informatik.hostage.HoneyService;
 import de.tudarmstadt.informatik.hostage.HoneyService.LocalBinder;
-import de.tudarmstadt.informatik.hostage.PlayGroundActivity;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.logging.Logger;

+ 5 - 4
src/de/tudarmstadt/informatik/hostage/PlayGroundActivity.java → src/de/tudarmstadt/informatik/hostage/ui/PlayGroundActivity.java

@@ -1,19 +1,20 @@
-package de.tudarmstadt.informatik.hostage;
+package de.tudarmstadt.informatik.hostage.ui;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Random;
 
-import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
-import de.tudarmstadt.informatik.hostage.sync.BluetoothSync;
-import de.tudarmstadt.informatik.hostage.sync.NFCSync;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.Menu;
 import android.view.View;
 import android.widget.TextView;
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
+import de.tudarmstadt.informatik.hostage.sync.BluetoothSync;
+import de.tudarmstadt.informatik.hostage.sync.NFCSync;
 
 public class PlayGroundActivity extends Activity{
 	

+ 6 - 8
src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java

@@ -9,13 +9,6 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
 
-import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.logging.Logger;
-import de.tudarmstadt.informatik.hostage.logging.MyLocationManager;
-import de.tudarmstadt.informatik.hostage.logging.Record;
-import de.tudarmstadt.informatik.hostage.logging.SQLLogger;
-import de.tudarmstadt.informatik.hostage.sync.BluetoothSync;
 import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.app.AlertDialog;
@@ -45,6 +38,11 @@ import android.widget.TableRow;
 import android.widget.TextView;
 import android.widget.TimePicker;
 import android.widget.Toast;
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.logging.Logger;
+import de.tudarmstadt.informatik.hostage.logging.Record;
+import de.tudarmstadt.informatik.hostage.logging.SQLLogger;
 /**
  * ViewLog shows Statistics about the recorded Attacks.
  * It also offers the user several options to perform actions with the database.
@@ -244,7 +242,7 @@ public class ViewLog extends Activity {
 	 * @see ViewLogTable
 	 */
 	public void showLog(View view) {
-//		startActivity(new Intent(this, ViewLogTable.class));
+		startActivity(new Intent(this, ViewLogTable.class));
 		//TODO Delete
 		
 	}

+ 2 - 3
src/de/tudarmstadt/informatik/hostage/ui/ViewLogTable.java

@@ -1,12 +1,11 @@
 package de.tudarmstadt.informatik.hostage.ui;
 
-import de.tudarmstadt.informatik.hostage.format.LogViewFormatter;
-import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
-import de.tudarmstadt.informatik.hostage.logging.Record;
 import android.app.Activity;
 import android.os.Bundle;
 import android.widget.ScrollView;
 import android.widget.TextView;
+import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
+import de.tudarmstadt.informatik.hostage.logging.Record;
 
 /**
  * Creates a simple log view. Shows the Information for every attack. The format ist defined in {@link Record#toString(int)}.

+ 0 - 55
src/de/tudarmstadt/informatik/hostage/wrapper/ByteArray.java

@@ -1,55 +0,0 @@
-package de.tudarmstadt.informatik.hostage.wrapper;
-/**
- * Wrapper class to use a byte array as an Object.
- * @author Mihai Plasoianu 
- *
- */
-public class ByteArray {
-
-	private final byte[] array;
-
-	/**
-	 * Constructor without parameters. Sets the internal array to null.
-	 */
-	public ByteArray() {
-		this.array = null;
-	}
-
-	/**
-	 * Constructor with a byte arrays as parameter. Sets the internal array to the given.
-	 * @param array The byte array that should be wrapped.
-	 */
-	public ByteArray(byte[] array) {
-		this.array = array;
-	}
-	
-	/**
-	 * Constructor with a String as parameter. Sets the internal array to a byte array representation of the string.
-	 * @param string
-	 */
-	public ByteArray(String string) {
-		this.array = string.getBytes();
-	}
-
-	/**
-	 * Returns the byte array.
-	 * @return The byte array
-	 */
-	public byte[] get() {
-		return array;
-	}
-
-	/**
-	 * Determines size of the array.
-	 * @return Size of the array
-	 */
-	public int size() {
-		return array.length;
-	}
-
-	@Override
-	public String toString() {
-		return new String(array);
-	}
-
-}

+ 91 - 0
src/de/tudarmstadt/informatik/hostage/wrapper/Packet.java

@@ -0,0 +1,91 @@
+package de.tudarmstadt.informatik.hostage.wrapper;
+
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+
+/**
+ * Wrapper class for IO content.
+ * @author Wulf Pfeiffer
+ */
+public class Packet {
+
+	private byte[] message		= null;
+	private boolean isStringMsg	= false;
+	private boolean isByteMsg	= false;
+
+	/**
+	 * Constructor.
+	 */
+	public Packet() {
+		message = null;
+	}
+	
+	/**
+	 * Constructor.
+	 * If Packet is created with a String value, it is marked with a boolean.
+	 * @param message
+	 */
+	public Packet(String message) {
+		this.message	= message.getBytes();
+		isStringMsg		= true;
+	}
+	
+	/**
+	 * Constructor.
+	 * If Packet is created with a byte[] value, it is marked with a boolean.
+	 * @param message
+	 */
+	public Packet(byte[] message) {
+		this.message	= message;
+		isByteMsg		= true;
+	}
+
+	/**
+	 * Returns the message value as byte[].
+	 * @return message value
+	 */
+	public byte[] getMessage() {
+		return message;
+	}
+
+	/**
+	 * Returns the class which the Packet was created with.
+	 * If the string constructor was used it returns String.class.
+	 * If the byte[] constructor was used it returns byte[].class.
+	 * Else it returns null.
+	 * @return class which the Packet was created with.
+	 */
+	public Class<? extends Object> getType() {
+		if (isStringMsg) {
+			return String.class;
+		} else if (isByteMsg){
+			return byte[].class;
+		} else {
+			return null;
+		}
+	}
+
+	/**
+	 * Checks whether the Packet was created with the given class or not.
+	 * @param type to be checked.
+	 * @return true if the packet was created with the given class, else false.
+	 */
+	public boolean isOfType(Class<? extends Object> type) {
+		return getType().equals(type);
+	}
+
+	/**
+	 * If the Packet was created with a byte[] it returns the hexadecimal byte value as a String,
+	 * else it returns a new String created by the byte[].
+	 */
+	@Override
+	public String toString() {
+		if (isStringMsg) {
+			return new String((byte[]) message);
+		} else if (isByteMsg) {
+			return HelperUtils.bytesToHexString((byte[]) message);
+		} else {
+			return null;
+		}
+	}
+
+}