SyncRecord.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. transient private AttackRecord attackRecord;
  30. // attack
  31. //private int id;
  32. //private long timestamp;
  33. //private MessageRecord.TYPE type;
  34. //private String packet;
  35. private ArrayList<MessageRecord> messageRecords;
  36. public static final Parcelable.Creator<SyncRecord> CREATOR = new Parcelable.Creator<SyncRecord>() {
  37. @Override
  38. public SyncRecord createFromParcel(Parcel source) {
  39. return new SyncRecord(source);
  40. }
  41. @Override
  42. public SyncRecord[] newArray(int size) {
  43. return new SyncRecord[size];
  44. }
  45. };
  46. public SyncRecord() {
  47. }
  48. public SyncRecord(AttackRecord attackRecord){
  49. this.attackRecord = attackRecord;
  50. this.setAttack_id(attackRecord.getAttack_id());
  51. this.setProtocol(attackRecord.getProtocol());
  52. this.setExternalIP(attackRecord.getExternalIP());
  53. this.setLocalPort(attackRecord.getLocalPort());
  54. this.setRemoteIP(attackRecord.getRemoteIP());
  55. this.setRemotePort(attackRecord.getRemotePort());
  56. this.setWasInternalAttack(attackRecord.getWasInternalAttack());
  57. this.setBssid(attackRecord.getBssid());
  58. this.setSync_id(attackRecord.getSync_id());
  59. this.setDevice(attackRecord.getDevice());
  60. }
  61. public SyncRecord(Parcel source) {
  62. super();
  63. this.attack_id = source.readLong();
  64. this.protocol = source.readString();
  65. this.localIP = source.readString();
  66. this.localPort = source.readInt();
  67. this.remoteIP = source.readString();
  68. this.remotePort = source.readInt();
  69. this.externalIP = source.readString();
  70. this.wasInternalAttack = source.readInt();
  71. this.bssid = source.readString();
  72. this.device = source.readString();
  73. this.sync_id = source.readLong();
  74. this.messageRecords = source.readArrayList(MessageRecord.class.getClassLoader());
  75. this.attackRecord = null;
  76. AttackRecord attack= this.getAttackRecord();
  77. //this.id = source.readInt();
  78. //this.timestamp = source.readLong();
  79. //this.type = MessageRecord.TYPE.valueOf(source.readString());
  80. //this.packet = source.readString();
  81. }
  82. @Override
  83. public int describeContents() {
  84. return 0;
  85. }
  86. @Override
  87. public void writeToParcel(Parcel dest, int flags) {
  88. dest.writeLong(attack_id);
  89. dest.writeString(protocol);
  90. dest.writeString(localIP);
  91. dest.writeInt(localPort);
  92. dest.writeString(remoteIP);
  93. dest.writeInt(remotePort);
  94. dest.writeString(externalIP);
  95. dest.writeInt(wasInternalAttack);
  96. dest.writeString(bssid);
  97. dest.writeString(device);
  98. dest.writeLong(sync_id);
  99. dest.writeList(this.messageRecords);
  100. //dest.writeInt(id);
  101. //dest.writeLong(timestamp);
  102. //dest.writeString(type.name());
  103. //dest.writeString(packet);
  104. }
  105. public AttackRecord getAttackRecord(){
  106. if (this.attackRecord == null){
  107. AttackRecord record = new AttackRecord(true);
  108. this.attack_id = record.getAttack_id();
  109. record.setProtocol(this.protocol);
  110. record.setSync_id(this.sync_id);
  111. record.setLocalIP(this.localIP);
  112. record.setLocalPort(this.localPort);
  113. record.setBssid(this.bssid);
  114. record.setDevice(this.device);
  115. record.setExternalIP(this.externalIP);
  116. record.setWasInternalAttack(this.getWasInternalAttack());
  117. record.setRemoteIP(this.remoteIP);
  118. record.setRemotePort(this.remotePort);
  119. this.attackRecord = record;
  120. if (messageRecords != null){
  121. for (MessageRecord messageRecord : this.messageRecords){
  122. messageRecord.setAttack_id(record.getAttack_id());
  123. }
  124. }
  125. }
  126. return this.attackRecord;
  127. }
  128. public ArrayList<MessageRecord> getMessageRecords(){
  129. return this.messageRecords;
  130. }
  131. public void setMessageRecords(ArrayList<MessageRecord> mr){
  132. this.messageRecords = mr;
  133. }
  134. /**
  135. * @return the attack_id
  136. */
  137. public long getAttack_id() {
  138. return attack_id;
  139. }
  140. /**
  141. * @param attack_id
  142. * the attack_id to set
  143. */
  144. public void setAttack_id(long attack_id) {
  145. this.attack_id = attack_id;
  146. }
  147. /**
  148. * @return the bssid
  149. */
  150. public String getBssid() {
  151. return bssid;
  152. }
  153. /**
  154. * @param bssid
  155. * the bssid to set
  156. */
  157. public void setBssid(String bssid) {
  158. this.bssid = bssid;
  159. }
  160. /**
  161. * @return the protocol
  162. */
  163. public String getProtocol() {
  164. return protocol;
  165. }
  166. /**
  167. * @param protocol
  168. * the protocol to set
  169. */
  170. public void setProtocol(String protocol) {
  171. this.protocol = protocol;
  172. }
  173. /**
  174. * @return the localIP
  175. */
  176. public String getLocalIP() {
  177. return localIP;
  178. }
  179. /**
  180. * @param localIP
  181. * the localIP to set
  182. */
  183. public void setLocalIP(String localIP) {
  184. this.localIP = localIP;
  185. }
  186. /**
  187. * @return the localPort
  188. */
  189. public int getLocalPort() {
  190. return localPort;
  191. }
  192. /**
  193. * @param localPort
  194. * the localPort to set
  195. */
  196. public void setLocalPort(int localPort) {
  197. this.localPort = localPort;
  198. }
  199. /**
  200. * @return the remoteIP
  201. */
  202. public String getRemoteIP() {
  203. return remoteIP;
  204. }
  205. /**
  206. * @param remoteIP
  207. * the remoteIP to set
  208. */
  209. public void setRemoteIP(String remoteIP) {
  210. this.remoteIP = remoteIP;
  211. }
  212. /**
  213. * @return the remotePort
  214. */
  215. public int getRemotePort() {
  216. return remotePort;
  217. }
  218. public long getSync_id(){return sync_id;}
  219. public String getDevice(){return device;}
  220. public void setDevice(String d){this.device = d;}
  221. public void setSync_id(long i){this.sync_id = i;}
  222. /**
  223. * @param remotePort
  224. * the remotePort to set
  225. */
  226. public void setRemotePort(int remotePort) {
  227. this.remotePort = remotePort;
  228. }
  229. /**
  230. * @return the externalIP
  231. */
  232. public String getExternalIP() {
  233. return externalIP;
  234. }
  235. /**
  236. * @param externalIP
  237. * the externalIP to set
  238. */
  239. public void setExternalIP(String externalIP) {
  240. this.externalIP = externalIP;
  241. }
  242. public boolean getWasInternalAttack() {return wasInternalAttack == 1;}
  243. public void setWasInternalAttack(boolean b) {wasInternalAttack = b ? 1 : 0;}
  244. /**
  245. * @return the number_of_attacks
  246. */
  247. @Deprecated
  248. public long getNumber_of_attacks() {
  249. return number_of_attacks;
  250. }
  251. /**
  252. * @param number_of_attacks the number_of_attacks to set
  253. */
  254. @Deprecated
  255. public void setNumber_of_attacks(long number_of_attacks) {
  256. this.number_of_attacks = number_of_attacks;
  257. }
  258. /**
  259. * @return the number_of_portscans
  260. */
  261. @Deprecated
  262. public long getNumber_of_portscans() {
  263. return number_of_portscans;
  264. }
  265. /**
  266. * @param number_of_portscans the number_of_portscans to set
  267. */
  268. @Deprecated
  269. public void setNumber_of_portscans(long number_of_portscans) {
  270. this.number_of_portscans = number_of_portscans;
  271. }
  272. private long number_of_attacks;
  273. private long number_of_portscans;
  274. @Override
  275. public String toString() {
  276. return "SyncRecord{" +
  277. "attack_id=" + attack_id +
  278. ", sync_id=" + sync_id +
  279. ", bssid='" + bssid + '\'' +
  280. ", device='" + device + '\'' +
  281. ", protocol='" + protocol + '\'' +
  282. ", localIP='" + localIP + '\'' +
  283. ", localPort=" + localPort +
  284. ", remoteIP='" + remoteIP + '\'' +
  285. ", remotePort=" + remotePort +
  286. ", externalIP='" + externalIP + '\'' +
  287. ", wasInternalAttack=" + wasInternalAttack +
  288. ", attackRecord=" + attackRecord +
  289. //", messageRecords=" + messageRecords +
  290. ", number_of_attacks=" + number_of_attacks +
  291. ", number_of_portscans=" + number_of_portscans +
  292. '}';
  293. }
  294. }