|
@@ -9,6 +9,7 @@ import javax.swing.JMenu;
|
|
import javax.swing.JMenuItem;
|
|
import javax.swing.JMenuItem;
|
|
|
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ExampleAnomalyController;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionPrecision;
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionPrecision;
|
|
@@ -59,6 +60,11 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
|
|
*/
|
|
*/
|
|
private JMenu mnValueAnomaly;
|
|
private JMenu mnValueAnomaly;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Anomaly Controller
|
|
|
|
+ */
|
|
|
|
+ private ExampleAnomalyController anomController;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Create a new MenuBar for anomaly insertion
|
|
* Create a new MenuBar for anomaly insertion
|
|
* @param controller main Controller of the framework
|
|
* @param controller main Controller of the framework
|
|
@@ -66,6 +72,7 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
|
|
public MenuBarInsertAnomalies(Controller controller) {
|
|
public MenuBarInsertAnomalies(Controller controller) {
|
|
super("Insert Example Anomaly");
|
|
super("Insert Example Anomaly");
|
|
this.controller = controller;
|
|
this.controller = controller;
|
|
|
|
+ this.anomController = controller.getNetworkController().getAnomalyController();
|
|
initialize();
|
|
initialize();
|
|
this.update(null, null);
|
|
this.update(null, null);
|
|
this.controller.addObserver(this);
|
|
this.controller.addObserver(this);
|
|
@@ -97,7 +104,7 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
|
|
* DDos Target Menu Item, which opens a DDosCreation Menu
|
|
* DDos Target Menu Item, which opens a DDosCreation Menu
|
|
*/
|
|
*/
|
|
JMenuItem mntmDDosTarget = new JMenuItem("Destination: "+d.getName());
|
|
JMenuItem mntmDDosTarget = new JMenuItem("Destination: "+d.getName());
|
|
- mntmDDosTarget.addActionListener(a->openDDosCreationMenu(d, (List<SmartDevice>)controller.getNetworkController().getVisibleSmartDevices()));
|
|
|
|
|
|
+ mntmDDosTarget.addActionListener(a->anomController.openDDosCreationMenu(d, (List<SmartDevice>)controller.getNetworkController().getVisibleSmartDevices()));
|
|
mnDDos.add(mntmDDosTarget);
|
|
mnDDos.add(mntmDDosTarget);
|
|
/**
|
|
/**
|
|
* Dos creation menus
|
|
* Dos creation menus
|
|
@@ -106,7 +113,7 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
|
|
for(SmartDevice t: controller.getNetworkController().getVisibleSmartDevices()){
|
|
for(SmartDevice t: controller.getNetworkController().getVisibleSmartDevices()){
|
|
if(d==t)continue;
|
|
if(d==t)continue;
|
|
JMenuItem mntmDosTarget = new JMenuItem("Destination: " +t.getName());
|
|
JMenuItem mntmDosTarget = new JMenuItem("Destination: " +t.getName());
|
|
- mntmDosTarget.addActionListener(a->runDosAttack(d,t));
|
|
|
|
|
|
+ mntmDosTarget.addActionListener(a->anomController.runDosAttack(d,t));
|
|
mntmDosSource.add(mntmDosTarget);
|
|
mntmDosSource.add(mntmDosTarget);
|
|
}
|
|
}
|
|
mnDos.add(mntmDosSource);
|
|
mnDos.add(mntmDosSource);
|
|
@@ -114,7 +121,7 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
|
|
* Menus to crash a device
|
|
* Menus to crash a device
|
|
*/
|
|
*/
|
|
JMenuItem crashDevice = new JMenuItem(d.getName());
|
|
JMenuItem crashDevice = new JMenuItem(d.getName());
|
|
- crashDevice.addActionListener(a->crashDevice(d));
|
|
|
|
|
|
+ crashDevice.addActionListener(a->anomController.crashDevice(d));
|
|
mnCrash.add(crashDevice);
|
|
mnCrash.add(crashDevice);
|
|
/**
|
|
/**
|
|
* Value Anomalies menus
|
|
* Value Anomalies menus
|
|
@@ -142,160 +149,4 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
|
|
mnValueAnomaly.setEnabled(mnValueAnomaly.getMenuComponentCount()!=0);
|
|
mnValueAnomaly.setEnabled(mnValueAnomaly.getMenuComponentCount()!=0);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Opens a DDosCreation Menu which targets the given Device
|
|
|
|
- * So far only a DDoS Attack is created
|
|
|
|
- * @param d Device which should be targeted
|
|
|
|
- */
|
|
|
|
- private void openDDosCreationMenu(SmartDevice d, List<SmartDevice> sources) {
|
|
|
|
- /**
|
|
|
|
- * Port of the largest connected connection to disguise DDoS
|
|
|
|
- */
|
|
|
|
- Port example = null;
|
|
|
|
- for(Port p: d.getPorts()) {
|
|
|
|
- if(example == null || example.getConnection() == null || example.getConnection().getProtocol()==null) {
|
|
|
|
- example = p;
|
|
|
|
- } else {
|
|
|
|
- if(p.getConnection() == null || p.getConnection().getProtocol() == null) {
|
|
|
|
- continue;
|
|
|
|
- } else if(p.getConnection().getParticipants().size()>example.getConnection().getParticipants().size()){
|
|
|
|
- example = p;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(example == null || example.getConnection() == null || example.getConnection().getProtocol()==null)
|
|
|
|
- example = null;
|
|
|
|
- /**
|
|
|
|
- * Role of the target device
|
|
|
|
- */
|
|
|
|
- int targetRole = 1;
|
|
|
|
- if(example != null) {
|
|
|
|
- targetRole = example.getConnection().getProtocol().getRoleOfDevice(example);
|
|
|
|
- if(targetRole == -1)
|
|
|
|
- targetRole = 1;
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * Attack Interval per device
|
|
|
|
- */
|
|
|
|
- long attackInterval = 1;
|
|
|
|
- if(example!=null) {
|
|
|
|
- int numDevices = 0;
|
|
|
|
- for(Port exP:example.getConnection().getParticipants()) {
|
|
|
|
- attackInterval+=exP.getTriggerInterval();
|
|
|
|
- numDevices++;
|
|
|
|
- }
|
|
|
|
- attackInterval /= numDevices == 0 ? 1 : numDevices;
|
|
|
|
- /**
|
|
|
|
- * Frequency Less or equal
|
|
|
|
- */
|
|
|
|
- attackInterval /= 4.0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Link of the DDoS attack
|
|
|
|
- */
|
|
|
|
- Link link = null;
|
|
|
|
- if(example !=null)
|
|
|
|
- link = example.getConnection().getLink();
|
|
|
|
- if(link == null) {
|
|
|
|
- if(d.getLinks().isEmpty()) {
|
|
|
|
- System.out.println("WARNING: Could not create DDos, as Device "+d.getName()+" is not connected to any Link");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- link = d.getLinks().get(0);
|
|
|
|
- }
|
|
|
|
- NetworkController networkController = controller.getNetworkController();
|
|
|
|
- Connection ddosConnection = new ConnectionPrecision();
|
|
|
|
- ddosConnection.setLabel((short)1);
|
|
|
|
- ddosConnection.setName("DDOS against "+d.getName());
|
|
|
|
- networkController.addConnectionToLink(ddosConnection, link);
|
|
|
|
- try {
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
- Class<Protocol> exampleProtocol = (Class<Protocol>) example.getConnection().getProtocol().getClass();
|
|
|
|
- ddosConnection.setProtocol(exampleProtocol.newInstance());
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- ddosConnection.setProtocol(new SimpleProtocol());
|
|
|
|
- }
|
|
|
|
- LinkedList<SmartDevice> devices = new LinkedList<SmartDevice>(sources);
|
|
|
|
- devices.retainAll(link.getDevices());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- Port pTarget = new Port(d, (short)80, 1000L);
|
|
|
|
- pTarget.setStatus(Port.OPEN);
|
|
|
|
- if(!networkController.addDeviceToConnectionAndProtocol(pTarget, ddosConnection, targetRole)) {
|
|
|
|
- System.out.println("WARNING: Could not add DDoS Target to role "+targetRole);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for(SmartDevice src: devices) {
|
|
|
|
- if(src==d)continue;
|
|
|
|
- Port pSource = new Port(src, (short)80, 1L);
|
|
|
|
- pSource.setTriggerHandler(new NormalDistributionHandler(attackInterval, attackInterval*0.05));
|
|
|
|
- pSource.setStatus(Port.SENDING);
|
|
|
|
- // Ten tries of assigning random role
|
|
|
|
- for(int i=0; i<10;i++) {
|
|
|
|
- int sourceRole = (int) Math.floor(Math.random()*ddosConnection.getProtocol().getNumberOfRoles());
|
|
|
|
- if(sourceRole==targetRole)
|
|
|
|
- continue;
|
|
|
|
- if(networkController.addDeviceToConnectionAndProtocol(pSource, ddosConnection, sourceRole))
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- networkController.addConnection(ddosConnection);
|
|
|
|
-
|
|
|
|
- controller.notifyObservers();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Crash Device, which wont send packets any longer
|
|
|
|
- * @param d Device to be crashed
|
|
|
|
- */
|
|
|
|
- private void crashDevice(SmartDevice d) {
|
|
|
|
- for(Port p:d.getPorts()) {
|
|
|
|
- p.setStatus(Port.CLOSED);
|
|
|
|
- }
|
|
|
|
- controller.notifyObservers();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Inserts DOS attack into the network
|
|
|
|
- * @param source
|
|
|
|
- * @param target
|
|
|
|
- */
|
|
|
|
- private void runDosAttack(SmartDevice source, SmartDevice target) {
|
|
|
|
- NetworkController networkController = controller.getNetworkController();
|
|
|
|
- Connection dosConnection = new ConnectionPrecision();
|
|
|
|
- dosConnection.setLabel((short)1);
|
|
|
|
- dosConnection.setName("DOS: "+source.getName()+"-"+target.getName());
|
|
|
|
- networkController.addConnectionToLink(dosConnection, getCommonLink(source, target));
|
|
|
|
- dosConnection.setProtocol(new SimpleProtocol());
|
|
|
|
- Port pSource = new Port(source, (short)80, 1L);
|
|
|
|
- pSource.setStatus(Port.SENDING);
|
|
|
|
- networkController.addDeviceToConnectionAndProtocol(pSource, dosConnection, 0);
|
|
|
|
- Port pTarget = new Port(target, (short)80, 1000L);
|
|
|
|
- pTarget.setStatus(Port.OPEN);
|
|
|
|
- networkController.addDeviceToConnectionAndProtocol(pSource, dosConnection, 0);
|
|
|
|
- networkController.addDeviceToConnectionAndProtocol(pTarget, dosConnection, 1);
|
|
|
|
- networkController.addConnection(dosConnection);
|
|
|
|
- controller.notifyObservers();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Returns a common Link of the given devices
|
|
|
|
- * @param a
|
|
|
|
- * @param b
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private Link getCommonLink(SmartDevice a, SmartDevice b) {
|
|
|
|
- LinkedList<Link> l = new LinkedList<Link>(a.getLinks());
|
|
|
|
- l.addAll(b.getLinks());
|
|
|
|
- if(l.isEmpty()) {
|
|
|
|
- NetworkController net = controller.getNetworkController();
|
|
|
|
- Link newLink = new PrecisionLink("Direct Link: " + a.getName()+"-"+b.getName());
|
|
|
|
- net.addLinkToDevice(newLink, a);
|
|
|
|
- net.addLinkToDevice(newLink, b);
|
|
|
|
- net.addLink(newLink);
|
|
|
|
- return newLink;
|
|
|
|
- }else
|
|
|
|
- return l.getFirst();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|