Forráskód Böngészése

Fixed bugs with SNMP,SMB,S7Comm and implemented detection of File Injection in Modbus Master Profile

Shreyas Srinivasa 9 éve
szülő
commit
5d3480e530

+ 1 - 1
build.gradle

@@ -21,7 +21,6 @@ dependencies {
     compile files('libs/nineoldandroids-2.4.0.jar')
     compile files('libs/nineoldandroids-2.4.0.jar')
     compile 'com.android.support:support-v4:18.0.0'
     compile 'com.android.support:support-v4:18.0.0'
     //compile fileTree(dir: 'libs', include: '*.jar')
     //compile fileTree(dir: 'libs', include: '*.jar')
-    compile files('libs/snmp4j-agent-2.3.3.jar')
     compile files('libs/swipelistview-1.0.jar')
     compile files('libs/swipelistview-1.0.jar')
     compile files('libs/sshlib-v1.1.jar')
     compile files('libs/sshlib-v1.1.jar')
     compile files('libs/chart-library2.2.jar')
     compile files('libs/chart-library2.2.jar')
@@ -29,6 +28,7 @@ dependencies {
     compile files('libs/alfresco-jlan.jar')
     compile files('libs/alfresco-jlan.jar')
     compile files('libs/cryptix-jce-provider.jar')
     compile files('libs/cryptix-jce-provider.jar')
     compile 'org.snmp4j:snmp4j:1.10.1'
     compile 'org.snmp4j:snmp4j:1.10.1'
+    compile files('libs/snmp4j-agent-2.3.3.jar')
 }
 }
 
 
 android {
 android {

BIN
res/drawable-hdpi/ic_profile_snmp.png


+ 18 - 0
res/layout/fragment_file_alert.xml

@@ -0,0 +1,18 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="de.tudarmstadt.informatik.hostage.ui.fragment.FileAlert">
+
+    <!-- TODO: Update blank fragment layout -->
+    <TextView android:layout_width="match_parent" android:layout_height="match_parent"
+        android:text="@string/hello_blank_fragment" />
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceSmall"
+        android:text="Small Text"
+        android:id="@+id/FileAlertText"
+        android:layout_gravity="left|center_vertical" />
+
+</FrameLayout>

+ 1 - 1
res/values/protocols.xml

@@ -26,7 +26,7 @@
         <item>The world\'s second most widely used relational database management system</item>
         <item>The world\'s second most widely used relational database management system</item>
         <item>ICS SCADA MODBUS</item>
         <item>ICS SCADA MODBUS</item>
         <item>Siemens SIMATIC Communication Protocol</item>
         <item>Siemens SIMATIC Communication Protocol</item>
-        <item>Simple Network Monitoring Protocol</item>
+        <item>Simple Network Management Protocol</item>
         <item>A protocol for VoIP (Voice over IP) services</item>
         <item>A protocol for VoIP (Voice over IP) services</item>
         <item>A protocol used for providing shared access to files, printers, serial ports, and miscellaneous communications between nodes on a network</item>
         <item>A protocol used for providing shared access to files, printers, serial ports, and miscellaneous communications between nodes on a network</item>
         <item>A network protocol that provides file access, file transfer, and file management functionalities over any reliable data stream</item>
         <item>A network protocol that provides file access, file transfer, and file management functionalities over any reliable data stream</item>

+ 3 - 0
res/values/strings.xml

@@ -273,4 +273,7 @@
 	</string>
 	</string>
     <string name="pref_sync_frequency_summary">The interval in minutes synchronization with TraCINg should be performed</string>
     <string name="pref_sync_frequency_summary">The interval in minutes synchronization with TraCINg should be performed</string>
     <string name="pref_sync_frequency_title">Synchronization interval</string>
     <string name="pref_sync_frequency_title">Synchronization interval</string>
+
+<!-- TODO: Remove or change this placeholder text -->
+    <string name="hello_blank_fragment">Hello blank fragment</string>
 </resources>
 </resources>

+ 5 - 0
src/de/tudarmstadt/informatik/hostage/Hostage.java

@@ -13,11 +13,13 @@ import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.util.EntityUtils;
 import org.apache.http.util.EntityUtils;
 import org.json.JSONObject;
 import org.json.JSONObject;
 
 
+import android.app.AlertDialog;
 import android.app.NotificationManager;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.PendingIntent;
 import android.app.Service;
 import android.app.Service;
 import android.content.BroadcastReceiver;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences;
@@ -655,4 +657,7 @@ public class Hostage extends Service {
 		this.mProtocolActiveAttacks.clear();		
 		this.mProtocolActiveAttacks.clear();		
 	}
 	}
 
 
+
+
+
 }
 }

+ 21 - 17
src/de/tudarmstadt/informatik/hostage/Listener.java

@@ -15,6 +15,8 @@ import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences;
 import android.preference.PreferenceManager;
 import android.preference.PreferenceManager;
 
 
+import org.snmp4j.agent.BaseAgent;
+
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
 import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
 import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
 import de.tudarmstadt.informatik.hostage.logging.AttackRecord;
