Record.java 6.4 KB

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