123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- package de.tudarmstadt.informatik.hostage.logging;
- import java.io.Serializable;
- import java.net.InetAddress;
- import de.tudarmstadt.informatik.hostage.format.LogViewFormatter;
- /**
- * This class defines the attributes of a record.<br>
- * A Record is a single message exchanged between the application and an attacker.<br>
- * The class has no own functionality except for getter and setter methods.
- * To change the logging mechanism you have to to change the logger in {@link de.tudarmstadt.informatik.hostage.HoneyService HoneyService} and
- * {@link de.tudarmstadt.informatik.hostage.ui.ViewLog ViewLog}
- * @author Mihai Plasoianu
- * @author Lars Pandikow
- */
- public class Record implements Serializable {
- private static final long serialVersionUID = 1L;
- public static enum TYPE {
- SEND, RECEIVE
- };
- private int id;
- private long attack_id;
- private String protocol;
- private TYPE type;
- private long timestamp;
- private String externalIP;
- private InetAddress localIP;
- private int localPort;
- private InetAddress remoteIP;
- private int remotePort;
- private String BSSID;
- private String SSID;
- private double latitude;
- private double longitude;
- private float accuracy;
- private String packet;
- /**
- * @return the id
- */
- public int getId() {
- return id;
- }
- /**
- * @param id the id to set
- */
- public void setId(int id) {
- this.id = id;
- }
- /**
- * @return the attack_id
- */
- public long getAttack_id() {
- return attack_id;
- }
- /**
- * @param attack_id the attack_id to set
- */
- public void setAttack_id(long attack_id) {
- this.attack_id = attack_id;
- }
- /**
- * @return the protocol
- */
- public String getProtocol() {
- return protocol;
- }
- /**
- * @param protocol the protocol to set
- */
- public void setProtocol(String protocol) {
- this.protocol = protocol;
- }
- /**
- * @return the type
- */
- public TYPE getType() {
- return type;
- }
- /**
- * @param type the type to set
- */
- public void setType(TYPE type) {
- this.type = type;
- }
- /**
- * @return the timestamp
- */
- public long getTimestamp() {
- return timestamp;
- }
- /**
- * @param timestamp the timestamp to set
- */
- public void setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- }
- /**
- * @return the externalIP
- */
- public String getExternalIP() {
- return externalIP;
- }
- /**
- * @param externalIP the externalIP to set
- */
- public void setExternalIP(String externalIP) {
- this.externalIP = externalIP;
- }
- /**
- * @return the localIP
- */
- public InetAddress getLocalIP() {
- return localIP;
- }
- /**
- * @param localIP the localIP to set
- */
- public void setLocalIP(InetAddress localIP) {
- this.localIP = localIP;
- }
- /**
- * @return the localPort
- */
- public int getLocalPort() {
- return localPort;
- }
- /**
- * @param localPort the localPort to set
- */
- public void setLocalPort(int localPort) {
- this.localPort = localPort;
- }
- /**
- * @return the remoteIP
- */
- public InetAddress getRemoteIP() {
- return remoteIP;
- }
- /**
- * @param remoteIP the remoteIP to set
- */
- public void setRemoteIP(InetAddress remoteIP) {
- this.remoteIP = remoteIP;
- }
- /**
- * @return the remotePort
- */
- public int getRemotePort() {
- return remotePort;
- }
- /**
- * @param remotePort the remotePort to set
- */
- public void setRemotePort(int remotePort) {
- this.remotePort = remotePort;
- }
- /**
- * @return the bSSID
- */
- public String getBSSID() {
- return BSSID;
- }
- /**
- * @param bSSID the bSSID to set
- */
- public void setBSSID(String bSSID) {
- BSSID = bSSID;
- }
- /**
- * @return the sSID
- */
- public String getSSID() {
- return SSID;
- }
- /**
- * @param sSID the sSID to set
- */
- public void setSSID(String sSID) {
- SSID = sSID;
- }
- /**
- * @return the latitude
- */
- public double getLatitude() {
- return latitude;
- }
- /**
- * @param latitude the latitude to set
- */
- public void setLatitude(double latitude) {
- this.latitude = latitude;
- }
- /**
- * @return the longitude
- */
- public double getLongitude() {
- return longitude;
- }
- /**
- * @param longitude the longitude to set
- */
- public void setLongitude(double longitude) {
- this.longitude = longitude;
- }
- /**
- * @return the accuracy
- */
- public float getAccuracy() {
- return accuracy;
- }
- /**
- * @param accuracy the accuracy to set
- */
- public void setAccuracy(float accuracy) {
- this.accuracy = accuracy;
- }
- /**
- * @return the packet
- */
- public String getPacket() {
- return packet;
- }
- /**
- * @param packet the packet to set
- */
- public void setPacket(String packet) {
- this.packet = packet;
- }
- @Override
- public String toString() {
- return String.format("%d %s [%d,%s:%d,%s:%d,%s]", attack_id,
- ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), timestamp,
- localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
- remotePort, LogViewFormatter.format(getProtocol(), getPacket()));
- }
-
- /**
- * 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(...)}
- * The Integer representation of the format is equal to its position in the format array.
- * @param format Integer representation of the format.
- * @return A string representation after chosen format.
- */
- public String toString(int format){
- // Choose String Format
- switch (format){
- // ViewLogTable format: contains all important information about an attack.
- case 0:
- 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()));
- // TraCINg Upload format, replaces internal ip's with external ip of network
- case 1:
- 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);
- default:
- return toString();
- }
- }
-
- }
|