Browse Source

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

Daniel Lazar 10 years ago
parent
commit
4096bc6804

+ 16 - 1
res/xml/profile_preferences.xml

@@ -23,7 +23,22 @@
 		            android:summary="@string/change_icon_of_profile" />
 	</PreferenceCategory>
 
-	<PreferenceCategory android:title="Montior protocols"
+	<PreferenceCategory android:title="Monitor GHOST"
+	                    android:key="pref_profile_protocols_ghost">
+
+		<CheckBoxPreference android:key="pref_profile_protocols_ghost_active"
+		                    android:title="Activate GHOST monitoring"
+							android:summary="This protocol mirrors an incoming connection back to the attacker on the same port, that it is running on"
+							android:defaultValue="false" />
+
+		<EditTextPreference android:key="pref_profile_protocols_ghost_text"
+		                    android:title="Mirror GHOST ports"
+		                    android:summary="Mirrors the traffic on the given ports. Separate them by ','"
+		                    android:defaultValue=""
+		                    android:dependency="pref_profile_protocols_ghost_active" />
+	</PreferenceCategory>
+
+	<PreferenceCategory android:title="Monitor protocols"
 	                    android:key="pref_profile_protocols_settings">
 		<Preference android:summary="Activate the protocols that should be monitored by HosTaGe" />
 	</PreferenceCategory>

+ 104 - 25
src/de/tudarmstadt/informatik/hostage/dao/ProfileManager.java

