Browse Source

Fixed bug in ViewLog.deleteByBSSID().
More source code commenting

lp-tu 10 years ago
parent
commit
054aea0695

+ 7 - 0
src/de/tudarmstadt/informatik/hostage/HoneyListener.java

@@ -106,6 +106,7 @@ public class HoneyListener implements Runnable {
 	public void stop() {
 		try {
 			server.close();
+			stopHandler();
 			thread.interrupt();
 			editor.putBoolean(protocol + MainActivity.LISTENER, false);
 			editor.commit();
@@ -115,6 +116,12 @@ public class HoneyListener implements Runnable {
 			e.printStackTrace();
 		}
 	}
+	
+	private void stopHandler(){
+		for(AbstractHandler handler : handlers){
+			handler.kill();
+		}
+	}
 
 	/**
 	 * Determine the name of the protocol the listener is running on.

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

@@ -107,7 +107,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 	private Record createRecord(Cursor cursor){
 		Record record = new Record();
 		try {
-		record.setID(Integer.parseInt(cursor.getString(0)));
+		record.setId(Integer.parseInt(cursor.getString(0)));
 		record.setAttack_id(cursor.getLong(1));
 		record.setProtocol(cursor.getString(2));
 		record.setType(cursor.getString(3).equals("SEND") ? TYPE.SEND : TYPE.RECEIVE);
@@ -321,6 +321,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
 		if (cursor.moveToFirst()) {
 			do {
 				bssidList[counter] = cursor.getString(0);
+				counter++;
 			} while (cursor.moveToNext());
 		}       
         cursor.close();

+ 53 - 13
src/de/tudarmstadt/informatik/hostage/logging/Record.java

@@ -32,18 +32,19 @@ public class Record implements Serializable {
 	private String SSID;
 	private String packet;	
 
+
+
 	/**
 	 * @return the id
 	 */
-	public int getID() {
+	public int getId() {
 		return id;
 	}
 
 	/**
-	 * @param id
-	 *            the id to set
+	 * @param id the id to set
 	 */
-	public void setID(int id) {
+	public void setId(int id) {
 		this.id = id;
 	}
 
@@ -55,8 +56,7 @@ public class Record implements Serializable {
 	}
 
 	/**
-	 * @param attack_id
-	 *            the attack_id to set
+	 * @param attack_id the attack_id to set
 	 */
 	public void setAttack_id(long attack_id) {
 		this.attack_id = attack_id;
@@ -70,56 +70,92 @@ public class Record implements Serializable {
 	}
 
 	/**
-	 * @param string the protocol to set
+	 * @param protocol the protocol to set
 	 */
-	public void setProtocol(String string) {
-		this.protocol = string;
+	public void setProtocol(String protocol) {
+		this.protocol = protocol;
 	}
 
+	/**
+	 * @return the type
+	 */
 	public TYPE getType() {
 		return type;
 	}
 
+	/**
+	 * @param type the type to set
+	 */
 	public void setType(TYPE type) {
 		this.type = type;
 	}
 
+	/**
+	 * @return the timestamp
+	 */
 	public long getTimestamp() {
 		return timestamp;
 	}
 
+	/**
+	 * @param timestamp the timestamp to set
+	 */
 	public void setTimestamp(long timestamp) {
 		this.timestamp = timestamp;
 	}
 
+	/**
+	 * @return the localIP
+	 */
 	public InetAddress getLocalIP() {
 		return localIP;
 	}
 
+	/**
+	 * @param localIP the localIP to set
+	 */
 	public void setLocalIP(InetAddress localIP) {
 		this.localIP = localIP;
 	}
 
+	/**
+	 * @return the localPort
+	 */
 	public int getLocalPort() {
 		return localPort;
 	}
 
+	/**
+	 * @param localPort the localPort to set
+	 */
 	public void setLocalPort(int localPort) {
 		this.localPort = localPort;
 	}
 
+	/**
+	 * @return the remoteIP
+	 */
 	public InetAddress getRemoteIP() {
 		return remoteIP;
 	}
 
+	/**
+	 * @param remoteIP the remoteIP to set
+	 */
 	public void setRemoteIP(InetAddress remoteIP) {
 		this.remoteIP = remoteIP;
 	}
 
+	/**
+	 * @return the remotePort
+	 */
 	public int getRemotePort() {
 		return remotePort;
 	}
 
+	/**
+	 * @param remotePort the remotePort to set
+	 */
 	public void setRemotePort(int remotePort) {
 		this.remotePort = remotePort;
 	}
@@ -152,10 +188,16 @@ public class Record implements Serializable {
 		SSID = sSID;
 	}
 
+	/**
+	 * @return the packet
+	 */
 	public String getPacket() {
 		return packet;
 	}
 
+	/**
+	 * @param packet the packet to set
+	 */
 	public void setPacket(String packet) {
 		this.packet = packet;
 	}
@@ -169,24 +211,22 @@ public class Record implements Serializable {
 	}
 	
 	/**
-	 * Returns a string representation after a chosen format. Formats should be defined in /res/values/export_formats.xml to use {@link de.tudarmstadt.informatik.hostage.ui.ViewLog#exportDatabase(android.view.View)}
+	 * Returns a string representation after a chosen format. Formats should be defined in /res/values/export_formats.xml to use with {@link de.tudarmstadt.informatik.hostage.ui.ViewLog#exportDatabase(android.view.View)}
 	 * The Intger representation of the format is equal to its position in the format array.
 	 * @param format Integer representation of the format.
 	 * @return A string representation after chosen format.
 	 */
 	public String toString(int format){
 		// Choose String Format
-		// Add additional case for your own Format. Also add format Name to 
 		switch (format){
 			case 1: 
-				return String.format("{ \"src\":{\"IP\": %s, \"Port\": %d} \"dst\": {\"IP\": %s, \"Port\": %d} \"type\": 0 \"name\": \"HOsTaGe\" }", localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
+				return String.format("{ \"sensor\":{\"type\": \"Honeypot\", \"name\": \"HOsTaGe\"}, \"type\": 0, \"src\":{\"ip\": \"%s\", \"port\": %d}, \"dst\":{\"ip\": \"%s\", \"port\": %d} }", localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
 					remotePort);
 			case 2: 
 				return String.format("%d: %s in %s(%s) from [%s:%d] to [%s:%d]", attack_id, protocol, SSID, BSSID, remoteIP.getHostAddress(), remotePort, localIP.getHostAddress(), localPort);
 			default:
 				return toString();
 		}
-
 	}
 	
 }

+ 4 - 2
src/de/tudarmstadt/informatik/hostage/ui/ViewLog.java

@@ -289,13 +289,15 @@ public class ViewLog extends Activity {
 	private void deleteByBSSID() {
 		AlertDialog.Builder builder = new AlertDialog.Builder(this);
 		final String[] bssidArray = logger.getAllBSSIDS();
+		final String[] strings = new String[bssidArray.length];
 		for(int i = 0; i < bssidArray.length; i++){
-			bssidArray[i] = bssidArray[i] + " (" + logger.getSSID(bssidArray[i]) +")";
+			strings[i] = bssidArray[i] + " (" + logger.getSSID(bssidArray[i]) +")";
 		}
 		builder.setTitle(R.string.delete_dialog_title);
-		builder.setItems(bssidArray, new DialogInterface.OnClickListener() {
+		builder.setItems(strings, new DialogInterface.OnClickListener() {
 			@SuppressLint("NewApi")
 			public void onClick(DialogInterface dialog, int position) {
+				
 				logger.deleteByBSSID(bssidArray[position]);
 				Toast.makeText(
 						getApplicationContext(),