SyncRecord.java 7.9 KB

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