Browse Source

Protocols: extended settings

Wulf Pfeiffer 10 years ago
parent
commit
0ad598054f

+ 19 - 22
src/de/tudarmstadt/informatik/hostage/commons/ProtocolSettings.java

@@ -2,10 +2,13 @@ package de.tudarmstadt.informatik.hostage.commons;
 
 import java.security.SecureRandom;
 
-
+/**
+ * This class holds informations for all protocols, e.g. server name, version etc.
+ * It provides getters and setters.
+ * @author Wulf Pfeiffer
+ */
 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"}},
@@ -18,17 +21,23 @@ public class ProtocolSettings {
 		{{"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 	= {
+	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"}
 	};
+	private static String[][][] possibleSshVersions = {
+		{{"3."},{"4","5","6","7","8","9"}},
+		{{"4."},{"0","1","2","3","4","5","6","7","9"}},
+		{{"5."},{"0","1","2","3","4","5","6","7","8","9"}},
+		{{"6."},{"0","1","2","3","4"}}
+	};
 	//HTTP
 	private static String httpQotd		; //is initialized by honeyservice
 	private static String httpVersion	= initHttpVersion();
-	private static boolean useHttpQotd	= true; //TODO
+	private static boolean useHttpQotd	= true; 
 	//MySQL
 	private static String mysqlVersion	= initMysqlVersion();
 	//SMB
@@ -36,18 +45,19 @@ public class ProtocolSettings {
 	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();
 	
+	//~~~ Initialize methods ~~~//
+	
 	private static String initHttpVersion() {
-		int majorVersion = rndm.nextInt(3);
+		int majorVersion = rndm.nextInt(possibleHttpVersions.length);
 		return possibleHttpVersions[majorVersion][0][0] + possibleHttpVersions[majorVersion][1][rndm.nextInt(possibleHttpVersions[majorVersion][1].length)];
 	}
 	
 	private static String initMysqlVersion() {
-		int majorVersion = rndm.nextInt(3);
+		int majorVersion = rndm.nextInt(possibleMysqlVersions.length);
 		return possibleMysqlVersions[majorVersion][0][0] + possibleMysqlVersions[majorVersion][1][rndm.nextInt(possibleMysqlVersions[majorVersion][1].length)];
 	}
 	
@@ -63,18 +73,13 @@ public class ProtocolSettings {
 		return HelperUtils.getRandomString(16, false);
 	}
 	
-	private static String initTelnetVersion() {
-		//TODO
-		return "ToBeDone";
-	}
-	
 	private static String initSshVersion() {
 		return "SSH-2.0-";
 	}
 	
 	private static String initSshType() {
-		//TODO
-		return "OpenSSH_6.0p1";
+		int majorVersion = rndm.nextInt(possibleSshVersions.length);
+		return "OpenSSH_" + possibleSshVersions[majorVersion][0][0] + possibleSshVersions[majorVersion][1][rndm.nextInt(possibleSshVersions[majorVersion][1].length)];
 	}
 
 	//~~~ Getters and Setters ~~//
@@ -135,14 +140,6 @@ public class ProtocolSettings {
 		ProtocolSettings.telnetName = telnetName;
 	}
 
-	public static String getTelnetVersion() {
-		return telnetVersion;
-	}
-
-	public static void setTelnetVersion(String telnetVersion) {
-		ProtocolSettings.telnetVersion = telnetVersion;
-	}
-
 	public static String getSshVersion() {
 		return sshVersion;
 	}

+ 1 - 3
src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java

@@ -50,7 +50,6 @@ public class TELNET implements Protocol<ByteArray> {
 		case OPEN:
 			if(request != null) {
 				response.add(new ByteArray(getOptionResponse(request)));
-				response.add(new ByteArray(serverVersion));
 				response.add(new ByteArray(serverName + " login: "));
 				state = STATE.LOGIN;
 			}
@@ -86,7 +85,7 @@ public class TELNET implements Protocol<ByteArray> {
 		case AUTHENTICATE:
 			if(request == null) break;
 			else if(checkForByte(request, (byte) 0x0d)) {
-				response.add(new ByteArray("\r\n" + serverVersion + "\r\n"));
+				response.add(new ByteArray("\r\n"));
 				response.add(new ByteArray(sessionToken));
 				state = STATE.LOGGED_IN;
 			} else if (checkForByte(request, (byte) 0x7f)) {
@@ -200,7 +199,6 @@ public class TELNET implements Protocol<ByteArray> {
 	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;