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.


This feature can be configured during the Malwarelytics initialization phase:

val raspConfig = RaspConfig.Builder()
    // configuration of other RASP features
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.


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.


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 (09:22) View product


Malwarelytics for Android