Browse Source

Protocols: more dynamic
Profile function: first steps

Wulf Pfeiffer 10 years ago
parent
commit
63ff248023

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

@@ -85,8 +85,8 @@ public class HoneyService extends Service {
 			listeners.add(new HoneyListener(this, protocol));
 		}
 		registerNetReceiver();
-		getLocationData(); //FIXME hier stimmt was nicht, crashed (evtl. wegen location deaktiviert im handy?
-		setProtocolSettings();
+//		getLocationData(); //FIXME hier stimmt was nicht, crashed (evtl. wegen location deaktiviert im handy?)
+		new QotdTask().execute(new String[]{});
 	}
 	
     @Override
@@ -357,13 +357,6 @@ public class HoneyService extends Service {
 			}
 		}
 	}
-
-	/**
-	 * Sets the protocol settings like server names etc.
-	 */
-	private void setProtocolSettings() {
-		new QotdTask().execute(new String[]{});
-	}
 	
 	/**
 	 * Task for accuiring a qotd from one of four possible servers
@@ -393,10 +386,11 @@ public class HoneyService extends Service {
 			 
 		 @Override
 		 protected void onPostExecute(String result){
+			 System.out.println("hi " + result);
 			 if (result != null)
-				 ProtocolSettings.setQotd(result);
+				 ProtocolSettings.setHttpQotd(result);
 			 else
-				 ProtocolSettings.setQotd(null);	
+				 ProtocolSettings.setHttpQotd(new String(HelperUtils.getRandomString(100, false)));
 		 }
 	};
 }

+ 27 - 0
src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java

@@ -274,6 +274,7 @@ public final class HelperUtils {
 	 * Produces a random String.
 	 * The String can be of random length with a maximum length, or it can be forced to have the length that was given.
 	 * @param length maximal / forced length of String.
+	 * @param forceLength forces the String to be exact the given length instead of maximum
 	 * @return random String.
 	 */
 	public static String getRandomString(int length, boolean forceLength) {
@@ -284,4 +285,30 @@ public final class HelperUtils {
 		}
 		return new String(c);
 	}
+	
+	/**
+	 * Puts a 0x00 byte between each byte and another 2 0x00 bytes at the end of a byte array.
+	 * @param bytes that need to be filled with 0x00.
+	 * @return filled byte array.
+	 */
+	public static byte[] fillWithZeroExtended(byte[] bytes) {
+		byte[] zeroBytes = fillWithZero(bytes);
+		byte[] newBytes = new byte[zeroBytes.length+2];
+		newBytes = HelperUtils.concat(zeroBytes, new byte[]{0x00, 0x00});
+		return newBytes;
+	}
+	
+	/**
+	 * Puts a 0x00 byte between each byte in a byte array.
+	 * @param bytes that need to be filled with 0x00.
+	 * @return filled byte array.
+	 */
+	public static byte[] fillWithZero(byte[] bytes) {
+		byte[] newBytes = new byte[(bytes.length * 2)];
+		for(int i = 0, j = 0; i < bytes.length && j < newBytes.length; i++, j=j+2) {
+			newBytes[j] = bytes[i];
+			newBytes[j+1] = 0x00;
+		}
+		return newBytes;
+	}
 }

+ 137 - 24
src/de/tudarmstadt/informatik/hostage/commons/ProtocolSettings.java

@@ -1,49 +1,162 @@
 package de.tudarmstadt.informatik.hostage.commons;
 
