Detection of VPN

A VPN (virtual private network) can be used to tunnel all traffic from the device through a remote server. Although VPNs are primarily used to add a level of security, they can also pose a danger when the device connects to a dubious network. For example some free VPN services might use invasive advertising or sell browsing data to third-parties. Last but not least usage of a VPN might be restricted or illegal in some countries.

Configuration

This feature can be configured during the Malwarelytics initialization phase:

val raspConfig = RaspConfig.Builder()
    .checkVpn(Boolean)
    .exitOnVpn(Boolean)
    .exitOnVpnUrl(String)
    // configuration of other RASP features
    .build()
Method Description
checkVpn(Boolean) indicates whether VPN use should be detected automatically. Defaults to true.
exitOnVpn(Boolean) indicates whether the app should be terminated when the use of a VPN is detected. Defaults to false.
exitOnVpnUrl(String) defines a URL to be opened when the app is terminated because of detection of a VPN. Defaults to null.

Usage

After initialization, the VPN detection feature can be accessed via RaspManager. This can be used to register an observer or to trigger a manual VPN detection check.

Registering an Observer

VPN detection can trigger a certain action. To achieve that, an observer needs to be configured and registered.

Observer configuration:

val raspObserver = object : RaspObserver {
    override fun onVpnDetected(vpnEnabled: Boolean) {
        // handle VPN detection
    }
    // handle detection of other RASP features
}

The observer can be registered in RaspManager. When it is no longer needed, it can be unregistered again.

raspManager.registerRaspObserver(raspObserver)
raspManager.unregisterRaspObserver(raspObserver)

Triggering a Manual Check

VPN detection check can be triggered manually in RaspManager by calling the isVpnEnabled() method. A simple boolean answer is given.

val isVpnEnabled = raspManager.isVpnEnabled()

More information on general RASP feature configuration and usage can be found in this overview.

Last updated on Feb 14, 2023 (10:22) View product
Search

0.23.x

Malwarelytics for Android