Record.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 double latitude;
  32. private double longitude;
  33. private float accuracy;
  34. private String packet;
  35. /**
  36. * @return the id
  37. */
  38. public int getId() {
  39. return id;
  40. }
  41. /**
  42. * @param id the id to set
  43. */
  44. public void setId(int id) {
  45. this.id = id;
  46. }
  47. /**
  48. * @return the attack_id
  49. */
  50. public long getAttack_id() {
  51. return attack_id;
  52. }
  53. /**
  54. * @param attack_id the attack_id to set
  55. */
  56. public void setAttack_id(long attack_id) {
  57. this.attack_id = attack_id;
  58. }
  59. /**
  60. * @return the protocol
  61. */
  62. public String getProtocol() {
  63. return protocol;
  64. }
  65. /**
  66. * @param protocol the protocol to set
  67. */
  68. public void setProtocol(String protocol) {
  69. this.protocol = protocol;
  70. }
  71. /**
  72. * @return the type
  73. */
  74. public TYPE getType() {
  75. return type;
  76. }
  77. /**
  78. * @param type the type to set
  79. */
  80. public void setType(TYPE type) {
  81. this.type = type;
  82. }
  83. /**
  84. * @return the timestamp
  85. */
  86. public long getTimestamp() {
  87. return timestamp;
  88. }
  89. /**
  90. * @param timestamp the timestamp to set
  91. */
  92. public void setTimestamp(long timestamp) {
  93. this.timestamp = timestamp;
  94. }
  95. /**
  96. * @return the externalIP
  97. */
  98. public String getExternalIP() {
  99. return externalIP;
  100. }
  101. /**
  102. * @param externalIP the externalIP to set
  103. */
  104. public void setExternalIP(String externalIP) {
  105. this.externalIP = externalIP;
  106. }
  107. /**
  108. * @return the localIP
  109. */
  110. public InetAddress getLocalIP() {
  111. return localIP;
  112. }
  113. /**
  114. * @param localIP the localIP to set
  115. */
  116. public void setLocalIP(InetAddress localIP) {
  117. this.localIP = localIP;
  118. }
  119. /**
  120. * @return the localPort
  121. */
  122. public int getLocalPort() {
  123. return localPort;
  124. }
  125. /**
  126. * @param localPort the localPort to set
  127. */
  128. public void setLocalPort(int localPort) {
  129. this.localPort = localPort;
  130. }
  131. /**
  132. * @return the remoteIP
  133. */
  134. public InetAddress getRemoteIP() {
  135. return remoteIP;
  136. }
  137. /**
  138. * @param remoteIP the remoteIP to set
  139. */
  140. public void setRemoteIP(InetAddress remoteIP) {
  141. this.remoteIP = remoteIP;
  142. }
  143. /**
  144. * @return the remotePort
  145. */
  146. public int getRemotePort() {
  147. return remotePort;
  148. }
  149. /**
  150. * @param remotePort the remotePort to set
  151. */
  152. public void setRemotePort(int remotePort) {
  153. this.remotePort = remotePort;
  154. }
  155. /**
  156. * @return the bSSID
  157. */
  158. public String getBSSID() {
  159. return BSSID;
  160. }
  161. /**
  162. * @param bSSID the bSSID to set
  163. */
  164. public void setBSSID(String bSSID) {
  165. BSSID = bSSID;
  166. }
  167. /**
  168. * @return the sSID
  169. */
  170. public String getSSID() {
  171. return SSID;
  172. }
  173. /**
  174. * @param sSID the sSID to set
  175. */
  176. public void setSSID(String sSID) {
  177. SSID = sSID;
  178. }
  179. /**
  180. * @return the latitude
  181. */
  182. public double getLatitude() {
  183. return latitude;
  184. }
  185. /**
  186. * @param latitude the latitude to set
  187. */
  188. public void setLatitude(double latitude) {
  189. this.latitude = latitude;
  190. }
  191. /**
  192. * @return the longitude
  193. */
  194. public double getLongitude() {
  195. return longitude;
  196. }
  197. /**
  198. * @param longitude the longitude to set
  199. */
  200. public void setLongitude(double longitude) {
  201. this.longitude = longitude;
  202. }
  203. /**
  204. * @return the accuracy
  205. */
  206. public float getAccuracy() {
  207. return accuracy;
  208. }
  209. /**
  210. * @param accuracy the accuracy to set
  211. */
  212. public void setAccuracy(float accuracy) {
  213. this.accuracy = accuracy;
  214. }
  215. /**
  216. * @return the packet
  217. */
  218. public String getPacket() {
  219. return packet;
  220. }
  221. /**
  222. * @param packet the packet to set
  223. */
  224. public void setPacket(String packet) {
  225. this.packet = packet;
  226. }
  227. @Override
  228. public String toString() {
  229. return String.format("%d %s [%d,%s:%d,%s:%d,%s]", attack_id,
  230. ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), timestamp,
  231. localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  232. remotePort, LogViewFormatter.format(getProtocol(), getPacket()));
  233. }
  234. /**
  235. * 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(...)}
  236. * The Integer representation of the format is equal to its position in the format array.
  237. * @param format Integer representation of the format.
  238. * @return A string representation after chosen format.
  239. */
  240. public String toString(int format){
  241. // Choose String Format
  242. switch (format){
  243. // ViewLogTable format: contains all important information about an attack.
  244. case 0:
  245. return String.format("%d: %s %s\nIn %s\n(%s)\nFrom [%s:%d]\nTo [%s:%d]\nLatitude: %f\nLongitude: %f\n%s\n\n", attack_id, protocol, ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), SSID, BSSID, remoteIP.getHostAddress(), remotePort, localIP.getHostAddress(), localPort, getLatitude(), getLongitude(), LogViewFormatter.format(getProtocol(), getPacket()));
  246. // TraCINg Upload format, replaces internal ip's with external ip of network
  247. case 1:
  248. 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);
  249. default:
  250. return toString();
  251. }
  252. }
  253. }