@@ -8,7 +8,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.Serializable;
 import java.io.StreamCorruptedException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -89,7 +88,7 @@ public class ProfileManager {
 			e.printStackTrace();
 		} finally {
 			if(holder.mProfiles.size() == 0){
-				this.fillWithSampleData();
+				this.fillWithDefaultData();
 				loadData();
 			}
 
@@ -133,6 +132,8 @@ public class ProfileManager {
 
 	public void randomizeProtocols(Profile profile){
 		LinkedList<String> protocols = new LinkedList<String>(Arrays.asList(MainActivity.getContext().getResources().getStringArray(R.array.protocols)));
+		protocols.remove("GHOST");
+
 		profile.mActiveProtocols.clear();
 
 		Random rand = new Random();
@@ -263,52 +264,130 @@ public class ProfileManager {
 		return holder.mProfiles.size();
 	}
 
-	public void fillWithSampleData(){
-		this.addProfile(new Profile(
+	public void fillWithDefaultData(){
+		Profile windowsVista = new Profile(
 				0,
 				"Windows Vista",
-				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+				"This profile will imitate a Windows Vista machine",
 				R.drawable.ic_profile_vista,
 				false
-		), false);
+		);
+
+		windowsVista.mActiveProtocols.put("ECHO", true);
+		windowsVista.mActiveProtocols.put("TELNET", true);
 
-		this.addProfile(new Profile(
+		this.addProfile(windowsVista, false);
+
+		Profile windowsXP = new Profile(
 				1,
-				"Windows 7",
-				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-				R.drawable.ic_profile_w7,
+				"Windows XP",
+				"This profile will activate Windows XP typical services",
+				R.drawable.ic_profile_xp,
 				false
-		), false);
+		);
 
-		this.addProfile(new Profile(
+		windowsXP.mActiveProtocols.put("ECHO", true);
+		windowsXP.mActiveProtocols.put("TELNET", true);
+		windowsXP.mActiveProtocols.put("MySQL", true);
+
+		this.addProfile(windowsXP, false);
+
+		Profile serverHTTP = new Profile(
 				2,
-				"Unix Distro",
-				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+				"Webserver HTTP",
+				"This profile will imitate a simple webserver, which just supports the HTTP protocol",
+				R.drawable.ic_profile_apache,
+				false
+		);
+
+		serverHTTP.mActiveProtocols.put("HTTP", true);
+
+		this.addProfile(serverHTTP, false);
+
+		Profile serverWeb = new Profile(
+				3,
+				"Webserver",
+				"This profile will imitate a simple webserver, which supports both the HTTP and HTTPS protocol",
+				R.drawable.ic_profile_apache,
+				false
+		);
+
+		serverWeb.mActiveProtocols.put("HTTP", true);
+		serverWeb.mActiveProtocols.put("HTTPS", true);
+
+		this.addProfile(serverWeb, false);
+
+		Profile unixMachine = new Profile(
+				4,
+				"Unix",
+				"This profile monitors unix typical services",
 				R.drawable.ic_profile_unix,
 				false
-		), false);
+		);
+
+		unixMachine.mActiveProtocols.put("SSH", true);
+		unixMachine.mActiveProtocols.put("ECHO", true);
+
+		this.addProfile(unixMachine, false);
+
+		Profile linuxMachine = new Profile(
+				5,
+				"Linux",
+				"This profile will imitate a linux machine by monitoring linux typical services",
+				R.drawable.ic_profile_linux,
+				false
+		);
+
+		linuxMachine.mActiveProtocols.put("SSH", true);
+		linuxMachine.mActiveProtocols.put("TELNET", true);
+		linuxMachine.mActiveProtocols.put("ECHO", true);
+		linuxMachine.mActiveProtocols.put("SMB", true);
+
+		this.addProfile(linuxMachine, false);
+
+		Profile voipServer = new Profile(
+				6,
+				"VOIP Server",
+				"This profile imitates a VOIP Server by monitoring the SIP service",
+				R.drawable.ic_profile_asterisks,
+				false
+		);
+
+		voipServer.mActiveProtocols.put("SIP", true);
+
+		this.addProfile(voipServer, false);
 
 		Profile randomProfile = new Profile(
-				3,
+				7,
 				"Random",
-				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-				R.drawable.ic_service_green,
+				"This profile monitors services randomly",
+				R.drawable.ic_launcher,
 				false
 		);
 
 		randomProfile.mIsRandom = true;
+		randomProfile.mActivated = true;
 
 		this.addProfile(randomProfile, false);
 
-		this.addProfile(new Profile(
-				4,
-				"Mix",
-				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-				R.drawable.ic_service_green,
+		Profile paranoidProfile = new Profile(
+				8,
+				"Paranoid",
+				"This profile monitors all available services",
+				R.drawable.ic_launcher,
 				false
-		), false);
+		);
+
+		for(String protocol: MainActivity.context.getResources().getStringArray(R.array.protocols)){
+			if(protocol.equals("GHOST")) continue;
+			paranoidProfile.mActiveProtocols.put(protocol, true);
+		}
+
+		this.addProfile(paranoidProfile, false);
+		holder.mIncrementValue = 8;
+
+		this.mCurrentActivatedProfile = randomProfile;
 
-		holder.mIncrementValue = 4;
 		persistData();
 	}
 }

+ 15 - 0
src/de/tudarmstadt/informatik/hostage/model/Profile.java

@@ -23,6 +23,8 @@ import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  * @created 14.01.14 18:04
  */
 public class Profile implements Serializable {
+	private static final long serialVersionUID = 7L;
+
 	public String mText;
 	public String mLabel;
 	public int mId;
@@ -38,6 +40,8 @@ public class Profile implements Serializable {
 	public boolean mIsRandom = false;
 
 	public HashMap<String, Boolean> mActiveProtocols = new HashMap<String, Boolean>();
+	public String mGhostPorts = "";
+	public boolean mGhostActive = false;
 
 	public Profile(){
 		this.mEditable = true;
@@ -143,4 +147,15 @@ public class Profile implements Serializable {
 	public Profile cloneProfile(){
 		return new Profile(mId, mLabel, mText, mIcon, mEditable);
 	}
+
+	public Integer[] getGhostPorts(){
+		String[] splits = this.mGhostPorts.split(",");
+		Integer[] ports = new Integer[splits.length];
+
+		for(int i=0; i<splits.length; i++){
+			ports[i] = Integer.valueOf(splits[i]);
+		}
+
+		return ports;
+	}
 }

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/ui2/activity/MainActivity.java

@@ -437,7 +437,7 @@ public class MainActivity extends Activity {
 	private void configureFragment(Fragment fragment){
 		if(fragment == null) return;
 
-		if(fragment instanceof HomeFragment){
+		if(fragment instanceof HomeFragment || fragment instanceof AboutFragment){
 			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
 		} else {
 			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

+ 13 - 3
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -15,6 +15,7 @@ import android.widget.ImageView;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
+import java.util.LinkedList;
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.R;
@@ -43,11 +44,13 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 
     private final Context context;
     private final List<Profile> values;
+	private SwipeListView list;
 
-    public ProfileManagerListAdapter(Context context, List<Profile> objects) {
+    public ProfileManagerListAdapter(Context context, List<Profile> objects, SwipeListView list) {
         super(context, R.layout.profile_manager_list_item, objects);
         this.context = context;
         this.values  = objects;
+	    this.list    = list;
     }
 
 
@@ -120,7 +123,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 
 								profileManager.deleteProfile(item);
 								profileManager.getProfileListAdapter().notifyDataSetChanged();
-
+								list.closeOpenedItems();
 							}
 						})
 						.setIcon(android.R.drawable.ic_dialog_alert)
@@ -130,7 +133,14 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 
 	    holder.badgesContainer.removeAllViews();
 	    boolean hasProtocols = false;
-	    for(String protocol: item.getActiveProtocols()){
+
+	    List<String> profiles = new LinkedList<String>(item.getActiveProtocols());
+
+	    if(item.mGhostActive){
+		    profiles.add("GHOST");
+	    }
+
+	    for(String protocol: profiles){
 		    hasProtocols = true;
 			TextView textView = new TextView(new ContextThemeWrapper(context, R.style.ProfileManagerListBadge));
 		    textView.setText(protocol);

+ 12 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java

@@ -180,7 +180,7 @@ public class HomeFragment extends Fragment {
 					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.logged));
+					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));
@@ -286,11 +286,22 @@ public class HomeFragment extends Fragment {
 							    }
 
 							    for(String protocol: profileManager.getCurrentActivatedProfile().getActiveProtocols()){
+								    if(protocol.equals("GHOST")) continue;
+
 								    if(!MainActivity.getInstance().getHoneyService().isRunning(protocol)) {
 									    MainActivity.getInstance().getHoneyService().startListener(protocol);
 									    protocolActivated = true;
 								    }
 							    }
+
+							    Profile currentProfile = profileManager.getCurrentActivatedProfile();
+
+							    if(currentProfile.mGhostActive){
+								    for(int port: currentProfile.getGhostPorts()){
+									    MainActivity.getInstance().getHoneyService().startListener("GHOST", port);
+									    protocolActivated = true;
+								    }
+							    }
 						    }
 
 						    if(protocolActivated){

+ 20 - 2
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileEditFragment.java

@@ -79,6 +79,13 @@ public class ProfileEditFragment extends PreferenceFragment implements
 				profile.mLabel = prefs.getString("pref_profile_general_name", profile.mLabel);
 				profile.mIconPath = prefs.getString("pref_profile_general_image", profile.mIconPath);
 				profile.mText = prefs.getString("pref_profile_general_description", profile.mText);
+				profile.mGhostActive = prefs.getBoolean("pref_profile_protocols_ghost_active", profile.mGhostActive);
+				profile.mGhostPorts = prefs.getString("pref_profile_protocols_ghost_text", "");
+
+				if(profile.mGhostPorts.isEmpty()){
+					profile.mGhostActive = false;
+				}
+
 				profile.mActiveProtocols = new HashMap<String, Boolean>(profileProtocols);
 
 				if(createNew){
@@ -108,17 +115,24 @@ public class ProfileEditFragment extends PreferenceFragment implements
 
 		String pname = "",
 			   pimage = null,
-			   pdesc = "";
+			   pdesc = "",
+			   pghost = "";
+
+		boolean pbghost = false;
 
 		if(profile != null){
 			pname = profile.mLabel;
 			pimage = profile.mIconPath;
 			pdesc = profile.mText;
+			pghost = profile.mGhostPorts;
+			pbghost = profile.mGhostActive;
 		}
 
 		prefs.putString("pref_profile_general_name", pname);
 		prefs.putString("pref_profile_general_image", pimage);
 		prefs.putString("pref_profile_general_description", pdesc);
+		prefs.putString("pref_profile_protocols_ghost_text", pghost);
+		prefs.putBoolean("pref_profile_protocols_ghost_active", pbghost);
 
 		prefs.commit();
 
@@ -152,6 +166,8 @@ public class ProfileEditFragment extends PreferenceFragment implements
 		if(profile != null){
 			findPreference("pref_profile_general_name").setSummary(profile.mLabel);
 			findPreference("pref_profile_general_description").setSummary(profile.mText);
+
+			if(!profile.mGhostPorts.isEmpty()) findPreference("pref_profile_protocols_ghost_text").setSummary(profile.mGhostPorts);
 		}
 
 		if(profile == null || profile.isEditable()){
@@ -163,6 +179,8 @@ public class ProfileEditFragment extends PreferenceFragment implements
 		String[] protocols_summary = getResources().getStringArray(R.array.protocols_description);
 
 		for(int i = 0; i<protocols.length; i++){
+			if(protocols[i].equals("GHOST")) continue;
+
 			prefs.putBoolean("pref_profile_protocol_" + protocols[i], profile != null && profile.isProtocolActive(protocols[i]));
 			prefs.commit();
 
@@ -219,7 +237,7 @@ public class ProfileEditFragment extends PreferenceFragment implements
 
 		if(p instanceof EditTextPreference){
 			p.setSummary(sharedPreferences.getString(key, ""));
-		} else if(p instanceof CheckBoxPreference){
+		} else if(p instanceof CheckBoxPreference && !p.getKey().equals("pref_profile_protocols_ghost_active")){
 			profileProtocols.put(p.getTitle().toString(), ((CheckBoxPreference) p).isChecked());
 			//System.out.println("------------------------------- P: " + ((CheckBoxPreference) p).isChecked());
 		}

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

@@ -47,7 +47,7 @@ public class ProfileManagerFragment extends Fragment {
 
         List<Profile> strList = pmanager.getProfilesList();
 
-		mAdapter = new ProfileManagerListAdapter(getActivity(), strList);
+		mAdapter = new ProfileManagerListAdapter(getActivity(), strList, list);
 		pmanager.setProfileListAdapter(mAdapter);
 
         list.setAdapter(mAdapter);