|
@@ -1,8 +1,6 @@
|
|
|
package de.tudarmstadt.informatik.hostage.ui;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
-import java.io.DataInputStream;
|
|
|
-import java.io.File;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -29,6 +27,7 @@ import android.content.SharedPreferences.Editor;
|
|
|
import android.net.ConnectivityManager;
|
|
|
import android.os.AsyncTask;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
import android.util.Log;
|
|
@@ -47,35 +46,39 @@ import android.widget.CheckBox;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.TextView;
|
|
|
-import android.widget.Toast;
|
|
|
import android.widget.ToggleButton;
|
|
|
import android.widget.ViewAnimator;
|
|
|
import de.tudarmstadt.informatik.hostage.HoneyService;
|
|
|
import de.tudarmstadt.informatik.hostage.HoneyService.LocalBinder;
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver.Receiver;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.Logger;
|
|
|
-import de.tudarmstadt.informatik.hostage.logging.SQLLogger;
|
|
|
+
|
|
|
/**
|
|
|
* MainActivity is the central activity for the GUI of the application.
|
|
|
- * MainActivity is launched when the application is first started.
|
|
|
- * It shows the user: <br>
|
|
|
+ * MainActivity is launched when the application is first started. It shows the
|
|
|
+ * user: <br>
|
|
|
* - information about the network<br>
|
|
|
* - light indicators for recorded attacks on each protocol<br>
|
|
|
* - amount of attacks on each protocols<br>
|
|
|
* The user can start and stop services.
|
|
|
+ *
|
|
|
* @author Mihai Plasoianu
|
|
|
* @author Lars Pandikow
|
|
|
* @author Wulf Pfeiffer
|
|
|
*/
|
|
|
-public class MainActivity extends Activity {
|
|
|
+public class MainActivity extends Activity implements Receiver {
|
|
|
// String constants for whole application
|
|
|
/**
|
|
|
- * Used for Broadcast between service and GUI. String: "de.tudarmstadt.informatik.hostage.BROADCAST"
|
|
|
+ * Used for Broadcast between service and GUI. String:
|
|
|
+ * "de.tudarmstadt.informatik.hostage.BROADCAST"
|
|
|
*/
|
|
|
public static final String BROADCAST = "de.tudarmstadt.informatik.hostage.BROADCAST";
|
|
|
/**
|
|
|
- * Used to store session related data in a SharedPrefereces. String: "de.tudarmstadt.informatik.hostage.SESSION_DATA"
|
|
|
+ * Used to store session related data in a SharedPrefereces. String:
|
|
|
+ * "de.tudarmstadt.informatik.hostage.SESSION_DATA"
|
|
|
*/
|
|
|
public static final String SESSION_DATA = "de.tudarmstadt.informatik.hostage.SESSION_DATA";
|
|
|
public static final String LISTENER = "_LISTENER";
|
|
@@ -84,7 +87,7 @@ public class MainActivity extends Activity {
|
|
|
public static final String BSSID = "BSSID";
|
|
|
public static final String INTERNAL_IP = "INTERNAL_IP";
|
|
|
public static final String EXTERNAL_IP = "EXTERNAL_IP";
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Flag for root acces. True if phone has root acces, else false.
|
|
|
*/
|
|
@@ -110,15 +113,15 @@ public class MainActivity extends Activity {
|
|
|
* Integer representing a yellow light.
|
|
|
*/
|
|
|
public static final int LIGHT_YELLOW = 0x04;
|
|
|
-
|
|
|
- private static Context context;
|
|
|
|
|
|
+ private static Context context;
|
|
|
+
|
|
|
+ public LogResultReceiver logResultReceiver;
|
|
|
|
|
|
private HoneyService mService;
|
|
|
private boolean serviceBound;
|
|
|
private SharedPreferences sessionPref;
|
|
|
private Editor sessionEditor;
|
|
|
- private Logger logger;
|
|
|
|
|
|
// variables for the swipe animation
|
|
|
private ViewAnimator viewAnimator;
|
|
@@ -130,22 +133,24 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
private ListView listView;
|
|
|
private ListViewAdapter adapter;
|
|
|
-
|
|
|
+
|
|
|
private String protocolClicked;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ private boolean isBssidSeen = false;
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
- MainActivity.context = getApplicationContext(); //set context
|
|
|
+ MainActivity.context = getApplicationContext(); // set context
|
|
|
+ logResultReceiver = new LogResultReceiver(new Handler());
|
|
|
setContentView(R.layout.activity_main);
|
|
|
-
|
|
|
+
|
|
|
// Create dynamic view elements
|
|
|
initViewAnimator();
|
|
|
initListView();
|
|
|
// Initialize Class variables
|
|
|
- sessionPref = getSharedPreferences(MainActivity.SESSION_DATA, Context.MODE_PRIVATE);
|
|
|
- logger = new SQLLogger(this);
|
|
|
+ sessionPref = getSharedPreferences(MainActivity.SESSION_DATA,
|
|
|
+ Context.MODE_PRIVATE);
|
|
|
sessionEditor = sessionPref.edit();
|
|
|
checkRootAndPorthack();
|
|
|
}
|
|
@@ -155,35 +160,37 @@ public class MainActivity extends Activity {
|
|
|
getMenuInflater().inflate(R.menu.main, menu);
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
- // Handle item selection
|
|
|
- switch (item.getItemId()) {
|
|
|
- case R.id.action_settings:
|
|
|
- startActivity(new Intent(this, SettingsActivity.class));
|
|
|
- break;
|
|
|
- case R.id.action_about:
|
|
|
- startActivity(new Intent(this, AboutActivity.class));
|
|
|
- break;
|
|
|
- default:
|
|
|
- }
|
|
|
- return super.onOptionsItemSelected(item);
|
|
|
+ // Handle item selection
|
|
|
+ switch (item.getItemId()) {
|
|
|
+ case R.id.action_settings:
|
|
|
+ startActivity(new Intent(this, SettingsActivity.class));
|
|
|
+ break;
|
|
|
+ case R.id.action_about:
|
|
|
+ startActivity(new Intent(this, AboutActivity.class));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onStart() {
|
|
|
super.onStart();
|
|
|
- //Register Broadcast Receiver
|
|
|
+ // Register Broadcast Receiver
|
|
|
registerReceiver();
|
|
|
registerNetReceiver();
|
|
|
- // Bind service if running, else check for connection change and delete sessionData
|
|
|
+ logResultReceiver.setReceiver(this);
|
|
|
+ // Bind service if running, else check for connection change and delete
|
|
|
+ // sessionData
|
|
|
if (isServiceRunning()) {
|
|
|
bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
|
|
|
} else {
|
|
|
String bssid_old = sessionPref.getString(MainActivity.BSSID, "");
|
|
|
String bssid_new = HelperUtils.getBSSID(this);
|
|
|
- if(bssid_new == null || !bssid_new.equals(bssid_old)){
|
|
|
+ if (bssid_new == null || !bssid_new.equals(bssid_old)) {
|
|
|
deleteSessionData();
|
|
|
}
|
|
|
}
|
|
@@ -194,27 +201,34 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
@Override
|
|
|
protected void onStop() {
|
|
|
- //Unbind running service
|
|
|
+ // Unbind running service
|
|
|
if (isServiceRunning()) {
|
|
|
unbindService(mConnection);
|
|
|
}
|
|
|
// Unregister Broadcast Receiver
|
|
|
unregisterNetReceiver();
|
|
|
unregisterReceiver();
|
|
|
+ logResultReceiver.setReceiver(null);
|
|
|
super.onStop();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- protected void onDestroy(){
|
|
|
+ protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
// If service not running delete session data
|
|
|
- if(!isServiceRunning()){
|
|
|
+ if (!isServiceRunning()) {
|
|
|
deleteSessionData();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onReceiveResult(int resultCode, Bundle resultData) {
|
|
|
+ isBssidSeen = resultData.getBoolean("result");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Called when User presses on/off button.
|
|
|
+ *
|
|
|
* @param view
|
|
|
*/
|
|
|
public void buttonOnOffClick(View view) {
|
|
@@ -223,129 +237,141 @@ public class MainActivity extends Activity {
|
|
|
protocolClicked = "PANIC";
|
|
|
} else {
|
|
|
protocolClicked = "SMB";
|
|
|
- }
|
|
|
+ }
|
|
|
startAndBind();
|
|
|
} else {
|
|
|
mService.stopListeners();
|
|
|
stopAndUnbind();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Starts the ViewLog activity, when the Button is pressed.
|
|
|
+ *
|
|
|
* @see ViewLog
|
|
|
- * @param view View elements which triggers the method call.
|
|
|
+ * @param view
|
|
|
+ * View elements which triggers the method call.
|
|
|
*/
|
|
|
- public void showLog(View view){
|
|
|
+ public void showLog(View view) {
|
|
|
startActivity(new Intent(this, ViewLog.class));
|
|
|
}
|
|
|
-
|
|
|
- public void startPlayGround(View view){
|
|
|
+
|
|
|
+ public void startPlayGround(View view) {
|
|
|
startActivity(new Intent(this, PlayGroundActivity.class));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * If mobile phone is connected to a wireless network starts the background service ands binds itself to it.
|
|
|
- * Else notifies the user that service could not be started.
|
|
|
+ * If mobile phone is connected to a wireless network starts the background
|
|
|
+ * service ands binds itself to it. Else notifies the user that service
|
|
|
+ * could not be started.
|
|
|
*/
|
|
|
private void startAndBind() {
|
|
|
startService(getServiceIntent());
|
|
|
- bindService();
|
|
|
+ bindService();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Binds service to Activity
|
|
|
+ *
|
|
|
* @see HoneyService
|
|
|
*/
|
|
|
- private void bindService(){
|
|
|
+ private void bindService() {
|
|
|
bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
|
|
|
serviceBound = true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Stops service and unbinds it.
|
|
|
+ *
|
|
|
* @see HoneyService
|
|
|
*/
|
|
|
private void stopAndUnbind() {
|
|
|
unbindService();
|
|
|
stopService(getServiceIntent());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Unbinds service.
|
|
|
+ *
|
|
|
* @see HoneyService
|
|
|
*/
|
|
|
- private void unbindService(){
|
|
|
+ private void unbindService() {
|
|
|
unbindService(mConnection);
|
|
|
serviceBound = false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Connection to bind the background service
|
|
|
+ *
|
|
|
* @see HoneyService
|
|
|
*/
|
|
|
private ServiceConnection mConnection = new ServiceConnection() {
|
|
|
- /**
|
|
|
- * After the service is bound, check which has been clicked and start it.
|
|
|
+ /**
|
|
|
+ * After the service is bound, check which has been clicked and start
|
|
|
+ * it.
|
|
|
+ *
|
|
|
* @see android.content.ServiceConnection#onServiceConnected(android.content.ComponentName)
|
|
|
*/
|
|
|
@Override
|
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
mService = ((LocalBinder) service).getService();
|
|
|
- if(protocolClicked != null && protocolClicked.equals("PANIC")){
|
|
|
+ if (protocolClicked != null && protocolClicked.equals("PANIC")) {
|
|
|
mService.startListeners();
|
|
|
- }else if (protocolClicked != null){
|
|
|
+ } else if (protocolClicked != null) {
|
|
|
mService.toggleListener(protocolClicked);
|
|
|
}
|
|
|
protocolClicked = null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* After the service is unbound, delete reference.
|
|
|
+ *
|
|
|
* @see android.content.ServiceConnection#onServiceDisconnected(android.content.ComponentName)
|
|
|
*/
|
|
|
@Override
|
|
|
public void onServiceDisconnected(ComponentName name) {
|
|
|
- mService = null;
|
|
|
+ mService = null;
|
|
|
}
|
|
|
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Checks if the phone ist rooted and if porthack is installed. Sets flags {@link isRooted} and {@link porthackInstalled}
|
|
|
+ * Checks if the phone ist rooted and if porthack is installed. Sets flags
|
|
|
+ * {@link isRooted} and {@link porthackInstalled}
|
|
|
*/
|
|
|
- private void checkRootAndPorthack(){
|
|
|
+ private void checkRootAndPorthack() {
|
|
|
isRooted = false;
|
|
|
porthackInstalled = false;
|
|
|
Process p;
|
|
|
try {
|
|
|
String found = "Found";
|
|
|
String notFound = "Not found";
|
|
|
- String command = "[ -f /data/local/p ] && echo " + found + " || echo " + notFound;
|
|
|
+ String command = "[ -f /data/local/p ] && echo " + found
|
|
|
+ + " || echo " + notFound;
|
|
|
p = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
|
|
|
- BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
|
- /* int av =
|
|
|
- byte[] b = new byte[av];
|
|
|
- if (av != 0) {
|
|
|
- in.read(b);
|
|
|
- }
|
|
|
- */
|
|
|
- String echoResponse = in.readLine();
|
|
|
- Log.i("MainAc", echoResponse);
|
|
|
- if(echoResponse.equals(found)){
|
|
|
- isRooted = true;
|
|
|
- porthackInstalled = true;
|
|
|
- } else if(echoResponse.equals(notFound)){
|
|
|
- isRooted = true;
|
|
|
- }
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(
|
|
|
+ p.getInputStream()));
|
|
|
+ /*
|
|
|
+ * int av = byte[] b = new byte[av]; if (av != 0) { in.read(b); }
|
|
|
+ */
|
|
|
+ String echoResponse = in.readLine();
|
|
|
+ Log.i("MainAc", echoResponse);
|
|
|
+ if (echoResponse.equals(found)) {
|
|
|
+ isRooted = true;
|
|
|
+ porthackInstalled = true;
|
|
|
+ } else if (echoResponse.equals(notFound)) {
|
|
|
+ isRooted = true;
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- }
|
|
|
- Log.i("MainAc", "Rooted: " + isRooted + " Porthack: " + porthackInstalled);
|
|
|
+ }
|
|
|
+ Log.i("MainAc", "Rooted: " + isRooted + " Porthack: "
|
|
|
+ + porthackInstalled);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Returns an intent to start HoneyService.
|
|
|
+ *
|
|
|
* @return An Intent to start HoneyService
|
|
|
*/
|
|
|
private Intent getServiceIntent() {
|
|
@@ -354,6 +380,7 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
/**
|
|
|
* Checks if user selected paranoid mode.
|
|
|
+ *
|
|
|
* @return True when paranoid mode is selected, else returns false.
|
|
|
*/
|
|
|
private boolean isParanoid() {
|
|
@@ -361,7 +388,8 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Initializes the ListView. Creating its contents dynamic from protocol res/values/protocols.xml
|
|
|
+ * Initializes the ListView. Creating its contents dynamic from protocol
|
|
|
+ * res/values/protocols.xml
|
|
|
*/
|
|
|
private void initListView() {
|
|
|
ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
|
|
@@ -391,42 +419,46 @@ public class MainActivity extends Activity {
|
|
|
String protocolName = (String) ((HashMap<?, ?>) adapter
|
|
|
.getItem(position)).get("protocol");
|
|
|
if (isServiceRunning()) {
|
|
|
- mService.toggleListener(protocolName);
|
|
|
- if(!mService.hasRunningListeners()){
|
|
|
+ mService.toggleListener(protocolName);
|
|
|
+ if (!mService.hasRunningListeners()) {
|
|
|
stopAndUnbind();
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
protocolClicked = protocolName;
|
|
|
startAndBind();
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Checks if a {@link HoneyService} instance is running.
|
|
|
- * @return True if {@link HoneyService} is running, else false.
|
|
|
+ *
|
|
|
+ * @return True if {@link HoneyService} is running, else false.
|
|
|
*/
|
|
|
private boolean isServiceRunning() {
|
|
|
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
- for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
|
- if (service.service.getClassName().equals(HoneyService.class.getName())) {
|
|
|
+ for (RunningServiceInfo service : manager
|
|
|
+ .getRunningServices(Integer.MAX_VALUE)) {
|
|
|
+ if (service.service.getClassName().equals(
|
|
|
+ HoneyService.class.getName())) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Deletes all session related Data.
|
|
|
*/
|
|
|
- private void deleteSessionData(){
|
|
|
- sessionEditor.clear();
|
|
|
- sessionEditor.commit();
|
|
|
+ private void deleteSessionData() {
|
|
|
+ sessionEditor.clear();
|
|
|
+ sessionEditor.commit();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Register broadcast receiver for custom broadcast.
|
|
|
+ *
|
|
|
* @see #BROADCAST
|
|
|
*/
|
|
|
private void registerReceiver() {
|
|
@@ -436,14 +468,16 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
/**
|
|
|
* Unregisters broadcast receiver for custom broadcast.
|
|
|
+ *
|
|
|
* @see #BROADCAST
|
|
|
*/
|
|
|
private void unregisterReceiver() {
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Receiver for custom broadcast.
|
|
|
+ *
|
|
|
* @see #BROADCAST
|
|
|
*/
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
@@ -456,12 +490,13 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
/**
|
|
|
* Register broadcast receiver for network state changes.
|
|
|
+ *
|
|
|
* @see ConnectivityManager#CONNECTIVITY_ACTION
|
|
|
*/
|
|
|
- private void registerNetReceiver() {
|
|
|
+ private void registerNetReceiver() {
|
|
|
IntentFilter intent = new IntentFilter();
|
|
|
- intent.addAction(ConnectivityManager.CONNECTIVITY_ACTION); //"android.net.conn.CONNECTIVITY_CHANGE"
|
|
|
- registerReceiver(netReceiver, intent);
|
|
|
+ intent.addAction(ConnectivityManager.CONNECTIVITY_ACTION); // "android.net.conn.CONNECTIVITY_CHANGE"
|
|
|
+ registerReceiver(netReceiver, intent);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -477,63 +512,70 @@ public class MainActivity extends Activity {
|
|
|
private BroadcastReceiver netReceiver = new BroadcastReceiver() {
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
-/* String bssid_old = sessionPref.getString(BSSID, "");
|
|
|
- String bssid_new = HelperUtils.getBSSID(context);
|
|
|
-
|
|
|
- if ((bssid_new == null || !bssid_new.equals(bssid_old)) && serviceBound) {
|
|
|
- Toast.makeText(getApplicationContext(),"Connection changed! Services stopped!", Toast.LENGTH_LONG).show();
|
|
|
- unbindService();
|
|
|
- }
|
|
|
-*/
|
|
|
+ /*
|
|
|
+ * String bssid_old = sessionPref.getString(BSSID, ""); String
|
|
|
+ * bssid_new = HelperUtils.getBSSID(context);
|
|
|
+ *
|
|
|
+ * if ((bssid_new == null || !bssid_new.equals(bssid_old)) &&
|
|
|
+ * serviceBound) { Toast.makeText(getApplicationContext(),
|
|
|
+ * "Connection changed! Services stopped!",
|
|
|
+ * Toast.LENGTH_LONG).show(); unbindService(); }
|
|
|
+ */
|
|
|
updateConnectionInfText();
|
|
|
}
|
|
|
- };
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
|
* Updates Information shown by the GUI.
|
|
|
*/
|
|
|
- private void updateUI() {
|
|
|
+ private void updateUI() {
|
|
|
boolean activeListeners = false;
|
|
|
boolean activeHandlers = false;
|
|
|
boolean yellowLight = false;
|
|
|
-
|
|
|
- //Check for all protocols if listeners are active and attacks have been recorded
|
|
|
- //Update protocol lights and connection information.
|
|
|
- for(String protocol : getResources().getStringArray(R.array.protocols)){
|
|
|
- //Check if protocol is active
|
|
|
- if(sessionPref.getBoolean(protocol + LISTENER, false)){
|
|
|
+
|
|
|
+ // Check for all protocols if listeners are active and attacks have been
|
|
|
+ // recorded
|
|
|
+ // Update protocol lights and connection information.
|
|
|
+ for (String protocol : getResources().getStringArray(R.array.protocols)) {
|
|
|
+ // Check if protocol is active
|
|
|
+ if (sessionPref.getBoolean(protocol + LISTENER, false)) {
|
|
|
activeListeners = true;
|
|
|
- int handlerCount = sessionPref.getInt(protocol + HANDLER_COUNT, 0);
|
|
|
- //Check if attacks have been recorded in this session.
|
|
|
- if(handlerCount > 0){
|
|
|
+ int handlerCount = sessionPref.getInt(protocol + HANDLER_COUNT,
|
|
|
+ 0);
|
|
|
+ // Check if attacks have been recorded in this session.
|
|
|
+ if (handlerCount > 0) {
|
|
|
activeHandlers = true;
|
|
|
updateProtocolLight(LIGHT_RED, protocol);
|
|
|
updateProtocolConnections(handlerCount, protocol);
|
|
|
- } else{
|
|
|
- //Check if the bssid of the wireless network has already been recorded as infected.
|
|
|
- if(logger.bssidSeen(protocol, HelperUtils.getBSSID(getApplicationContext()))){
|
|
|
+ } else {
|
|
|
+ // Check if the bssid of the wireless network has already
|
|
|
+ // been recorded as infected.
|
|
|
+ Logger.isBssidSeen(getApplicationContext(), protocol,
|
|
|
+ HelperUtils.getBSSID(getApplicationContext()),
|
|
|
+ logResultReceiver);
|
|
|
+ if (isBssidSeen) {
|
|
|
updateProtocolLight(LIGHT_YELLOW, protocol);
|
|
|
yellowLight = true;
|
|
|
- } else{
|
|
|
- updateProtocolLight(LIGHT_GREEN, protocol);
|
|
|
+ } else {
|
|
|
+ updateProtocolLight(LIGHT_GREEN, protocol);
|
|
|
}
|
|
|
updateProtocolConnections(0, protocol);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
updateProtocolLight(LIGHT_GREY, protocol);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //Update the big attack indicator.
|
|
|
+ // Update the big attack indicator.
|
|
|
if (activeListeners) {
|
|
|
if (activeHandlers) {
|
|
|
updateStatusLight(LIGHT_RED);
|
|
|
} else {
|
|
|
- if(yellowLight){
|
|
|
+ if (yellowLight) {
|
|
|
updateStatusLight(LIGHT_YELLOW);
|
|
|
} else {
|
|
|
updateStatusLight(LIGHT_GREEN);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
((ToggleButton) findViewById(R.id.toggleButtonOnOff))
|
|
|
.setChecked(true);
|
|
@@ -548,8 +590,10 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
/**
|
|
|
* Sets the big light indicator.
|
|
|
- * @param light Integer code to set the light color.
|
|
|
- * @see #LIGHT_GREY
|
|
|
+ *
|
|
|
+ * @param light
|
|
|
+ * Integer code to set the light color.
|
|
|
+ * @see #LIGHT_GREY
|
|
|
* @see #LIGHT_GREEN
|
|
|
* @see #LIGHT_RED
|
|
|
* @see #LIGHT_YELLOW
|
|
@@ -577,8 +621,11 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
/**
|
|
|
* Sets the light indicator for a given protocol.
|
|
|
- * @param light Integer code to set the light color.
|
|
|
- * @param protocolName Name of the protocol which should be updated.
|
|
|
+ *
|
|
|
+ * @param light
|
|
|
+ * Integer code to set the light color.
|
|
|
+ * @param protocolName
|
|
|
+ * Name of the protocol which should be updated.
|
|
|
*/
|
|
|
private void updateProtocolLight(int light, String protocolName) {
|
|
|
for (int i = 0; i < adapter.getCount(); ++i) {
|
|
@@ -607,8 +654,11 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
/**
|
|
|
* Sets the connections count for a given protocol.
|
|
|
- * @param connections New value for recorded connections.
|
|
|
- * @param protocolName Name of the protocol which should be updated.
|
|
|
+ *
|
|
|
+ * @param connections
|
|
|
+ * New value for recorded connections.
|
|
|
+ * @param protocolName
|
|
|
+ * Name of the protocol which should be updated.
|
|
|
*/
|
|
|
private void updateProtocolConnections(int connections, String protocolName) {
|
|
|
for (int i = 0; i < adapter.getCount(); ++i) {
|
|
@@ -625,100 +675,105 @@ public class MainActivity extends Activity {
|
|
|
* Gets Information about connection state and updates the GUI.
|
|
|
*/
|
|
|
private void updateConnectionInfText() {
|
|
|
- TextView ssidView = (TextView) findViewById(R.id.textViewSSIDValue);
|
|
|
- TextView bssidView = (TextView) findViewById(R.id.textViewBSSIDValue);
|
|
|
- TextView internalIPView = (TextView) findViewById(R.id.textViewInternalIPValue);
|
|
|
- TextView externalIPView = (TextView) findViewById(R.id.textViewExternalIPValue);
|
|
|
-
|
|
|
- externalIPView.setText("Loading...");
|
|
|
-
|
|
|
- //Update the connection information
|
|
|
- updateConnectionInfo();
|
|
|
- SetExternalIPTask async = new SetExternalIPTask();
|
|
|
- async.execute(new String[]{"http://ip2country.sourceforge.net/ip2c.php?format=JSON"});
|
|
|
-
|
|
|
- //Get connection information
|
|
|
- String ssid = sessionPref.getString(SSID, null);
|
|
|
- String bssid = sessionPref.getString(BSSID, null);
|
|
|
- String internalIP = sessionPref.getString(INTERNAL_IP, null);
|
|
|
-
|
|
|
- //Set text fields
|
|
|
- if (ssid != null)
|
|
|
- ssidView.setText(ssid);
|
|
|
- else
|
|
|
- ssidView.setText("-");
|
|
|
-
|
|
|
- if (bssid != null)
|
|
|
- bssidView.setText(bssid);
|
|
|
- else
|
|
|
- bssidView.setText("-");
|
|
|
-
|
|
|
- if (internalIP != null)
|
|
|
- internalIPView.setText(internalIP);
|
|
|
- else
|
|
|
- internalIPView.setText("-");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Updates the connection info and saves them in the the SharedPreferences for session data.
|
|
|
- * @param context Needs a context to get system recourses.
|
|
|
+ TextView ssidView = (TextView) findViewById(R.id.textViewSSIDValue);
|
|
|
+ TextView bssidView = (TextView) findViewById(R.id.textViewBSSIDValue);
|
|
|
+ TextView internalIPView = (TextView) findViewById(R.id.textViewInternalIPValue);
|
|
|
+ TextView externalIPView = (TextView) findViewById(R.id.textViewExternalIPValue);
|
|
|
+
|
|
|
+ externalIPView.setText("Loading...");
|
|
|
+
|
|
|
+ // Update the connection information
|
|
|
+ updateConnectionInfo();
|
|
|
+ SetExternalIPTask async = new SetExternalIPTask();
|
|
|
+ async.execute(new String[] { "http://ip2country.sourceforge.net/ip2c.php?format=JSON" });
|
|
|
+
|
|
|
+ // Get connection information
|
|
|
+ String ssid = sessionPref.getString(SSID, null);
|
|
|
+ String bssid = sessionPref.getString(BSSID, null);
|
|
|
+ String internalIP = sessionPref.getString(INTERNAL_IP, null);
|
|
|
+
|
|
|
+ // Set text fields
|
|
|
+ if (ssid != null)
|
|
|
+ ssidView.setText(ssid);
|
|
|
+ else
|
|
|
+ ssidView.setText("-");
|
|
|
+
|
|
|
+ if (bssid != null)
|
|
|
+ bssidView.setText(bssid);
|
|
|
+ else
|
|
|
+ bssidView.setText("-");
|
|
|
+
|
|
|
+ if (internalIP != null)
|
|
|
+ internalIPView.setText(internalIP);
|
|
|
+ else
|
|
|
+ internalIPView.setText("-");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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#SESSION_DATA
|
|
|
*/
|
|
|
- private void updateConnectionInfo() {
|
|
|
- SharedPreferences pref = context.getSharedPreferences(MainActivity.SESSION_DATA, Context.MODE_PRIVATE);
|
|
|
+ private void updateConnectionInfo() {
|
|
|
+ SharedPreferences pref = context.getSharedPreferences(
|
|
|
+ MainActivity.SESSION_DATA, 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.putString(MainActivity.INTERNAL_IP,
|
|
|
+ HelperUtils.getInternalIP(context));
|
|
|
editor.commit();
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 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){
|
|
|
- sessionEditor.putString(MainActivity.EXTERNAL_IP, result);
|
|
|
- sessionEditor.commit();
|
|
|
- TextView externalIPView = (TextView) findViewById(R.id.textViewExternalIPValue);
|
|
|
- if (result != null)
|
|
|
- externalIPView.setText(result);
|
|
|
- else
|
|
|
- externalIPView.setText("-");
|
|
|
+ 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) {
|
|
|
+ sessionEditor.putString(MainActivity.EXTERNAL_IP, result);
|
|
|
+ sessionEditor.commit();
|
|
|
+ TextView externalIPView = (TextView) findViewById(R.id.textViewExternalIPValue);
|
|
|
+ if (result != null)
|
|
|
+ externalIPView.setText(result);
|
|
|
+ else
|
|
|
+ externalIPView.setText("-");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /* ############# Help functions for animation ################## */
|
|
|
|
|
|
- /*############# Help functions for animation ##################*/
|
|
|
-
|
|
|
@Override
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
return gestureDetector.onTouchEvent(event);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Initializes variables for screen animation
|
|
|
*/
|
|
@@ -735,7 +790,7 @@ public class MainActivity extends Activity {
|
|
|
animFlipOutRL = AnimationUtils.loadAnimation(this,
|
|
|
R.anim.out_right_to_left);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Called when a swipe to the Left is registered.
|
|
|
*/
|
|
@@ -775,9 +830,10 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
/**
|
|
|
* Returns the context of the App.
|
|
|
+ *
|
|
|
* @return context.
|
|
|
*/
|
|
|
- public static Context getContext() {
|
|
|
- return MainActivity.context;
|
|
|
- }
|
|
|
+ public static Context getContext() {
|
|
|
+ return MainActivity.context;
|
|
|
+ }
|
|
|
}
|