Browse Source

Code clean-up
Added comments
Renamed all 'renderer' into 'formatter'

qam 10 years ago
parent
commit
e6521b1958
31 changed files with 215 additions and 131 deletions
  1. 4 4
      src/de/tudarmstadt/informatik/hostage/HoneyListener.java
  2. 4 4
      src/de/tudarmstadt/informatik/hostage/HoneyService.java
  3. 13 11
      src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java
  4. 14 0
      src/de/tudarmstadt/informatik/hostage/format/DefaultFormatter.java
  5. 46 0
      src/de/tudarmstadt/informatik/hostage/format/LogViewFormatter.java
  6. 16 6
      src/de/tudarmstadt/informatik/hostage/format/MySQLFormatter.java
  7. 17 0
      src/de/tudarmstadt/informatik/hostage/format/ProtocolFormatter.java
  8. 30 10
      src/de/tudarmstadt/informatik/hostage/format/SMBFormatter.java
  9. 14 5
      src/de/tudarmstadt/informatik/hostage/format/TELNETFormatter.java
  10. 0 2
      src/de/tudarmstadt/informatik/hostage/handler/AbstractHandler.java
  11. 8 3
      src/de/tudarmstadt/informatik/hostage/handler/ByteArrayHandler.java
  12. 5 1
      src/de/tudarmstadt/informatik/hostage/handler/StringHandler.java
  13. 10 1
      src/de/tudarmstadt/informatik/hostage/io/ByteArrayReaderWriter.java
  14. 9 0
      src/de/tudarmstadt/informatik/hostage/io/StringReaderWriter.java
  15. 1 2
      src/de/tudarmstadt/informatik/hostage/logging/DatabaseHandler.java
  16. 0 1
      src/de/tudarmstadt/informatik/hostage/net/MySSLSocketFactory.java
  17. 4 0
      src/de/tudarmstadt/informatik/hostage/net/MyServerSocketFactory.java
  18. 0 5
      src/de/tudarmstadt/informatik/hostage/protocol/ECHO.java
  19. 1 4
      src/de/tudarmstadt/informatik/hostage/protocol/FTP.java
  20. 0 4
      src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java
  21. 0 4
      src/de/tudarmstadt/informatik/hostage/protocol/HTTPS.java
  22. 2 7
      src/de/tudarmstadt/informatik/hostage/protocol/SSH.java
  23. 6 0
      src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java
  24. 0 12
      src/de/tudarmstadt/informatik/hostage/render/DefaultRenderer.java
  25. 0 6
      src/de/tudarmstadt/informatik/hostage/render/ProtocolRenderer.java
  26. 0 29
      src/de/tudarmstadt/informatik/hostage/render/ViewLogRenderer.java
  27. 4 0
      src/de/tudarmstadt/informatik/hostage/system/PrivilegedPort.java
  28. 4 0
      src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java
  29. 0 1
      src/de/tudarmstadt/informatik/hostage/ui/SettingsActivity.java
  30. 0 6
      src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java
  31. 3 3
      src/de/tudarmstadt/informatik/hostage/ui/ViewLogTable.java

+ 4 - 4
src/de/tudarmstadt/informatik/hostage/HoneyListener.java

@@ -39,7 +39,7 @@ public class HoneyListener implements Runnable {
 		return handlers.size();
 	}
 
-	private Protocol protocol;
+	private Protocol<?> protocol;
 	private ServerSocket server;
 	private Thread thread;
 
