This application is designed to demonstrate how a Tapjacking attack can be performed and mitigated in a controlled Android environment. It is intended for security researchers, developers, and students to understand this vulnerability.
Tapjacking is an attack where a malicious application displays a transparent or opaque overlay on top of a victim application. When the user interacts with the overlay (e.g., taps a button), they are unknowingly interacting with the underlying victim application. This can lead to unauthorized actions.
This app simulates:
- A victim UI (
MainActivity) with sensitive buttons. - A transparent overlay (
OverlayActivity) that attempts to hijack taps. - Defenses against Tapjacking.
- Target Interface: A simple screen (
MainActivity) with buttons simulating sensitive actions. - Overlay Screen: A semi-transparent overlay (
OverlayActivity) that intercepts touch events. - Click Feedback: Toast messages to indicate where taps are registered (overlay or underlying buttons).
- XML-based Defense: Demonstrates
android:filterTouchesWhenObscured="true"on target Views. - Kotlin-based Defense: Demonstrates overriding
onFilterTouchEventForSecurity()at the Activity level.
- Clone this repository or import the project into Android Studio.
- Connect an Android emulator or a physical device (with USB debugging enabled).
- Select the
appconfiguration and click the "Run" button in Android Studio.
- Once the app is running, you'll see
MainActivity. - Click the "Launch Overlay (Simulate Attack)" button.
- This will launch
OverlayActivity, which appears as a semi-transparent layer overMainActivity. - You'll see text like "DECEPTIVE OVERLAY CONTENT" from the overlay.
- This will launch
- Try tapping on the area where the "Sensitive Action 1 (XML Defense)" or "Sensitive Action 2 (XML Defense)" buttons are visually positioned underneath the overlay.
- You should see a Toast message: "Overlay Tapped! You thought you were tapping the screen below."
- This confirms that the overlay intercepted your tap.
- Because of the defenses implemented, the underlying buttons should NOT register this tap.
This demo includes two types of defenses:
- The "Sensitive Action 1 (XML Defense)" and "Sensitive Action 2 (XML Defense)" buttons in
MainActivityhave theandroid:filterTouchesWhenObscured="true"attribute set inapp/src/main/res/layout/activity_main.xml. - Test:
- Launch the overlay as described above.
- Tap on the location of these "Sensitive Action..." buttons.
- Expected Behavior:
- You will only see the "Overlay Tapped!" Toast.
- You will NOT see Toasts like "Sensitive Action 1 TAPPED!" from the underlying buttons. This is because
filterTouchesWhenObscured="true"prevents them from receiving taps when an overlay (like ourOverlayActivity) is present.
MainActivity.ktoverrides theonFilterTouchEventForSecurity()method. This is an Activity-level defense.- Test:
- Launch the overlay.
- Tap anywhere on the screen that is part of
MainActivitybut now covered by the overlay. - Expected Behavior:
- You will see the "Overlay Tapped!" Toast (as the overlay always gets the event first).
- You should then see a Toast: "Blocked obscured touch (Kotlin defense)!".
- Check Android Studio's Logcat (filter by "MainActivityTJ" or "Tapjacking"). You will see a warning:
"Blocked touch event because window is obscured (Tapjacking attempt detected)". - This shows the entire
MainActivityis preventing touches from passing through when it's obscured.
Note on Defense Interaction:
- If a View has
android:filterTouchesWhenObscured="true", it handles the event first. If it blocks the touch, the Activity'sonFilterTouchEventForSecuritymight not even be called for that specific view's area, or its return value for that event might be superseded. - If a View has
android:filterTouchesWhenObscured="false"(or it's not set, defaulting to false for many views), then the Activity'sonFilterTouchEventForSecurityprovides a fallback defense.
app/src/main/java/com/example/tapjackingdemo/MainActivity.kt: Simulates the victim application's screen. Implements Kotlin-based defense.OverlayActivity.kt: Implements the deceptive overlay screen.
app/src/main/res/layout/activity_main.xml: Layout forMainActivity, including buttons with XML-based defense.activity_overlay.xml: Layout forOverlayActivity.
app/src/main/AndroidManifest.xml: Declares activities, sets themes (e.g., translucent theme forOverlayActivity), and includes educational comments.app/src/main/res/values/: Contains strings, colors, and themes.
This application is strictly for educational and security testing purposes. Understanding how attacks like Tapjacking work is crucial for building more secure applications. Do not use the techniques demonstrated here for any malicious activities. Always respect privacy and ethical guidelines.