Harmless “malware” for Android (training only!)¶
This example uses harmless behaviours to simulate shady Android activity, using freely available tools and code.
Tools you’ll need¶
Test phone or Android Emulator (built into Android Studio)
What it simulates¶
Accessing files it shouldn’t
Background network activity
Abusing permissions
Creating suspicious logs
How to build it¶
Open Android Studio
Create a new project (Empty Activity)
Call it FakeMalwareDemo
In
MainActivity.java
(or.kt
), add the following suspicious-but-safe behaviours:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Fake data snooping
File file = new File(getExternalFilesDir(null), "leaked_data.txt");
try {
FileOutputStream fos = new FileOutputStream(file);
fos.write("FAKE user data".getBytes());
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
// Simulate suspicious network request
new Thread(() -> {
try {
URL url = new URL("http://malicious.example.com/ping");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
int code = urlConnection.getResponseCode();
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
Build and run on emulator or test phone
Observe
logcat
output and file writes
Detection practice¶
Look in
logcat
for network and file access activityUse
adb shell
to inspect written files (/data/data/your.app.package/
)Use Android’s built-in Permission Manager to spot overreach
Do not forget to remove it. It is harmless, but still …
Last update:
2025-06-11 07:09