|
@ -19,6 +19,7 @@ package com.breakpointingbad.networkgenie; |
|
|
Copyright 2015-2024 by Marcel Bokhorst (M66B) |
|
|
Copyright 2015-2024 by Marcel Bokhorst (M66B) |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest; |
|
|
import android.annotation.TargetApi; |
|
|
import android.annotation.TargetApi; |
|
|
import android.app.AlarmManager; |
|
|
import android.app.AlarmManager; |
|
|
import android.app.ForegroundServiceStartNotAllowedException; |
|
|
import android.app.ForegroundServiceStartNotAllowedException; |
|
@ -144,10 +145,12 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
private static String currConnInfo = "none"; |
|
|
private static String currConnInfo = "none"; |
|
|
private static String currGenieDestIp = "1.1.1.1"; //207.x |
|
|
private static String currGenieDestIp = "1.1.1.1"; //207.x |
|
|
|
|
|
|
|
|
|
|
|
private Map<Integer, ArrayList<String>> genieAppConnList = new HashMap<>(); |
|
|
|
|
|
|
|
|
private static Object jni_lock = new Object(); |
|
|
private static Object jni_lock = new Object(); |
|
|
private static long jni_context = 0; |
|
|
private static long jni_context = 0; |
|
|
private Thread tunnelThread = null; |
|
|
private Thread tunnelThread = null; |
|
|
private ServiceSinkhole.Builder last_builder = null; |
|
|
|
|
|
|
|
|
private Builder last_builder = null; |
|
|
private ParcelFileDescriptor vpn = null; |
|
|
private ParcelFileDescriptor vpn = null; |
|
|
private boolean temporarilyStopped = false; |
|
|
private boolean temporarilyStopped = false; |
|
|
|
|
|
|
|
@ -566,7 +569,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
List<Rule> listAllowed = getAllowedRules(listRule); |
|
|
List<Rule> listAllowed = getAllowedRules(listRule); |
|
|
ServiceSinkhole.Builder builder = getBuilder(listAllowed, listRule); |
|
|
|
|
|
|
|
|
Builder builder = getBuilder(listAllowed, listRule); |
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { |
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { |
|
|
last_builder = builder; |
|
|
last_builder = builder; |
|
@ -1140,7 +1143,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
Log.d(TAG, "Start foreground state=" + state.toString()); |
|
|
Log.d(TAG, "Start foreground state=" + state.toString()); |
|
|
} else { |
|
|
} else { |
|
|
if (Util.canNotify(ServiceSinkhole.this)) |
|
|
if (Util.canNotify(ServiceSinkhole.this)) |
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -2120,17 +2123,14 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
currConnInfo = cinfo; |
|
|
currConnInfo = cinfo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int dport = packet.dport; |
|
|
|
|
|
if (dport == 53 || dport == 443 || dport == 80) { |
|
|
|
|
|
genieLogPktInfo(packet); |
|
|
|
|
|
} |
|
|
|
|
|
allowed.sender = sendConn; |
|
|
allowed.sender = sendConn; |
|
|
System.out.println("Genie handling sink pkt with daddr: " + packet.daddr + ", current genie dest: " + currGenieDestIp); |
|
|
System.out.println("Genie handling sink pkt with daddr: " + packet.daddr + ", current genie dest: " + currGenieDestIp); |
|
|
System.out.println("return some allowed object: " + allowed.toString() + " for packet: " + packet); |
|
|
|
|
|
|
|
|
System.out.println("return allowed object: " + allowed.toString() + " for packet: " + packet); |
|
|
|
|
|
|
|
|
return allowed; |
|
|
return allowed; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getLastInfo() { |
|
|
public static String getLastInfo() { |
|
|
return genieInfo; |
|
|
return genieInfo; |
|
|
} |
|
|
} |
|
@ -2168,28 +2168,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
|
|
|
|
|
|
private String readRom() |
|
|
private String readRom() |
|
|
{ |
|
|
{ |
|
|
return "blahh"; |
|
|
|
|
|
|
|
|
return "test"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void genieLogPktInfo(Packet packet) { |
|
|
|
|
|
|
|
|
|
|
|
int dport = packet.dport; |
|
|
|
|
|
int sport = packet.sport; |
|
|
|
|
|
String ptype = "using something"; |
|
|
|
|
|
if (dport == 80) { |
|
|
|
|
|
ptype = "cleartext HTTP"; |
|
|
|
|
|
} else if(dport == 443) { |
|
|
|
|
|
ptype = "HTTPS"; |
|
|
|
|
|
} else if(dport == 53) { |
|
|
|
|
|
ptype = "DNS reply"; |
|
|
|
|
|
} else if(sport == 53) { |
|
|
|
|
|
ptype = "DNS response"; |
|
|
|
|
|
} |
|
|
|
|
|
DatabaseHelper dh = DatabaseHelper.getInstance(this); |
|
|
|
|
|
String dname = dh.getQName(packet.uid, packet.daddr); |
|
|
|
|
|
String cinfo = packet.saddr + ">" + sport + ">" + packet.daddr + ">" + dport + " TO: " + dname; |
|
|
|
|
|
System.out.println("Genie found a packet " + ptype + ": " + cinfo + " from uid: " + packet.uid); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Called from native code |
|
|
// Called from native code |
|
|
private void accountUsage(Usage usage) { |
|
|
private void accountUsage(Usage usage) { |
|
@ -2550,7 +2531,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
|
|
|
|
|
|
// Build Wi-Fi action |
|
|
// Build Wi-Fi action |
|
|
Intent riWifi = new Intent(this, ServiceSinkhole.class); |
|
|
Intent riWifi = new Intent(this, ServiceSinkhole.class); |
|
|
riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); |
|
|
|
|
|
|
|
|
riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, Command.set); |
|
|
riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); |
|
|
riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); |
|
|
riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); |
|
|
riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); |
|
|
riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); |
|
|
riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); |
|
@ -2566,7 +2547,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
|
|
|
|
|
|
// Build mobile action |
|
|
// Build mobile action |
|
|
Intent riOther = new Intent(this, ServiceSinkhole.class); |
|
|
Intent riOther = new Intent(this, ServiceSinkhole.class); |
|
|
riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); |
|
|
|
|
|
|
|
|
riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, Command.set); |
|
|
riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); |
|
|
riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); |
|
|
riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); |
|
|
riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); |
|
|
riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); |
|
|
riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); |
|
@ -2582,7 +2563,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
// Show notification |
|
|
// Show notification |
|
|
if (internet) { |
|
|
if (internet) { |
|
|
if (Util.canNotify(this)) |
|
|
if (Util.canNotify(this)) |
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -3197,7 +3178,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
notification.bigText(getString(R.string.msg_revoked)); |
|
|
notification.bigText(getString(R.string.msg_revoked)); |
|
|
|
|
|
|
|
|
if (Util.canNotify(this)) |
|
|
if (Util.canNotify(this)) |
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -3228,7 +3209,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
notification.bigText(getString(R.string.msg_always_on_lockdown)); |
|
|
notification.bigText(getString(R.string.msg_always_on_lockdown)); |
|
|
|
|
|
|
|
|
if (Util.canNotify(this)) |
|
|
if (Util.canNotify(this)) |
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -3263,7 +3244,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
notification.bigText(getString(R.string.msg_autostart)); |
|
|
notification.bigText(getString(R.string.msg_autostart)); |
|
|
|
|
|
|
|
|
if (Util.canNotify(this)) |
|
|
if (Util.canNotify(this)) |
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -3294,7 +3275,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
notification.setSummaryText(message); |
|
|
notification.setSummaryText(message); |
|
|
|
|
|
|
|
|
if (Util.canNotify(this)) |
|
|
if (Util.canNotify(this)) |
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -3387,7 +3368,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (Util.canNotify(this)) |
|
|
if (Util.canNotify(this)) |
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -3414,7 +3395,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS |
|
|
.setVisibility(NotificationCompat.VISIBILITY_SECRET); |
|
|
.setVisibility(NotificationCompat.VISIBILITY_SECRET); |
|
|
|
|
|
|
|
|
if (Util.canNotify(this)) |
|
|
if (Util.canNotify(this)) |
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
System.out.println("unable to get permission to post notificatoins.."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|