Ver código fonte

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-student-hostagev2

Daniel Lazar 10 anos atrás
pai
commit
2fa34b627e

+ 1 - 1
res/layout/fragment_home.xml

@@ -148,7 +148,7 @@
 			        android:src="@drawable/ic_launcher"
 			        android:scaleType="fitCenter"
 			        android:layout_alignBottom="@+id/home_text_profile"
-			        android:layout_toLeftOf="@+id/home_text_profile_header"
+			        android:layout_toLeftOf="@+id/home_text_profile"
 			        android:layout_alignTop="@+id/home_text_profile_header"/>
         </RelativeLayout>
     </LinearLayout>

+ 5 - 1
res/values-de/strings.xml

@@ -145,12 +145,16 @@
 	<string name="record_details_remote_ip">REMOTE IP</string>
 	<string name="record_details_conversation">Unterhaltung</string>
     <string name="profile_vista_desc">Dieses Profil immitiert Windows Vista</string>
+	<string name="profile_seven_desc">Dieses Profil immitiert Windows 7</string>
     <string name="profile_xp_desc">Dieses Profil aktiviert Dienste die Typisch für Windows XP sind</string>
     <string name="profile_webserv_http_desc">Dieses Profil immitiert einen simplen Webserver, welcher nur den Port für das HTTP Protokoll überwacht</string>
+	<string name="profile_webserv_apache_desc">Dieses Profil immitiert einen Apache Webserver</string>
+	<string name="profile_webserv_iis_desc">Dieses Profil immitiert einen IIS Webserver</string>
     <string name="profile_webserv_desc">Dieses Profil immitiert einen simplen Webserver, welcher neben dem HTTP Protokoll auch das HTTPS Protokoll unterstützt</string>
     <string name="profile_unix_desc">Dieses Profil aktiviert Unix-typische Dienste</string>
     <string name="profile_linux_desc">Dieses Profil immitiert ein Linux System mit entsprechenden Diensten</string>
-    <string name="profile_voip_desc">Dieses Profil immitiert einen VOIP Server, welcher das SIP Protokoll überwacht</string>
+	<string name="profile_linux_hard_desc">Dieses Profil immitiert ein Linux System, bei welchem nur SSH aktiv ist</string>
+	<string name="profile_voip_desc">Dieses Profil immitiert einen VOIP Server, welcher das SIP Protokoll überwacht</string>
     <string name="profile_random_desc">In diesem Profil werden zufällige Protokolle aktiviert</string>
     <string name="profile_paranoid_desc">Dieses Profil aktiviert alle Protokolle</string>
 </resources>

+ 4 - 0
res/values/strings.xml

@@ -147,11 +147,15 @@
 	<string name="record_details_conversation">Conversation</string>
 	<string name="record_details_confirm_delete">Do you really want to delete this record?</string>
     <string name="profile_vista_desc">This profile will imitate a Windows Vista machine</string>
+	<string name="profile_seven_desc">This profile will imitate a Windows 7 machine</string>
     <string name="profile_xp_desc">This profile will activate Windows XP typical services</string>
     <string name="profile_webserv_http_desc">This profile will imitate a simple webserver, which just supports the HTTP protocol</string>
+	<string name="profile_webserv_apache_desc">This profile will imitate an apache web server</string>
+	<string name="profile_webserv_iis_desc">This profile will imitate an IIS web server</string>
     <string name="profile_webserv_desc">This profile will imitate a simple webserver, which supports both the HTTP and HTTPS protocol</string>
     <string name="profile_unix_desc">This profile monitors unix typical services</string>
     <string name="profile_linux_desc">This profile will imitate a linux machine by monitoring linux typical services</string>
+	<string name="profile_linux_hard_desc">This profile will imitate a linux machine which has just SSH activated</string>
     <string name="profile_voip_desc">This profile imitates a VOIP Server by monitoring the SIP service</string>
     <string name="profile_random_desc">This profile monitors services randomly</string>
     <string name="profile_paranoid_desc">This profile monitors all available services</string>

+ 54 - 19
src/de/tudarmstadt/informatik/hostage/persistence/ProfileManager.java

@@ -17,10 +17,12 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
+import java.util.Set;
 
 import de.tudarmstadt.informatik.hostage.Hostage;
 import de.tudarmstadt.informatik.hostage.Listener;
@@ -477,22 +479,46 @@ public class ProfileManager {
 		return mProfiles.size();
 	}
 
