SyncRecord.java 9.3 KB

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