Record.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. package de.tudarmstadt.informatik.hostage.logging;
  2. import java.io.Serializable;
  3. import java.net.InetAddress;
  4. import de.tudarmstadt.informatik.hostage.format.LogViewFormatter;
  5. /**
  6. * This class defines the attributes of a record.<br>
  7. * A Record is a single message exchanged between the application and an attacker.<br>
  8. * The class has no own functionality except for getter and setter methods.
  9. * To change the logging mechanism you have to to change the logger in {@link de.tudarmstadt.informatik.hostage.HoneyService HoneyService} and
  10. * {@link de.tudarmstadt.informatik.hostage.ui.ViewLog ViewLog}
  11. * @author Mihai Plasoianu
  12. * @author Lars Pandikow
  13. */
  14. public class Record implements Serializable {
  15. private static final long serialVersionUID = 1L;
  16. public static enum TYPE {
  17. SEND, RECEIVE
  18. };
  19. private int id;
  20. private long attack_id;
  21. private String protocol;
  22. private TYPE type;
  23. private long timestamp;
  24. private String externalIP;
  25. private InetAddress localIP;
  26. private int localPort;
  27. private InetAddress remoteIP;
  28. private int remotePort;
  29. private String BSSID;
  30. private String SSID;
  31. private String packet;
  32. /**
  33. * @return the id
  34. */
  35. public int getId() {
  36. return id;
  37. }
  38. /**
  39. * @param id the id to set
  40. */
  41. public void setId(int id) {
  42. this.id = id;
  43. }
  44. /**
  45. * @return the attack_id
  46. */
  47. public long getAttack_id() {
  48. return attack_id;
  49. }
  50. /**
  51. * @param attack_id the attack_id to set
  52. */
  53. public void setAttack_id(long attack_id) {
  54. this.attack_id = attack_id;
  55. }
  56. /**
  57. * @return the protocol
  58. */
  59. public String getProtocol() {
  60. return protocol;
  61. }
  62. /**
  63. * @param protocol the protocol to set
  64. */
  65. public void setProtocol(String protocol) {
  66. this.protocol = protocol;
  67. }
  68. /**
  69. * @return the type
  70. */
  71. public TYPE getType() {
  72. return type;
  73. }
  74. /**
  75. * @param type the type to set
  76. */
  77. public void setType(TYPE type) {
  78. this.type = type;
  79. }
  80. /**
  81. * @return the timestamp
  82. */
  83. public long getTimestamp() {
  84. return timestamp;
  85. }
  86. /**
  87. * @param timestamp the timestamp to set
  88. */
  89. public void setTimestamp(long timestamp) {
  90. this.timestamp = timestamp;
  91. }
  92. /**
  93. * @return the externalIP
  94. */
  95. public String getExternalIP() {
  96. return externalIP;
  97. }
  98. /**
  99. * @param externalIP the externalIP to set
  100. */
  101. public void setExternalIP(String externalIP) {
  102. this.externalIP = externalIP;
  103. }
  104. /**
  105. * @return the localIP
  106. */
  107. public InetAddress getLocalIP() {
  108. return localIP;
  109. }
  110. /**
  111. * @param localIP the localIP to set
  112. */
  113. public void setLocalIP(InetAddress localIP) {
  114. this.localIP = localIP;
  115. }
  116. /**
  117. * @return the localPort
  118. */
  119. public int getLocalPort() {
  120. return localPort;
  121. }
  122. /**
  123. * @param localPort the localPort to set
  124. */
  125. public void setLocalPort(int localPort) {
  126. this.localPort = localPort;
  127. }
  128. /**
  129. * @return the remoteIP
  130. */
  131. public InetAddress getRemoteIP() {
  132. return remoteIP;
  133. }
  134. /**
  135. * @param remoteIP the remoteIP to set
  136. */
  137. public void setRemoteIP(InetAddress remoteIP) {
  138. this.remoteIP = remoteIP;
  139. }
  140. /**
  141. * @return the remotePort
  142. */
  143. public int getRemotePort() {
  144. return remotePort;
  145. }
  146. /**
  147. * @param remotePort the remotePort to set
  148. */
  149. public void setRemotePort(int remotePort) {
  150. this.remotePort = remotePort;
  151. }
  152. /**
  153. * @return the bSSID
  154. */
  155. public String getBSSID() {
  156. return BSSID;
  157. }
  158. /**
  159. * @param bSSID the bSSID to set
  160. */
  161. public void setBSSID(String bSSID) {
  162. BSSID = bSSID;
  163. }
  164. /**
  165. * @return the sSID
  166. */
  167. public String getSSID() {
  168. return SSID;
  169. }
  170. /**
  171. * @param sSID the sSID to set
  172. */
  173. public void setSSID(String sSID) {
  174. SSID = sSID;
  175. }
  176. /**
  177. * @return the packet
  178. */
  179. public String getPacket() {
  180. return packet;
  181. }
  182. /**
  183. * @param packet the packet to set
  184. */
  185. public void setPacket(String packet) {
  186. this.packet = packet;
  187. }
  188. @Override
  189. public String toString() {
  190. return String.format("%d %s [%d,%s:%d,%s:%d,%s]", attack_id,
  191. ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), timestamp,
  192. localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  193. remotePort, LogViewFormatter.format(getProtocol(), getPacket()));
  194. }
  195. /**
  196. * Returns a string representation after a chosen format. Formats should be defined in /res/values/arrays.xml to use with {@link de.tudarmstadt.informatik.hostage.ui.ViewLog#exportDatabase(android.view.View) exportDatabase(...)}
  197. * The Integer representation of the format is equal to its position in the format array.
  198. * @param format Integer representation of the format.
  199. * @return A string representation after chosen format.
  200. */
  201. public String toString(int format){
  202. // Choose String Format
  203. switch (format){
  204. // ViewLogTable format: contains all important information about an attack.
  205. case 0:
  206. 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()));
  207. // TraCINg Upload format, replaces internal ip's with external ip of network
  208. case 1:
  209. 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);
  210. default:
  211. return toString();
  212. }
  213. }
  214. }