|
@@ -5,8 +5,17 @@ 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;
|
|
@@ -26,6 +35,7 @@ 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.TextView;
|
|
|
import android.widget.Toast;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.MyLocationManager;
|
|
@@ -57,10 +67,11 @@ public class HoneyService extends Service {
|
|
|
return HoneyService.context;
|
|
|
}
|
|
|
|
|
|
+ private LinkedList<Protocol> implementedProtocols;
|
|
|
private ArrayList<HoneyListener> listeners = new ArrayList<HoneyListener>();
|
|
|
private NotificationCompat.Builder builder;
|
|
|
- private SharedPreferences sessionPref;
|
|
|
- private Editor editor;
|
|
|
+ private SharedPreferences connectionInfo;
|
|
|
+ private Editor connectionInfoEditor;
|
|
|
|
|
|
public List<HoneyListener> getListeners() {
|
|
|
return listeners;
|
|
@@ -83,14 +94,12 @@ public class HoneyService extends Service {
|
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
|
HoneyService.context = getApplicationContext();
|
|
|
- sessionPref = getSharedPreferences(MainActivity.SESSION_DATA, Context.MODE_PRIVATE);
|
|
|
- editor = sessionPref.edit();
|
|
|
- deleteSessionData();
|
|
|
+ implementedProtocols = getImplementedProtocols();
|
|
|
+ connectionInfo = getSharedPreferences(MainActivity.CONNECTION_INFO, Context.MODE_PRIVATE);
|
|
|
+ connectionInfoEditor = connectionInfo.edit();
|
|
|
createNotification();
|
|
|
- for (Protocol protocol : getProtocolArray()) {
|
|
|
- listeners.add(new HoneyListener(this, protocol));
|
|
|
- }
|
|
|
registerNetReceiver();
|
|
|
+ updateConnectionInfo();
|
|
|
getLocationData();
|
|
|
new QotdTask().execute(new String[] {});
|
|
|
}
|
|
@@ -106,7 +115,6 @@ public class HoneyService extends Service {
|
|
|
public void onDestroy() {
|
|
|
cancelNotification();
|
|
|
unregisterNetReceiver();
|
|
|
- deleteSessionData();
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
|
|
@@ -123,9 +131,9 @@ public class HoneyService extends Service {
|
|
|
/**
|
|
|
* Deletes all session related data.
|
|
|
*/
|
|
|
- private void deleteSessionData() {
|
|
|
- editor.clear();
|
|
|
- editor.commit();
|
|
|
+ private void deleteConnectionData() {
|
|
|
+ connectionInfoEditor.clear();
|
|
|
+ connectionInfoEditor.commit();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -153,118 +161,75 @@ public class HoneyService extends Service {
|
|
|
private BroadcastReceiver netReceiver = new BroadcastReceiver() {
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
- String bssid_old = sessionPref.getString(MainActivity.BSSID, "");
|
|
|
+ String bssid_old = connectionInfo.getString(MainActivity.BSSID, "");
|
|
|
String bssid_new = HelperUtils.getBSSID(context);
|
|
|
if (bssid_new == null || !bssid_new.equals(bssid_old)) {
|
|
|
+ deleteConnectionData();
|
|
|
+ updateConnectionInfo();
|
|
|
getLocationData();
|
|
|
- notifyUI("SERVICE", "CONNECTIVITY_CHANGE");
|
|
|
+ notifyUI(this.getClass().getName(), "CONNECTIVITY_CHANGE");
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
- * Creates a Notification in the notification bar.
|
|
|
- */
|
|
|
- private void createNotification() {
|
|
|
- UglyDbHelper dbh = new UglyDbHelper(this);
|
|
|
- boolean activeHandlers = false;
|
|
|
- boolean bssidSeen = false;
|
|
|
-
|
|
|
- for (String protocol : getResources().getStringArray(R.array.protocols)) {
|
|
|
- int handlerCount = sessionPref.getInt(protocol
|
|
|
- + MainActivity.HANDLER_COUNT, 0);
|
|
|
- if (handlerCount > 0) {
|
|
|
- activeHandlers = true;
|
|
|
- }
|
|
|
- if (dbh.bssidSeen(protocol,
|
|
|
- HelperUtils.getBSSID(getApplicationContext()))) {
|
|
|
- bssidSeen = true;
|
|
|
- }
|
|
|
- }
|
|
|
- builder = new NotificationCompat.Builder(this).setContentTitle(
|
|
|
- getString(R.string.app_name)).setWhen(
|
|
|
- System.currentTimeMillis());
|
|
|
- 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);
|
|
|
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
- mNotificationManager.notify(1, builder.build());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Updates the notification when a attack is registered.
|
|
|
+ * Notifies the GUI about a event.
|
|
|
+ *
|
|
|
+ * @param protocol
|
|
|
+ * The protocol where the event happened.
|
|
|
+ * @param key
|
|
|
+ * The key for the event.
|
|
|
*/
|
|
|
- private void updateNotification() {
|
|
|
- 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("Network is infected!")
|
|
|
- .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 });
|
|
|
+ public void notifyUI(String sender, String key) {
|
|
|
+ // Send Notification
|
|
|
+ if (key.equals(MainActivity.HANDLER_COUNT)) {
|
|
|
+ updateNotification();
|
|
|
}
|
|
|
-
|
|
|
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
- mNotificationManager.notify(1, builder.build());
|
|
|
+ Log.i("HoneyService", sender + key);
|
|
|
+ // Inform UI of Preference Change
|
|
|
+ Intent intent = new Intent(MainActivity.BROADCAST);
|
|
|
+ intent.putExtra("SENDER", sender);
|
|
|
+ intent.putExtra("KEY", key);
|
|
|
+ LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
- /**
|
|
|
- * Cancels the Notification
|
|
|
- */
|
|
|
- private void cancelNotification() {
|
|
|
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
- mNotificationManager.cancel(1);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- * Creates a instance of each protocol defined in /res/values/protocols.xml
|
|
|
- * and puts it in a List
|
|
|
+ * Returns an LinkedList<String> with the names of all implemented protocols.
|
|
|
*
|
|
|
* @return ArrayList of
|
|
|
* {@link de.tudarmstadt.informatik.hostage.protocol.Protocol
|
|
|
* Protocol}
|
|
|
*/
|
|
|
- private ArrayList<Protocol> getProtocolArray() {
|
|
|
+ private LinkedList<Protocol> getImplementedProtocols() {
|
|
|
String[] protocols = getResources().getStringArray(R.array.protocols);
|
|
|
String packageName = Protocol.class.getPackage().getName();
|
|
|
- ArrayList<Protocol> protocolArray = new ArrayList<Protocol>();
|
|
|
+ LinkedList<Protocol> implementedProtocols = new LinkedList<Protocol>();
|
|
|
|
|
|
for (String protocol : protocols) {
|
|
|
try {
|
|
|
- protocolArray.add((Protocol) Class.forName(
|
|
|
- String.format("%s.%s", packageName, protocol))
|
|
|
- .newInstance());
|
|
|
+ implementedProtocols.add((Protocol) Class.forName(String.format("%s.%s", packageName, protocol)).newInstance());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- return protocolArray;
|
|
|
+ return implementedProtocols;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -279,30 +244,81 @@ public class HoneyService extends Service {
|
|
|
}
|
|
|
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);
|
|
|
+ if(port >= 0) return isRunning(protocolName, port);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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 (HoneyListener listener : listeners) {
|
|
|
+ if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
|
|
|
+ return listener.isRunning();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Determines the number of active connections for a protocol running on its default port.
|
|
|
+ * @param protocolName The protocol name
|
|
|
+ * @return Number of active connections if protocol is implemented, else -1.
|
|
|
+ */
|
|
|
+ public int getHandlerCount(String protocolName){
|
|
|
+ int port = getDefaultPort(protocolName);
|
|
|
+ if(port >= 0) return getHandlerCount(protocolName, port);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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 if protocol is implemented, else -1.
|
|
|
+ */
|
|
|
+ public int getHandlerCount(String protocolName, int port){
|
|
|
+ for (HoneyListener listener : listeners) {
|
|
|
+ if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
|
|
|
+ return listener.getHandlerCount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- * Notifies the GUI about a event.
|
|
|
+ * 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 protocol
|
|
|
- * The protocol where the event happened.
|
|
|
- * @param key
|
|
|
- * The key for the event.
|
|
|
+ * @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.
|
|
|
*/
|
|
|
- public void notifyUI(String sender, String key) {
|
|
|
- // Send Notification
|
|
|
- if (key.equals(MainActivity.HANDLER_COUNT)) {
|
|
|
- updateNotification();
|
|
|
+ private HoneyListener createListener(String protocolName, int port){
|
|
|
+ for(Protocol protocol : implementedProtocols){
|
|
|
+ if(protocolName.equals(protocol.toString())){
|
|
|
+ HoneyListener listener = new HoneyListener(this, protocol, port);
|
|
|
+ listeners.add(listener);
|
|
|
+ return listener;
|
|
|
+ }
|
|
|
}
|
|
|
- Log.i("HoneyService", sender + key);
|
|
|
- // Inform UI of Preference Change
|
|
|
- Intent intent = new Intent(MainActivity.BROADCAST);
|
|
|
- intent.putExtra("SENDER", sender);
|
|
|
- intent.putExtra("KEY", key);
|
|
|
- LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Starts all listeners which are not already running
|
|
|
+ * Starts all listeners which are not already running.
|
|
|
*/
|
|
|
public void startListeners() {
|
|
|
for (HoneyListener listener : listeners) {
|
|
@@ -328,21 +344,49 @@ public class HoneyService extends Service {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Starts the listener for the specified protocol.
|
|
|
+ * 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 void startListener(String protocolName) {
|
|
|
+ public boolean startListener(String protocolName) {
|
|
|
+ int port = getDefaultPort(protocolName);
|
|
|
+ if(port >= 0) return startListener(protocolName, port);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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 (HoneyListener listener : listeners) {
|
|
|
- if (listener.getProtocolName().equals(protocolName)) {
|
|
|
+ if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
|
|
|
if (!listener.isRunning()) {
|
|
|
- listener.start();
|
|
|
+ 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;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- Toast.makeText(getApplicationContext(),
|
|
|
- protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT).show();
|
|
|
+ HoneyListener 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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -352,37 +396,30 @@ public class HoneyService extends Service {
|
|
|
* Name of the protocol that should be stopped.
|
|
|
*/
|
|
|
public void stopListener(String protocolName) {
|
|
|
- for (HoneyListener listener : listeners) {
|
|
|
- if (listener.getProtocolName().equals(protocolName)) {
|
|
|
- if (listener.isRunning()) {
|
|
|
- listener.stop();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Toast.makeText(getApplicationContext(),
|
|
|
- protocolName + " SERVICE STOPPED!", Toast.LENGTH_SHORT).show();
|
|
|
+ int port = getDefaultPort(protocolName);
|
|
|
+ if(port >= 0) stopListener(protocolName, port);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Toggles a listener for specified protocol.
|
|
|
+ * Stops the listener for the specified protocol.
|
|
|
*
|
|
|
* @param protocolName
|
|
|
- * Name of the protocol that should be toggled.
|
|
|
+ * Name of the protocol that should be stopped.
|
|
|
+ * @param port The port number in which the listener is running.
|
|
|
*/
|
|
|
- public void toggleListener(String protocolName) {
|
|
|
+ public void stopListener(String protocolName, int port) {
|
|
|
for (HoneyListener listener : listeners) {
|
|
|
- if (listener.getProtocolName().equals(protocolName)) {
|
|
|
+ if (listener.getProtocolName().equals(protocolName) && listener.getPort() == port) {
|
|
|
if (listener.isRunning()) {
|
|
|
- stopListener(protocolName);
|
|
|
- } else {
|
|
|
- startListener(protocolName);
|
|
|
+ listener.stop();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ Toast.makeText(getApplicationContext(), protocolName + " SERVICE STOPPED!", Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Task for accuiring a qotd from one of four possible servers.
|
|
|
+ * Task for acquiring a qotd from one of four possible servers.
|
|
|
*
|
|
|
* @author Wulf Pfeiffer
|
|
|
*/
|
|
@@ -419,4 +456,141 @@ public class HoneyService extends Service {
|
|
|
.getRandomString(100, false)));
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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(
|
|
|
+ MainActivity.CONNECTION_INFO, Context.MODE_PRIVATE);
|
|
|
+ Editor editor = pref.edit();
|
|
|
+ editor.putString(MainActivity.SSID, HelperUtils.getSSID(context));
|
|
|
+ editor.putString(MainActivity.BSSID, HelperUtils.getBSSID(context));
|
|
|
+ editor.putString(MainActivity.INTERNAL_IP,
|
|
|
+ HelperUtils.getInternalIP(context));
|
|
|
+ editor.commit();
|
|
|
+ SetExternalIPTask async = new SetExternalIPTask();
|
|
|
+ async.execute(new String[] { "http://ip2country.sourceforge.net/ip2c.php?format=JSON" });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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(MainActivity.EXTERNAL_IP, result);
|
|
|
+ connectionInfoEditor.commit();
|
|
|
+ notifyUI(this.getClass().getName(), MainActivity.EXTERNAL_IP);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // Notifications
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates a Notification in the notification bar.
|
|
|
+ */
|
|
|
+ private void createNotification() {
|
|
|
+ UglyDbHelper dbh = new UglyDbHelper(this);
|
|
|
+ boolean activeHandlers = false;
|
|
|
+ boolean bssidSeen = false;
|
|
|
+
|
|
|
+ for (HoneyListener listener : listeners) {
|
|
|
+ if(listener.isRunning())
|
|
|
+ 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 (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);
|
|
|
+ NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
+ mNotificationManager.notify(1, builder.build());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Updates the notification when a attack is registered.
|
|
|
+ */
|
|
|
+ private void updateNotification() {
|
|
|
+ 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("Network is infected!")
|
|
|
+ .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(1, builder.build());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Cancels the Notification
|
|
|
+ */
|
|
|
+ private void cancelNotification() {
|
|
|
+ NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
+ mNotificationManager.cancel(1);
|
|
|
+ }
|
|
|
+
|
|
|
}
|