Record.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package de.tudarmstadt.informatik.hostage.logging;
  2. import java.io.Serializable;
  3. import java.net.InetAddress;
  4. /**
  5. * This class defines the attributes of a record.<br>
  6. * A Record is a single message exchanged between the application and an attacker.<br>
  7. * The class has no own functionality except for getter and setter methods.
  8. * To change the logging mechanism you have to to change the logger in {@link de.tudarmstadt.informatik.hostage.HoneyService} and
  9. * {@link de.tudarmstadt.informatik.hostage.ui.ViewLog}
  10. * @author Mihai Plasoianu
  11. * @author Lars Pandikow
  12. */
  13. public class Record implements Serializable {
  14. private static final long serialVersionUID = 1L;
  15. public static enum TYPE {
  16. SEND, RECEIVE
  17. };
  18. private int id;
  19. private long attack_id;
  20. private String protocol;
  21. private TYPE type;
  22. private long timestamp;
  23. private InetAddress localIP;
  24. private int localPort;
  25. private InetAddress remoteIP;
  26. private int remotePort;
  27. private String BSSID;
  28. private String SSID;
  29. private String packet;
  30. /**
  31. * @return the id
  32. */
  33. public int getID() {
  34. return id;
  35. }
  36. /**
  37. * @param id
  38. * the id to set
  39. */
  40. public void setID(int id) {
  41. this.id = id;
  42. }
  43. /**
  44. * @return the attack_id
  45. */
  46. public long getAttack_id() {
  47. return attack_id;
  48. }
  49. /**
  50. * @param attack_id
  51. * 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 string the protocol to set
  64. */
  65. public void setProtocol(String string) {
  66. this.protocol = string;
  67. }
  68. public TYPE getType() {
  69. return type;
  70. }
  71. public void setType(TYPE type) {
  72. this.type = type;
  73. }
  74. public long getTimestamp() {
  75. return timestamp;
  76. }
  77. public void setTimestamp(long timestamp) {
  78. this.timestamp = timestamp;
  79. }
  80. public InetAddress getLocalIP() {
  81. return localIP;
  82. }
  83. public void setLocalIP(InetAddress localIP) {
  84. this.localIP = localIP;
  85. }
  86. public int getLocalPort() {
  87. return localPort;
  88. }
  89. public void setLocalPort(int localPort) {
  90. this.localPort = localPort;
  91. }
  92. public InetAddress getRemoteIP() {
  93. return remoteIP;
  94. }
  95. public void setRemoteIP(InetAddress remoteIP) {
  96. this.remoteIP = remoteIP;
  97. }
  98. public int getRemotePort() {
  99. return remotePort;
  100. }
  101. public void setRemotePort(int remotePort) {
  102. this.remotePort = remotePort;
  103. }
  104. /**
  105. * @return the bSSID
  106. */
  107. public String getBSSID() {
  108. return BSSID;
  109. }
  110. /**
  111. * @param bSSID the bSSID to set
  112. */
  113. public void setBSSID(String bSSID) {
  114. BSSID = bSSID;
  115. }
  116. /**
  117. * @return the sSID
  118. */
  119. public String getSSID() {
  120. return SSID;
  121. }
  122. /**
  123. * @param sSID the sSID to set
  124. */
  125. public void setSSID(String sSID) {
  126. SSID = sSID;
  127. }
  128. public String getPacket() {
  129. return packet;
  130. }
  131. public void setPacket(String packet) {
  132. this.packet = packet;
  133. }
  134. @Override
  135. public String toString() {
  136. return String.format("%d %s [%d,%s:%d,%s:%d,%s]", attack_id,
  137. ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), timestamp,
  138. localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  139. remotePort, packet);
  140. }
  141. /**
  142. * Returns a string representation after a chosen format. Formats should be defined in /res/values/export_formats.xml to use {@link de.tudarmstadt.informatik.hostage.ui.ViewLog#exportDatabase(android.view.View)}
  143. * The Intger representation of the format is equal to its position in the format array.
  144. * @param format Integer representation of the format.
  145. * @return A string representation after chosen format.
  146. */
  147. public String toString(int format){
  148. // Choose String Format
  149. // Add additional case for your own Format. Also add format Name to
  150. switch (format){
  151. case 1:
  152. return String.format("{ \"src\":{\"IP\": %s, \"Port\": %d} \"dst\": {\"IP\": %s, \"Port\": %d} \"type\": 0 \"name\": \"HOsTaGe\" }", localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  153. remotePort);
  154. case 2:
  155. return String.format("%d: %s in %s(%s) from [%s:%d] to [%s:%d]", attack_id, protocol, SSID, BSSID, remoteIP.getHostAddress(), remotePort, localIP.getHostAddress(), localPort);
  156. default:
  157. return toString();
  158. }
  159. }
  160. }