@@ -24,6 +26,7 @@ import de.tudarmstadt.informatik.hostage.net.MyServerSocketFactory;
 import de.tudarmstadt.informatik.hostage.protocol.SMB;
 import de.tudarmstadt.informatik.hostage.protocol.SMB;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.SNMP;
 import de.tudarmstadt.informatik.hostage.protocol.SNMP;
+
 import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
 import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
 import de.tudarmstadt.informatik.hostage.system.Device;
 import de.tudarmstadt.informatik.hostage.system.Device;
 
 
@@ -132,8 +135,9 @@ public class Listener implements Runnable {
 
 
 	@Override
 	@Override
 	public void run() {
 	public void run() {
-        if(protocol.toString().equals("SMB")) return;
-		if(protocol.toString().equals("SNMP")) return;
+		if (protocol.toString().equals("SMB")) return;
+
+				//||(protocol.toString().equals("SNMP"))) return;
 
 
 		while (!thread.isInterrupted()) {
 		while (!thread.isInterrupted()) {
 			addHandler();
 			addHandler();
@@ -168,23 +172,23 @@ public class Listener implements Runnable {
             ((SMB) protocol).initialize(this);
             ((SMB) protocol).initialize(this);
         }
         }
 
 
-		else {
-			if (protocol.toString().equals("SNMP")) {
+	//	else if (protocol.toString().equals("SNMP")) {
 
 
-				if (!Device.isPortRedirectionAvailable()) {
-					return false;
-				}
-				if (Device.isPorthackInstalled()) {
+		//	if (!Device.isPortRedirectionAvailable()) {
+			//		return false;
+		//	}
+		//	if (Device.isPorthackInstalled()) {
 				/*
 				/*
 				Currently the port binder is the preferred method for creating sockets.
 				Currently the port binder is the preferred method for creating sockets.
 				If it installed, we can't use iptables to create UDP sockets.
 				If it installed, we can't use iptables to create UDP sockets.
 				@see MyServerSocketFactory
 				@see MyServerSocketFactory
 				 */
 				 */
-					return false;
-				}
-				((SNMP) protocol).start();
-			}
-		}
+		//		return false;
+		//	}
+		//	((SNMP) protocol).setUp();
+
+
+		//}
 
 
 		try {
 		try {
 			server = new MyServerSocketFactory().createServerSocket(port);
 			server = new MyServerSocketFactory().createServerSocket(port);
@@ -209,10 +213,10 @@ public class Listener implements Runnable {
             if(protocol.toString().equals("SMB")){
             if(protocol.toString().equals("SMB")){
                 ((SMB) protocol).stop();
                 ((SMB) protocol).stop();
 
 
-			if(protocol.toString().equals("SNMP")){
-				((SNMP)protocol).stop();
-			}
-            }
+		//if(protocol.toString().equals("SNMP")){
+		//	((SNMP)protocol).stop();
+		//	}
+         }
 
 
 			server.close();
 			server.close();
 			thread.interrupt();
 			thread.interrupt();

+ 22 - 0
src/de/tudarmstadt/informatik/hostage/commons/HelperUtils.java

@@ -58,6 +58,28 @@ import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
  */
  */
 public final class HelperUtils {
 public final class HelperUtils {
 
 
+
+	public static boolean isFileAlert() {
+		return fileAlert;
+	}
+
+	public static void setFileAlert(boolean fileAlert) {
+		HelperUtils.fileAlert = fileAlert;
+	}
+
+	public static String getFileName() {
+		return fileName;
+	}
+
+	public static void setFileName(String fileName) {
+		HelperUtils.fileName = fileName;
+	}
+
+	public static boolean fileAlert = false;
+	public static String fileName;
+
+
+
 	/**
 	/**
 	 * Converts a byte array into a hexadecimal String, e.g. {0x00, 0x01} to
 	 * Converts a byte array into a hexadecimal String, e.g. {0x00, 0x01} to
 	 * "00, 01".
 	 * "00, 01".

+ 22 - 3
src/de/tudarmstadt/informatik/hostage/persistence/ProfileManager.java

@@ -41,7 +41,7 @@ import de.tudarmstadt.informatik.hostage.ui.adapter.ProfileManagerListAdapter;
  * @author Alexander Brakowski
  * @author Alexander Brakowski
  * @created 10.02.14 20:24
  * @created 10.02.14 20:24
  */
  */
-public class ProfileManager {
+public class  ProfileManager {
 
 
 	/**
 	/**
 	 * The singleton instance holder
 	 * The singleton instance holder
@@ -682,7 +682,8 @@ public class ProfileManager {
 
 
 		modbusMaster.mActiveProtocols.put("MODBUS",true);
 		modbusMaster.mActiveProtocols.put("MODBUS",true);
 		modbusMaster.mActiveProtocols.put("SMB",true);
 		modbusMaster.mActiveProtocols.put("SMB",true);
-		modbusMaster.mActiveProtocols.put("SMB", true);
+		modbusMaster.mActiveProtocols.put("SNMP", true);
+		modbusMaster.mActiveProtocols.put("S7COMM",true);
 		modbusMaster.mGhostActive = true;
 		modbusMaster.mGhostActive = true;
 		modbusMaster.mGhostPorts = "135";
 		modbusMaster.mGhostPorts = "135";
 
 
@@ -694,8 +695,26 @@ public class ProfileManager {
 
 
 		this.addProfile(modbusMaster, false);
 		this.addProfile(modbusMaster, false);
 
 
-		Profile paranoidProfile = new Profile(
+		Profile SNMPProfile = new Profile(
 				11,
 				11,
+				"SNMP",
+				"This profile provides SNMP service",
+				R.drawable.ic_profile_snmp,
+				false
+
+		);
+
+		SNMPProfile.mActiveProtocols.put("SNMP",true);
+		this.addProfile(SNMPProfile,false);
+
+
+
+
+
+
+
+		Profile paranoidProfile = new Profile(
+				12,
 				"Paranoid",
 				"Paranoid",
                 MainActivity.getInstance().getString(R.string.profile_paranoid_desc),
                 MainActivity.getInstance().getString(R.string.profile_paranoid_desc),
 				R.drawable.ic_profile_paranoid,
 				R.drawable.ic_profile_paranoid,

+ 1 - 0
src/de/tudarmstadt/informatik/hostage/protocol/MODBUS.java

@@ -34,6 +34,7 @@ public class MODBUS implements Protocol {
         return "MODBUS";
         return "MODBUS";
     }
     }
 
 
+    @Override
     public TALK_FIRST whoTalksFirst() {
     public TALK_FIRST whoTalksFirst() {
         return TALK_FIRST.CLIENT;
         return TALK_FIRST.CLIENT;
     }
     }

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/protocol/S7COMM.java

@@ -36,7 +36,7 @@ public class S7COMM implements Protocol {
 
 
             //getRequestType(request);
             //getRequestType(request);
 
 
-            responsePackets.add(new Packet(request,"")); // Response packets have to be studied yet
+            responsePackets.add(requestPacket); // Response packets have to be studied yet
             System.out.println(responsePackets);
             System.out.println(responsePackets);
 
 
 
 

+ 151 - 84
src/de/tudarmstadt/informatik/hostage/protocol/SNMP.java

@@ -1,24 +1,14 @@
 package de.tudarmstadt.informatik.hostage.protocol;
 package de.tudarmstadt.informatik.hostage.protocol;
 
 
 import android.content.SharedPreferences;
 import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
 
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import de.tudarmstadt.informatik.hostage.Hostage;
-import de.tudarmstadt.informatik.hostage.Listener;
-import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.wrapper.Packet;
-
-import org.alfresco.jlan.server.auth.spnego.OID;
 import org.snmp4j.TransportMapping;
 import org.snmp4j.TransportMapping;
 import org.snmp4j.agent.BaseAgent;
 import org.snmp4j.agent.BaseAgent;
 import org.snmp4j.agent.CommandProcessor;
 import org.snmp4j.agent.CommandProcessor;
 import org.snmp4j.agent.DuplicateRegistrationException;
 import org.snmp4j.agent.DuplicateRegistrationException;
 import org.snmp4j.agent.MOGroup;
 import org.snmp4j.agent.MOGroup;
 import org.snmp4j.agent.ManagedObject;
 import org.snmp4j.agent.ManagedObject;
+import org.snmp4j.agent.mo.MOAccessImpl;
 import org.snmp4j.agent.mo.MOTableRow;
 import org.snmp4j.agent.mo.MOTableRow;
 import org.snmp4j.agent.mo.snmp.RowStatus;
 import org.snmp4j.agent.mo.snmp.RowStatus;
 import org.snmp4j.agent.mo.snmp.SnmpCommunityMIB;
 import org.snmp4j.agent.mo.snmp.SnmpCommunityMIB;
@@ -32,16 +22,30 @@ import org.snmp4j.security.SecurityLevel;
 import org.snmp4j.security.SecurityModel;
 import org.snmp4j.security.SecurityModel;
 import org.snmp4j.security.USM;
 import org.snmp4j.security.USM;
 import org.snmp4j.smi.Address;
 import org.snmp4j.smi.Address;
+import org.snmp4j.smi.Gauge32;
 import org.snmp4j.smi.GenericAddress;
 import org.snmp4j.smi.GenericAddress;
 import org.snmp4j.smi.Integer32;
 import org.snmp4j.smi.Integer32;
+import org.snmp4j.smi.OID;
 import org.snmp4j.smi.OctetString;
 import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.SMIConstants;
 import org.snmp4j.smi.Variable;
 import org.snmp4j.smi.Variable;
 import org.snmp4j.transport.TransportMappings;
 import org.snmp4j.transport.TransportMappings;
 
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import de.tudarmstadt.informatik.hostage.Listener;
+import de.tudarmstadt.informatik.hostage.protocol.SNMPUtils.MOTableBuilder;
+import de.tudarmstadt.informatik.hostage.wrapper.Packet;
+
 /**
 /**
  * Created by root on 06.07.15.
  * Created by root on 06.07.15.
  */
  */
 public class SNMP extends BaseAgent implements Protocol {
 public class SNMP extends BaseAgent implements Protocol {
+
+
     @Override
     @Override
     public int getPort() {
     public int getPort() {
         return 161;
         return 161;
@@ -59,12 +63,22 @@ public class SNMP extends BaseAgent implements Protocol {
 
 
     @Override
     @Override
     public List<Packet> processMessage(Packet requestPacket) {
     public List<Packet> processMessage(Packet requestPacket) {
-        return null;
+        List<Packet> responsePackets = new ArrayList<Packet>();
+
+        responsePackets.add(requestPacket);
+
+        try {
+            setUp();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return responsePackets;
     }
     }
 
 
     @Override
     @Override
     public TALK_FIRST whoTalksFirst() {
     public TALK_FIRST whoTalksFirst() {
-        return null;
+        return TALK_FIRST.CLIENT;
     }
     }
 
 
     @Override
     @Override
@@ -73,42 +87,67 @@ public class SNMP extends BaseAgent implements Protocol {
     }
     }
 
 
 
 
-    private String address;
 
 
-    private String externalIP;
+        private String address;
 
 
-    SharedPreferences pref1;
+        private String externalIP;
 
 
-    private Listener sListener;
+        SharedPreferences pref1;
+
+        private Listener sListener;
+
+        public SNMP(String address) throws IOException {
+
+            super(new File("conf.agent"), new File("bootCounter.agent"),
+                    new CommandProcessor(
+                            new OctetString(MPv3.createLocalEngineID())));
+            this.address = address;
+        }
 
 
-    public SNMP(String address) throws IOException {
 
 
-        super(new File("conf.agent"), new File("bootCounter.agent"),
-                new CommandProcessor(
-                        new OctetString(MPv3.createLocalEngineID())));
-        this.address = address;
-    }
 
 
     @Override
     @Override
-    protected void registerManagedObjects() {
+    protected void addCommunities(SnmpCommunityMIB snmpCommunityMIB) {
 
 
+        Variable[] com2sec = new Variable[]{
+
+                new OctetString("public"),
+
+                new OctetString("cpublic"), // security name
+
+                getAgent().getContextEngineID(), // local engine ID
+
+                new OctetString("public"), // default context name
+
+                new OctetString(), // transport tag
+
+                new Integer32(StorageType.nonVolatile), // storage type
+
+                new Integer32(RowStatus.active) // row status
+
+        };
+
+        MOTableRow row = snmpCommunityMIB.getSnmpCommunityEntry().createRow(
+
+            new OctetString("public2public").toSubIndex(true), com2sec);
+
+            snmpCommunityMIB.getSnmpCommunityEntry().addRow((SnmpCommunityMIB.SnmpCommunityEntryRow) row);
     }
     }
 
 
+
     @Override
     @Override
-    protected void unregisterManagedObjects() {
+    protected void addNotificationTargets(SnmpTargetMIB snmpTargetMIB, SnmpNotificationMIB snmpNotificationMIB) {
 
 
     }
     }
 
 
+
     @Override
     @Override
     protected void addUsmUser(USM usm) {
     protected void addUsmUser(USM usm) {
 
 
     }
     }
 
 
 
 
-    @Override
-    protected void addNotificationTargets(SnmpTargetMIB snmpTargetMIB, SnmpNotificationMIB snmpNotificationMIB) {
 
 
-    }
 
 
     @Override
     @Override
     protected void addViews(VacmMIB vacmMIB) {
     protected void addViews(VacmMIB vacmMIB) {
@@ -124,95 +163,123 @@ public class SNMP extends BaseAgent implements Protocol {
                 new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
                 new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
     }
     }
 
 
-    @Override
-    protected void addCommunities(SnmpCommunityMIB snmpCommunityMIB) {
 
 
-        Variable[] com2sec = new Variable[]{new OctetString("public"),
 
 
-                new OctetString("cpublic"), // security name
 
 
-                getAgent().getContextEngineID(), // local engine ID
-
-                new OctetString("public"), // default context name
 
 
-                new OctetString(), // transport tag
+        @Override
+        protected void registerManagedObjects() {
 
 
-                new Integer32(StorageType.nonVolatile), // storage type
+        }
 
 
-                new Integer32(RowStatus.active) // row status
+        @Override
+        protected void unregisterManagedObjects() {
 
 
-        };
+        }
 
 
-        MOTableRow row = snmpCommunityMIB.getSnmpCommunityEntry().createRow(
 
 
-                new OctetString("public2public").toSubIndex(true), com2sec);
 
 
-        snmpCommunityMIB.getSnmpCommunityEntry().addRow((SnmpCommunityMIB.SnmpCommunityEntryRow) row);
+    public SNMP() {
+        super("");
     }
     }
 
 
-    public void start() {
 
 
-        try {
-            init();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        // This method reads some old config from a file and causes
-        // unexpected behavior.
-        // loadConfig(ImportModes.REPLACE_CREATE);
-        addShutdownHook();
-        getServer().addContext(new OctetString("public"));
 
 
 
 
-        finishInit();
-        run();
-        sendColdStartNotification();
-    }
 
 
+        public void start() throws IOException{
 
 
-    protected void initTransportMappings() {
-        transportMappings = new TransportMapping[1];
-        Address addr = GenericAddress.parse(address);
 
 
-        TransportMapping tm = TransportMappings.getInstance()
-                .createTransportMapping(addr);
-        transportMappings[0] = tm;
-    }
+                init();
+            try {
+                setUp();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
 
 
 
 
-    public void registerManagedObject(ManagedObject mo) {
-        try {
-            server.register(mo, null);
-        } catch (DuplicateRegistrationException ex) {
+            // This method reads some old config from a file and causes
+            // unexpected behavior.
+            // loadConfig(ImportModes.REPLACE_CREATE);
+            addShutdownHook();
+            getServer().addContext(new OctetString("public"));
+            finishInit();
+            run();
+            sendColdStartNotification();
+        }
+
+
+        protected void initTransportMappings() throws IOException {
+            transportMappings = new TransportMapping[1];
+            Address addr = GenericAddress.parse(address);
 
 
-            throw new RuntimeException(ex);
+            TransportMapping tm = TransportMappings.getInstance()
+                    .createTransportMapping(addr);
+            transportMappings[0] = tm;
         }
         }
 
 
-    }
 
 
+        public void registerManagedObject(ManagedObject mo) {
+            try {
+                server.register(mo, null);
+            } catch (DuplicateRegistrationException ex) {
+
+                throw new RuntimeException(ex);
+            }
 
 
-    public void unregisterManagedObject(MOGroup moGroup) {
-        moGroup.unregisterMOs(server, getContext(moGroup));
-    }
 
 
+        }
 
 
-    //Listner for SNMP
-    public Listener getListener() {
-        return sListener;
 
 
+    public void unregisterManagedObject(MOGroup moGroup) {
+        moGroup.unregisterMOs(server, getContext(moGroup));
     }
     }
 
 
 
 
-    public void initialize(Listener sListener) {
 
 
-        this.sListener = sListener;
-
-     //   Hostage service = sListener.getService();
-      //  pref1 = PreferenceManager.getDefaultSharedPreferences(service);
-      //  agent = new SNMP();
-      //  externalIP = connInfo.getString(service.getString(R.string.connection_info_external_ip), null);
+    // standard in RFC-1213
+    static final OID interfacesTable = new OID(".1.3.6.1.2.1.2.2.1");
+
+    public static void setUp() throws Exception {
+        
+     SNMP  agent = new SNMP("0.0.0.0/161");
+        agent.start();
+
+        MOTableBuilder builder = new MOTableBuilder(interfacesTable)
+                .addColumnType(SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_ONLY)
+                .addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_READ_ONLY)
+                .addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_ONLY)
+                .addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_ONLY)
+                .addColumnType(SMIConstants.SYNTAX_GAUGE32,MOAccessImpl.ACCESS_READ_ONLY)
+                .addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_READ_ONLY)
+                .addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_ONLY)
+                .addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_ONLY)
+
+                
+                .addRowValue(new Integer32(1))
+                .addRowValue(new OctetString("loopback"))
+                .addRowValue(new Integer32(24))
+                .addRowValue(new Integer32(1500))
+                .addRowValue(new Gauge32(10000000))
+                .addRowValue(new OctetString("00:00:00:00:01"))
+                .addRowValue(new Integer32(1500))
+                .addRowValue(new Integer32(1500))
+//next row
+                .addRowValue(new Integer32(2))
+                .addRowValue(new OctetString("eth0"))
+                .addRowValue(new Integer32(24))
+                .addRowValue(new Integer32(1500))
+                .addRowValue(new Gauge32(10000000))
+                .addRowValue(new OctetString("00:00:00:00:02"))
+                .addRowValue(new Integer32(1500))
+                .addRowValue(new Integer32(1500));
+
+        agent.registerManagedObject(builder.build());
+
+// Setup the client to use our newly started agent
+        //client = new SimpleSnmpClient("udp:127.0.0.1/2001");
+    }
 
 
 
 
 
 
     }
     }
-}

+ 11 - 0
src/de/tudarmstadt/informatik/hostage/protocol/cifs/CifsServer.java

@@ -3,6 +3,7 @@ package de.tudarmstadt.informatik.hostage.protocol.cifs;
 import android.content.Context;
 import android.content.Context;
 import android.net.DhcpInfo;
 import android.net.DhcpInfo;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WifiManager;
+import android.widget.Toast;
 
 
 import org.alfresco.jlan.app.JLANCifsServer;
 import org.alfresco.jlan.app.JLANCifsServer;
 import org.alfresco.jlan.app.XMLServerConfiguration;
 import org.alfresco.jlan.app.XMLServerConfiguration;
@@ -88,6 +89,7 @@ public class CifsServer extends JLANCifsServer {
         File progData = new File(jlanFolder.getAbsolutePath() + "/ProgramData");
         File progData = new File(jlanFolder.getAbsolutePath() + "/ProgramData");
         File users = new File(jlanFolder.getAbsolutePath() + "/Users");
         File users = new File(jlanFolder.getAbsolutePath() + "/Users");
         File temp= new File(jlanFolder.getAbsolutePath() + "/temp");
         File temp= new File(jlanFolder.getAbsolutePath() + "/temp");
+
         jlanFolder.mkdir();
         jlanFolder.mkdir();
         anotherFolder.mkdir();
         anotherFolder.mkdir();
         progData.mkdir();
         progData.mkdir();
@@ -120,8 +122,17 @@ public class CifsServer extends JLANCifsServer {
                     public void fileClosed(SrvSession sess, NetworkFile file) {
                     public void fileClosed(SrvSession sess, NetworkFile file) {
                     }
                     }
 
 
+
+
+
                     @Override
                     @Override
                     public void fileOpened(SrvSession sess, NetworkFile file) {
                     public void fileOpened(SrvSession sess, NetworkFile file) {
+
+                        file.getName();
+                        System.out.print(file.getName());
+
+                        file.getFullName();
+
                     }
                     }
                 });
                 });
             }
             }

+ 67 - 0
src/de/tudarmstadt/informatik/hostage/protocol/cifs/PseudoJavaFileDiskDriver.java

@@ -1,5 +1,14 @@
 package de.tudarmstadt.informatik.hostage.protocol.cifs;
 package de.tudarmstadt.informatik.hostage.protocol.cifs;
 
 
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.FragmentManager;
+import android.app.Notification;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.widget.Toast;
+
 import org.alfresco.jlan.server.SrvSession;
 import org.alfresco.jlan.server.SrvSession;
 import org.alfresco.jlan.server.core.DeviceContext;
 import org.alfresco.jlan.server.core.DeviceContext;
 import org.alfresco.jlan.server.filesys.FileExistsException;
 import org.alfresco.jlan.server.filesys.FileExistsException;
@@ -9,6 +18,7 @@ import org.alfresco.jlan.server.filesys.NetworkFile;
 import org.alfresco.jlan.server.filesys.TreeConnection;
 import org.alfresco.jlan.server.filesys.TreeConnection;
 import org.alfresco.jlan.smb.server.disk.JavaFileDiskDriver;
 import org.alfresco.jlan.smb.server.disk.JavaFileDiskDriver;
 import org.alfresco.jlan.smb.server.disk.JavaNetworkFile;
 import org.alfresco.jlan.smb.server.disk.JavaNetworkFile;
+import org.apache.log4j.chainsaw.Main;
 
 
 import java.io.File;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileInputStream;
@@ -17,8 +27,14 @@ import java.math.BigInteger;
 import java.security.MessageDigest;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchAlgorithmException;
 
 
+import de.tudarmstadt.informatik.hostage.Hostage;
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
 import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
 import de.tudarmstadt.informatik.hostage.protocol.SMB;
 import de.tudarmstadt.informatik.hostage.protocol.SMB;
+import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
+import de.tudarmstadt.informatik.hostage.ui.fragment.ConnectionInfoDialogFragment;
+import de.tudarmstadt.informatik.hostage.ui.fragment.FileAlertDialogFragment;
+import de.tudarmstadt.informatik.hostage.ui.fragment.HomeFragment;
 
 
 /**
 /**
  * HostageV3
  * HostageV3
@@ -30,17 +46,27 @@ import de.tudarmstadt.informatik.hostage.protocol.SMB;
  * so that we can get more information about the attack
  * so that we can get more information about the attack
  */
  */
 public class PseudoJavaFileDiskDriver extends JavaFileDiskDriver {
 public class PseudoJavaFileDiskDriver extends JavaFileDiskDriver {
+
+
+
+
     private static class PseudoJavaNetworkFile extends JavaNetworkFile {
     private static class PseudoJavaNetworkFile extends JavaNetworkFile {
         protected final SMB SMB;
         protected final SMB SMB;
         private final SrvSession sess;
         private final SrvSession sess;
         boolean wasWrittenTo = false;
         boolean wasWrittenTo = false;
 
 
+
+
+
+
         public PseudoJavaNetworkFile(File file, String netPath, SMB SMB, SrvSession sess) {
         public PseudoJavaNetworkFile(File file, String netPath, SMB SMB, SrvSession sess) {
             super(file, netPath);
             super(file, netPath);
             this.SMB = SMB;
             this.SMB = SMB;
             this.sess = sess;
             this.sess = sess;
         }
         }
 
 
+        Context context = null;
+
         /**
         /**
          * method that checks if the file was just written, then gets the MD5 checksum of the
          * method that checks if the file was just written, then gets the MD5 checksum of the
          * file and logs it. Afterwards the file gets deleted.
          * file and logs it. Afterwards the file gets deleted.
@@ -64,6 +90,8 @@ public class PseudoJavaFileDiskDriver extends JavaFileDiskDriver {
 
 
                     String message = "File received: " + m_file.getName() + "\n\nCHECKSUM:\n" + checksum;
                     String message = "File received: " + m_file.getName() + "\n\nCHECKSUM:\n" + checksum;
 
 
+                    System.out.print(m_file.getName());
+
                     SMB.log(MessageRecord.TYPE.RECEIVE, message, 445, sess.getRemoteAddress(), 445);
                     SMB.log(MessageRecord.TYPE.RECEIVE, message, 445, sess.getRemoteAddress(), 445);
                 } catch (NoSuchAlgorithmException e) {
                 } catch (NoSuchAlgorithmException e) {
                     e.printStackTrace();
                     e.printStackTrace();
@@ -101,14 +129,29 @@ public class PseudoJavaFileDiskDriver extends JavaFileDiskDriver {
         //  Check if the file already exists
         //  Check if the file already exists
 
 
         File file = new File(fname);
         File file = new File(fname);
+        System.out.print(fname);
+
+
+
+
+
         if (file.exists())
         if (file.exists())
             throw new FileExistsException();
             throw new FileExistsException();
 
 
         //  Create the new file
         //  Create the new file
 
 
         FileWriter newFile = new FileWriter(fname, false);
         FileWriter newFile = new FileWriter(fname, false);
+
+
+        HelperUtils.setFileAlert(true);
+        HelperUtils.setFileName(fname);
+
+
+
         newFile.close();
         newFile.close();
 
 
+
+
         //  Create a Java network file
         //  Create a Java network file
 
 
         file = new File(fname);
         file = new File(fname);
@@ -117,7 +160,31 @@ public class PseudoJavaFileDiskDriver extends JavaFileDiskDriver {
         netFile.setFullName(params.getPath());
         netFile.setFullName(params.getPath());
 
 
         //  Return the network file
         //  Return the network file
+       // Toast.makeText(MainActivity.getInstance().getApplicationContext(),fname,Toast.LENGTH_LONG).show();
+
+
+        displayAlert();
+
+
+
 
 
         return netFile;
         return netFile;
+
+
     }
     }
+
+    private void displayAlert() {
+
+        Context context = null;
+        final Activity activity = (MainActivity)context;
+
+        final FragmentManager fragmentManager = activity.getFragmentManager();
+        if (fragmentManager != null) {
+            FileAlertDialogFragment fileAlertDialogFragment = new FileAlertDialogFragment();
+            fileAlertDialogFragment.show(fragmentManager.beginTransaction(), fileAlertDialogFragment.getTag());
+        }
+
+    }
+
+
 }
 }

+ 4 - 0
src/de/tudarmstadt/informatik/hostage/ui/activity/MainActivity.java

@@ -786,4 +786,8 @@ public class MainActivity extends Activity {
 			displayView(position);
 			displayView(position);
 		}
 		}
 	}
 	}
+
+
+
+
 }
 }

+ 89 - 0
src/de/tudarmstadt/informatik/hostage/ui/fragment/FileAlertDialogFragment.java

@@ -0,0 +1,89 @@
+package de.tudarmstadt.informatik.hostage.ui.fragment;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.ContextThemeWrapper;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.persistence.ProfileManager;
+import de.tudarmstadt.informatik.hostage.ui.model.LogFilter;
+import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
+
+/**
+ * Created by Fabio Arnold on 03.03.14.
+ * displays details about the current connection
+ */
+public class FileAlertDialogFragment extends DialogFragment {
+    public Dialog onCreateDialog(Bundle savedInstance) {
+        // the data we want to display
+        String fname= "undefined";
+        String ssid = "undefined";
+        String protocol = "undefined";
+        ProfileManager mProfileManager;
+        mProfileManager = ProfileManager.getInstance();
+
+
+
+
+        // get infos about the current connection using SharedPreferences
+        final Activity activity = getActivity();
+        if (activity != null) {
+            fname = HelperUtils.getFileName();
+            SharedPreferences sharedPreferences = activity.getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
+            ssid = sharedPreferences.getString(getString(R.string.connection_info_ssid), "");
+            protocol = "SMB";
+        }
+
+        // inflate the layout with a dark theme
+        Context context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo);
+        LayoutInflater localInflater = getActivity().getLayoutInflater().cloneInContext(context);
+        View view = localInflater.inflate(R.layout.fragment_file_alert, null);
+
+        // assign values in layout
+        if (view != null) {
+            ((TextView)view.findViewById(R.id.FileAlertText)).setText(fname);
+
+        }
+
+        // capture the SSID for the button action
+        final String filterSSID = ssid;
+        final String filterProtocol = protocol;
+
+        // build the actual dialog
+        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_DARK);
+        builder.setView(view);
+        builder.setTitle("File Injection Alert");
+        builder.setIcon(android.R.drawable.ic_dialog_info);
+        builder.setPositiveButton(R.string.show_records, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                ArrayList<String> ssids = new ArrayList<String>();
+                ssids.add(filterProtocol);
+
+                LogFilter filter = new LogFilter();
+                filter.setESSIDs(ssids);
+
+                RecordOverviewFragment recordOverviewFragment = new RecordOverviewFragment();
+                recordOverviewFragment.setFilter(filter);
+                recordOverviewFragment.setGroupKey("ESSID");
+
+                MainActivity.getInstance().injectFragment(recordOverviewFragment);
+            }
+        });
+        builder.setNegativeButton(R.string.close, null);
+
+        return builder.create();
+    }
+}

+ 51 - 4
src/de/tudarmstadt/informatik/hostage/ui/fragment/HomeFragment.java

@@ -1,5 +1,6 @@
 package de.tudarmstadt.informatik.hostage.ui.fragment;
 package de.tudarmstadt.informatik.hostage.ui.fragment;
 
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.List;
 import java.util.List;
@@ -15,6 +16,7 @@ import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences;
+import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.support.v4.content.LocalBroadcastManager;
 import android.support.v4.content.LocalBroadcastManager;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
@@ -79,6 +81,17 @@ public class HomeFragment extends Fragment {
 	private boolean isActive = false;
 	private boolean isActive = false;
 	private boolean isConnected = false;
 	private boolean isConnected = false;
 
 
+	public Context getContext() {
+		return context;
+	}
+
+	public void setContext(Context context) {
+		this.context = context;
+	}
+
+	public Context context;
+
+
 	private ThreatIndicatorGLRenderer.ThreatLevel mThreatLevel = ThreatIndicatorGLRenderer.ThreatLevel.NOT_MONITORING;
 	private ThreatIndicatorGLRenderer.ThreatLevel mThreatLevel = ThreatIndicatorGLRenderer.ThreatLevel.NOT_MONITORING;
 
 
 	private void assignViews() {
 	private void assignViews() {
@@ -170,6 +183,8 @@ public class HomeFragment extends Fragment {
 			mHomeProfileImage.setImageBitmap(profile.getIconBitmap());
 			mHomeProfileImage.setImageBitmap(profile.getIconBitmap());
 		}
 		}
 
 
+		//new FileAlertTask().execute();
+
 		if (HelperUtils.isNetworkAvailable(getActivity())) {
 		if (HelperUtils.isNetworkAvailable(getActivity())) {
 			setStateConnected();
 			setStateConnected();
 			String ssid = mConnectionInfo.getString(getString(R.string.connection_info_ssid), "");
 			String ssid = mConnectionInfo.getString(getString(R.string.connection_info_ssid), "");
@@ -238,6 +253,7 @@ public class HomeFragment extends Fragment {
 		} else {
 		} else {
 			setStateNotActive();
 			setStateNotActive();
 		}
 		}
+
 	}
 	}
 
 
 	@Override
 	@Override
@@ -260,8 +276,8 @@ public class HomeFragment extends Fragment {
 		mRootView.findViewById(R.id.surfaceview).setOnTouchListener(new View.OnTouchListener() {
 		mRootView.findViewById(R.id.surfaceview).setOnTouchListener(new View.OnTouchListener() {
 			@Override
 			@Override
 			public boolean onTouch(View v, MotionEvent event) {
 			public boolean onTouch(View v, MotionEvent event) {
-				float relx = event.getX() / (float)v.getWidth();
-				float rely = event.getY() / (float)v.getHeight();
+				float relx = event.getX() / (float) v.getWidth();
+				float rely = event.getY() / (float) v.getHeight();
 				if (relx < 0.25f || relx > 0.75f) return false;
 				if (relx < 0.25f || relx > 0.75f) return false;
 				if (rely < 0.25f || rely > 0.9f) return false;
 				if (rely < 0.25f || rely > 0.9f) return false;
 
 
@@ -352,7 +368,7 @@ public class HomeFragment extends Fragment {
 										.setPositiveButton(android.R.string.ok,
 										.setPositiveButton(android.R.string.ok,
 												new DialogInterface.OnClickListener() {
 												new DialogInterface.OnClickListener() {
 													public void onClick(DialogInterface dialog,
 													public void onClick(DialogInterface dialog,
-															int which) {
+																		int which) {
 
 
 													}
 													}
 												}).setIcon(android.R.drawable.ic_dialog_info)
 												}).setIcon(android.R.drawable.ic_dialog_info)
@@ -425,4 +441,35 @@ public class HomeFragment extends Fragment {
 		super.onDestroy();
 		super.onDestroy();
 		unregisterBroadcastReceiver();
 		unregisterBroadcastReceiver();
 	}
 	}
-}
+
+
+	public void AlertFile(String fname) {
+
+
+		AlertDialog alert = new AlertDialog.Builder(getActivity()).create();
+		alert.setTitle("Delete entry");
+		alert.setMessage("Are you sure you want to delete this entry?:\n" + fname);
+		alert.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
+				new DialogInterface.OnClickListener() {
+					public void onClick(DialogInterface dialog, int which) {
+						dialog.dismiss();
+					}
+				});
+		alert.show();
+
+
+	}
+
+
+
+
+
+
+
+
+}
+
+
+
+
+