Record.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 the id to set
  38. */
  39. public void setId(int id) {
  40. this.id = id;
  41. }
  42. /**
  43. * @return the attack_id
  44. */
  45. public long getAttack_id() {
  46. return attack_id;
  47. }
  48. /**
  49. * @param attack_id the attack_id to set
  50. */
  51. public void setAttack_id(long attack_id) {
  52. this.attack_id = attack_id;
  53. }
  54. /**
  55. * @return the protocol
  56. */
  57. public String getProtocol() {
  58. return protocol;
  59. }
  60. /**
  61. * @param protocol the protocol to set
  62. */
  63. public void setProtocol(String protocol) {
  64. this.protocol = protocol;
  65. }
  66. /**
  67. * @return the type
  68. */
  69. public TYPE getType() {
  70. return type;
  71. }
  72. /**
  73. * @param type the type to set
  74. */
  75. public void setType(TYPE type) {
  76. this.type = type;
  77. }
  78. /**
  79. * @return the timestamp
  80. */
  81. public long getTimestamp() {
  82. return timestamp;
  83. }
  84. /**
  85. * @param timestamp the timestamp to set
  86. */
  87. public void setTimestamp(long timestamp) {
  88. this.timestamp = timestamp;
  89. }
  90. /**
  91. * @return the localIP
  92. */
  93. public InetAddress getLocalIP() {
  94. return localIP;
  95. }
  96. /**
  97. * @param localIP the localIP to set
  98. */
  99. public void setLocalIP(InetAddress localIP) {
  100. this.localIP = localIP;
  101. }
  102. /**
  103. * @return the localPort
  104. */
  105. public int getLocalPort() {
  106. return localPort;
  107. }
  108. /**
  109. * @param localPort the localPort to set
  110. */
  111. public void setLocalPort(int localPort) {
  112. this.localPort = localPort;
  113. }
  114. /**
  115. * @return the remoteIP
  116. */
  117. public InetAddress getRemoteIP() {
  118. return remoteIP;
  119. }
  120. /**
  121. * @param remoteIP the remoteIP to set
  122. */
  123. public void setRemoteIP(InetAddress remoteIP) {
  124. this.remoteIP = remoteIP;
  125. }
  126. /**
  127. * @return the remotePort
  128. */
  129. public int getRemotePort() {
  130. return remotePort;
  131. }
  132. /**
  133. * @param remotePort the remotePort to set
  134. */
  135. public void setRemotePort(int remotePort) {
  136. this.remotePort = remotePort;
  137. }
  138. /**
  139. * @return the bSSID
  140. */
  141. public String getBSSID() {
  142. return BSSID;
  143. }
  144. /**
  145. * @param bSSID the bSSID to set
  146. */
  147. public void setBSSID(String bSSID) {
  148. BSSID = bSSID;
  149. }
  150. /**
  151. * @return the sSID
  152. */
  153. public String getSSID() {
  154. return SSID;
  155. }
  156. /**
  157. * @param sSID the sSID to set
  158. */
  159. public void setSSID(String sSID) {
  160. SSID = sSID;
  161. }
  162. /**
  163. * @return the packet
  164. */
  165. public String getPacket() {
  166. return packet;
  167. }
  168. /**
  169. * @param packet the packet to set
  170. */
  171. public void setPacket(String packet) {
  172. this.packet = packet;
  173. }
  174. @Override
  175. public String toString() {
  176. return String.format("%d %s [%d,%s:%d,%s:%d,%s]", attack_id,
  177. ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), timestamp,
  178. localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  179. remotePort, packet);
  180. }
  181. /**
  182. * Returns a string representation after a chosen format. Formats should be defined in /res/values/export_formats.xml to use with {@link de.tudarmstadt.informatik.hostage.ui.ViewLog#exportDatabase(android.view.View)}
  183. * The Intger representation of the format is equal to its position in the format array.
  184. * @param format Integer representation of the format.
  185. * @return A string representation after chosen format.
  186. */
  187. public String toString(int format){
  188. // Choose String Format
  189. switch (format){
  190. case 1:
  191. return String.format("{ \"sensor\":{\"type\": \"Honeypot\", \"name\": \"HOsTaGe\"}, \"type\": 0, \"src\":{\"ip\": \"%s\", \"port\": %d}, \"dst\":{\"ip\": \"%s\", \"port\": %d} }", localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  192. remotePort);
  193. case 2:
  194. 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);
  195. default:
  196. return toString();
  197. }
  198. }
  199. }