Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable / Check for Mock Location (prevent gps spoofing)

Tags:

android

gps

spoof

Looking to find the best way to prevent / detect GPS spoofing on Android. Any suggestions on how this is accomplished, and what can be done to stop it? I am guessing the user has to turn on mock locations to spoof GPS, if this is done, then they can spoof GPS?

I guess I would need to just detect if Mock Locations are enabled? Any other suggestions?

like image 444
Chrispix Avatar asked Jul 30 '11 00:07

Chrispix


People also ask

How do I stop GPS spoofing?

Select Android > Restrictions > Click on Configure button. Under Allow Developer Options, uncheck Mock location option to restrict users from turning on Mock Locations on their devices.

Can apps detect location spoofing?

A large number of users have discovered the power of mock location apps in order to fake their locations and game the system. Ironically mock location app were created by developers as a tool to test location features.

How do I hide my mock location without knowing?

Download and install “Xposed Framework” on your phone to commence the process. Turn on the unit “Hide Mock location” in the menu Modules Xposed Installer. Go to the “Hide Mock location” option and mark the applications from which you want to hide your actual location. Restart your phone to accomplish the process.


1 Answers

I have done some investigation and sharing my results here,this may be useful for others.

First, we can check whether MockSetting option is turned ON

public static boolean isMockSettingsON(Context context) {     // returns true if mock location enabled, false if not enabled.     if (Settings.Secure.getString(context.getContentResolver(),                                 Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))         return false;     else         return true; } 

Second, we can check whether are there other apps in the device, which are using android.permission.ACCESS_MOCK_LOCATION (Location Spoofing Apps)

public static boolean areThereMockPermissionApps(Context context) {     int count = 0;      PackageManager pm = context.getPackageManager();     List<ApplicationInfo> packages =         pm.getInstalledApplications(PackageManager.GET_META_DATA);      for (ApplicationInfo applicationInfo : packages) {         try {             PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName,                                                         PackageManager.GET_PERMISSIONS);              // Get Permissions             String[] requestedPermissions = packageInfo.requestedPermissions;              if (requestedPermissions != null) {                 for (int i = 0; i < requestedPermissions.length; i++) {                     if (requestedPermissions[i]                         .equals("android.permission.ACCESS_MOCK_LOCATION")                         && !applicationInfo.packageName.equals(context.getPackageName())) {                         count++;                     }                 }             }         } catch (NameNotFoundException e) {             Log.e("Got exception " , e.getMessage());         }     }      if (count > 0)         return true;     return false; } 

If both above methods, first and second are true, then there are good chances that location may be spoofed or fake.

Now, spoofing can be avoided by using Location Manager's API.

We can remove the test provider before requesting the location updates from both the providers (Network and GPS)

LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);  try {     Log.d(TAG ,"Removing Test providers")     lm.removeTestProvider(LocationManager.GPS_PROVIDER); } catch (IllegalArgumentException error) {     Log.d(TAG,"Got exception in removing test  provider"); }  lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationListener); 

I have seen that removeTestProvider(~) works very well over Jelly Bean and onwards version. This API appeared to be unreliable till Ice Cream Sandwich.

Flutter Update: Use Geolocator and check Position object's isMocked property.

like image 50
Jambaaz Avatar answered Dec 03 '22 13:12

Jambaaz