Browse Source

Improved logging for TELNET and MySQL

qam 10 years ago
parent
commit
021e70771b

+ 1 - 0
.classpath

@@ -4,5 +4,6 @@
 	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+	<classpathentry kind="src" path="gen"/>
 	<classpathentry kind="output" path="bin/classes"/>
 </classpath>

+ 45 - 1
src/de/tudarmstadt/informatik/hostage/render/MySQLRenderer.java

@@ -1,10 +1,54 @@
 package de.tudarmstadt.informatik.hostage.render;
 
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+
 public class MySQLRenderer implements ProtocolRenderer {
 
 	@Override
 	public String render(String packet) {
-		return "";
+		byte[] bytes = HelperUtils.hexStringToByte(packet);
+		String command = getCommand(bytes) + "\n";
+		String content = HelperUtils.byteToStr(bytes) + "\n";
+		return command + content;
+	}
+	
+	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
+		
+		switch(bytes[4]) {
+		case 0x00: return "COM_SLEEP";
+		case 0x01: return "COM_QUIT";
+		case 0x02: return "COM_INIT_DB";
+		case 0x03: return "COM_QUERY";
+		case 0x04: return "COM_FIELD_LIST";
+		case 0x05: return "COM_CREATE_DB";
+		case 0x06: return "COM_DROP_DB";
+		case 0x07: return "COM_REFRESH";
+		case 0x08: return "COM_SHUTDOWN";
+		case 0x09: return "COM_STATISTICS";
+		case 0x0a: return "COM_PROCESS_INFO";
+		case 0x0b: return "COM_CONNECT";
+		case 0x0c: return "COM_PROCESS_KILL";
+		case 0x0d: return "COM_DEBUG";
+		case 0x0e: return "COM_PING";
+		case 0x0f: return "COM_TIME";
+		case 0x10: return "COM_DELAYED_INSERT";
+		case 0x11: return "COM_CHANGE_USER";
+		case 0x12: return "COM_BINLOG_DUMP";
+		case 0x13: return "COM_TABLE_DUMP";
+		case 0x14: return "COM_CONNECT_OUT";
+		case 0x15: return "COM_REGISTER_SLAVE";
+		case 0x16: return "COM_STMT_PREPARE";
+		case 0x17: return "COM_STMT_EXECUTE";
+		case 0x18: return "COM_STMT_SEND_LONG_DATA";
+		case 0x19: return "COM_STMT_CLOSE";
+		case 0x1a: return "COM_STMT_RESET";
+		case 0x1b: return "COM_SET_OPTION";
+		case 0x1c: return "COM_STMT_FETCH";
+		case 0x1d: return "COM_DAEMON";
+		case 0x1e: return "COM_BINLOG_DUMP_GTID";
+		default: return "unkown command";
+		}
 	}
 
 }

+ 147 - 1
src/de/tudarmstadt/informatik/hostage/render/TELNETRenderer.java

@@ -6,7 +6,153 @@ public class TELNETRenderer implements ProtocolRenderer {
 
 	@Override
 	public String render(String packet) {
-		return HelperUtils.byteToStr(HelperUtils.hexStringToByte(packet));
+		byte[] bytes = HelperUtils.hexStringToByte(packet);
+		String options = "Options:\n" + checkForOptions(bytes) + "\n";
+		String content = "Content: " + HelperUtils.byteToStr(bytes);
+		return options + content;
+	}
+	
+	private String checkForOptions(byte[] bytes) {
+		StringBuffer options = new StringBuffer();
+		for(int i = 0; i < bytes.length; i++) {
+			if(bytes[i] == (byte) 0xff && i+2 < bytes.length) {
+				switch(bytes[i+1]) {
+				case (byte) 0xfb: 
+					options.append(" WILL ");
+					break;
+				case (byte) 0xfc:
+					options.append(" WON'T "); 
+					break;
+				case (byte) 0xfd: 
+					options.append(" DO ");
+					break;
+				case (byte) 0xfe: 
+					options.append(" DON'T ");
+					break;
+				default: 
+					options.append(" unkown command ");
+					break;
+				}
+				
+				switch(bytes[i+2]) {
+				case 0x00: 
+					options.append("Binary Transmission\n");
+					break;
+				case 0x01: 
+					options.append("Echo\n");
+					break;
+				case 0x02: 
+					options.append("Reconnection\n");
+					break;
+				case 0x03: 
+					options.append("Suppress Go Ahead\n");
+					break;
+				case 0x04: 
+					options.append("Approx Message Size Negotiation\n");
+					break;
+				case 0x05: 
+					options.append("Status\n");
+					break;
+				case 0x06: 
+					options.append("Timing Mark\n");
+					break;
+				case 0x07:
+					options.append("Remote Controlled Trans and Echo\n");
+					break;
+				case 0x08:
+					options.append("Output Line Width\n");
+					break;
+				case 0x09:
+					options.append("Output Page Size\n");
+					break;
+				case 0x0a:
+					options.append("Output Carriage-Return Disposition\n");
+					break;
+				case 0x0b:
+					options.append("Output Horizontal Tab Stops\n");
+					break;
+				case 0x0c:
+					options.append("Output Horizontal Tab Disposition\n");
+					break;
+				case 0x0d:
+					options.append("Output Formfeed Disposition\n");
+					break;
+				case 0x0e:
+					options.append("Output Vertical Tabstops\n");
+					break;
+				case 0x0f:
+					options.append("Output Vertical Tab Disposition\n");
+					break;
+				case 0x10:
+					options.append("Output Linefeed Disposition\n");
+					break;
+				case 0x11:
+					options.append("Extended ASCII\n");
+					break;
+				case 0x12:
+					options.append("Logout\n");
+					break;
+				case 0x13:
+					options.append("Byte Macro\n");
+					break;
+				case 0x14:
+					options.append("Data Entry Terminal\n");
+					break;
+				case 0x15:
+					options.append("SUPDUP\n");
+					break;
+				case 0x16:
+					options.append("SUPDUP Output\n");
+					break;
+				case 0x17:
+					options.append("Send Location\n");
+					break;
+				case 0x18:
+					options.append("Terminal Type\n");
+					break;
+				case 0x19:
+					options.append("End of Record\n");
+					break;
+				case 0x1a:
+					options.append("TACACS User Identification\n");
+					break;
+				case 0x1b:
+					options.append("Output Marking\n");
+					break;
+				case 0x1c:
+					options.append("Terminal Location Number\n");
+					break;
+				case 0x1d:
+					options.append("Telnet 3270 Regime\n");
+					break;
+				case 0x1e:
+					options.append("X.3 PAD\n");
+					break;
+				case 0x1f:
+					options.append("Negotiate About Window Size\n");
+					break;
+				case 0x20:
+					options.append("Terminal Speed\n");
+					break;
+				case 0x21:
+					options.append("Remote Flow Control\n");
+					break;
+				case 0x22: 
+					options.append("Linemode\n");
+					break;
+				case 0x23:
+					options.append("X Display Location\n");
+					break;
+				case (byte) 0xff: 
+					options.append("Extended-Options-List\n");
+					break;
+				default: 
+					options.append("unknown option\n");
+					break;
+				}
+			}
+		}
+		return options.toString();
 	}
 
 }