Skip to content

Commit

Permalink
Merge pull request scottyab#116 from scottyab/feature/remove_busybox_…
Browse files Browse the repository at this point in the history
…default_check

Feature/remove busybox default check
  • Loading branch information
stealthcopter authored Jan 30, 2020
2 parents 6c29d40 + e7b4490 commit 53b32c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ These are the current checks/tricks we are using to give an indication of root.

**Java checks**

* CheckRootManagementApps
* CheckPotentiallyDangerousApps
* CheckRootCloakingApps
* CheckTestKeys
* checkRootManagementApps
* checkPotentiallyDangerousApps
* checkRootCloakingApps
* checkTestKeys
* checkForDangerousProps
* checkForBusyBoxBinary
* checkForSuBinary
Expand Down Expand Up @@ -56,10 +56,12 @@ You can also call each of the checks individually as the sample app does.

### False positives

Note that sometimes the `isRooted()` method can return a false positive. This is often because the manufacturer of the device rom has left the busybox binary. This alone doesn't mean that the device is rooted, if you wish to avoid this but still use a convenience method to you can use the following:
Manufacturers often leave the busybox binary in production builds and this doesn't always mean that a device is root. We have removed the busybox check we used to include as standard in the isRooted() method to avoid these false positives.

If you want to detect the busybox binary in your app you can use `checkForBinary(BINARY_BUSYBOX)` to detect it alone, or as part of the complete root detection method:

```java
rootBeer.isRootedWithoutBusyBoxCheck()
rootBeer.isRootedWithBusyBoxCheck();
```

The following devices are known the have the busybox binary present on the stock rom:
Expand Down
21 changes: 15 additions & 6 deletions rootbeerlib/src/main/java/com/scottyab/rootbeer/RootBeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,28 @@ public RootBeer(Context context) {
public boolean isRooted() {

return detectRootManagementApps() || detectPotentiallyDangerousApps() || checkForBinary(BINARY_SU)
|| checkForBinary(BINARY_BUSYBOX) || checkForDangerousProps() || checkForRWPaths()
|| checkForDangerousProps() || checkForRWPaths()
|| detectTestKeys() || checkSuExists() || checkForRootNative() || checkForMagiskBinary();
}

/**
* Run all the checks apart from checking for the busybox binary. This is because it can sometimes be a false positive
* as some manufacturers leave the binary in production builds.
* @return true, we think there's a good *indication* of root | false good *indication* of no root (could still be cloaked)
* @deprecated This method is deprecated as checking without the busybox binary is now the
* default. This is because many manufacturers leave this binary on production devices.
*/
public boolean isRootedWithoutBusyBoxCheck() {
return isRooted();
}

/**
* Run all the checks apart including checking for the busybox binary.
* Warning: Busybox binary is not always an indication of root, many manufacturers leave this
* binary on production devices
* @return true, we think there's a good *indication* of root | false good *indication* of no root (could still be cloaked)
*/
public boolean isRootedWithBusyBoxCheck() {

return detectRootManagementApps() || detectPotentiallyDangerousApps() || checkForBinary(BINARY_SU)
|| checkForDangerousProps() || checkForRWPaths()
|| checkForBinary(BINARY_BUSYBOX) || checkForDangerousProps() || checkForRWPaths()
|| detectTestKeys() || checkSuExists() || checkForRootNative() || checkForMagiskBinary();
}

Expand Down Expand Up @@ -163,7 +172,7 @@ public boolean checkForSuBinary(){
* @return true if found
*/
public boolean checkForBusyBoxBinary(){
return checkForBinary("busybox");
return checkForBinary(BINARY_BUSYBOX);
}

/**
Expand Down
16 changes: 6 additions & 10 deletions rootbeerlib/src/test/java/com/scottyab/rootbeer/RootBeerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void testIsRooted() {

when(rootBeer.detectRootManagementApps()).thenReturn(false);
when(rootBeer.detectPotentiallyDangerousApps()).thenReturn(false);
when(rootBeer.checkForBinary(Const.BINARY_BUSYBOX)).thenReturn(false);
when(rootBeer.checkForBinary(Const.BINARY_SU)).thenReturn(false);
when(rootBeer.checkForDangerousProps()).thenReturn(false);
when(rootBeer.checkForRWPaths()).thenReturn(false);
Expand All @@ -40,7 +39,7 @@ public void testIsRooted() {
when(rootBeer.checkForRootNative()).thenReturn(false);

// Test we return false when all methods return false
assertTrue(!rootBeer.isRooted());
assertFalse(rootBeer.isRooted());

when(rootBeer.checkForRootNative()).thenReturn(true);

Expand All @@ -49,13 +48,11 @@ public void testIsRooted() {
}

@Test
public void testIsRootedWithoutBusyBoxCheck() {
public void testIsRootedWithBusyBoxCheck() {

RootBeer rootBeer = Mockito.mock(RootBeer.class);

when(rootBeer.isRooted()).thenCallRealMethod();
when(rootBeer.isRootedWithoutBusyBoxCheck()).thenCallRealMethod();

when(rootBeer.detectRootManagementApps()).thenReturn(false);
when(rootBeer.detectPotentiallyDangerousApps()).thenReturn(false);
when(rootBeer.checkForBinary(Const.BINARY_BUSYBOX)).thenReturn(true);
Expand All @@ -66,12 +63,11 @@ public void testIsRootedWithoutBusyBoxCheck() {
when(rootBeer.checkSuExists()).thenReturn(false);
when(rootBeer.checkForRootNative()).thenReturn(false);

// Test we return false when all methods return false
assertTrue(rootBeer.isRooted());

// Test it doesn't matter what checkForBinary("busybox") returns
assertTrue(!rootBeer.isRootedWithoutBusyBoxCheck());
// Test we return false as busybox binary presence is ignored
assertFalse(rootBeer.isRooted());

// Check busybox present is detected
assertTrue(rootBeer.checkForBinary(Const.BINARY_BUSYBOX));
}

@Test
Expand Down

0 comments on commit 53b32c3

Please sign in to comment.