@@ -66,7 +66,7 @@ public class HoneyListener implements Runnable {
 	 * @param service The Background service that started the listener. 
 	 * @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(
@@ -171,7 +171,7 @@ public class HoneyListener implements Runnable {
 	 * @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);
@@ -199,7 +199,7 @@ public class HoneyListener implements Runnable {
 	 * @return A Instance of a {@link AbstractHandler} with the specified parameter.
 	 */
 	private AbstractHandler newInstance(HoneyService service,
-			HoneyListener listener, Protocol protocol, Socket client) {
+			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)) {

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

@@ -73,7 +73,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();
@@ -252,14 +252,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) {

+ 13 - 11
src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java

@@ -3,9 +3,7 @@ package de.tudarmstadt.informatik.hostage.commons;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.security.KeyStore;
-import java.util.concurrent.ExecutionException;
 
-import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpPost;
@@ -24,10 +22,7 @@ import org.apache.http.protocol.HTTP;
 
 import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.net.MySSLSocketFactory;
-import de.tudarmstadt.informatik.hostage.ui.MainActivity;
 import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.net.wifi.WifiInfo;
@@ -185,7 +180,7 @@ public final class HelperUtils {
 			StringEntity se = new StringEntity(record.toString(0x01));
 			httppost.setEntity(se);
 			// Execute HttpPost
-			HttpResponse response = httpclient.execute(httppost);
+			httpclient.execute(httppost);
 		} catch (Exception e) {
 			e.printStackTrace();
 			return false;
@@ -241,8 +236,12 @@ public final class HelperUtils {
 		return (character > 31 && character < 127);
 	}
 	
-	
-	public static String byteToHexString(byte[] bytes) {
+	/**
+	 * Converts a byte array into a hexadecimal String, e.g. {0x00, 0x01} to "0x00, 0x01". 
+	 * @param bytes that will be converted.
+	 * @return converted String.
+	 */
+	public static String bytesToHexString(byte[] bytes) {
 		char[] hexArray = "0123456789ABCDEF".toCharArray();
 	    int v;
 	    StringBuffer buffer = new StringBuffer();
@@ -255,9 +254,12 @@ public final class HelperUtils {
 	    return buffer.toString();
 	}
 	
-	public static byte[] hexStringToByte(String string) {
-		char[] hexArray = "0123456789ABCDEF".toCharArray();
-	    int v;
+	/**
+	 * Converts a String into a byte array, e.g. "0x00, 0x01" to {0x00, 0x01}. 
+	 * @param string that will be converted.
+	 * @return converted byte array.
+	 */
+	public static byte[] hexStringToBytes(String string) {
 	    String[] hexStrings = string.split(", ");
 	    byte[] bytes = new byte[hexStrings.length];
 	    for(int j = 0; j < hexStrings.length; j++ ) {

+ 14 - 0
src/de/tudarmstadt/informatik/hostage/format/DefaultFormatter.java

@@ -0,0 +1,14 @@
+package de.tudarmstadt.informatik.hostage.format;
+
+/**
+ * Default log view formatter.
+ * @author Wulf Pfeiffer
+ */
+public class DefaultFormatter implements ProtocolFormatter {
+
+	@Override
+	public String format(String packet) {
+		return packet;
+	}
+
+}

+ 46 - 0
src/de/tudarmstadt/informatik/hostage/format/LogViewFormatter.java

@@ -0,0 +1,46 @@
+package de.tudarmstadt.informatik.hostage.format;
+
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.ui.MainActivity;
+
+/**
+ * Log view formatter used to format packet contents for the log view.
+ * @author Wulf Pfeiffer
+ */
+public class LogViewFormatter {
+	
+	/**
+	 * Formats the content of a packet giving it a specific format specified by a ProtocolFormatter. 
+	 * @param protocol that is used for packet.
+	 * @param packet content.
+	 * @return formatted String of the packet content.
+	 */
+	public static String format(String protocol, String packet) {		
+		return getFormatter(protocol).format(packet);
+	}
+	
+	/**
+	 * Loads a ProtocolFormatter for a protocol.
+	 * If the protocol has its own formatter, with the name *protocol name*Formatter and it is located in .format package, it is loaded,
+	 * else a default formatter is loaded.
+	 * @param protocol that a formatter should be loaded for.
+	 * @return the loaded formatter.
+	 */
+	private static ProtocolFormatter getFormatter(String protocol) {
+		String[] protocols = MainActivity.getContext().getResources().getStringArray(R.array.protocols);
+		String packageName = ProtocolFormatter.class.getPackage().getName();
+		ProtocolFormatter formatter = new DefaultFormatter();
+
+		for (String prot : protocols) {
+			try {
+				if(protocol.equals(prot)) formatter = (ProtocolFormatter) Class.forName(
+						String.format("%s.%s", packageName, protocol+"Formatter"))
+						.newInstance();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		return formatter;
+	}
+
+}

+ 16 - 6
src/de/tudarmstadt/informatik/hostage/render/MySQLRenderer.java → src/de/tudarmstadt/informatik/hostage/format/MySQLFormatter.java

@@ -1,20 +1,30 @@
-package de.tudarmstadt.informatik.hostage.render;
+package de.tudarmstadt.informatik.hostage.format;
 
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 
-public class MySQLRenderer implements ProtocolRenderer {
+/**
+ * MySQL log view formatter.
+ * @author Wulf Pfeiffer
+ */
+public class MySQLFormatter implements ProtocolFormatter {
 
 	@Override
-	public String render(String packet) {
-		byte[] bytes = HelperUtils.hexStringToByte(packet);
+	public String format(String packet) {
+		byte[] bytes = HelperUtils.hexStringToBytes(packet);
 		String command = getCommand(bytes) + "\n";
 		String content = HelperUtils.byteToStr(bytes) + "\n";
 		return command + content;
 	}
 	
+	/**
+	 * Checks a packet for its command code and returns the name of this command.
+	 * @param bytes to check.
+	 * @return name of the command.
+	 */
 	private String getCommand(byte[] bytes) {
-		if(bytes[3] == 0x01) return "Login request"; //if packet number is 1 server started conversation so it must be login
-		
+		//if packet number is 1 server started conversation so it must be login
+		if(bytes[3] == 0x01) return "Login request"; 
+		//else check for command code
 		switch(bytes[4]) {
 		case 0x00: return "COM_SLEEP";
 		case 0x01: return "COM_QUIT";

+ 17 - 0
src/de/tudarmstadt/informatik/hostage/format/ProtocolFormatter.java

@@ -0,0 +1,17 @@
+package de.tudarmstadt.informatik.hostage.format;
+
+/**
+ * Interface for log view formatter.
+ * This class provides functionality to format the presentation of specific protocols.
+ * @author Wulf Pfeiffer
+ */
+public interface ProtocolFormatter {
+
+	/**
+	 * Formats the content of packet. The packet content can be a normal String or a hexadecimal String,
+	 * depending of the type of the protocol. ByteArray protocols receive hexdecimal String, else normal Strings.
+	 * @param packet that should be formatted.
+	 * @return new format of the packet content.
+	 */
+	String format(String packet);
+}

+ 30 - 10
src/de/tudarmstadt/informatik/hostage/render/SMBRenderer.java → src/de/tudarmstadt/informatik/hostage/format/SMBFormatter.java

@@ -1,13 +1,17 @@
-package de.tudarmstadt.informatik.hostage.render;
+package de.tudarmstadt.informatik.hostage.format;
 
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 
-public class SMBRenderer implements ProtocolRenderer {
+/**
+ * SMB log view formatter.
+ * @author Wulf Pfeiffer
+ */
+public class SMBFormatter implements ProtocolFormatter {
 
 	@Override
-	public String render(String packet) {
-		byte[] bytes = HelperUtils.hexStringToByte(packet);
-		byte cmd = bytes[8];
+	public String format(String packet) {
+		byte[] bytes = HelperUtils.hexStringToBytes(packet);
+		byte cmd = bytes[8]; //command code located at 8
 		StringBuffer buffer = new StringBuffer();
 		buffer.append("Command: ");
 		buffer.append(getCommandString(cmd));
@@ -17,9 +21,14 @@ public class SMBRenderer implements ProtocolRenderer {
 		
 		return buffer.toString();
 	}
-		
-	private String getCommandString(byte cmd) {
-		switch(cmd) {
+	
+	/**
+	 * Checks command code for its command code and returns the name of this command.
+	 * @param command as byte.
+	 * @return command name as String.
+	 */
+	private String getCommandString(byte command) {
+		switch(command) {
 		case 0x00: return "SMB_COM_CREATE_DIRECTORY";
 		case 0x01: return "SMB_COM_DELETE_DIRECTORY";
 		case 0x02: return "SMB_COM_OPEN";
@@ -97,8 +106,14 @@ public class SMBRenderer implements ProtocolRenderer {
 		}
 	}
 	
-	private String getContent(byte cmd, byte[] packet) {
-		switch(cmd) {
+	/**
+	 * Returns the content of a packet as a String value, depending on its command code
+	 * @param command of the packet.
+	 * @param packet content as byte array. 
+	 * @return content as a String.
+	 */
+	private String getContent(byte command, byte[] packet) {
+		switch(command) {
 		case 0x72: return get0x72content(packet);
 		case 0x73: return HelperUtils.byteToStr(packet);
 		case (byte) 0xa2: return HelperUtils.byteToStr(packet);
@@ -107,6 +122,11 @@ public class SMBRenderer implements ProtocolRenderer {
 		}
 	}
 	
+	/**
+	 * Returns the content of a packet with command code 0x72.
+	 * @param packet content as byte array.
+	 * @return content as String.
+	 */
 	private String get0x72content(byte[] packet) {
 		byte[] content = new byte[packet.length-39];
 		System.arraycopy(packet, 39, content, 0, content.length);

+ 14 - 5
src/de/tudarmstadt/informatik/hostage/render/TELNETRenderer.java → src/de/tudarmstadt/informatik/hostage/format/TELNETFormatter.java

@@ -1,17 +1,26 @@
-package de.tudarmstadt.informatik.hostage.render;
+package de.tudarmstadt.informatik.hostage.format;
 
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 
-public class TELNETRenderer implements ProtocolRenderer {
+/**
+ * Telnet log view formatter.
+ * @author Wulf Pfeiffer
+ */
+public class TELNETFormatter implements ProtocolFormatter {
 
 	@Override
-	public String render(String packet) {
-		byte[] bytes = HelperUtils.hexStringToByte(packet);
+	public String format(String packet) {
+		byte[] bytes = HelperUtils.hexStringToBytes(packet);
 		String options = "Options:\n" + checkForOptions(bytes) + "\n";
 		String content = "Content: " + HelperUtils.byteToStr(bytes);
 		return options + content;
 	}
 	
+	/**
+	 * Checks a packet for option commands and returns their names as Strings.
+	 * @param bytes that are checked.
+	 * @return names of the option commands as String.
+	 */
 	private String checkForOptions(byte[] bytes) {
 		StringBuffer options = new StringBuffer();
 		for(int i = 0; i < bytes.length; i++) {
@@ -33,7 +42,7 @@ public class TELNETRenderer implements ProtocolRenderer {
 					options.append(" unkown command ");
 					break;
 				}
-				
+				// option name
 				switch(bytes[i+2]) {
 				case 0x00: 
 					options.append("Binary Transmission\n");

+ 0 - 2
src/de/tudarmstadt/informatik/hostage/handler/AbstractHandler.java

@@ -11,7 +11,6 @@ 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.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.logging.Logger;
 import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
@@ -20,7 +19,6 @@ import de.tudarmstadt.informatik.hostage.ui.MainActivity;
 /**
  * Abstract class for a connection handler using a given protocol.
  * @author Mihai Plasoianu 
- *
  */
 public abstract class AbstractHandler implements Runnable {
 

+ 8 - 3
src/de/tudarmstadt/informatik/hostage/handler/ByteArrayHandler.java

@@ -19,12 +19,17 @@ 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) {
+			Protocol<?> protocol, Socket client) {
 		super(service, listener, protocol, client);
 		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(service);
 		SLEEPTIME = pref.getInt("sleeptime", 500);
@@ -48,11 +53,11 @@ public class ByteArrayHandler extends AbstractHandler {
 
 		while (!thread.isInterrupted() && (inputLine = stream.read()) != null) {
 			outputLine = protocol.processMessage(inputLine);
-			log.write(createRecord(TYPE.RECEIVE, HelperUtils.byteToHexString(inputLine.get())));
+			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.byteToHexString(s.get())));
+					log.write(createRecord(TYPE.SEND, HelperUtils.bytesToHexString(s.get())));
 				}
 			}
 			if (protocol.isClosed()) {

+ 5 - 1
src/de/tudarmstadt/informatik/hostage/handler/StringHandler.java

@@ -14,10 +14,14 @@ 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) {
+			Protocol<?> protocol, Socket client) {
 		super(service, listener, protocol, client);
 	}
 

+ 10 - 1
src/de/tudarmstadt/informatik/hostage/io/ByteArrayReaderWriter.java

@@ -2,7 +2,6 @@ package de.tudarmstadt.informatik.hostage.io;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -10,12 +9,22 @@ import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
 
+/**
+ * Handles the reading and writing of the socket in- and outputstream for byte arrays
+ * @author Mihai Plasoianu
+ */
 public class ByteArrayReaderWriter implements ReaderWriter<ByteArray> {
 
 	private BufferedInputStream in;
 	private BufferedOutputStream out;
 	private int SLEEPTIME;
 
+	/**
+	 * Constructor
+	 * @param in inputstream of socket
+	 * @param out outputstream of socket
+	 * @param SLEEPTIME time until timeout
+	 */
 	public ByteArrayReaderWriter(InputStream in, OutputStream out, int SLEEPTIME) {
 		this.in = new BufferedInputStream(in);
 		this.out = new BufferedOutputStream(out);

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

@@ -9,11 +9,20 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.util.List;
 
+/**
+ * Handles the reading and writing of the socket in- and outputstream for strings
+ * @author Mihai Plasoianu
+ */
 public class StringReaderWriter implements ReaderWriter<String> {
 
 	private BufferedReader in;
 	private BufferedWriter out;
 
+	/**
+	 * Constructor
+	 * @param in inputstream
+	 * @param out outputstream
+	 */
 	public StringReaderWriter(InputStream in, OutputStream out) {
 		this.in = new BufferedReader(new InputStreamReader(in));
 		this.out = new BufferedWriter(new OutputStreamWriter(out));

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

@@ -16,7 +16,6 @@ import android.database.sqlite.SQLiteOpenHelper;
  * {@link #TABLE_RECORDS} contains all logging information of a single message record except the SSID.<br>
  * {@link #TABLE_BSSIDS} contains the BSSID of all recorded Networks and the corresponding SSID.<br>
  * @author Lars Pandikow
- *
  */
 public class DatabaseHandler extends SQLiteOpenHelper {
 
@@ -211,7 +210,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
     
 	/**
 	 * Gets all received {@link Record Records} for every attack identified by its attack id and ordered by date.
-	 * @return A ArrayList with one {@link Record Records} for each attack id in the Database.
+	 * @return A ArrayList with all received {@link Record Records} for each attack id in the Database.
 	 */
     public ArrayList<Record> getAllReceivedRecordsOfEachAttack() {
     	ArrayList<Record> recordList = new ArrayList<Record>();

+ 0 - 1
src/de/tudarmstadt/informatik/hostage/net/MySSLSocketFactory.java

@@ -18,7 +18,6 @@ import javax.net.ssl.X509TrustManager;
 import org.apache.http.conn.ssl.SSLSocketFactory;
 /**
  * SocketFactory to create a SSL socket that accepts every certificate.
- *
  */
 public class MySSLSocketFactory extends SSLSocketFactory {
 	private SSLContext sslContext = SSLContext.getInstance("TLS");

+ 4 - 0
src/de/tudarmstadt/informatik/hostage/net/MyServerSocketFactory.java

@@ -11,6 +11,10 @@ import javax.net.ServerSocketFactory;
 
 import de.tudarmstadt.informatik.hostage.system.PrivilegedPort;
 
+/**
+ * Server Socket Factory using the porthack.
+ * @author Mihai Plasoianu
+ */
 public class MyServerSocketFactory extends ServerSocketFactory {
 
 	/**

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

@@ -3,7 +3,6 @@ package de.tudarmstadt.informatik.hostage.protocol;
 import java.util.ArrayList;
 import java.util.List;
 
-import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
 
 /**
@@ -22,12 +21,8 @@ public class ECHO implements Protocol<ByteArray>{
 		return TALK_FIRST.CLIENT;
 	}
 	
-	private byte[] lastMessage;
-
 	@Override
 	public List<ByteArray> processMessage(ByteArray message) {
-		if(message != null)
-			lastMessage = message.get();
 		List<ByteArray> response = new ArrayList<ByteArray>();
 		//respond with the received message
 		response.add(message);

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

@@ -20,8 +20,6 @@ public final class FTP implements Protocol<String> {
 	 */
 	private STATE state = STATE.NONE;
 	
-	private String lastMessage;
-
 	@Override
 	public int getPort() {
 		return 21;
@@ -34,8 +32,6 @@ public final class FTP implements Protocol<String> {
 
 	@Override
 	public List<String> processMessage(String message) {
-		if(message != null)
-			lastMessage = message;
 		List<String> response = new ArrayList<String>();
 		switch (state) {
 		case NONE:
@@ -87,6 +83,7 @@ public final class FTP implements Protocol<String> {
 		return response;
 	}
 	
+	//commands
 	private String c220 = "220 Service ready for new user.";
 	private String c221 = "221 Service closing control connection.";
 	private String c230 = "230 User logged in.";

+ 0 - 4
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -18,13 +18,9 @@ public final class HTTP implements Protocol<String> {
 	public TALK_FIRST whoTalksFirst() {
 		return TALK_FIRST.CLIENT;
 	}
-
-	private String lastMessage;
 	
 	@Override
 	public List<String> processMessage(String message) {
-		if(message != null)
-			lastMessage = message;
 		List<String> response = new ArrayList<String>();
 		request = message + request;
 

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

@@ -25,12 +25,8 @@ public class HTTPS implements SSLProtocol<String> {
 		return TALK_FIRST.CLIENT;
 	}
 	
-	private String lastMessage;
-
 	@Override
 	public List<String> processMessage(String message) {
-		if(message != null)
-			lastMessage = message;
 		List<String> response = new ArrayList<String>();
 		request = message + request;
 

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

@@ -96,8 +96,6 @@ public final class SSH implements Protocol<ByteArray> {
 	/** Denotes in which state the protocol is right now */
 	private STATE state = STATE.NONE;
 	
-	private byte[] lastMessage;
-
 	@Override
 	public int getPort() {
 		return 22;
@@ -110,8 +108,6 @@ public final class SSH implements Protocol<ByteArray> {
 
 	@Override
 	public List<ByteArray> processMessage(ByteArray message) {
-		if(message != null)
-			lastMessage = message.get();
 		List<ByteArray> response = new ArrayList<ByteArray>();
 		byte[] request = null;
 		if(message != null) request = message.get();
@@ -130,7 +126,7 @@ public final class SSH implements Protocol<ByteArray> {
 		case CLIENT_VERSION:
 			extractPubKey(request);
 			response.add(new ByteArray(dhKexReply()));
-			//FIXME signature in dhKexReply is wrong, don't know why
+			//FIXME signature in dhKexReply seems to be wrong
 			response.add(new ByteArray(newKeys()));
 			connectionState = STATE.KEX_INIT;
 			break;
@@ -415,7 +411,6 @@ public final class SSH implements Protocol<ByteArray> {
 	 * @return r and s as byte[]
 	 */
 	private byte[] extractSignature(byte[] signature) {
-        //{ r INTEGER, s INTEGER }
         int length = 0;
         int index = 3;
         length = signature[index++] & 0xff;
@@ -426,7 +421,7 @@ public final class SSH implements Protocol<ByteArray> {
         byte[] s = new byte[length];
         System.arraycopy(signature, index, s, 0, s.length);
         byte[] result = new byte[40];
-        // result must be 40 bytes, but length of r and s may not be 20 bytes
+        // result must be 40 bytes, but r and s may be longer than 20
         System.arraycopy(r,
                          (r.length > 20) ? 1 : 0,
                          result,

+ 6 - 0
src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java

@@ -168,6 +168,12 @@ public final class TELNET implements Protocol<ByteArray> {
 		return ByteArray.class;
 	}
 	
+	/**
+	 * Checks a byte array for occurence of one byte.
+	 * @param bytes byte array that is checked.
+	 * @param b searched byte.
+	 * @return true if the byte was found, else false.
+	 */
 	private boolean checkForByte(byte[] bytes, byte b) {
 		for(byte oneByte : bytes) {
 			if(oneByte == b) return true;

+ 0 - 12
src/de/tudarmstadt/informatik/hostage/render/DefaultRenderer.java

@@ -1,12 +0,0 @@
-package de.tudarmstadt.informatik.hostage.render;
-
-import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-
-public class DefaultRenderer implements ProtocolRenderer {
-
-	@Override
-	public String render(String packet) {
-		return packet;
-	}
-
-}

+ 0 - 6
src/de/tudarmstadt/informatik/hostage/render/ProtocolRenderer.java

@@ -1,6 +0,0 @@
-package de.tudarmstadt.informatik.hostage.render;
-
-public interface ProtocolRenderer {
-
-	String render(String packet);
-}

+ 0 - 29
src/de/tudarmstadt/informatik/hostage/render/ViewLogRenderer.java

@@ -1,29 +0,0 @@
-package de.tudarmstadt.informatik.hostage.render;
-
-import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.ui.MainActivity;
-
-public class ViewLogRenderer {
-	
-	public static String render(String protocol, String packet) {		
-		return getRenderer(protocol).render(packet);
-	}
-	
-	private static ProtocolRenderer getRenderer(String protocol) {
-		String[] protocols = MainActivity.getContext().getResources().getStringArray(R.array.protocols);
-		String packageName = ProtocolRenderer.class.getPackage().getName();
-		ProtocolRenderer renderer = new DefaultRenderer();
-
-		for (String prot : protocols) {
-			try {
-				if(protocol.equals(prot)) renderer = (ProtocolRenderer) Class.forName(
-						String.format("%s.%s", packageName, protocol+"Renderer"))
-						.newInstance();
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-		return renderer;
-	}
-
-}

+ 4 - 0
src/de/tudarmstadt/informatik/hostage/system/PrivilegedPort.java

@@ -5,6 +5,10 @@ import java.io.FileDescriptor;
 import android.net.LocalServerSocket;
 import android.net.LocalSocket;
 
+/**
+ * Port loaded with porthack with root rights
+ * @author Mihai Plasoianu
+ */
 public class PrivilegedPort implements Runnable {
 
 	/**

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

@@ -625,6 +625,10 @@ public class MainActivity extends Activity {
 		editor.commit();
 	}	
 	
+	/**
+	 * Task to find out the external IP.
+	 * @author Lars Pandikow
+	 */
 	private class SetExternalIPTask extends AsyncTask<String, Void, String>{	
 		 @Override
 		    protected String doInBackground(String... url) {

+ 0 - 1
src/de/tudarmstadt/informatik/hostage/ui/SettingsActivity.java

@@ -8,7 +8,6 @@ import android.preference.EditTextPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceManager;
-import android.util.Log;
 import android.widget.Toast;
 /**
  * SettingsActivity creates the settings defined in /res/xml/preferences.xml.

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

@@ -2,7 +2,6 @@ package de.tudarmstadt.informatik.hostage.ui;
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.net.InetAddress;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -10,11 +9,6 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
 
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.logging.Logger;

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

@@ -1,13 +1,13 @@
 package de.tudarmstadt.informatik.hostage.ui;
 
-import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.format.LogViewFormatter;
 import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
 import de.tudarmstadt.informatik.hostage.logging.Record;
-import de.tudarmstadt.informatik.hostage.render.ViewLogRenderer;
 import android.app.Activity;
 import android.os.Bundle;
 import android.widget.ScrollView;
 import android.widget.TextView;
+
 /**
  * Creates a simple log view. Shows the Information for every attack. The format ist defined in {@link Record#toString(int)}.
  * @author Lars Pandikow
@@ -23,7 +23,7 @@ public class ViewLogTable extends Activity{
 		//Create a log entry for every attack in the Database
 		for(Record record: dbh.getAllReceivedRecordsOfEachAttack()) {
 			log.append(record.toString(2));
-			log.append(ViewLogRenderer.render(record.getProtocol(), record.getPacket()));
+			log.append(LogViewFormatter.format(record.getProtocol(), record.getPacket()));
 			log.append("\n");
 			log.append("\n");
 		}