Browse Source

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

Fabio Arnold 11 years ago
parent
commit
da896c8019

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

@@ -17,6 +17,7 @@ import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
 import de.tudarmstadt.informatik.hostage.nio.Reader;
 import de.tudarmstadt.informatik.hostage.nio.Writer;
+import de.tudarmstadt.informatik.hostage.protocol.GHOST;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.Protocol.TALK_FIRST;
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
@@ -63,6 +64,10 @@ public class HoneyHandler implements Runnable {
 		this.service = service;
 		this.listener = listener;
 		this.protocol = protocol;
+		if (protocol.toString().equals("GHOST")) {
+			((GHOST) protocol).setAttackerIP(client.getInetAddress());
+			((GHOST) protocol).setCurrentPort(listener.getPort());
+		}
 		this.client = client;
 		this.thread = new Thread(this);
 		SharedPreferences pref = PreferenceManager

+ 10 - 11
src/de/tudarmstadt/informatik/hostage/dao/ProfileManager.java

@@ -11,7 +11,6 @@ import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
 import de.tudarmstadt.informatik.hostage.model.Profile;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ProfileManagerListAdapter;
-import de.tudarmstadt.informatik.hostage.ui2.model.ProfileListItem;
 
 /**
  * @author Alexander Brakowski
@@ -52,9 +51,9 @@ public class ProfileManager {
 		this.mProfiles.clear();
 
 		for(Profile p: profiles){
-			this.mProfiles.put(p.id, p);
+			this.mProfiles.put(p.mId, p);
 
-			if(p.activated){
+			if(p.mActivated){
 				this.mCurrentActivatedProfile = p;
 			}
 		}
@@ -79,8 +78,8 @@ public class ProfileManager {
 	public long persistProfile(Profile profile){
 		int id = (int) this.dbh.persistProfile(profile);
 
-		if(profile.id != id){
-			profile.id = id;
+		if(profile.mId != id){
+			profile.mId = id;
 		}
 
 		this.mProfiles.put(id, profile);
@@ -101,7 +100,7 @@ public class ProfileManager {
 
 	public void addProfile(Profile profile){
 		int id = (int) this.dbh.persistProfile(profile);
-		profile.id = id;
+		profile.mId = id;
 
 		this.mProfiles.put(id, profile);
 		if(this.mProfileListAdapter != null){
@@ -111,9 +110,9 @@ public class ProfileManager {
 	}
 
 	public void deleteProfile(Profile profile){
-		if(this.mProfiles.containsKey(profile.id)){
-			this.mProfiles.remove(profile.id);
-			this.dbh.deleteProfile(profile.id);
+		if(this.mProfiles.containsKey(profile.mId)){
+			this.mProfiles.remove(profile.mId);
+			this.dbh.deleteProfile(profile.mId);
 
 			if(this.mProfileListAdapter != null){
 				this.mProfileListAdapter.remove(profile);
@@ -126,11 +125,11 @@ public class ProfileManager {
 		if(profile.equals(this.mCurrentActivatedProfile)) return;
 
 		if(this.mCurrentActivatedProfile != null){
-			this.mCurrentActivatedProfile.activated = false;
+			this.mCurrentActivatedProfile.mActivated = false;
 			this.persistProfile(this.mCurrentActivatedProfile);
 		}
 
-		profile.activated = true;
+		profile.mActivated = true;
 		this.mCurrentActivatedProfile = profile;
 
 		this.dbh.persistProfile(profile);

+ 9 - 9
src/de/tudarmstadt/informatik/hostage/logging/UglyDbHelper.java

@@ -764,7 +764,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 				Profile profile = new Profile(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(4) == 1);
 
 				if(cursor.getInt(5) == 1){
-					profile.activated = true;
+					profile.mActivated = true;
 				}
 
 				// Adding record to list
@@ -789,15 +789,15 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 
 		ContentValues values = new ContentValues();
 
-		if(profile.id != -1){
-			values.put(KEY_PROFILE_ID, profile.id);
+		if(profile.mId != -1){
+			values.put(KEY_PROFILE_ID, profile.mId);
 		}
 
-		values.put(KEY_PROFILE_NAME, profile.label);
-		values.put(KEY_PROFILE_DESCRIPTION, profile.text);
-		values.put(KEY_PROFILE_ICON, profile.iconPath);
-		values.put(KEY_PROFILE_ACTIVE, profile.activated);
-		values.put(KEY_PROFILE_EDITABLE, profile.editable);
+		values.put(KEY_PROFILE_NAME, profile.mLabel);
+		values.put(KEY_PROFILE_DESCRIPTION, profile.mText);
+		values.put(KEY_PROFILE_ICON, profile.mIconPath);
+		values.put(KEY_PROFILE_ACTIVE, profile.mActivated);
+		values.put(KEY_PROFILE_EDITABLE, profile.mEditable);
 
 		return db.replace(TABLE_PROFILES, null, values);
 	}
@@ -814,7 +814,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 			profile = new Profile(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(4) == 1);
 
 			if(cursor.getInt(5) == 1){
-				profile.activated = true;
+				profile.mActivated = true;
 			}
 		}
 

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

@@ -12,23 +12,23 @@ import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  * @created 14.01.14 18:04
  */
 public class Profile {
-	public String text;
-	public String label;
-	public int id;
-	public boolean activated;
-	public Bitmap icon;
-	public String iconPath;
+	public String mText;
+	public String mLabel;
+	public int mId;
+	public boolean mActivated;
+	public Bitmap mIcon;
+	public String mIconPath;
 
-	public boolean isBackVisible = false;
-	public boolean editable = false;
+	public boolean mIsBackVisible = false;
+	public boolean mEditable = false;
 
 	public Profile(int id, String label, String text, Bitmap icon, boolean editable){
-		this.id = id;
-		this.label = text;
-		this.text = label;
-		this.activated = false;
-		this.icon = icon;
-		this.editable = editable;
+		this.mId = id;
+		this.mLabel = text;
+		this.mText = label;
+		this.mActivated = false;
+		this.mIcon = icon;
+		this.mEditable = editable;
 	}
 
 	public Profile(int id, String label, String text, int icon, boolean editable){
@@ -36,29 +36,29 @@ public class Profile {
 	}
 
 	public Profile(int id, String label, String text, String iconPath, boolean editable){
-		this.id = id;
-		this.label = label;
-		this.text = text;
-		this.activated = false;
-		this.iconPath = iconPath;
-		this.editable = editable;
+		this.mId = id;
+		this.mLabel = label;
+		this.mText = text;
+		this.mActivated = false;
+		this.mIconPath = iconPath;
+		this.mEditable = editable;
 	}
 
 	public void setIcon(Bitmap bitmap){
-		this.icon = bitmap;
+		this.mIcon = bitmap;
 	}
 
 	public void setIcon(int icon){
-		this.icon = BitmapFactory.decodeResource(MainActivity.context.getResources(), icon);
+		this.mIcon = BitmapFactory.decodeResource(MainActivity.context.getResources(), icon);
 	}
 
 	public Bitmap getIconBitmap(){
-		if(this.icon != null) return icon;
+		if(this.mIcon != null) return mIcon;
 
-		if(this.iconPath != null){
+		if(this.mIconPath != null){
 			BitmapFactory.Options options = new BitmapFactory.Options();
 			options.inPreferredConfig = Bitmap.Config.ARGB_8888;
-			Bitmap bitmap = BitmapFactory.decodeFile(this.iconPath, options);
+			Bitmap bitmap = BitmapFactory.decodeFile(this.mIconPath, options);
 
 			return bitmap;
 		}
@@ -71,10 +71,10 @@ public class Profile {
 	}
 
 	public boolean isEditable(){
-		return this.editable;
+		return this.mEditable;
 	}
 
 	public Profile cloneProfile(){
-		return new Profile(id, label, text, icon, editable);
+		return new Profile(mId, mLabel, mText, mIcon, mEditable);
 	}
 }

+ 19 - 8
src/de/tudarmstadt/informatik/hostage/protocol/GHOST.java

@@ -3,6 +3,7 @@ package de.tudarmstadt.informatik.hostage.protocol;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.List;
@@ -26,10 +27,23 @@ public class GHOST implements Protocol {
 	private BufferedInputStream mirrorInputStream;
 
 	private BufferedOutputStream mirrorOutputStream;
+	
+	private int currentPort;
+	
+	private InetAddress attackerIP;
+	
+
+	public void setCurrentPort(int currentPort) {
+		this.currentPort = currentPort;
+	}
+
+	public void setAttackerIP(InetAddress attackerIP) {
+		this.attackerIP = attackerIP;
+	}
 
 	@Override
 	public int getPort() {
-		return 5050; // TODO dynamic port / whats the default!? (1433)
+		return 5050; // TODO whats the default!? (1433)
 	}
 
 	@Override
@@ -47,7 +61,7 @@ public class GHOST implements Protocol {
 		List<Packet> responsePackets = new ArrayList<Packet>();
 		try {
 			if (mirroredConnection == null) {
-				mirroredConnection = new Socket("192.168.178.86", 5050); // FIXME
+				mirroredConnection = new Socket(attackerIP, currentPort);
 				mirrorInputStream = new BufferedInputStream(
 						mirroredConnection.getInputStream());
 				mirrorOutputStream = new BufferedOutputStream(
@@ -66,24 +80,21 @@ public class GHOST implements Protocol {
 
 			int availableBytes;
 			while ((availableBytes = mirrorInputStream.available()) <= 0) {
-				try {
-					Thread.sleep(1);
-				} catch (InterruptedException e) {
-					e.printStackTrace();
-				}
+				Thread.yield();
 			}
 			byte[] mirrorResponse = new byte[availableBytes];
 			mirrorInputStream.read(mirrorResponse);
 			responsePackets.add(new Packet(mirrorResponse));
 		} catch (IOException e) {
 			e.printStackTrace();
+			responsePackets.add(requestPacket);
 		}
 		return responsePackets;
 	}
 
 	@Override
 	public String toString() {
-		return "GhostProtocol";
+		return "GHOST";
 	}
 
 	@Override

+ 7 - 4
src/de/tudarmstadt/informatik/hostage/protocol/SMB.java

@@ -34,10 +34,11 @@ public class SMB implements Protocol {
 	private static String[][] possibleSmbVersions = {
 			{ "Windows 7 Professional 7600", "Windows 7 Professional 6.1" },
 			{ "Windows 8 Enterprise 9200", "Windows 8 Enterprise 9200" },
-			{ "Windows Server 2008 R2 Enterprise 7600",
-					"Windows Server 2008 R2 Enterprise 6.1" },
-			{ "Windows Server 2012 Standard 6.2",
-					"Windows Server 2012 Standard 6.2" }, { "Unix", "Samba" } };
+			{ "Windows Server 2008 R2 Enterprise 7600", "Windows Server 2008 R2 Enterprise 6.1" },
+			{ "Windows Server 2012 Standard 6.2", "Windows Server 2012 Standard 6.2" },
+			{ "Unix", "Samba" },
+			{ "Windows 2002 Service Pack 2", "Windows 2002 5.1"}
+	};
 
 	/**
 	 * Converts the current system time into a byte[] with windows specific time
@@ -115,6 +116,8 @@ public class SMB implements Protocol {
 			return possibleSmbVersions[3];
 		} else if (profile.equals("Linux")) {
 			return possibleSmbVersions[4];
+		} else if (profile.equals("Windows XP")) {
+			return possibleSmbVersions[5];
 		} else {
 			return possibleSmbVersions[new SecureRandom()
 					.nextInt(possibleSmbVersions.length)];

+ 4 - 5
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -4,7 +4,6 @@ import android.app.AlertDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
-import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -79,8 +78,8 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 
 	    ((SwipeListView)parent).recycle(rowView, position);
 
-	    holder.textView.setText(item.text);
-	    holder.labelView.setText(item.label);
+	    holder.textView.setText(item.mText);
+	    holder.labelView.setText(item.mLabel);
 
 	    if(item.getIconBitmap() != null){
 	        //Bitmap bitmap = Bitmap.createScaledBitmap(item.getIconBitmap(), 32, 32, true);
@@ -94,7 +93,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 			public void onClick(View v) {
 				Intent intent = new Intent(context, ProfileEditActivity.class);
 				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-				intent.putExtra("profile_id", item.id);
+				intent.putExtra("profile_id", item.mId);
 				context.startActivity(intent);
 			}
 		});
@@ -127,7 +126,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 
 		RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.textView.getLayoutParams();
 
-        if(!item.activated){
+        if(!item.mActivated){
             lp.setMargins(0, 0, 0, 0);
 
 	        holder.textView.setLayoutParams(lp);

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

@@ -58,16 +58,16 @@ public class ProfileEditFragment extends PreferenceFragment implements
 
 				if(!profile.isEditable()){
 					profile = profile.cloneProfile();
-					profile.editable = true;
+					profile.mEditable = true;
 					createNew = true;
 				}
 
-				profile.label = prefs.getString("pref_profile_general_name", profile.label);
-				profile.iconPath = prefs.getString("pref_profile_general_image", profile.iconPath);
-				profile.text = prefs.getString("pref_profile_general_description", profile.text);
+				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);
 
 				if(createNew){
-					profile.id = -1;
+					profile.mId = -1;
 					pmanager.addProfile(profile);
 				} else {
 					pmanager.persistProfile(profile);
@@ -88,9 +88,9 @@ public class ProfileEditFragment extends PreferenceFragment implements
 		prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
 
 		if(profile != null){
-			prefs.putString("pref_profile_general_name", profile.label);
-			prefs.putString("pref_profile_general_image", profile.iconPath);
-			prefs.putString("pref_profile_general_description", profile.text);
+			prefs.putString("pref_profile_general_name", profile.mLabel);
+			prefs.putString("pref_profile_general_image", profile.mIconPath);
+			prefs.putString("pref_profile_general_description", profile.mText);
 
 			prefs.commit();
 		}
@@ -119,8 +119,8 @@ public class ProfileEditFragment extends PreferenceFragment implements
 				}
 		);
 
-		findPreference("pref_profile_general_name").setSummary(profile.label);
-		findPreference("pref_profile_general_description").setSummary(profile.text);
+		findPreference("pref_profile_general_name").setSummary(profile.mLabel);
+		findPreference("pref_profile_general_description").setSummary(profile.mText);
 	}
 
 	public Profile getProfile(){