Browse Source

Fixed some problems with export log

qam 10 years ago
parent
commit
cd1be37113

+ 2 - 2
res/values/strings.xml

@@ -4,8 +4,8 @@
     <string name="app_name">HosTaGe</string>
     <string name="action_settings">Settings</string>
     <string name="action_about">About</string>
-    <string name="capital_on">ON</string>
-    <string name="capital_off">OFF</string>
+    <string name="capital_on">OFF</string>
+    <string name="capital_off">ON</string>
     <string name="status">Status</string>
     <string name="paranoid">Paranoid Mode</string>
     <string name="details">Connection info</string>

+ 1 - 0
src/de/tudarmstadt/informatik/hostage/format/MySQLFormatter.java

@@ -23,6 +23,7 @@ public class MySQLFormatter implements ProtocolFormatter {
 	 */
 	private String getCommand(byte[] bytes) {
 		//if packet number is 1 server started conversation so it must be login
+		if(bytes.length < 5) return "";
 		if(bytes[3] == 0x01) return "Login request"; 
 		//else check for command code
 		switch(bytes[4]) {

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

@@ -47,7 +47,7 @@ public class ByteArrayHandler extends AbstractHandler {
 			outputLine = protocol.processMessage(null);
 			stream.write(outputLine);
 			for (ByteArray s : outputLine) {
-				log.write(createRecord(TYPE.SEND, s.toString()));
+				log.write(createRecord(TYPE.SEND, HelperUtils.bytesToHexString(s.get())));
 			}
 		}
 

+ 6 - 4
src/de/tudarmstadt/informatik/hostage/logging/Record.java

@@ -3,6 +3,8 @@ package de.tudarmstadt.informatik.hostage.logging;
 import java.io.Serializable;
 import java.net.InetAddress;
 
+import de.tudarmstadt.informatik.hostage.format.LogViewFormatter;
+
 /**
  * This class defines the attributes of a record.<br>
  * A Record is a single message exchanged between the application and an attacker.<br>
@@ -223,7 +225,7 @@ public class Record implements Serializable {
 		return String.format("%d %s [%d,%s:%d,%s:%d,%s]", attack_id,
 				((type == TYPE.SEND) ? "SEND" : "RECEIVE"), timestamp,
 				localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
-				remotePort, packet);
+				remotePort, LogViewFormatter.format(getProtocol(), getPacket()));
 	}
 	
 	/**
@@ -235,12 +237,12 @@ public class Record implements Serializable {
 	public String toString(int format){
 		// Choose String Format
 		switch (format){
+			// ViewLogTable format: contains all important information about an attack.
+			case 0: 
+				return String.format("%d: %s %s\nIn %s\n(%s)\nFrom [%s:%d]\nTo [%s:%d]\n%s\n\n", attack_id, protocol, ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), SSID, BSSID, remoteIP.getHostAddress(), remotePort, localIP.getHostAddress(), localPort, LogViewFormatter.format(getProtocol(), getPacket()));	
 			// TraCINg Upload format, replaces internal ip's with external ip of network
 			case 1: 
 				return String.format("{ \"sensor\":{\"type\": \"Honeypot\", \"name\": \"HOsTaGe\"}, \"type\": \"%s\", \"src\":{\"ip\": \"%s\", \"port\": %d}, \"dst\":{\"ip\": \"%s\", \"port\": %d} }", protocol + " server access", externalIP, remotePort, externalIP, localPort);
-			// ViewLogTable format: contains all important information about an attack.
-			case 2: 
-				return String.format("%d: %s\nIn %s\n(%s)\nFrom [%s:%d]\nTo [%s:%d]\n", attack_id, protocol, SSID, BSSID, remoteIP.getHostAddress(), remotePort, localIP.getHostAddress(), localPort);
 			default:
 				return toString();
 		}

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

@@ -138,7 +138,7 @@ public class ViewLog extends Activity {
 			
 			ArrayList<Record> records = logger.getAllRecords();
 			for(Record record : records){
-					log.write((record.toString(format) + "\n").getBytes());
+					log.write((record.toString(format)).getBytes());
 			}
 			log.flush();
 			log.close();

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

@@ -22,10 +22,7 @@ public class ViewLogTable extends Activity{
 		StringBuffer log = new StringBuffer();
 		//Create a log entry for every attack in the Database
 		for(Record record: dbh.getAllReceivedRecordsOfEachAttack()) {
-			log.append(record.toString(2));
-			log.append(LogViewFormatter.format(record.getProtocol(), record.getPacket()));
-			log.append("\n");
-			log.append("\n");
+			log.append(record.toString(0));
 		}
 		
 		ScrollView scroll = new ScrollView(this);