Browse Source

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

Conflicts:
src/de/tudarmstadt/informatik/hostage/HoneyService.java
src/de/tudarmstadt/informatik/hostage/protocol/GHOST.java

Mihai Plasoianu 10 years ago
parent
commit
136283f4b5

+ 11 - 11
src/de/tudarmstadt/informatik/hostage/Handler.java → src/de/tudarmstadt/informatik/hostage/HoneyHandler.java

@@ -15,9 +15,9 @@ import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
 import de.tudarmstadt.informatik.hostage.logging.Logger;
 import de.tudarmstadt.informatik.hostage.logging.Record;
 import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
-import de.tudarmstadt.informatik.hostage.mirror.Mirror;
 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;
@@ -28,12 +28,12 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
  * @author Mihai Plasoianu
  * @author Wulf Pfeiffer
  */
-public class Handler implements Runnable {
+public class HoneyHandler implements Runnable {
 
 	/** Time until the socket throws a time out. The time is in milliseconds. */
 	private int TIMEOUT;
 
-	private Hostage service;
+	private HoneyService service;
 	protected Protocol protocol;
 	private Socket client;
 	protected Thread thread;
@@ -44,7 +44,7 @@ public class Handler implements Runnable {
 	private String BSSID;
 	private String SSID;
 
-	private Listener listener;
+	private HoneyListener listener;
 
 	/**
 	 * Constructor of the class. Initializes class variables for communication
@@ -59,13 +59,13 @@ public class Handler implements Runnable {
 	 * @param client
 	 *            A Socket for the communication with a remote client.
 	 */
-	public Handler(Hostage service, Listener listener, Protocol protocol, Socket client) {
+	public HoneyHandler(HoneyService service, HoneyListener listener, Protocol protocol, Socket client) {
 		this.service = service;
 		this.listener = listener;
 		this.protocol = protocol;
-		if (protocol.toString().equals("Mirror")) {
-			((Mirror) protocol).setAttackerIP(client.getInetAddress());
-			((Mirror) protocol).setCurrentPort(listener.getPort());
+		if (protocol.toString().equals("GHOST")) {
+			((GHOST) protocol).setAttackerIP(client.getInetAddress());
+			((GHOST) protocol).setCurrentPort(listener.getPort());
 		}
 		this.client = client;
 		this.thread = new Thread(this);
@@ -216,16 +216,16 @@ public class Handler implements Runnable {
 			outputLine = protocol.processMessage(null);
 			writer.write(outputLine);
 			for (Packet o : outputLine) {
-				Logger.log(Hostage.getContext(), createRecord(TYPE.SEND, o.toString()));
+				Logger.log(HoneyService.getContext(), createRecord(TYPE.SEND, o.toString()));
 			}
 		}
 		while (!thread.isInterrupted() && (inputLine = reader.read()) != null) {
 			outputLine = protocol.processMessage(inputLine);
-			Logger.log(Hostage.getContext(), createRecord(TYPE.RECEIVE, inputLine.toString()));
+			Logger.log(HoneyService.getContext(), createRecord(TYPE.RECEIVE, inputLine.toString()));
 			if (outputLine != null) {
 				writer.write(outputLine);
 				for (Packet o : outputLine) {
-					Logger.log(Hostage.getContext(), createRecord(TYPE.SEND, o.toString()));
+					Logger.log(HoneyService.getContext(), createRecord(TYPE.SEND, o.toString()));
 				}
 			}
 			if (protocol.isClosed()) {

+ 23 - 34
src/de/tudarmstadt/informatik/hostage/Listener.java → src/de/tudarmstadt/informatik/hostage/HoneyListener.java

@@ -17,21 +17,21 @@ import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
  * Protocol listener class:<br>
  * Creates a Socket on the port of a given protocol and listens for incoming
  * connections.<br>
- * For each connection creates a Socket and instantiate an {@link Handler}.
+ * For each connection creates a Socket and instantiate an {@link HoneyHandler}.
  * 
  * @author Mihai Plasoianu
  * 
  */
-public class Listener implements Runnable {
+public class HoneyListener implements Runnable {
 
-	private ArrayList<Handler> handlers = new ArrayList<Handler>();
+	private ArrayList<HoneyHandler> handlers = new ArrayList<HoneyHandler>();
 
 	private Protocol protocol;
 
 	private ServerSocket server;
 	private Thread thread;
 	private int port;
-	private Hostage service;
+	private HoneyService service;
 
 	private ConnectionRegister conReg;
 	private boolean running = false;
@@ -44,14 +44,14 @@ public class Listener implements Runnable {
 	 * @param protocol
 	 *            The Protocol on which the listener is running.
 	 */
-	public Listener(Hostage service, Protocol protocol) {
+	public HoneyListener(HoneyService service, Protocol protocol) {
 		this.service = service;
 		this.protocol = protocol;
 		port = protocol.getPort();
 		conReg = new ConnectionRegister(service);
 	}
 
-	public Listener(Hostage service, Protocol protocol, int port) {
+	public HoneyListener(HoneyService service, Protocol protocol, int port) {
 		this.service = service;
 		this.protocol = protocol;
 		this.port = port;
@@ -98,9 +98,8 @@ public class Listener implements Runnable {
 	 * Remove all terminated handlers from its internal ArrayList.
 	 */
 	public void refreshHandlers() {
-		for (Iterator<Handler> iterator = handlers.iterator(); iterator
-				.hasNext();) {
-			Handler handler = iterator.next();
+		for (Iterator<HoneyHandler> iterator = handlers.iterator(); iterator.hasNext();) {
+			HoneyHandler handler = iterator.next();
 			if (handler.isTerminated()) {
 				conReg.closeConnection();
 				iterator.remove();
@@ -113,7 +112,7 @@ public class Listener implements Runnable {
 		while (!thread.isInterrupted()) {
 			addHandler();
 		}
-		for (Handler handler : handlers) {
+		for (HoneyHandler handler : handlers) {
 			handler.kill();
 		}
 	}
@@ -129,11 +128,8 @@ public class Listener implements Runnable {
 				return false;
 			(this.thread = new Thread(this)).start();
 			running = true;
-			service.notifyUI(
-					this.getClass().getName(),
-					new String[] {
-							service.getString(R.string.broadcast_started),
-							protocol.toString(), Integer.toString(port) });
+			service.notifyUI(this.getClass().getName(),
+					new String[] { service.getString(R.string.broadcast_started), protocol.toString(), Integer.toString(port) });
 			return true;
 		} catch (Exception e) {
 			e.printStackTrace();
@@ -150,11 +146,8 @@ public class Listener implements Runnable {
 			server.close();
 			thread.interrupt();
 			running = false;
-			service.notifyUI(
-					this.getClass().getName(),
-					new String[] {
-							service.getString(R.string.broadcast_stopped),
-							protocol.toString(), Integer.toString(port) });
+			service.notifyUI(this.getClass().getName(),
+					new String[] { service.getString(R.string.broadcast_stopped), protocol.toString(), Integer.toString(port) });
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
@@ -162,7 +155,7 @@ public class Listener implements Runnable {
 
 	/**
 	 * Waits for an incoming connection, accepts it and starts a
-	 * {@link Handler}
+	 * {@link HoneyHandler}
 	 */
 	private void addHandler() {
 		if (conReg.isConnectionFree()) {
@@ -181,7 +174,7 @@ public class Listener implements Runnable {
 	}
 
 	/**
-	 * Creates a new instance of an {@link Handler}.
+	 * Creates a new instance of an {@link HoneyHandler}.
 	 * 
 	 * @param service
 	 *            The background service
@@ -191,29 +184,27 @@ public class Listener implements Runnable {
 	 *            The Protocol the handler will run on
 	 * @param client
 	 *            The Socket the handler uses
-	 * @return A Instance of a {@link Handler} with the specified
+	 * @return A Instance of a {@link HoneyHandler} with the specified
 	 *         parameter.
 	 */
-	private Handler newInstance(Hostage service,
-			Listener listener, Protocol protocol, Socket client) {
-		return new Handler(service, listener, protocol, client);
+	private HoneyHandler newInstance(HoneyService service, HoneyListener listener, Protocol protocol, Socket client) {
+		return new HoneyHandler(service, listener, protocol, client);
 	}
 
 	/**
-	 * Starts a {@link Handler} with the given socket.
+	 * Starts a {@link HoneyHandler} with the given socket.
 	 * 
 	 * @param client
 	 *            The socket with the accepted connection.
 	 * @throws Exception
 	 */
 	private void startHandler(Socket client) throws Exception {
-		handlers.add(newInstance(service, this, protocol.getClass()
-				.newInstance(), client));
+		handlers.add(newInstance(service, this, protocol.getClass().newInstance(), client));
 	}
 
 	/**
 	 * Creates a SSLSocket out of the given socket and starts a
-	 * {@link Handler}.
+	 * {@link HoneyHandler}.
 	 * 
 	 * @param client
 	 *            The socket with the accepted connection.
@@ -222,10 +213,8 @@ public class Listener implements Runnable {
 	private void startSecureHandler(Socket client) throws Exception {
 		SSLContext sslContext = ((SSLProtocol) protocol).getSSLContext();
 		SSLSocketFactory factory = sslContext.getSocketFactory();
-		SSLSocket sslClient = (SSLSocket) factory.createSocket(client, null,
-				client.getPort(), false);
+		SSLSocket sslClient = (SSLSocket) factory.createSocket(client, null, client.getPort(), false);
 		sslClient.setUseClientMode(false);
-		handlers.add(newInstance(service, this, protocol.getClass()
-				.newInstance(), sslClient));
+		handlers.add(newInstance(service, this, protocol.getClass().newInstance(), sslClient));
 	}
 }

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

@@ -1,604 +0,0 @@
-package de.tudarmstadt.informatik.hostage;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.net.Socket;
-import java.security.SecureRandom;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.util.EntityUtils;
-import org.json.JSONObject;
-
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
-import android.net.ConnectivityManager;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Binder;
-import android.os.IBinder;
-import android.preference.PreferenceManager;
-import android.support.v4.app.NotificationCompat;
-import android.support.v4.app.TaskStackBuilder;
-import android.support.v4.content.LocalBroadcastManager;
-import android.util.Log;
-import android.widget.Toast;
-import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
-import de.tudarmstadt.informatik.hostage.location.MyLocationManager;
-import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
-import de.tudarmstadt.informatik.hostage.protocol.HTTP;
-import de.tudarmstadt.informatik.hostage.protocol.Protocol;
-import de.tudarmstadt.informatik.hostage.ui.MainActivity;
-
-/**
- * Background service running as long as at least one protocol is active.
- * Service controls start and stop of protocol listener. Notifies GUI about
- * events happening in the background. Creates Notifications to inform the user
- * what it happening.
- * 
- * @author Mihai Plasoianu
- * @author Lars Pandikow
- * @author Wulf Pfeiffer
- */
-public class Hostage extends Service {
-
-	public class LocalBinder extends Binder {
-		public Hostage getService() {
-			return Hostage.this;
-		}
-	}
-
-	/**
-	 * Task for accuiring a qotd from one of four possible servers.
-	 * 
-	 * @author Wulf Pfeiffer
-	 */
-	private class QotdTask extends AsyncTask<String, Void, String> {
-		@Override
-		protected String doInBackground(String... unused) {
-			String[] sources = new String[] { "djxmmx.net", "ota.iambic.com", "alpha.mike-r.com", "electricbiscuit.org" };
-			SecureRandom rndm = new SecureRandom();
-			StringBuffer sb = new StringBuffer();
-			try {
-				Socket client = new Socket(sources[rndm.nextInt(4)], 17);
-				BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
-				while (!in.ready())
-					;
-				while (in.ready()) {
-					sb.append(in.readLine());
-				}
-				in.close();
-				client.close();
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-			return sb.toString();
-		}
-
-		@Override
-		protected void onPostExecute(String result) {
-			if (result != null)
-				HTTP.setHtmlDocumentContent(result);
-		}
-	}
-
-	/**
-	 * Task to find out the external IP.
-	 * 
-	 * @author Lars Pandikow
-	 */
-	private class SetExternalIPTask extends AsyncTask<String, Void, String> {
-		@Override
-		protected String doInBackground(String... url) {
-			String ipAddress = null;
-			try {
-				HttpClient httpclient = new DefaultHttpClient();
-				HttpGet httpget = new HttpGet(url[0]);
-				HttpResponse response;
-
-				response = httpclient.execute(httpget);
-
-				HttpEntity entity = response.getEntity();
-				entity.getContentLength();
-				String str = EntityUtils.toString(entity);
-				JSONObject json_data = new JSONObject(str);
-				ipAddress = json_data.getString("ip");
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-			return ipAddress;
-		}
-
-		@Override
-		protected void onPostExecute(String result) {
-			connectionInfoEditor.putString(getString(R.string.connection_info_external_ip), result);
-			connectionInfoEditor.commit();
-			notifyUI(this.getClass().getName(), new String[] { getString(R.string.broadcast_connectivity) });
-		}
-	}
-
-	private static Context context;
-
-	/**
-	 * Returns the application context.
-	 * 
-	 * @return context.
-	 */
-	public static Context getContext() {
-		return Hostage.context;
-	}
-
-	private LinkedList<Protocol> implementedProtocols;
-	private ArrayList<Listener> listeners = new ArrayList<Listener>();
-
-	private NotificationCompat.Builder builder;
-
-	private SharedPreferences connectionInfo;
-
-	private Editor connectionInfoEditor;
-
-	private final IBinder mBinder = new LocalBinder();
-
-	/**
-	 * Receiver for connectivity change broadcast.
-	 * 
-	 * @see MainActivity#BROADCAST
-	 */
-	private BroadcastReceiver netReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			String bssid_old = connectionInfo.getString(getString(R.string.connection_info_bssid), "");
-			String bssid_new = HelperUtils.getBSSID(context);
-			if (bssid_new == null || !bssid_new.equals(bssid_old)) {
-				deleteConnectionData();
-				updateConnectionInfo();
-				getLocationData();
-				notifyUI(this.getClass().getName(), new String[] { getString(R.string.broadcast_connectivity) });
-			}
-		}
-	};
-
-	public List<Listener> getListeners() {
-		return listeners;
-	}
-
-	/**
-	 * Determines the number of active connections for a protocol running on its
-	 * default port.
-	 * 
-	 * @param protocolName
-	 *            The protocol name
-	 * @return Number of active connections
-	 */
-	public int getNumberOfActiveConnections(String protocolName) {
-		int port = getDefaultPort(protocolName);
-		return getNumberOfActiveConnections(protocolName, port);
-	}
-
-	/**
-	 * Determines the number of active connections for a protocol running on the
-	 * given port.
-	 * 
-	 * @param protocolName
-	 *            The protocol name
-	 * @param port
-	 *            Specific port
-	 * @return Number of active connections
-	 */
-	public int getNumberOfActiveConnections(String protocolName, int port) {
-		for (Listener listener : listeners) {
-			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
-				return listener.getHandlerCount();
-			}
-		}
-		return 0;
-	}
-
-	/**
-	 * Determines if there any listener is currently running.
-	 * 
-	 * @return True if there is a running listener, else false.
-	 */
-	public boolean hasRunningListeners() {
-		for (Listener listener : listeners) {
-			if (listener.isRunning())
-				return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Determines if a protocol with the given name is running on its default
-	 * port.
-	 * 
-	 * @param protocolName
-	 *            The protocol name
-	 * @return True if protocol is running, else false.
-	 */
-	public boolean isRunning(String protocolName) {
-		int port = getDefaultPort(protocolName);
-		return isRunning(protocolName, port);
-	}
-
-	/**
-	 * Determines if a protocol with the given name is running on the given
-	 * port.
-	 * 
-	 * @param protocolName
-	 *            The protocol name
-	 * @param port
-	 *            Specific port
-	 * @return True if protocol is running, else false.
-	 */
-	public boolean isRunning(String protocolName, int port) {
-		for (Listener listener : listeners) {
-			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
-				return listener.isRunning();
-			}
-		}
-		return false;
-	}
-
-	/**
-	 * Notifies the GUI about a event.
-	 * 
-	 * @param sender
-	 *            Source where the event took place.
-	 * @param key
-	 *            Detailed information about the event.
-	 */
-	public void notifyUI(String sender, String[] values) {
-		createNotification();
-		// Send Notification
-		if (sender.equals(Handler.class.getName()) && values[0].equals(R.string.broadcast_started)) {
-			attackNotification();
-		}
-		// Inform UI of Preference Change
-		Intent intent = new Intent(getString(R.string.broadcast));
-		intent.putExtra("SENDER", sender);
-		intent.putExtra("VALUES", values);
-		Log.i("Sender", sender);
-		LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
-	}
-
-	@Override
-	public IBinder onBind(Intent intent) {
-		return mBinder;
-	}
-
-	@Override
-	public void onCreate() {
-		super.onCreate();
-		Hostage.context = getApplicationContext();
-		implementedProtocols = getImplementedProtocols();
-		connectionInfo = getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
-		connectionInfoEditor = connectionInfo.edit();
-		createNotification();
-		registerNetReceiver();
-		updateConnectionInfo();
-		getLocationData();
-
-		String sharedPreferencePath = getString(R.string.shared_preference_path);
-		boolean useQotd = getSharedPreferences(sharedPreferencePath, MODE_PRIVATE).getBoolean("useQotd", true);
-		if (useQotd) {
-			new QotdTask().execute(new String[] {});
-		}
-	}
-
-	@Override
-	public void onDestroy() {
-		cancelNotification();
-		unregisterNetReceiver();
-		super.onDestroy();
-	}
-
-	@Override
-	public int onStartCommand(Intent intent, int flags, int startId) {
-		// We want this service to continue running until it is explicitly
-		// stopped, so return sticky.
-		return START_STICKY;
-	}
-
-	/**
-	 * Starts the listener for the specified protocol. Creates a new
-	 * HoneyService if no matching HoneyListener is found.
-	 * 
-	 * @param protocolName
-	 *            Name of the protocol that should be started.
-	 */
-	public boolean startListener(String protocolName) {
-		return startListener(protocolName, getDefaultPort(protocolName));
-	}
-
-	/**
-	 * Starts the listener for the specified protocol and port. Creates a new
-	 * HoneyService if no matching HoneyListener is found.
-	 * 
-	 * @param protocolName
-	 *            Name of the protocol that should be started.
-	 * @param port
-	 *            The port number in which the listener should run.
-	 */
-	public boolean startListener(String protocolName, int port) {
-		for (Listener listener : listeners) {
-			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
-				if (!listener.isRunning()) {
-					if (listener.start()) {
-						Toast.makeText(getApplicationContext(), protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
-						return true;
-					}
-					Toast.makeText(getApplicationContext(), protocolName + " SERVICE COULD NOT BE STARTED!", Toast.LENGTH_SHORT).show();
-					return false;
-				}
-
-			}
-		}
-		Listener listener = createListener(protocolName, port);
-		if (listener != null) {
-			if (listener.start()) {
-				Toast.makeText(getApplicationContext(), protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
-				return true;
-			}
-		}
-		Toast.makeText(getApplicationContext(), protocolName + " SERVICE COULD NOT BE STARTED!", Toast.LENGTH_SHORT).show();
-		return false;
-	}
-
-	/**
-	 * Starts all listeners which are not already running.
-	 */
-	public void startListeners() {
-		for (Listener listener : listeners) {
-			if (!listener.isRunning()) {
-				listener.start();
-			}
-		}
-		Toast.makeText(getApplicationContext(), "SERVICES STARTED!", Toast.LENGTH_SHORT).show();
-	}
-
-	/**
-	 * Stops the listener for the specified protocol.
-	 * 
-	 * @param protocolName
-	 *            Name of the protocol that should be stopped.
-	 */
-	public void stopListener(String protocolName) {
-		stopListener(protocolName, getDefaultPort(protocolName));
-	}
-
-	/**
-	 * Stops the listener for the specified protocol.
-	 * 
-	 * @param protocolName
-	 *            Name of the protocol that should be stopped.
-	 * @param port
-	 *            The port number in which the listener is running.
-	 */
-	public void stopListener(String protocolName, int port) {
-		for (Listener listener : listeners) {
-			if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
-				if (listener.isRunning()) {
-					listener.stop();
-				}
-			}
-		}
-		Toast.makeText(getApplicationContext(), protocolName + " SERVICE STOPPED!", Toast.LENGTH_SHORT).show();
-	}
-
-	/**
-	 * Stops all running listeners.
-	 */
-	public void stopListeners() {
-		for (Listener listener : listeners) {
-			if (listener.isRunning()) {
-				listener.stop();
-			}
-		}
-		Toast.makeText(getApplicationContext(), "SERVICES STOPPED!", Toast.LENGTH_SHORT).show();
-	}
-
-	/**
-	 * Updates the notification when a attack is registered.
-	 */
-	private void attackNotification() {
-		SharedPreferences defaultPref = PreferenceManager.getDefaultSharedPreferences(this);
-		String strRingtonePreference = defaultPref.getString("pref_notification_sound", "content://settings/system/notification_sound");
-		builder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)).setTicker("Honeypot under attack!")
-				.setContentText("Honeypot under attack!").setSmallIcon(R.drawable.ic_service_red).setAutoCancel(true).setWhen(System.currentTimeMillis())
-				.setSound(Uri.parse(strRingtonePreference));
-		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
-		stackBuilder.addParentStack(MainActivity.class);
-		stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
-		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
-		builder.setContentIntent(resultPendingIntent);
-		if (defaultPref.getBoolean("pref_vibration", false)) {
-			builder.setVibrate(new long[] { 100, 200, 100, 200 });
-		}
-
-		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-		mNotificationManager.notify(2, builder.build());
-	}
-
-	/**
-	 * Cancels the Notification
-	 */
-	private void cancelNotification() {
-		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-		mNotificationManager.cancel(1);
-	}
-
-	/**
-	 * Creates a Listener for a given protocol on a specific port. After
-	 * creation the Listener is not started. Checks if the protocol is
-	 * implemented first.
-	 * 
-	 * @param protocolName
-	 *            Name of the protocol
-	 * @param port
-	 *            Port on which to start the Listener
-	 * @return Returns the created HoneyListener, if creation failed returns
-	 *         null.
-	 */
-	private Listener createListener(String protocolName, int port) {
-		for (Protocol protocol : implementedProtocols) {
-			if (protocolName.equals(protocol.toString())) {
-				Listener listener = new Listener(this, protocol, port);
-				listeners.add(listener);
-				return listener;
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * Creates a Notification in the notification bar.
-	 */
-	private void createNotification() {
-		HostageDBOpenHelper dbh = new HostageDBOpenHelper(this);
-		boolean activeHandlers = false;
-		boolean bssidSeen = false;
-		boolean listening = false;
-
-		for (Listener listener : listeners) {
-			if (listener.isRunning())
-				listening = true;
-			if (listener.getHandlerCount() > 0) {
-				activeHandlers = true;
-			}
-			if (dbh.bssidSeen(listener.getProtocolName(), HelperUtils.getBSSID(getApplicationContext()))) {
-				bssidSeen = true;
-			}
-		}
-		builder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)).setWhen(System.currentTimeMillis());
-		if (!listening) {
-			builder.setSmallIcon(R.drawable.ic_launcher);
-			builder.setContentText("HosTaGe is not active.");
-		} else if (activeHandlers) {
-			builder.setSmallIcon(R.drawable.ic_service_red);
-			builder.setContentText("Network is infected!");
-		} else if (bssidSeen) {
-			builder.setSmallIcon(R.drawable.ic_service_yellow);
-			builder.setContentText("Network has been infected in previous session!");
-		} else {
-			builder.setSmallIcon(R.drawable.ic_service_green);
-			builder.setContentText("Everything looks fine!");
-		}
-		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
-		stackBuilder.addParentStack(MainActivity.class);
-		stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
-		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
-		builder.setContentIntent(resultPendingIntent);
-		builder.setOngoing(true);
-		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-		mNotificationManager.notify(1, builder.build());
-	}
-
-	/**
-	 * Deletes all session related data.
-	 */
-	private void deleteConnectionData() {
-		connectionInfoEditor.clear();
-		connectionInfoEditor.commit();
-	}
-
-	/**
-	 * Returns the default port number, if the protocol is implemented.
-	 * 
-	 * @param protocolName
-	 *            The name of the protocol
-	 * @return Returns the default port number, if the protocol is implemented.
-	 *         Else returns -1.
-	 */
-	private int getDefaultPort(String protocolName) {
-		for (Protocol protocol : implementedProtocols) {
-			if (protocolName.equals(protocol.toString())) {
-				return protocol.getPort();
-			}
-		}
-		return -1;
-	};
-
-	/**
-	 * Returns an LinkedList<String> with the names of all implemented
-	 * protocols.
-	 * 
-	 * @return ArrayList of
-	 *         {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
-	 *         Protocol}
-	 */
-	private LinkedList<Protocol> getImplementedProtocols() {
-		String[] protocols = getResources().getStringArray(R.array.protocols);
-		String packageName = Protocol.class.getPackage().getName();
-		LinkedList<Protocol> implementedProtocols = new LinkedList<Protocol>();
-
-		for (String protocol : protocols) {
-			try {
-				implementedProtocols.add((Protocol) Class.forName(String.format("%s.%s", packageName, protocol)).newInstance());
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-		return implementedProtocols;
-	}
-
-	/**
-	 * Starts an Instance of MyLocationManager to set the location within this
-	 * class.
-	 */
-	private void getLocationData() {
-		MyLocationManager locationManager = new MyLocationManager(this);
-		locationManager.getUpdates(60 * 1000, 3);
-	};
-
-	// Notifications
-
-	/**
-	 * Register broadcast receiver for connectivity changes
-	 */
-	private void registerNetReceiver() {
-		// register BroadcastReceiver on network state changes
-		IntentFilter intent = new IntentFilter();
-		intent.addAction(ConnectivityManager.CONNECTIVITY_ACTION); // "android.net.conn.CONNECTIVITY_CHANGE"
-		registerReceiver(netReceiver, intent);
-	}
-
-	/**
-	 * Unregister broadcast receiver for connectivity changes
-	 */
-	private void unregisterNetReceiver() {
-		unregisterReceiver(netReceiver);
-	}
-
-	/**
-	 * Updates the connection info and saves them in the the SharedPreferences
-	 * for session data.
-	 * 
-	 * @param context
-	 *            Needs a context to get system recourses.
-	 * @see MainActivity#CONNECTION_INFO
-	 */
-	private void updateConnectionInfo() {
-		SharedPreferences pref = context.getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
-		Editor editor = pref.edit();
-		editor.putString(getString(R.string.connection_info_ssid), HelperUtils.getSSID(context));
-		editor.putString(getString(R.string.connection_info_bssid), HelperUtils.getBSSID(context));
-		editor.putString(getString(R.string.connection_info_internal_ip), HelperUtils.getInternalIP(context));
-		editor.commit();
-		SetExternalIPTask async = new SetExternalIPTask();
-		async.execute(new String[] { "http://ip2country.sourceforge.net/ip2c.php?format=JSON" });
-	}
-
-}

+ 13 - 10
src/de/tudarmstadt/informatik/hostage/mirror/Mirror.java → src/de/tudarmstadt/informatik/hostage/protocol/GHOST.java

@@ -1,4 +1,4 @@
-package de.tudarmstadt.informatik.hostage.mirror;
+package de.tudarmstadt.informatik.hostage.protocol;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -8,7 +8,6 @@ import java.net.Socket;
 import java.util.ArrayList;
 import java.util.List;
 
-import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
@@ -19,7 +18,7 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
  * 
  * @author Wulf Pfeiffer
  */
-public class Mirror implements Protocol {
+public class GHOST implements Protocol {
 
 	private boolean isClosed = false;
 
@@ -28,10 +27,11 @@ public class Mirror implements Protocol {
 	private BufferedInputStream mirrorInputStream;
 
 	private BufferedOutputStream mirrorOutputStream;
-
+	
 	private int currentPort;
-
+	
 	private InetAddress attackerIP;
+	
 
 	public void setCurrentPort(int currentPort) {
 		this.currentPort = currentPort;
@@ -43,7 +43,7 @@ public class Mirror implements Protocol {
 
 	@Override
 	public int getPort() {
-		return 5050; // TODO whats the default!? (1433)
+		return 1433;
 	}
 
 	@Override
@@ -62,10 +62,13 @@ public class Mirror implements Protocol {
 		try {
 			if (mirroredConnection == null) {
 				mirroredConnection = new Socket(attackerIP, currentPort);
-				mirrorInputStream = new BufferedInputStream(mirroredConnection.getInputStream());
-				mirrorOutputStream = new BufferedOutputStream(mirroredConnection.getOutputStream());
+				mirrorInputStream = new BufferedInputStream(
+						mirroredConnection.getInputStream());
+				mirrorOutputStream = new BufferedOutputStream(
+						mirroredConnection.getOutputStream());
 			}
-			if (mirroredConnection.isInputShutdown() || mirroredConnection.isOutputShutdown()) {
+			if (mirroredConnection.isInputShutdown()
+					|| mirroredConnection.isOutputShutdown()) {
 				mirrorInputStream.close();
 				mirrorOutputStream.close();
 				mirroredConnection.close();
@@ -91,7 +94,7 @@ public class Mirror implements Protocol {
 
 	@Override
 	public String toString() {
-		return "Mirror";
+		return "GHOST";
 	}
 
 	@Override

+ 56 - 2
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -1,5 +1,8 @@
 package de.tudarmstadt.informatik.hostage.protocol;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.Socket;
 import java.security.SecureRandom;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -8,6 +11,11 @@ import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
 
+import android.content.Context;
+import android.os.AsyncTask;
+
+import de.tudarmstadt.informatik.hostage.HoneyService;
+import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
@@ -19,6 +27,53 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
  * @author Wulf Pfeiffer
  */
 public class HTTP implements Protocol {
+	
+	public HTTP() {
+		htmlDocumentContent = HelperUtils.getRandomString(32, false);
+		Context context = HoneyService.getContext();
+		String sharedPreferencePath = context.getString(R.string.shared_preference_path);
+		boolean useQotd = context.getSharedPreferences(sharedPreferencePath,
+				HoneyService.MODE_PRIVATE).getBoolean("useQotd", true);
+		if (useQotd) {
+			new QotdTask().execute(new String[] {});
+		}
+	}
+
+	/**
+	 * Task for accuiring a qotd from one of four possible servers.
+	 * 
+	 * @author Wulf Pfeiffer
+	 */
+	private class QotdTask extends AsyncTask<String, Void, String> {
+		@Override
+		protected String doInBackground(String... unused) {
+			String[] sources = new String[] { "djxmmx.net", "ota.iambic.com",
+					"alpha.mike-r.com", "electricbiscuit.org" };
+			SecureRandom rndm = new SecureRandom();
+			StringBuffer sb = new StringBuffer();
+			try {
+				Socket client = new Socket(sources[rndm.nextInt(4)], 17);
+				BufferedReader in = new BufferedReader(new InputStreamReader(
+						client.getInputStream()));
+				while (!in.ready())
+					;
+				while (in.ready()) {
+					sb.append(in.readLine());
+				}
+				in.close();
+				client.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			return sb.toString();
+		}
+
+		@Override
+		protected void onPostExecute(String result) {
+			if (result != null)
+				HTTP.setHtmlDocumentContent(result);
+		}
+	}
 
 	/**
 	 * Get the current time in html header format.
@@ -65,8 +120,7 @@ public class HTTP implements Protocol {
 
 	private String httpVersion = "HTTP/1.1";
 
-	private static String htmlDocumentContent = HelperUtils.getRandomString(32,
-			false);
+	private static String htmlDocumentContent;
 
 	// request codes
 	private static final String OPTIONS = "OPTIONS";

+ 2 - 2
src/de/tudarmstadt/informatik/hostage/protocol/HTTPS.java

@@ -5,7 +5,7 @@ import java.security.KeyStore;
 import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
 
-import de.tudarmstadt.informatik.hostage.Hostage;
+import de.tudarmstadt.informatik.hostage.HoneyService;
 
 /**
  * HTTPS protocol. Extends HTTP. Implementation of RFC document 2818. It can handle the
@@ -30,7 +30,7 @@ public class HTTPS extends HTTP implements SSLProtocol {
 		try {
 			keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
 			keyStore.load(
-					Hostage.getContext().getAssets().open(keyStoreName),
+					HoneyService.getContext().getAssets().open(keyStoreName),
 					keyStorePassword);
 			keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory
 					.getDefaultAlgorithm());

+ 113 - 3
src/de/tudarmstadt/informatik/hostage/protocol/SIP.java

@@ -1,10 +1,29 @@
 package de.tudarmstadt.informatik.hostage.protocol;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
+/**
+ * SIP protocol. Implementation of RFC document 3261 It can handle the
+ * following requests: INVITE, BYE. For all other requests
+ * '400 Bad Request' will be replied.
+ * @author Wulf Pfeiffer
+ */
 public class SIP implements Protocol {
+		
+	private static final String VERSION = "SIP/2.0";
+	private static final String INVITE = "INVITE";
+	private static final String ACK= "ACK";
+	private static final String BYE = "BYE";
+	private static final String STATUS_CODE_180 = "180 Ringing";
+	private static final String STATUS_CODE_200 = "200 OK";
+	private static final String STATUS_CODE_400 = "400 Bad Request";
+	private static final String STATUS_CODE_505 = "505 Version Not Supported";
+	
+	private String header;
+	private String sdpPayload;
 
 	@Override
 	public int getPort() {
@@ -14,7 +33,7 @@ public class SIP implements Protocol {
 	@Override
 	public boolean isClosed() {
 		// TODO Auto-generated method stub
-		return true;
+		return false;
 	}
 
 	@Override
@@ -23,14 +42,105 @@ public class SIP implements Protocol {
 	}
 
 	@Override
-	public List<Packet> processMessage(Packet packet) {
+	public List<Packet> processMessage(Packet requestPacket) {
 		// TODO Auto-generated method stub
-		return null;
+		String request = null;
+		if (requestPacket != null) {
+			request = requestPacket.toString();
+		}
+		List<Packet> responsePackets = new ArrayList<Packet>();
+		String[] lines = request.split("\r\n");
+		extractLines(lines);
+		
+		if(!lines[0].contains(VERSION)) {
+			responsePackets.add(new Packet(STATUS_CODE_505));
+			return responsePackets;
+		} else if(lines[0].contains(INVITE)) {
+			responsePackets.add(getRingResponse());
+			responsePackets.add(getOkResponseWithSDP());
+		} else if(lines[0].contains(BYE)) {
+			responsePackets.add(getOkResponse());
+		} else if(lines[0].contains(ACK)) {
+			//nothing here
+		} else {
+			responsePackets.add(getBadRequestResponse());
+		}
+		
+		return responsePackets;
 	}
 
 	@Override
 	public TALK_FIRST whoTalksFirst() {
 		return TALK_FIRST.CLIENT;
 	}
+	
+	@Override
+	public String toString() {
+		return "SIP";
+	}
+	
+	private void extractLines(String[] lines) {
+		StringBuffer sbHeader = new StringBuffer();
+		StringBuffer sbSdp = new StringBuffer();
+		boolean recordHeader = false;
+		boolean recordSdp = false;
+		for (String line : lines) {
+			if (line.startsWith("Via:")) {
+				recordHeader = true;
+			} else if (line.startsWith("Max-Forwards:")) {
+				recordHeader = false;
+			} else if(line.startsWith("v=")) {
+				recordSdp = true;
+			} else if(line.startsWith("a=")) {
+				sbSdp.append(line + "\r\n");
+				header = sbHeader.toString();
+				sdpPayload = sbSdp.toString();
+			}
+			if(recordHeader) {
+				sbHeader.append(line + "\r\n");
+			} else if(recordSdp) {
+				sbSdp.append(line + "\r\n");
+			}
+		}
+	}
+	
+	private Packet getRingResponse() {
+		StringBuffer sb = new StringBuffer();
+		sb.append(VERSION + " " + STATUS_CODE_180 + "\r\n");
+		sb.append(header);
+		sb.append("Content-Length: 0\r\n");
+		
+		return new Packet(sb.toString());
+	}
+	
+	private Packet getOkResponseWithSDP() {
+		StringBuffer sb = new StringBuffer();
+		sb.append(VERSION + " " + STATUS_CODE_200 + "\r\n");
+		sb.append(header);
+		sb.append("Content-Type: application/sdp\r\n");
+		sb.append("Content-Length:   " + sdpPayload.length() + "\r\n");
+		sb.append("\r\n");
+		sb.append(sdpPayload);
+
+		return new Packet(sb.toString());
+	}
+	
+	private Packet getOkResponse() {
+		StringBuffer sb = new StringBuffer();
+		sb.append(VERSION + " " + STATUS_CODE_200 + "\r\n");
+		sb.append(header);
+		sb.append("Content-Length:   0\r\n");
+		
+		return new Packet(sb.toString());
+	}
+	
+	private Packet getBadRequestResponse() {
+		StringBuffer sb = new StringBuffer();
+		sb.append(VERSION + " " + STATUS_CODE_400 + "\r\n");
+		sb.append(header);
+		sb.append("Content-Length:   0\r\n");
+		
+		return new Packet(sb.toString());
+	}
 
 }

+ 13 - 14
src/de/tudarmstadt/informatik/hostage/protocol/SMB.java

@@ -9,7 +9,7 @@ import java.util.List;
 import java.util.TimeZone;
 
 import android.content.Context;
-import de.tudarmstadt.informatik.hostage.Hostage;
+import de.tudarmstadt.informatik.hostage.HoneyService;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
@@ -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
@@ -68,12 +69,8 @@ public class SMB implements Protocol {
 	 * @return current timezone in windows format as byte[]
 	 */
 	private static byte[] getTimeZoneInBytes() {
-		Integer offset = new GregorianCalendar().getTimeZone().getRawOffset() / 1000 / 60; // get
-																							// current
-																							// timezone
-																							// offset
-																							// in
-																							// minutes
+		// get current timezone offset in minutes
+		Integer offset = new GregorianCalendar().getTimeZone().getRawOffset() / 1000 / 60; 
 		char[] offsetChars = Integer.toBinaryString(offset).toCharArray();
 		boolean invert = false;
 		for (int i = offsetChars.length - 1; i > -1; i--) {
@@ -98,12 +95,12 @@ public class SMB implements Protocol {
 	}
 
 	private static String[] initServerVersion() {
-		String sharedPreferencePath = Hostage.getContext().getString(
+		String sharedPreferencePath = HoneyService.getContext().getString(
 				R.string.shared_preference_path);
-		String profile = Hostage
+		String profile = HoneyService
 				.getContext()
 				.getSharedPreferences(sharedPreferencePath,
-						Context.MODE_PRIVATE).getString("profile", "");
+						Context.MODE_PRIVATE).getString("os", "");
 		System.out.println(profile);
 		if (profile.equals("Windows 7")) {
 			return possibleSmbVersions[0];
@@ -115,6 +112,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 - 7
src/de/tudarmstadt/informatik/hostage/protocol/SSH.java

@@ -623,9 +623,8 @@ public class SSH implements Protocol {
 	 * @return wrapped packet.
 	 */
 	private Packet wrapPacket(byte[] response) {
-		int packetLength = 5 + response.length; // 4 byte packet length, 1 byte
-												// padding length, payload
-												// length
+		// 4 byte packet length, 1 byte padding length, payload length
+		int packetLength = 5 + response.length;
 		int paddingLengthCBS = cipherBlockSize
 				- (packetLength % cipherBlockSize);
 		int paddingLength8 = 8 - (packetLength % 8);
@@ -633,10 +632,8 @@ public class SSH implements Protocol {
 				: paddingLength8;
 		if (paddingLength < 4)
 			paddingLength += cipherBlockSize;
-		packetLength = packetLength + paddingLength - 4; // add padding string
-															// length to packet
-															// length
-
+		// add padding string length to packet length
+		packetLength = packetLength + paddingLength - 4; 
 		byte[] packetLen = ByteBuffer.allocate(4).putInt(packetLength).array();
 		byte[] paddingLen = { (byte) paddingLength };
 		byte[] paddingString = HelperUtils.randomBytes(paddingLength);

+ 49 - 8
src/de/tudarmstadt/informatik/hostage/protocol/TELNET.java

@@ -3,6 +3,10 @@ package de.tudarmstadt.informatik.hostage.protocol;
 import java.util.ArrayList;
 import java.util.List;
 
+import android.content.Context;
+
+import de.tudarmstadt.informatik.hostage.HoneyService;
+import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
@@ -33,11 +37,18 @@ public class TELNET implements Protocol {
 	/** name of the server */
 	private static String serverName = HelperUtils.getRandomString(16, false);
 
+	private static String serverVersion = initServerVersion();
+	
+	private static String login = initLogin();
+	
+	private static String serverBanner = initServerBanner();
+	
 	/** command line prefix */
 	private static byte[] sessionToken = null;
 
 	/** options requested by the server */
-	private static final byte[] optionRequest = { (byte) 0xff, (byte) 0xfb,
+	private static final byte[] optionRequest = {
+			(byte) 0xff, (byte) 0xfb,
 			0x03, // will suppress go ahead
 			(byte) 0xff, (byte) 0xfb, 0x01 // will echo
 	};
@@ -83,7 +94,7 @@ public class TELNET implements Protocol {
 		case OPEN:
 			if (request != null) {
 				responsePackets.add(new Packet(getOptionResponse(request)));
-				responsePackets.add(new Packet(serverName + " login: "));
+				responsePackets.add(new Packet(login + "login: "));
 				state = STATE.LOGIN;
 			}
 			break;
@@ -98,12 +109,16 @@ public class TELNET implements Protocol {
 					responsePackets.add(new Packet(buffer));
 				}
 				responsePackets.add(new Packet("\r\n"));
-				responsePackets.add(new Packet("Password: "));
+				responsePackets.add(new Packet("password: "));
 				state = STATE.AUTHENTICATE;
-				sessionToken = HelperUtils.concat(sessionPrefix, user,
-						"@".getBytes(), serverName.getBytes(), sessionMiddle,
-						user, "@".getBytes(), serverName.getBytes(),
-						sessionSuffix);
+				if (serverVersion.contains("Windows")) {
+					sessionToken = HelperUtils.concat("C:\\Users\\".getBytes(), user);
+				} else {
+					sessionToken = HelperUtils.concat(sessionPrefix, user,
+							"@".getBytes(), serverName.getBytes(), sessionMiddle,
+							user, "@".getBytes(), serverName.getBytes(),
+							sessionSuffix);
+				}
 				break;
 			} else if (checkForByte(request, (byte) 0x7f) && user != null
 					&& user.length != 0) {
@@ -124,7 +139,7 @@ public class TELNET implements Protocol {
 			if (request == null)
 				break;
 			else if (checkForByte(request, (byte) 0x0d)) {
-				responsePackets.add(new Packet("\r\n"));
+				responsePackets.add(new Packet("\r\n"+serverBanner));
 				responsePackets.add(new Packet(sessionToken));
 				state = STATE.LOGGED_IN;
 			} else if (checkForByte(request, (byte) 0x7f)) {
@@ -187,6 +202,32 @@ public class TELNET implements Protocol {
 	public TALK_FIRST whoTalksFirst() {
 		return TALK_FIRST.SERVER;
 	}
+	
+	private static String initServerVersion() {
+		String sharedPreferencePath = HoneyService.getContext().getString(
+				R.string.shared_preference_path);
+		String profile = HoneyService
+				.getContext()
+				.getSharedPreferences(sharedPreferencePath,
+						Context.MODE_PRIVATE).getString("os", "");
+		return profile;
+	}
+	
+	private static String initServerBanner() {
+		if (serverVersion.contains("Windows")) {
+			return "\r\n*===============================================================\r\n"
+					+ "Microsoft Telnet Server.\r\n"
+					+ "*===============================================================\r\n";
+		}
+		return "";
+	}
+	
+	private static String initLogin() {
+		if (serverVersion.contains("Windows")) {
+			return "Welcome to Microsoft Telnet Service \r\n\r\n";
+		}
+		return "Debian GNU/Linux 7.0\r\n";
+	}
 
 	/**
 	 * Checks a byte array for occurence of one byte.

+ 5 - 5
src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java

@@ -33,8 +33,8 @@ import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.ToggleButton;
 import android.widget.ViewAnimator;
-import de.tudarmstadt.informatik.hostage.Hostage;
-import de.tudarmstadt.informatik.hostage.Hostage.LocalBinder;
+import de.tudarmstadt.informatik.hostage.HoneyService;
+import de.tudarmstadt.informatik.hostage.HoneyService.LocalBinder;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
 
@@ -72,7 +72,7 @@ public class MainActivity extends FragmentActivity {
 
 	private SharedPreferences connectionInfo;
 
-	private Hostage mService;
+	private HoneyService mService;
 	private boolean serviceBound;
 
 	// variables for the swipe animation
@@ -227,7 +227,7 @@ public class MainActivity extends FragmentActivity {
 	 * @return An Intent to start HoneyService
 	 */
 	private Intent getServiceIntent() {
-		return new Intent(this, Hostage.class);
+		return new Intent(this, HoneyService.class);
 	}
 
 	/**
@@ -307,7 +307,7 @@ public class MainActivity extends FragmentActivity {
 	private boolean isServiceRunning() {
 		ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
 		for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
-			if (service.service.getClassName().equals(Hostage.class.getName())) {
+			if (service.service.getClassName().equals(HoneyService.class.getName())) {
 				return true;
 			}
 		}

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/wrapper/Packet.java

@@ -47,7 +47,7 @@ public class Packet {
 	public String toString() {
 		StringBuilder builder = new StringBuilder(payload.length);
 		for (int i = 0; i < payload.length; ++i) {
-			if (payload[i] < 32) {
+			if (payload[i] < 10) {
 				builder.append("{0x").append(payload[i]).append("}");
 			} else {
 				builder.append(Character.toString((char) payload[i]));