-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from cruxprotocol/feature/insecure-environment…
…-security-fixes Feature/insecure environment security fixes
- Loading branch information
Showing
12 changed files
with
695 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.crux.sdk.security; | ||
|
||
import android.content.Context; | ||
import android.os.Debug; | ||
import android.content.pm.ApplicationInfo; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.net.Socket; | ||
import java.net.UnknownHostException; | ||
|
||
public class AntiDebug { | ||
|
||
private final Context mContext; | ||
|
||
public AntiDebug(Context context) { | ||
mContext = context; | ||
} | ||
|
||
public boolean isDebugging() { | ||
|
||
if (Debug.isDebuggerConnected()) { | ||
return true; | ||
} | ||
|
||
return (mContext.getApplicationContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; | ||
} | ||
|
||
//**************************************** TracerPid begin ************************************ | ||
|
||
public static boolean isTracerPid() { | ||
|
||
if (isLocalPortUsing(23946)) { | ||
return true; | ||
} | ||
|
||
String tracerPid = getTracerPid(); | ||
if (!"0".equals(tracerPid)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/*** | ||
* true:already in using false:not using | ||
* @param port | ||
*/ | ||
private static boolean isLocalPortUsing(int port) { | ||
boolean flag = true; | ||
try { | ||
flag = isPortUsing("127.0.0.1", port); | ||
} catch (Exception e) { | ||
} | ||
return flag; | ||
} | ||
|
||
/*** | ||
* true:already in using false:not using | ||
* @param host | ||
* @param port | ||
* @throws UnknownHostException | ||
*/ | ||
private static boolean isPortUsing(String host, int port) throws UnknownHostException { | ||
boolean flag = false; | ||
InetAddress theAddress = InetAddress.getByName(host); | ||
try { | ||
Socket socket = new Socket(theAddress, port); | ||
flag = true; | ||
} catch (IOException e) { | ||
} | ||
return flag; | ||
} | ||
|
||
private static String getTracerPid() { | ||
BufferedReader bufferedReader = null; | ||
String readLine = ""; | ||
try { | ||
bufferedReader = new BufferedReader(new FileReader("/proc/self/status")); | ||
do { | ||
readLine = bufferedReader.readLine(); | ||
if (readLine == null) { | ||
break; | ||
} | ||
|
||
} while (!readLine.startsWith("TracerPid:")); | ||
readLine = readLine.substring("TracerPid:".length()).trim(); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} finally { | ||
if (bufferedReader != null) { | ||
try { | ||
bufferedReader.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
return readLine; | ||
} | ||
//**************************************** TracerPid end ************************************** | ||
|
||
//**************************************** network test begin ********************************* | ||
public static boolean checkGrabData() { | ||
try { | ||
String proxyHost = System.getProperty("http.proxyHost"); | ||
String proxyPort = System.getProperty("http.proxyPort"); | ||
return proxyHost != null || proxyPort != null; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
} | ||
//**************************************** network test end *********************************** | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.crux.sdk.security; | ||
|
||
import android.os.Build; | ||
|
||
import androidx.core.os.EnvironmentCompat; | ||
|
||
public class AntiEmulator { | ||
public static boolean isEmulator() { | ||
int rating = 0; | ||
if (Build.PRODUCT.equals("sdk") || Build.PRODUCT.equals("google_sdk") || Build.PRODUCT.equals( | ||
"sdk_x86") || Build.PRODUCT.equals("vbox86p")) { | ||
rating = 1; | ||
} | ||
|
||
if (Build.MANUFACTURER.equals(EnvironmentCompat.MEDIA_UNKNOWN) || Build.MANUFACTURER.equals( | ||
"Genymotion")) { | ||
rating++; | ||
} | ||
|
||
if (Build.BRAND.equals("generic") || Build.BRAND.equals("generic_x86")) { | ||
rating++; | ||
} | ||
|
||
if (Build.DEVICE.equals("generic") || Build.DEVICE.equals("generic_x86") || Build.DEVICE.equals( | ||
"vbox86p")) { | ||
rating++; | ||
} | ||
|
||
if (Build.MODEL.equals("sdk") || Build.MODEL.equals("google_sdk") || Build.MODEL.equals( | ||
"Android SDK built for x86")) { | ||
rating++; | ||
} | ||
|
||
if (Build.HARDWARE.equals("goldfish") || Build.HARDWARE.equals("vbox86")) { | ||
rating++; | ||
} | ||
|
||
if (Build.FINGERPRINT.contains("generic/sdk/generic") || Build.FINGERPRINT.contains( | ||
"generic_x86/sdk_x86/generic_x86") || Build.FINGERPRINT.contains( | ||
"generic/google_sdk/generic") || Build.FINGERPRINT.contains("generic/vbox86p/vbox86p")) { | ||
rating++; | ||
} | ||
return rating >= 2; | ||
} | ||
} |
Oops, something went wrong.