+
+
+	/**
+	 * Pick n numbers between 0 (inclusive) and k (inclusive)
+	 * While there are very deterministic ways to do this,
+	 * for large k and small n, this could be easier than creating
+	 * an large array and sorting, i.e. k = 10,000
+	 */
+	public Set<Integer> pickRandom(int n, int s, int k) {
+		Random random = new Random(); // if this method is used often, perhaps define random at class level
+		Set<Integer> picked = new HashSet<Integer>();
+		while(picked.size() < n) {
+			picked.add(random.nextInt(k-s) + s);
+		}
+		return picked;
+	}
+
 	/**
 	 * Fills the profiles manager with default profiles
 	 */
 	public void fillWithDefaultData(){
-		Profile windowsVista = new Profile(
+		Profile windowsSeven = new Profile(
 				0,
-				"Windows Vista",
-				MainActivity.getInstance().getString(R.string.profile_vista_desc),
+				"Windows 7",
+				MainActivity.getInstance().getString(R.string.profile_seven_desc),
 				R.drawable.ic_profile_vista,
 				false
 		);
 
-		windowsVista.mActiveProtocols.put("ECHO", true);
-		windowsVista.mActiveProtocols.put("TELNET", true);
+		windowsSeven.mActiveProtocols.put("SMB", true);
+		windowsSeven.mGhostActive = true;
+		windowsSeven.mGhostPorts = "135,5357";
 
-		this.addProfile(windowsVista, false);
+		for(int i: pickRandom(3, 49152, 70000)){
+			windowsSeven.mGhostPorts += "," + i;
+		}
+
+		windowsSeven.mActiveProtocols.put("ECHO", true);
+
+		this.addProfile(windowsSeven, false);
 
 		Profile windowsXP = new Profile(
 				1,
@@ -502,62 +528,71 @@ public class ProfileManager {
 				false
 		);
 
+		windowsXP.mActiveProtocols.put("SMB", true);
+		windowsXP.mGhostActive = true;
+		windowsXP.mGhostPorts = "135";
+
+		for(int i: pickRandom(3, 49152, 80000)){
+			windowsXP.mGhostPorts += "," + i;
+		}
+
 		windowsXP.mActiveProtocols.put("ECHO", true);
-		windowsXP.mActiveProtocols.put("TELNET", true);
-		windowsXP.mActiveProtocols.put("MySQL", true);
 
 		this.addProfile(windowsXP, false);
 
 		Profile serverHTTP = new Profile(
 				2,
-				"Webserver HTTP",
-                MainActivity.getInstance().getString(R.string.profile_webserv_http_desc),
+				"Web Server Apache",
+                MainActivity.getInstance().getString(R.string.profile_webserv_apache_desc),
 				R.drawable.ic_profile_apache,
 				false
 		);
 
 		serverHTTP.mActiveProtocols.put("HTTP", true);
+		serverHTTP.mActiveProtocols.put("HTTPS", true);
+		serverHTTP.mActiveProtocols.put("MYSQL", true);
 
 		this.addProfile(serverHTTP, false);
 
 		Profile serverWeb = new Profile(
 				3,
-				"Webserver",
-                MainActivity.getInstance().getString(R.string.profile_webserv_desc),
+				"Web Server IIS",
+                MainActivity.getInstance().getString(R.string.profile_webserv_iis_desc),
 				R.drawable.ic_profile_apache,
 				false
 		);
 
 		serverWeb.mActiveProtocols.put("HTTP", true);
 		serverWeb.mActiveProtocols.put("HTTPS", true);
+		serverWeb.mActiveProtocols.put("FTP", true);
 
 		this.addProfile(serverWeb, false);
 
 		Profile unixMachine = new Profile(
 				4,
-				"Unix",
-                MainActivity.getInstance().getString(R.string.profile_unix_desc),
+				"\"Hardened\" Linux system ",
+                MainActivity.getInstance().getString(R.string.profile_linux_hard_desc),
 				R.drawable.ic_profile_unix,
 				false
 		);
 
 		unixMachine.mActiveProtocols.put("SSH", true);
-		unixMachine.mActiveProtocols.put("ECHO", true);
 
 		this.addProfile(unixMachine, false);
 
 		Profile linuxMachine = new Profile(
 				5,
-				"Linux",
+				"Linux system",
                 MainActivity.getInstance().getString(R.string.profile_linux_desc),
 				R.drawable.ic_profile_linux,
 				false
 		);
 
-		linuxMachine.mActiveProtocols.put("SSH", true);
+		linuxMachine.mActiveProtocols.put("FTP", true);
 		linuxMachine.mActiveProtocols.put("TELNET", true);
-		linuxMachine.mActiveProtocols.put("ECHO", true);
-		linuxMachine.mActiveProtocols.put("SMB", true);
+		linuxMachine.mActiveProtocols.put("HTTP", true);
+		linuxMachine.mActiveProtocols.put("HTTPS", true);
+		linuxMachine.mActiveProtocols.put("MYSQL", true);
 
 		this.addProfile(linuxMachine, false);
 

+ 38 - 32
src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java

@@ -180,11 +180,10 @@ public class HomeFragment extends Fragment {
 
 		if (HelperUtils.isNetworkAvailable(getActivity())) {
 			setStateConnected();
-			mHomeTextName.setText(mConnectionInfo.getString(getString(R.string.connection_info_ssid), ""));
+			String ssid = mConnectionInfo.getString(getString(R.string.connection_info_ssid), "\"\"");
+			mHomeTextName.setText(ssid.substring(1,ssid.length() - 1));
 		} else {
 			setStateNotConnected();
-			if(isActive) ThreatIndicatorGLRenderer.setThreatLevel(ThreatIndicatorGLRenderer.ThreatLevel.NO_THREAT);
-			return;
 		}
 
 		boolean hasActiveListeners = false;
@@ -208,38 +207,40 @@ public class HomeFragment extends Fragment {
 		if (hasActiveListeners) {
 			setStateActive(true);
 
-			switch (threatLevel) {
-				case NO_THREAT:
-					mHomeTextAttacks.setText(R.string.zero_attacks);
-					mHomeTextSecurity.setText(R.string.secure);
-					mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_dark_green));
-					mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_dark_green));
-					break;
-				case PAST_THREAT:
-					mHomeTextAttacks.setText(totalAttacks
-							+ (totalAttacks == 1 ? getResources().getString(R.string.attack) : getResources().getString(R.string.attacks))
-							+ getResources().getString(R.string.recorded));
-					mHomeTextSecurity.setText(R.string.insecure);
-					mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_yellow));
-					mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_yellow));
-					break;
-				case LIVE_THREAT:
-					mHomeTextAttacks.setText(totalAttacks
-							+ (totalAttacks == 1 ? getResources().getString(R.string.attack) : getResources().getString(R.string.attacks))
-							+ getResources().getString(R.string.recorded));
-					mHomeTextSecurity.setText(R.string.insecure);
-					mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_red));
-					mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_red));
-					break;
-			}
+			if(!isConnected){
+				ThreatIndicatorGLRenderer.setThreatLevel(ThreatIndicatorGLRenderer.ThreatLevel.NO_THREAT);
+				mHomeTextAttacks.setText("");
+				mHomeTextSecurity.setText("");
+			} else {
+				switch (threatLevel) {
+					case NO_THREAT:
+						mHomeTextAttacks.setText(R.string.zero_attacks);
+						mHomeTextSecurity.setText(R.string.secure);
+						mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_dark_green));
+						mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_dark_green));
+						break;
+					case PAST_THREAT:
+						mHomeTextAttacks.setText(totalAttacks
+								+ (totalAttacks == 1 ? getResources().getString(R.string.attack) : getResources().getString(R.string.attacks))
+								+ getResources().getString(R.string.recorded));
+						mHomeTextSecurity.setText(R.string.insecure);
+						mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_yellow));
+						mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_yellow));
+						break;
+					case LIVE_THREAT:
+						mHomeTextAttacks.setText(totalAttacks
+								+ (totalAttacks == 1 ? getResources().getString(R.string.attack) : getResources().getString(R.string.attacks))
+								+ getResources().getString(R.string.recorded));
+						mHomeTextSecurity.setText(R.string.insecure);
+						mHomeTextAttacks.setTextColor(getResources().getColor(R.color.holo_red));
+						mHomeTextSecurity.setTextColor(getResources().getColor(R.color.holo_red));
+						break;
+				}
 