+import java.security.SecureRandom;
+
 
 public class ProtocolSettings {
 	//TODO documentation
+	//TODO all decisions here
+	private static SecureRandom rndm = new SecureRandom();
+	private static String[][][] possibleHttpVersions = {
+		{{"Apache/2.0."},{"28","32","35","36","39","40","42","43","44","45","46","47","48","49","50","51","52","53","54","55","58","59","61","63","64","65"}},
+		{{"Apache/2.2."},{"0","2","3","4","6","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"}},
+		{{"Apache/2.3."},{"4","5","6","8","10","11","12","14","15","16"}},
+		{{"Apache/2.4."},{"1","2","3","4","6"}}
+	};
+	private static String[][][] possibleMysqlVersions = {
+		{{"5.7."},{"1","2"}},
+		{{"5.6."},{"2","3","4","5","6","7","8","9","10","11","12","13","14"}},
+		{{"5.5."},{"27","28","29","30","31","32","33","34"}}
+	};
+	private static String[][] possibleSmbVersions 	= {
+		{"Windows Server 2008 R2 Enterprise 7600","Windows Server 2008 R2 Enterprise 6.1"},
+		{"Windows 7 Professional 7600","Windows 7 Professional 6.1"},
+		{"Windows 8 Enterprise 9200", "Windows 8 Enterprise 9200"},
+		{"Windows Server 2012 Standard 6.2", "Windows Server 2012 Standard 6.2"},
+		{"Unix", "Samba"}
+	};
 	//HTTP
-	private static String qotd;
-	private static boolean useQotd;
+	private static String httpQotd		; //is initialized by honeyservice
+	private static String httpVersion	= initHttpVersion();
+	private static boolean useHttpQotd	= true; //TODO
+	//MySQL
+	private static String mysqlVersion	= initMysqlVersion();
 	//SMB
-	private static String smbServerName = null;
-	private static String[] smbServerVersion = null;
+	private static byte[] smbName		= initSmbName();
+	private static String[] smbVersion	= initSmbVersion();
+	//TELNET
+	private static String telnetName	= initTelnetName();
+	private static String telnetVersion	= initTelnetVersion();
+	//SSH
+	private static String sshVersion	= initSshVersion();
+	private static String sshType		= initSshType();
+	
+	private static String initHttpVersion() {
+		int majorVersion = rndm.nextInt(3);
+		return possibleHttpVersions[majorVersion][0][0] + possibleHttpVersions[majorVersion][1][rndm.nextInt(possibleHttpVersions[majorVersion][1].length)];
+	}
 	
-	public static String getQotd() {
-		return qotd;
+	private static String initMysqlVersion() {
+		int majorVersion = rndm.nextInt(3);
+		return possibleMysqlVersions[majorVersion][0][0] + possibleMysqlVersions[majorVersion][1][rndm.nextInt(possibleMysqlVersions[majorVersion][1].length)];
 	}
 	
-	public static void setQotd(String qotd) {
-		ProtocolSettings.qotd = qotd;
-		if(qotd == null) { //if no qotd was received, use random qotd
-			ProtocolSettings.qotd = new String(HelperUtils.getRandomString(100, false));
-		}
+	private static byte[] initSmbName() {
+		return HelperUtils.fillWithZero(HelperUtils.getRandomString(16, true).getBytes());
 	}
 	
-	public static boolean getUseQotd() {
-		return useQotd;
+	private static String[] initSmbVersion() {
+		return possibleSmbVersions[rndm.nextInt(possibleSmbVersions.length)];
 	}
 	
-	public static void setUseQotd(boolean useQotd) {
-		ProtocolSettings.useQotd = useQotd;
+	private static String initTelnetName() {
+		return HelperUtils.getRandomString(16, false);
 	}
 	
-	public static String getSmbServerName() {
-		return smbServerName;
+	private static String initTelnetVersion() {
+		//TODO
+		return "ToBeDone";
 	}
 	
-	public static void setSmbServerName(String smbServerName) {
-		ProtocolSettings.smbServerName = smbServerName;
+	private static String initSshVersion() {
+		return "SSH-2.0-";
+	}
+	
+	private static String initSshType() {
+		//TODO
+		return "OpenSSH_6.0p1";
 	}
 
-	public static String[] getSmbServerVersion() {
-		return smbServerVersion;
+	//~~~ Getters and Setters ~~//
+	
+	public static String getHttpQotd() {
+		return httpQotd;
 	}
 
-	public static void setSmbServerVersion(String[] smbServerVersion) {
-		ProtocolSettings.smbServerVersion = smbServerVersion;
+	public static void setHttpQotd(String httpQotd) {
+ 		ProtocolSettings.httpQotd = httpQotd;
+	}
+
+	public static String getHttpVersion() {
+		return httpVersion;
+	}
+
+	public static void setHttpVersion(String httpVersion) {
+		ProtocolSettings.httpVersion = httpVersion;
+	}
+
+	public static boolean isUseHttpQotd() {
+		return useHttpQotd;
+	}
+
+	public static void setUseHttpQotd(boolean useHttpQotd) {
+		ProtocolSettings.useHttpQotd = useHttpQotd;
+	}
+
+	public static String getMysqlVersion() {
+		return mysqlVersion;
+	}
+
+	public static void setMysqlVersion(String mysqlVersion) {
+		ProtocolSettings.mysqlVersion = mysqlVersion;
+	}
+
+	public static byte[] getSmbName() {
+		return smbName;
+	}
+
+	public static void setSmbName(byte[] smbName) {
+		ProtocolSettings.smbName = smbName;
+	}
+
+	public static String[] getSmbVersion() {
+		return smbVersion;
+	}
+
+	public static void setSmbVersion(String[] smbVersion) {
+		ProtocolSettings.smbVersion = smbVersion;
+	}
+
+	public static String getTelnetName() {
+		return telnetName;
+	}
+
+	public static void setTelnetName(String telnetName) {
+		ProtocolSettings.telnetName = telnetName;
+	}
+
+	public static String getTelnetVersion() {
+		return telnetVersion;
+	}
+
+	public static void setTelnetVersion(String telnetVersion) {
+		ProtocolSettings.telnetVersion = telnetVersion;
+	}
+
+	public static String getSshVersion() {
+		return sshVersion;
+	}
+
+	public static void setSshVersion(String sshVersion) {
+		ProtocolSettings.sshVersion = sshVersion;
+	}
+
+	public static String getSshType() {
+		return sshType;
+	}
+
+	public static void setSshType(String sshType) {
+		ProtocolSettings.sshType = sshType;
 	}
-	
 	
 }

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

@@ -1,6 +1,5 @@
 package de.tudarmstadt.informatik.hostage.protocol;
 
-import java.security.SecureRandom;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -102,17 +101,8 @@ public class HTTP implements Protocol<String> {
 	    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
 	    return dateFormat.format(calendar.getTime());
 	}
-	
-	private static String[][][] possibleVersions = {
-			{{"Apache/2.0."},{"28","32","35","36","39","40","42","43","44","45","46","47","48","49","50","51","52","53","54","55","58","59","61","63","64","65"}},
-			{{"Apache/2.2."},{"0","2","3","4","6","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"}},
-			{{"Apache/2.3."},{"4","5","6","8","10","11","12","14","15","16"}},
-			{{"Apache/2.4."},{"1","2","3","4","6"}}
-	};
-	private static SecureRandom rndm = new SecureRandom();
-	private static int majorVersion = rndm.nextInt(3);
-	private static final String serverVersion = possibleVersions[majorVersion][0][0] + possibleVersions[majorVersion][1][rndm.nextInt(possibleVersions[majorVersion][1].length)];
-	private static final String qotd = ProtocolSettings.getQotd();
+
+	private static final String serverVersion = ProtocolSettings.getHttpVersion();
 	//html header pre and suffix
 	private static final String headerPrefix =				
 			"Date: " + getServerTime() + "\r\n" +
@@ -131,8 +121,8 @@ public class HTTP implements Protocol<String> {
 			"<html lang=\"en\">\n" +
 			"<head>\n" +
 			"<meta charset=\"UTF-8\">\n" +
-			"<title>" + qotd + "</title>\n" +
-			"<body>" + qotd + "</body>\n" +
+			"<title>" + ProtocolSettings.getHttpQotd() + "</title>\n" +
+			"<body>" + ProtocolSettings.getHttpQotd() + "</body>\n" +
 			"</head>\n" +
 			"</html>";
 	//html error pre and suffix

+ 2 - 10
src/de/tudarmstadt/informatik/hostage/protocol/MySQL.java

@@ -1,10 +1,10 @@
 package de.tudarmstadt.informatik.hostage.protocol;
 
 import java.nio.ByteBuffer;
-import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.List;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.commons.ProtocolSettings;
 import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
 
 /**
@@ -150,13 +150,5 @@ public class MySQL implements Protocol<ByteArray>{
 		byte[] response = HelperUtils.concat(fill1, code, fill2, state.getBytes(), msg.getBytes());		
 		return wrapPacket(response);
 	}
-	
-	private static String[][][] possibleVersions = {
-		{{"5.7."},{"1","2"}},
-		{{"5.6."},{"2","3","4","5","6","7","8","9","10","11","12","13","14"}},
-		{{"5.5."},{"27","28","29","30","31","32","33","34"}}
-	};
-	private static SecureRandom rndm = new SecureRandom();
-	private static int majorVersion = rndm.nextInt(2);
-	private static final String serverVersion = possibleVersions[majorVersion][0][0] + possibleVersions[majorVersion][1][rndm.nextInt(possibleVersions[majorVersion][1].length)];
+	private static final String serverVersion = ProtocolSettings.getMysqlVersion();
 }

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

@@ -204,15 +204,8 @@ public class SMB implements Protocol<ByteArray> {
 	 * Denotes a SMB packet
 	 */
 	private static class SMBPacket {
-		private static SecureRandom rndm 					= new SecureRandom();
-		private static String[][] possibleVersions 	= { {"Windows Server 2008 R2 Enterprise 7600","Windows Server 2008 R2 Enterprise 6.1"},
-														{"Windows 7 Professional 7600","Windows 7 Professional 6.1"},
-														{"Windows 8 Enterprise 9200", "Windows 8 Enterprise 9200"},
-														{"Windows Server 2012 Standard 6.2", "Windows Server 2012 Standard 6.2"},
-														{"Unix", "Samba"}
-		};
-		private static byte[] serverName 		= fillWithZero(HelperUtils.getRandomString(16, true).getBytes());
-		private static String[] serverVersion	= possibleVersions[rndm.nextInt(possibleVersions.length)];
+		private static byte[] serverName 			= ProtocolSettings.getSmbName();
+		private static String[] serverVersion		= ProtocolSettings.getSmbVersion();
 		private byte[] message						= null; 
 		private static final byte[] serverGUID		= randomBytes(16);
 		private boolean authenticateNext			= false;
@@ -232,14 +225,7 @@ public class SMB implements Protocol<ByteArray> {
 				
 		/** Constructor */
 		private SMBPacket() {
-			String customServerName			= ProtocolSettings.getSmbServerName();
-			String[] customServerVersion	= ProtocolSettings.getSmbServerVersion();
-			if(customServerName != null) {
-				serverName = fillWithZero(customServerName.getBytes());
-			}
-			if(customServerVersion != null) {
-				serverVersion = customServerVersion;
-			}
+			
 		}
 		
 		/**
@@ -408,8 +394,8 @@ public class SMB implements Protocol<ByteArray> {
 												version, serverName, attributeNBDomain, serverName, attributeNBcomputer, serverName,
 												attributeDNSDomain, serverName, attributeDNScomputer, serverName, attributeTimeStamp,
 												timeStamp, attributeEnd);
-			byte[] nativOS				= fillWithZeroExtended(serverVersion[0].getBytes());
-			byte[] nativLanMngr			= fillWithZeroExtended(serverVersion[1].getBytes());
+			byte[] nativOS				= HelperUtils.fillWithZeroExtended(serverVersion[0].getBytes());
+			byte[] nativLanMngr			= HelperUtils.fillWithZeroExtended(serverVersion[1].getBytes());
 
 			buffer				= ByteBuffer.allocate(4).putInt(secBlob.length).array();
 			secBlobLength				= new byte[]{buffer[3], buffer[2]};
@@ -437,8 +423,8 @@ public class SMB implements Protocol<ByteArray> {
 			byte[] secBlobLength;
 			byte[] byteCount;
 			byte[] secBlob			= {(byte) 0xa1, 0x07, 0x30, 0x05, (byte) 0xa0, 0x03, 0x0a, 0x01, 0x00};
-			byte[] nativOS			= fillWithZeroExtended(serverVersion[0].getBytes());
-			byte[] nativLanMngr		= fillWithZeroExtended(serverVersion[1].getBytes());
+			byte[] nativOS			= HelperUtils.fillWithZeroExtended(serverVersion[0].getBytes());
+			byte[] nativLanMngr		= HelperUtils.fillWithZeroExtended(serverVersion[1].getBytes());
 			
 			byte[] buffer				= ByteBuffer.allocate(4).putInt(secBlob.length).array();
 			secBlobLength				= new byte[]{buffer[3], buffer[2]};
@@ -729,31 +715,5 @@ public class SMB implements Protocol<ByteArray> {
 		private byte getSmbCommand() {
 			return smbCommand[0];
 		}
-		
-		/**
-		 * Puts a 0x00 byte between each byte and another 2 0x00 bytes at the end of a byte array.
-		 * @param bytes that need to be filled with 0x00.
-		 * @return filled byte array.
-		 */
-		private static byte[] fillWithZeroExtended(byte[] bytes) {
-			byte[] zeroBytes = fillWithZero(bytes);
-			byte[] newBytes = new byte[zeroBytes.length+2];
-			newBytes = HelperUtils.concat(zeroBytes, new byte[]{0x00, 0x00});
-			return newBytes;
-		}
-		
-		/**
-		 * Puts a 0x00 byte between each byte in a byte array.
-		 * @param bytes that need to be filled with 0x00.
-		 * @return filled byte array.
-		 */
-		private static byte[] fillWithZero(byte[] bytes) {
-			byte[] newBytes = new byte[(bytes.length * 2)];
-			for(int i = 0, j = 0; i < bytes.length && j < newBytes.length; i++, j=j+2) {
-				newBytes[j] = bytes[i];
-				newBytes[j+1] = 0x00;
-			}
-			return newBytes;
-		}
 	}
 }

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

@@ -18,6 +18,7 @@ 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.commons.ProtocolSettings;
 import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
 
 /**
@@ -41,59 +42,6 @@ public class SSH implements Protocol<ByteArray> {
 	 */
 	private STATE connectionState = STATE.NONE;
 	
-	//TODO
-	private String serverVersion = "SSH-2.0-";
-	private String serverType = "OpenSSH_6.0p1";
-		
-	//Diffie-Hellman-Group-1 p and g
-	private final byte[] p = {
-            (byte)0x00,
-            (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
-            (byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
-            (byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
-            (byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
-            (byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
-            (byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
-            (byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
-            (byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
-            (byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
-            (byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
-            (byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
-            (byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
-            (byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
-            (byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
-            (byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE6,(byte)0x53,(byte)0x81,
-            (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
-      };
-	private final byte[] g = {0x02};
-	
-	//SSH Parameters for Kex etc.
-    private byte[] V_S = serverType.getBytes();
-    private byte[] V_C;
-    private byte[] I_S;
-    private byte[] I_C;
-    private byte[] e;
-    private byte[] f;
-    private byte[] k;
-    private byte[] h;
-    private byte[] K_S;
-    private byte[] sig;
-
-    //Keys for signature
-    private KeyPair dsa;
-			
-    //allowed algorithms for kexinit
-	private String kex_alg = "diffie-hellman-group1-sha1";
-	private String server_alg = "ssh-dss";
-	private String encrypt_alg_c = "aes128-ctr";
-	private String encrypt_alg_s = "aes128-ctr";
-	private String mac_alg_c = "hmac-sha1";
-	private String mac_alg_s = "hmac-sha1";
-	private String comp_alg_c = "none";
-	private String comp_alg_s = "none";
-	
-	private int cipherBlockSize = 16;
-	
 	/** Denotes in which state the protocol is right now */
 	private STATE state = STATE.NONE;
 	
@@ -436,5 +384,57 @@ public class SSH implements Protocol<ByteArray> {
                          (s.length > 20) ? 20 : s.length);
         return result;
     }
+	
+	private String serverVersion = ProtocolSettings.getSshVersion();
+	private String serverType = ProtocolSettings.getSshType();
+		
+	//Diffie-Hellman-Group-1 p and g
+	private final byte[] p = {
+            (byte)0x00,
+            (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
+            (byte)0xC9,(byte)0x0F,(byte)0xDA,(byte)0xA2,(byte)0x21,(byte)0x68,(byte)0xC2,(byte)0x34,
+            (byte)0xC4,(byte)0xC6,(byte)0x62,(byte)0x8B,(byte)0x80,(byte)0xDC,(byte)0x1C,(byte)0xD1,
+            (byte)0x29,(byte)0x02,(byte)0x4E,(byte)0x08,(byte)0x8A,(byte)0x67,(byte)0xCC,(byte)0x74,
+            (byte)0x02,(byte)0x0B,(byte)0xBE,(byte)0xA6,(byte)0x3B,(byte)0x13,(byte)0x9B,(byte)0x22,
+            (byte)0x51,(byte)0x4A,(byte)0x08,(byte)0x79,(byte)0x8E,(byte)0x34,(byte)0x04,(byte)0xDD,
+            (byte)0xEF,(byte)0x95,(byte)0x19,(byte)0xB3,(byte)0xCD,(byte)0x3A,(byte)0x43,(byte)0x1B,
+            (byte)0x30,(byte)0x2B,(byte)0x0A,(byte)0x6D,(byte)0xF2,(byte)0x5F,(byte)0x14,(byte)0x37,
+            (byte)0x4F,(byte)0xE1,(byte)0x35,(byte)0x6D,(byte)0x6D,(byte)0x51,(byte)0xC2,(byte)0x45,
+            (byte)0xE4,(byte)0x85,(byte)0xB5,(byte)0x76,(byte)0x62,(byte)0x5E,(byte)0x7E,(byte)0xC6,
+            (byte)0xF4,(byte)0x4C,(byte)0x42,(byte)0xE9,(byte)0xA6,(byte)0x37,(byte)0xED,(byte)0x6B,
+            (byte)0x0B,(byte)0xFF,(byte)0x5C,(byte)0xB6,(byte)0xF4,(byte)0x06,(byte)0xB7,(byte)0xED,
+            (byte)0xEE,(byte)0x38,(byte)0x6B,(byte)0xFB,(byte)0x5A,(byte)0x89,(byte)0x9F,(byte)0xA5,
+            (byte)0xAE,(byte)0x9F,(byte)0x24,(byte)0x11,(byte)0x7C,(byte)0x4B,(byte)0x1F,(byte)0xE6,
+            (byte)0x49,(byte)0x28,(byte)0x66,(byte)0x51,(byte)0xEC,(byte)0xE6,(byte)0x53,(byte)0x81,
+            (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
+      };
+	private final byte[] g = {0x02};
+	
+	//SSH Parameters for Kex etc.
+    private byte[] V_S = serverType.getBytes();
+    private byte[] V_C;
+    private byte[] I_S;
+    private byte[] I_C;
+    private byte[] e;
+    private byte[] f;
+    private byte[] k;
+    private byte[] h;
+    private byte[] K_S;
+    private byte[] sig;
+
+    //Keys for signature
+    private KeyPair dsa;
+			
+    //allowed algorithms for kexinit
+	private String kex_alg = "diffie-hellman-group1-sha1";
+	private String server_alg = "ssh-dss";
+	private String encrypt_alg_c = "aes128-ctr";
+	private String encrypt_alg_s = "aes128-ctr";
+	private String mac_alg_c = "hmac-sha1";
+	private String mac_alg_s = "hmac-sha1";
+	private String comp_alg_c = "none";
+	private String comp_alg_s = "none";
+	
+	private int cipherBlockSize = 16;
 
 }

+ 24 - 25
src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java

@@ -4,6 +4,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.commons.ProtocolSettings;
 import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
 
 /**
@@ -23,18 +24,6 @@ public class TELNET implements Protocol<ByteArray> {
 	 */
 	private STATE state = STATE.NONE;
 	
-	private byte[] lastMessage;
-
-	/** user entered by the client */
-	private byte[] user;
-	/** last command sent by the client */
-	private byte[] command;
-	/** name of the server */
-	private String server = "raspberrypi"; //TODO
-	/** command line prefix */
-	private byte[] sessionToken = null;
-
-	
 	public int getPort() {
 		return 23;
 	}
@@ -48,9 +37,8 @@ public class TELNET implements Protocol<ByteArray> {
 	public List<ByteArray> processMessage(ByteArray message) {
 		byte[] request = null;
 		if(message != null) {
-			lastMessage = message.get();
+			message.get();
 			request = message.get();
-			System.out.println(HelperUtils.byteToStr(lastMessage));
 		}
 		List<ByteArray> response = new ArrayList<ByteArray>();
 		
@@ -62,8 +50,8 @@ public class TELNET implements Protocol<ByteArray> {
 		case OPEN:
 			if(request != null) {
 				response.add(new ByteArray(getOptionResponse(request)));
-				response.add(new ByteArray("Debian GNU/Linux 7.0\r\n")); //TODO
-				response.add(new ByteArray(server + " login: "));
+				response.add(new ByteArray(serverVersion));
+				response.add(new ByteArray(serverName + " login: "));
 				state = STATE.LOGIN;
 			}
 			break;
@@ -79,7 +67,7 @@ public class TELNET implements Protocol<ByteArray> {
 				response.add(new ByteArray("\r\n"));
 				response.add(new ByteArray("Password: "));
 				state = STATE.AUTHENTICATE;
-				sessionToken = HelperUtils.concat(sessionPrefix, user, "@".getBytes(), server.getBytes(), sessionMiddle, user, "@".getBytes(), server.getBytes(), sessionSuffix);
+				sessionToken = HelperUtils.concat(sessionPrefix, user, "@".getBytes(), serverName.getBytes(), sessionMiddle, user, "@".getBytes(), serverName.getBytes(), sessionSuffix);
 				break;
 			} else if (checkForByte(request, (byte) 0x7f) && user != null && user.length != 0) {
 				byte[] tmp = new byte[user.length - 1];
@@ -98,7 +86,7 @@ public class TELNET implements Protocol<ByteArray> {
 		case AUTHENTICATE:
 			if(request == null) break;
 			else if(checkForByte(request, (byte) 0x0d)) {
-				response.add(new ByteArray("\r\nLinux" + server + " 3.6.11+\r\n")); //TODO
+				response.add(new ByteArray("\r\n" + serverVersion + "\r\n"));
 				response.add(new ByteArray(sessionToken));
 				state = STATE.LOGGED_IN;
 			} else if (checkForByte(request, (byte) 0x7f)) {
@@ -193,7 +181,7 @@ public class TELNET implements Protocol<ByteArray> {
 			if(request[i] == (byte) 0xff && request[i+2] != 0x03 && request[i+2] != 0x01) {
 				cmdResp = new byte[3];
 				cmdResp[0] = request[i];
-				cmdResp[1] = request[i + 1] == (byte) 0xfd ? (byte) 0xfc : (byte) 0xfe; 
+				cmdResp[1] = request[i+1] == (byte) 0xfd ? (byte) 0xfc : (byte) 0xfe; 
 				cmdResp[2] = request[i+2];
 				respList.add(cmdResp);
 			}			
@@ -205,15 +193,26 @@ public class TELNET implements Protocol<ByteArray> {
 		return response;
 	}
 
+
+	/** user entered by the client */
+	private static byte[] user;
+	/** last command sent by the client */
+	private byte[] command;
+	/** name of the server */
+	private static String serverName = ProtocolSettings.getTelnetName();
+	private static String serverVersion = ProtocolSettings.getTelnetVersion();
+	/** command line prefix */
+	private static byte[] sessionToken = null;
+	
 	/** options requested by the server */
-	private static final byte[] optionRequest = {(byte) 0xff, (byte) 0xfb, 0x03,	//will suppress go ahead
-										(byte) 0xff, (byte) 0xfb, 0x01};	//will echo
-	//session token prefix, mid and suffix //TODO
+	private static final byte[] optionRequest = {
+			(byte) 0xff, (byte) 0xfb, 0x03,	//will suppress go ahead
+			(byte) 0xff, (byte) 0xfb, 0x01 	//will echo
+	};
+	//session token prefix, mid and suffix
 	private static final byte[] sessionPrefix = {0x1b, 0x5d, 0x30, 0x3b};
-	private static final byte[] sessionMiddle = {0x40, 0x72, 0x61, 0x73, 
-			0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x70, 0x69, 0x3a, 0x20, 0x7e, 0x07, 0x1b, 0x5b, 0x30, 0x31, 
+	private static final byte[] sessionMiddle = {0x3a, 0x20, 0x7e, 0x07, 0x1b, 0x5b, 0x30, 0x31, 
 			0x3b, 0x33, 0x32, 0x6d};	
 	private static final byte[] sessionSuffix = {0x1b, 0x5b, 0x30, 0x30, 0x6d, 0x20, 0x1b, 0x5b, 0x30, 0x31, 
 			0x3b, 0x33, 0x34, 0x6d, 0x7e, 0x20, 0x24, 0x1b, 0x5b, 0x30, 0x30, 0x6d, 0x20};
-
 }