SyncRecord.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. package de.tudarmstadt.informatik.hostage.logging;
  2. /**
  3. * Created by Julien on 08.12.2014.
  4. */
  5. import android.os.Parcel;
  6. import android.os.Parcelable;
  7. import java.io.Serializable;
  8. import android.os.Parcel;
  9. import android.os.Parcelable;
  10. import java.io.Serializable;
  11. import java.util.zip.Deflater;
  12. public class SyncRecord implements Parcelable, Serializable {
  13. private static final long serialVersionUID = 7106818788090434192L;
  14. private long attack_id;
  15. private long sync_id;
  16. private String bssid;
  17. private String device;
  18. private String protocol;
  19. private String localIP;
  20. private int localPort;
  21. private String remoteIP;
  22. private int remotePort;
  23. private String externalIP;
  24. private int wasInternalAttack; // 1 if attacker ip and local ip were in same subnet, else 0
  25. // attack
  26. private int id;
  27. private long timestamp;
  28. private MessageRecord.TYPE type;
  29. private String packet;
  30. public static final Parcelable.Creator<SyncRecord> CREATOR = new Parcelable.Creator<SyncRecord>() {
  31. @Override
  32. public SyncRecord createFromParcel(Parcel source) {
  33. return new SyncRecord(source);
  34. }
  35. @Override
  36. public SyncRecord[] newArray(int size) {
  37. return new SyncRecord[size];
  38. }
  39. };
  40. public SyncRecord() {
  41. }
  42. public SyncRecord(Parcel source) {
  43. super();
  44. this.attack_id = source.readLong();
  45. this.protocol = source.readString();
  46. this.localIP = source.readString();
  47. this.localPort = source.readInt();
  48. this.remoteIP = source.readString();
  49. this.remotePort = source.readInt();
  50. this.externalIP = source.readString();
  51. this.wasInternalAttack = source.readInt();
  52. this.bssid = source.readString();
  53. this.device = source.readString();
  54. this.sync_id = source.readLong();
  55. this.id = source.readInt();
  56. this.timestamp = source.readLong();
  57. this.type = MessageRecord.TYPE.valueOf(source.readString());
  58. this.packet = source.readString();
  59. }
  60. @Override
  61. public int describeContents() {
  62. return 0;
  63. }
  64. @Override
  65. public void writeToParcel(Parcel dest, int flags) {
  66. dest.writeLong(attack_id);
  67. dest.writeString(protocol);
  68. dest.writeString(localIP);
  69. dest.writeInt(localPort);
  70. dest.writeString(remoteIP);
  71. dest.writeInt(remotePort);
  72. dest.writeString(externalIP);
  73. dest.writeInt(wasInternalAttack);
  74. dest.writeString(bssid);
  75. dest.writeString(device);
  76. dest.writeLong(sync_id);
  77. dest.writeInt(id);
  78. dest.writeLong(timestamp);
  79. dest.writeString(type.name());
  80. dest.writeString(packet);
  81. }
  82. public AttackRecord getAttackRecord(){
  83. boolean autoincrement = !this.device.equals(SyncDevice.currentDevice().getDeviceID());
  84. AttackRecord record = new AttackRecord(autoincrement);
  85. if (!autoincrement)
  86. record.setAttack_id(this.attack_id);
  87. this.attack_id = record.getAttack_id();
  88. record.setProtocol(this.protocol);
  89. record.setSync_id(this.sync_id);
  90. record.setLocalIP(this.localIP);
  91. record.setLocalPort(this.localPort);
  92. record.setBssid(this.bssid);
  93. record.setDevice(this.device);
  94. record.setExternalIP(this.externalIP);
  95. record.setWasInternalAttack(this.getWasInternalAttack());
  96. record.setRemoteIP(this.remoteIP);
  97. record.setRemotePort(this.remotePort);
  98. return record;
  99. }
  100. public MessageRecord getMessageRecord(){
  101. MessageRecord record = new MessageRecord();
  102. record.setAttack_id(this.attack_id);
  103. record.setPacket(this.packet);
  104. record.setTimestamp(this.timestamp);
  105. record.setType(this.type);
  106. return record;
  107. }
  108. /**
  109. * @return the attack_id
  110. */
  111. public long getAttack_id() {
  112. return attack_id;
  113. }
  114. /**
  115. * @param attack_id
  116. * the attack_id to set
  117. */
  118. public void setAttack_id(long attack_id) {
  119. this.attack_id = attack_id;
  120. }
  121. /**
  122. * @return the bssid
  123. */
  124. public String getBssid() {
  125. return bssid;
  126. }
  127. /**
  128. * @param bssid
  129. * the bssid to set
  130. */
  131. public void setBssid(String bssid) {
  132. this.bssid = bssid;
  133. }
  134. /**
  135. * @return the protocol
  136. */
  137. public String getProtocol() {
  138. return protocol;
  139. }
  140. /**
  141. * @param protocol
  142. * the protocol to set
  143. */
  144. public void setProtocol(String protocol) {
  145. this.protocol = protocol;
  146. }
  147. /**
  148. * @return the localIP
  149. */
  150. public String getLocalIP() {
  151. return localIP;
  152. }
  153. /**
  154. * @param localIP
  155. * the localIP to set
  156. */
  157. public void setLocalIP(String localIP) {
  158. this.localIP = localIP;
  159. }
  160. /**
  161. * @return the localPort
  162. */
  163. public int getLocalPort() {
  164. return localPort;
  165. }
  166. /**
  167. * @param localPort
  168. * the localPort to set
  169. */
  170. public void setLocalPort(int localPort) {
  171. this.localPort = localPort;
  172. }
  173. /**
  174. * @return the remoteIP
  175. */
  176. public String getRemoteIP() {
  177. return remoteIP;
  178. }
  179. /**
  180. * @param remoteIP
  181. * the remoteIP to set
  182. */
  183. public void setRemoteIP(String remoteIP) {
  184. this.remoteIP = remoteIP;
  185. }
  186. /**
  187. * @return the remotePort
  188. */
  189. public int getRemotePort() {
  190. return remotePort;
  191. }
  192. public long getSync_id(){return sync_id;}
  193. public String getDevice(){return device;}
  194. public void setDevice(String d){this.device = d;}
  195. public void setSync_id(long i){this.sync_id = i;}
  196. /**
  197. * @param remotePort
  198. * the remotePort to set
  199. */
  200. public void setRemotePort(int remotePort) {
  201. this.remotePort = remotePort;
  202. }
  203. /**
  204. * @return the externalIP
  205. */
  206. public String getExternalIP() {
  207. return externalIP;
  208. }
  209. /**
  210. * @param externalIP
  211. * the externalIP to set
  212. */
  213. public void setExternalIP(String externalIP) {
  214. this.externalIP = externalIP;
  215. }
  216. public boolean getWasInternalAttack() {return wasInternalAttack == 1;}
  217. public void setWasInternalAttack(boolean b) {wasInternalAttack = b ? 1 : 0;}
  218. /*
  219. *
  220. *
  221. * MESSAGE RECORD
  222. *
  223. *
  224. */
  225. /**
  226. * @return the id
  227. */
  228. public int getId() {
  229. return id;
  230. }
  231. /**
  232. * @param id the id to set
  233. */
  234. public void setId(int id) {
  235. this.id = id;
  236. }
  237. /**
  238. * @return the timestamp
  239. */
  240. public long getTimestamp() {
  241. return timestamp;
  242. }
  243. /**
  244. * @param timestamp the timestamp to set
  245. */
  246. public void setTimestamp(long timestamp) {
  247. this.timestamp = timestamp;
  248. }
  249. /**
  250. * @return the type
  251. */
  252. public MessageRecord.TYPE getType() {
  253. return type;
  254. }
  255. /**
  256. * @param type the type to set
  257. */
  258. public void setType(MessageRecord.TYPE type) {
  259. this.type = type;
  260. }
  261. /**
  262. * @return the packet
  263. */
  264. public String getPacket() {
  265. return packet;
  266. }
  267. /**
  268. * @param packet the packet to set
  269. */
  270. public void setPacket(String packet) {
  271. this.packet = packet;
  272. }
  273. /**
  274. * @return the number_of_attacks
  275. */
  276. @Deprecated
  277. public long getNumber_of_attacks() {
  278. return number_of_attacks;
  279. }
  280. /**
  281. * @param number_of_attacks the number_of_attacks to set
  282. */
  283. @Deprecated
  284. public void setNumber_of_attacks(long number_of_attacks) {
  285. this.number_of_attacks = number_of_attacks;
  286. }
  287. /**
  288. * @return the number_of_portscans
  289. */
  290. @Deprecated
  291. public long getNumber_of_portscans() {
  292. return number_of_portscans;
  293. }
  294. /**
  295. * @param number_of_portscans the number_of_portscans to set
  296. */
  297. @Deprecated
  298. public void setNumber_of_portscans(long number_of_portscans) {
  299. this.number_of_portscans = number_of_portscans;
  300. }
  301. private long number_of_attacks;
  302. private long number_of_portscans;
  303. }