Record.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 HoneyService} and
  9. * {@link de.tudarmstadt.informatik.hostage.ui.ViewLog 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 String externalIP;
  24. private InetAddress localIP;
  25. private int localPort;
  26. private InetAddress remoteIP;
  27. private int remotePort;
  28. private String BSSID;
  29. private String SSID;
  30. private String packet;
  31. /**
  32. * @return the id
  33. */
  34. public int getId() {
  35. return id;
  36. }
  37. /**
  38. * @param id 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 the attack_id to set
  51. */
  52. public void setAttack_id(long attack_id) {
  53. this.attack_id = attack_id;
  54. }
  55. /**
  56. * @return the protocol
  57. */
  58. public String getProtocol() {
  59. return protocol;
  60. }
  61. /**
  62. * @param protocol the protocol to set
  63. */
  64. public void setProtocol(String protocol) {
  65. this.protocol = protocol;
  66. }
  67. /**
  68. * @return the type
  69. */
  70. public TYPE getType() {
  71. return type;
  72. }
  73. /**
  74. * @param type the type to set
  75. */
  76. public void setType(TYPE type) {
  77. this.type = type;
  78. }
  79. /**
  80. * @return the timestamp
  81. */
  82. public long getTimestamp() {
  83. return timestamp;
  84. }
  85. /**
  86. * @param timestamp the timestamp to set
  87. */
  88. public void setTimestamp(long timestamp) {
  89. this.timestamp = timestamp;
  90. }
  91. /**
  92. * @return the externalIP
  93. */
  94. public String getExternalIP() {
  95. return externalIP;
  96. }
  97. /**
  98. * @param externalIP the externalIP to set
  99. */
  100. public void setExternalIP(String externalIP) {
  101. this.externalIP = externalIP;
  102. }
  103. /**
  104. * @return the localIP
  105. */
  106. public InetAddress getLocalIP() {
  107. return localIP;
  108. }
  109. /**
  110. * @param localIP the localIP to set
  111. */
  112. public void setLocalIP(InetAddress localIP) {
  113. this.localIP = localIP;
  114. }
  115. /**
  116. * @return the localPort
  117. */
  118. public int getLocalPort() {
  119. return localPort;
  120. }
  121. /**
  122. * @param localPort the localPort to set
  123. */
  124. public void setLocalPort(int localPort) {
  125. this.localPort = localPort;
  126. }
  127. /**
  128. * @return the remoteIP
  129. */
  130. public InetAddress getRemoteIP() {
  131. return remoteIP;
  132. }
  133. /**
  134. * @param remoteIP the remoteIP to set
  135. */
  136. public void setRemoteIP(InetAddress remoteIP) {
  137. this.remoteIP = remoteIP;
  138. }
  139. /**
  140. * @return the remotePort
  141. */
  142. public int getRemotePort() {
  143. return remotePort;
  144. }
  145. /**
  146. * @param remotePort the remotePort to set
  147. */
  148. public void setRemotePort(int remotePort) {
  149. this.remotePort = remotePort;
  150. }
  151. /**
  152. * @return the bSSID
  153. */
  154. public String getBSSID() {
  155. return BSSID;
  156. }
  157. /**
  158. * @param bSSID the bSSID to set
  159. */
  160. public void setBSSID(String bSSID) {
  161. BSSID = bSSID;
  162. }
  163. /**
  164. * @return the sSID
  165. */
  166. public String getSSID() {
  167. return SSID;
  168. }
  169. /**
  170. * @param sSID the sSID to set
  171. */
  172. public void setSSID(String sSID) {
  173. SSID = sSID;
  174. }
  175. /**
  176. * @return the packet
  177. */
  178. public String getPacket() {
  179. return packet;
  180. }
  181. /**
  182. * @param packet the packet to set
  183. */
  184. public void setPacket(String packet) {
  185. this.packet = packet;
  186. }
  187. @Override
  188. public String toString() {
  189. return String.format("%d %s [%d,%s:%d,%s:%d,%s]", attack_id,
  190. ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), timestamp,
  191. localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  192. remotePort, packet);
  193. }
  194. /**
  195. * 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(...)}
  196. * The Integer representation of the format is equal to its position in the format array.
  197. * @param format Integer representation of the format.
  198. * @return A string representation after chosen format.
  199. */
  200. public String toString(int format){
  201. // Choose String Format
  202. switch (format){
  203. // TraCINg Upload format, replaces internal ip's with external ip of network
  204. case 1:
  205. return String.format("{ \"sensor\":{\"type\": \"Honeypot\", \"name\": \"HOsTaGe\"}, \"type\": 0, \"src\":{\"ip\": \"%s\", \"port\": %d}, \"dst\":{\"ip\": \"%s\", \"port\": %d} }", externalIP, localPort, externalIP, remotePort);
  206. // ViewLogTable format: contains all important information about an attack.
  207. case 2:
  208. 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);
  209. default:
  210. return toString();
  211. }
  212. }
  213. }