-			ThreatIndicatorGLRenderer.setThreatLevel(threatLevel);
+				ThreatIndicatorGLRenderer.setThreatLevel(threatLevel);
+			}
 		} else {
 			setStateNotActive();
-
-			if (!HelperUtils.isNetworkAvailable(getActivity())) {
-				setStateNotConnected();
-			}
 		}
 	}
 
@@ -396,6 +397,11 @@ public class HomeFragment extends Fragment {
 	public void onStart() {
 		super.onStart();
 		registerBroadcastReceiver();
+	}
+
+	@Override
+	public void onResume(){
+		super.onResume();
 		updateUI();
 	}
 

+ 5 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -1188,7 +1188,11 @@ public class RecordOverviewFragment extends UpNavigatibleFragment implements Che
                     message.setTimestamp(cal.getTimeInMillis()
                             - ((messageID * 60 * 60 * 24) * 1000) + (1000 * ((messageID - attackId) + 1)));
 
-                    message.setType(MessageRecord.TYPE.SEND);
+                    if ((messageID - attackId) % 2 == 0){
+                        message.setType(MessageRecord.TYPE.RECEIVE);
+                    } else {
+                        message.setType(MessageRecord.TYPE.SEND);
+                    }
                     message.setPacket("");
 
                     dbh.addMessageRecord(message);