ProtocolSettings.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package de.tudarmstadt.informatik.hostage.commons;
  2. import java.security.SecureRandom;
  3. /**
  4. * This class holds informations for all protocols, e.g. server name, version etc.
  5. * It provides getters and setters.
  6. * @author Wulf Pfeiffer
  7. */
  8. public class ProtocolSettings {
  9. //TODO documentation
  10. private static SecureRandom rndm = new SecureRandom();
  11. private static String[][][] possibleHttpVersions = {
  12. {{"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"}},
  13. {{"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"}},
  14. {{"Apache/2.3."},{"4","5","6","8","10","11","12","14","15","16"}},
  15. {{"Apache/2.4."},{"1","2","3","4","6"}}
  16. };
  17. private static String[][][] possibleMysqlVersions = {
  18. {{"5.7."},{"1","2"}},
  19. {{"5.6."},{"2","3","4","5","6","7","8","9","10","11","12","13","14"}},
  20. {{"5.5."},{"27","28","29","30","31","32","33","34"}}
  21. };
  22. private static String[][] possibleSmbVersions = {
  23. {"Windows Server 2008 R2 Enterprise 7600","Windows Server 2008 R2 Enterprise 6.1"},
  24. {"Windows 7 Professional 7600","Windows 7 Professional 6.1"},
  25. {"Windows 8 Enterprise 9200", "Windows 8 Enterprise 9200"},
  26. {"Windows Server 2012 Standard 6.2", "Windows Server 2012 Standard 6.2"},
  27. {"Unix", "Samba"}
  28. };
  29. private static String[][][] possibleSshVersions = {
  30. {{"3."},{"4","5","6","7","8","9"}},
  31. {{"4."},{"0","1","2","3","4","5","6","7","9"}},
  32. {{"5."},{"0","1","2","3","4","5","6","7","8","9"}},
  33. {{"6."},{"0","1","2","3","4"}}
  34. };
  35. //HTTP
  36. private static String httpQotd ; //is initialized by honeyservice
  37. private static String httpVersion = initHttpVersion();
  38. private static boolean useHttpQotd = true;
  39. //MySQL
  40. private static String mysqlVersion = initMysqlVersion();
  41. //SMB
  42. private static byte[] smbName = initSmbName();
  43. private static String[] smbVersion = initSmbVersion();
  44. //TELNET
  45. private static String telnetName = initTelnetName();
  46. //SSH
  47. private static String sshVersion = initSshVersion();
  48. private static String sshType = initSshType();
  49. //~~~ Initialize methods ~~~//
  50. private static String initHttpVersion() {
  51. int majorVersion = rndm.nextInt(possibleHttpVersions.length);
  52. return possibleHttpVersions[majorVersion][0][0] + possibleHttpVersions[majorVersion][1][rndm.nextInt(possibleHttpVersions[majorVersion][1].length)];
  53. }
  54. private static String initMysqlVersion() {
  55. int majorVersion = rndm.nextInt(possibleMysqlVersions.length);
  56. return possibleMysqlVersions[majorVersion][0][0] + possibleMysqlVersions[majorVersion][1][rndm.nextInt(possibleMysqlVersions[majorVersion][1].length)];
  57. }
  58. private static byte[] initSmbName() {
  59. return HelperUtils.fillWithZero(HelperUtils.getRandomString(16, true).getBytes());
  60. }
  61. private static String[] initSmbVersion() {
  62. return possibleSmbVersions[rndm.nextInt(possibleSmbVersions.length)];
  63. }
  64. private static String initTelnetName() {
  65. return HelperUtils.getRandomString(16, false);
  66. }
  67. private static String initSshVersion() {
  68. return "SSH-2.0-";
  69. }
  70. private static String initSshType() {
  71. int majorVersion = rndm.nextInt(possibleSshVersions.length);
  72. return "OpenSSH_" + possibleSshVersions[majorVersion][0][0] + possibleSshVersions[majorVersion][1][rndm.nextInt(possibleSshVersions[majorVersion][1].length)];
  73. }
  74. //~~~ Getters and Setters ~~//
  75. public static String getHttpQotd() {
  76. return httpQotd;
  77. }
  78. public static void setHttpQotd(String httpQotd) {
  79. ProtocolSettings.httpQotd = httpQotd;
  80. }
  81. public static String getHttpVersion() {
  82. return httpVersion;
  83. }
  84. public static void setHttpVersion(String httpVersion) {
  85. ProtocolSettings.httpVersion = httpVersion;
  86. }
  87. public static boolean isUseHttpQotd() {
  88. return useHttpQotd;
  89. }
  90. public static void setUseHttpQotd(boolean useHttpQotd) {
  91. ProtocolSettings.useHttpQotd = useHttpQotd;
  92. }
  93. public static String getMysqlVersion() {
  94. return mysqlVersion;
  95. }
  96. public static void setMysqlVersion(String mysqlVersion) {
  97. ProtocolSettings.mysqlVersion = mysqlVersion;
  98. }
  99. public static byte[] getSmbName() {
  100. return smbName;
  101. }
  102. public static void setSmbName(byte[] smbName) {
  103. ProtocolSettings.smbName = smbName;
  104. }
  105. public static String[] getSmbVersion() {
  106. return smbVersion;
  107. }
  108. public static void setSmbVersion(String[] smbVersion) {
  109. ProtocolSettings.smbVersion = smbVersion;
  110. }
  111. public static String getTelnetName() {
  112. return telnetName;
  113. }
  114. public static void setTelnetName(String telnetName) {
  115. ProtocolSettings.telnetName = telnetName;
  116. }
  117. public static String getSshVersion() {
  118. return sshVersion;
  119. }
  120. public static void setSshVersion(String sshVersion) {
  121. ProtocolSettings.sshVersion = sshVersion;
  122. }
  123. public static String getSshType() {
  124. return sshType;
  125. }
  126. public static void setSshType(String sshType) {
  127. ProtocolSettings.sshType = sshType;
  128. }
  129. }