|
@@ -5,6 +5,7 @@ import static com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayS
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import android.app.Activity;
|
|
@@ -38,7 +39,9 @@ import com.google.android.gms.maps.model.MarkerOptions;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.SyncInfoRecord;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.LogFilter;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
@@ -148,38 +151,41 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
|
* see MAX_DISTANCE
|
|
|
*/
|
|
|
private class SSIDArea {
|
|
|
- private Point mMinimum, mMaximum;
|
|
|
- public int numPoints;
|
|
|
+ public long numAttacks;
|
|
|
+ public long numPortscans;
|
|
|
+ Point mMinimum;
|
|
|
+ Point mMaximum;
|
|
|
|
|
|
public static final int MAX_NUM_ATTACKS = 20;
|
|
|
public static final float MAX_DISTANCE = 1000.0f; // 1km
|
|
|
|
|
|
- public SSIDArea(LatLng initialLocation) {
|
|
|
- //mMinimum = new Point(360.0, 360.0);
|
|
|
- //mMaximum = new Point(-360.0, -360.0);
|
|
|
- mMinimum = new Point(initialLocation.latitude, initialLocation.longitude);
|
|
|
- mMaximum = new Point(initialLocation.latitude, initialLocation.longitude);
|
|
|
- numPoints = 1;
|
|
|
+
|
|
|
+ public SSIDArea(LatLng initLocation, long attacks, long portscans) {
|
|
|
+ mMinimum = new Point(initLocation.latitude, initLocation.longitude);
|
|
|
+ mMaximum = new Point(initLocation.latitude, initLocation.longitude);
|
|
|
+ numAttacks = attacks;
|
|
|
+ numPortscans = portscans;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public boolean doesLocationBelongToArea(LatLng location) {
|
|
|
LatLng center = calculateCenterLocation();
|
|
|
float[] result = new float[1];
|
|
|
Location.distanceBetween(center.latitude, center.longitude, location.latitude, location.longitude, result);
|
|
|
return result[0] < MAX_DISTANCE;
|
|
|
}
|
|
|
-
|
|
|
- public void addLocation(LatLng location) {
|
|
|
+
|
|
|
+ public LatLng calculateCenterLocation() {
|
|
|
+ return new LatLng(0.5 * (mMinimum.x + mMaximum.x), 0.5 * (mMinimum.y + mMaximum.y));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addLocation(LatLng location, long attacks, long portscans) {
|
|
|
Point point = new Point(location.latitude, location.longitude);
|
|
|
if (point.x < mMinimum.x) mMinimum.x = point.x;
|
|
|
if (point.x > mMaximum.x) mMaximum.x = point.x;
|
|
|
if (point.y < mMinimum.y) mMinimum.y = point.y;
|
|
|
if (point.y > mMaximum.y) mMaximum.y = point.y;
|
|
|
- numPoints++;
|
|
|
- }
|
|
|
-
|
|
|
- public LatLng calculateCenterLocation() {
|
|
|
- return new LatLng(0.5 * (mMinimum.x + mMaximum.x), 0.5 * (mMinimum.y + mMaximum.y));
|
|
|
+ numAttacks += attacks;
|
|
|
+ numPortscans += portscans;
|
|
|
}
|
|
|
|
|
|
public float calculateRadius() {
|
|
@@ -189,7 +195,7 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
|
}
|
|
|
|
|
|
public int calculateColor() {
|
|
|
- int threatLevel = numPoints;
|
|
|
+ long threatLevel = numAttacks;
|
|
|
if (threatLevel > MAX_NUM_ATTACKS) threatLevel = MAX_NUM_ATTACKS;
|
|
|
float alpha = 1.0f - (float)(threatLevel-1) / (float)(MAX_NUM_ATTACKS-1);
|
|
|
return Color.argb(127, (int) (240.0 + 15.0 * alpha), (int) (80.0 + 175.0 * alpha), 60);
|
|
@@ -201,49 +207,65 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
|
|
|
*/
|
|
|
private void populateMap() {
|
|
|
HostageDBOpenHelper dbh = new HostageDBOpenHelper(getActivity());
|
|
|
- ArrayList<Record> records = dbh.getAllRecords();
|
|
|
-
|
|
|
+ ArrayList<NetworkRecord> netRecords = dbh.getNetworkInformation();
|
|
|
+ ArrayList<SyncInfoRecord> syncRecords = dbh.getSyncInfo();
|
|
|
+
|
|
|
HashMap<String, ArrayList<SSIDArea>> threadAreas = new HashMap<String, ArrayList<SSIDArea>>();
|
|
|
|
|
|
- for (Record record : records) {
|
|
|
- LatLng location = new LatLng(record.getLatitude(), record.getLongitude());
|
|
|
+ for (NetworkRecord netRecord : netRecords) {
|
|
|
+ LatLng location = new LatLng(netRecord.getLatitude(), netRecord.getLongitude());
|
|
|
+ long number_of_attack = 0;
|
|
|
+ long number_of_portscans = 0;
|
|
|
+ for ( Iterator<SyncInfoRecord> i = syncRecords.iterator(); i.hasNext(); ){
|
|
|
+ SyncInfoRecord info = i.next();
|
|
|
+ if(info.getBSSID().equals(netRecord.getBssid())){
|
|
|
+ number_of_attack += info.getNumber_of_attacks();
|
|
|
+ number_of_portscans += info.getNumber_of_portscans();
|
|
|
+ i.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
ArrayList<SSIDArea> areas;
|
|
|
- if (threadAreas.containsKey(record.getSsid())) {
|
|
|
- areas = threadAreas.get(record.getSsid());
|
|
|
+ if (threadAreas.containsKey(netRecord.getSsid())) {
|
|
|
+ areas = threadAreas.get(netRecord.getSsid());
|
|
|
boolean foundArea = false;
|
|
|
for (SSIDArea area : areas) {
|
|
|
if (area.doesLocationBelongToArea(location)) {
|
|
|
- area.addLocation(location);
|
|
|
+ area.addLocation(location, number_of_attack, number_of_portscans);
|
|
|
foundArea = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!foundArea) {
|
|
|
- areas.add(new SSIDArea(location));
|
|
|
+ areas.add(new SSIDArea(location, number_of_attack, number_of_portscans));
|
|
|
}
|
|
|
} else {
|
|
|
areas = new ArrayList<SSIDArea>();
|
|
|
- areas.add(new SSIDArea(location));
|
|
|
- threadAreas.put(record.getSsid(), areas);
|
|
|
- }
|
|
|
+ areas.add(new SSIDArea(location, number_of_attack, number_of_portscans));
|
|
|
+ threadAreas.put(netRecord.getSsid(), areas);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
CircleOptions circleOptions = new CircleOptions().radius(200.0).fillColor(Color.argb(127, 240, 80, 60)).strokeWidth(0.0f);
|
|
|
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.wifi_marker);
|
|
|
+
|
|
|
for (Map.Entry<String, ArrayList<SSIDArea>> entry : threadAreas.entrySet()) {
|
|
|
String ssid = entry.getKey();
|
|
|
ArrayList<SSIDArea> areas = entry.getValue();
|
|
|
-
|
|
|
- for (SSIDArea area : areas) {
|
|
|
+
|
|
|
+ for (SSIDArea area : areas) {
|
|
|
int color = area.calculateColor();
|
|
|
LatLng center = area.calculateCenterLocation();
|
|
|
float radius = area.calculateRadius();
|
|
|
|
|
|
sMap.addCircle(circleOptions.center(center).radius(100.0 + radius).fillColor(color));
|
|
|
Marker marker = sMap.addMarker(new MarkerOptions()
|
|
|
- .title(ssid + ": " + area.numPoints + (area.numPoints == 1 ? getResources()
|
|
|
+ .title(ssid + ": " + area.numAttacks + (area.numAttacks == 1 ? getResources()
|
|
|
.getString(R.string.attack)
|
|
|
- : getResources().getString(R.string.attacks))).position(
|
|
|
+ : getResources().getString(R.string.attacks)
|
|
|
+ + " + " + area.numPortscans + (area.numPortscans == 1 ? getResources()
|
|
|
+ .getString(R.string.portscan)
|
|
|
+ : getResources().getString(R.string.portscans)))).position(
|
|
|
center));
|
|
|
marker.setIcon(bitmapDescriptor);
|
|
|
|