-
Notifications
You must be signed in to change notification settings - Fork 527
Better internet access block? #132
Comments
By the way, LBE Security Master can block internet for RR3 and app won't give exception. But actually, i want to move from LBE to XPrivacy. |
It happened to me with other apps as well, it's because xprivacy blocks the internet access. |
I will see what I can do. |
This will be realized in the next release. |
Both RealRacing 3 and Youtube still crash upon starting if i apply internet restriction to them. Did you implement new way to restrict internet already or not yet? |
RealRacing 3: E/AndroidRuntime( 9669): java.lang.SecurityException: Permission denied (missing INTERNET permission?) Is it possible to not remove INTERNET permission, but still intercept "inet" framework access and report disconnected/not connected status? |
XPrivacy already reports internet as offline, but some applications ignore this. |
But it looks like XPrivacy also revokes android.permission.INTERNET making application crash. |
Maybe, I will look into it. |
How about intercept functions of java.net.InetAddress ? E/AndroidRuntime( 9669): java.lang.SecurityException: Permission denied (missing INTERNET permission?) E/AndroidRuntime( 9669): at java.net.InetAddress.lookupHostByName(InetAddress.java:418) E/AndroidRuntime( 9669): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) E/AndroidRuntime( 9669): at java.net.InetAddress.getAllByName(InetAddress.java:214) I'm not sure is Youtube crash on the same function or not, but you can start from investigating Youtube crash since it's pre-installed already. |
Sorry, to spam the topic. Just as an idea: Probably if you intercept DNS queries and return error while resolving address then most applications should give up to connect. |
I'm ready to experiment by myself. I've download source code and it compiles fine. The only problem - i don't know how to trow exception to original application. InetAddress functions trigger exception if host name cannot be resolved. So, i need simulate this exception to original application. |
@sorgelig if you want to chat (so I can help you), send me a XDA PM to exchange addresses. |
Ok, it looks like working :)
Now both RR3 and Youtube start fine and cannot see any connections! :) @M66B, thanks for help offering. I will contact you at XDA if i will have further thoughts/questions about XPrivacy. package biz.bokhorst.xprivacy;
import java.lang.reflect.Field;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
public class XInetAddress extends XHook {
public XInetAddress(String methodName, String restrictionName, String[] permissions) {
super(methodName, restrictionName, permissions, null);
}
// static InetAddress[] getAllByName(String host)
// static InetAddress getByAddress(byte[] ipAddress)
// static InetAddress getByAddress(String hostName, byte[] ipAddress)
// static InetAddress getByName(String host)
// static InetAddress getLocalHost()
// libcore/luni/src/main/java/java/net/InetAddress.java
@Override
protected void before(MethodHookParam param) throws Throwable {
if (isRestricted(param)) {
String methodName = param.method.getName();
if (methodName.equals("getAllByName") ||
methodName.equals("getByAddress"))
{
param.setThrowable(new UnknownHostException("Unable to resolve host"));
}
else if (methodName.equals("getByName"))
{
if(param.args[0] != null)
{
String name = (String)param.args[0];
if(name.equals("localhost"))
{
InetAddress addr = getLoopback();
if(addr != null)
{
param.setResult(addr);
return;
}
}
}
param.setThrowable(new UnknownHostException("Unable to resolve host"));
}
else if (methodName.equals("getLocalHost"))
{
InetAddress addr = getLoopback();
if(addr != null)
{
param.setResult(addr);
return;
}
param.setThrowable(new UnknownHostException("Unable to resolve host"));
}
}
}
InetAddress getLoopback()
{
try
{
Field f = Inet4Address.class.getDeclaredField("LOOPBACK");
f.setAccessible(true);
return (InetAddress) f.get(Inet4Address.class);
}
catch (Exception e)
{
}
return null;
}
@Override
protected void after(MethodHookParam param) throws Throwable
{
}
} package biz.bokhorst.xprivacy;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
public class XNetworkInterface2 extends XHook {
public XNetworkInterface2(String methodName, String restrictionName, String[] permissions) {
super(methodName, restrictionName, permissions, null);
}
// static NetworkInterface getByInetAddress(InetAddress address)
// static NetworkInterface getByName(String interfaceName)
// static Enumeration<NetworkInterface> getNetworkInterfaces()
// libcore/luni/src/main/java/java/net/NetworkInterface.java
@Override
protected void before(MethodHookParam param) throws Throwable {
if (isRestricted(param)) {
String methodName = param.method.getName();
if (methodName.equals("getByInetAddress") ||
methodName.equals("getByName") ||
methodName.equals("getNetworkInterfaces"))
{
param.setResult(null);
}
}
}
@Override
protected void after(MethodHookParam param) throws Throwable
{
}
} |
Thanks for your code contribution. |
I've found more functions to block. ConnectivityManager, for example. |
Why do you replace localhost by loopback? Why do you hook getByInetAddress, getByName and getNetworkInterfaces? |
If this is going to work okay, inet can be marked dangerous and exclude by default, like this: |
InetAddress has no loopback and loopback is the same as localhost:
|
Internet restricting will probably not work if an application uses IP addresses instead of domain names. |
DNS restriction will be part of the next release, thanks @sorgelig |
"Why do you replace localhost by loopback?" because, according to description from SDK, localhost will have 127.0.0.1 if there is no connections. If there is connection, then it may have some real IP address: "Why do you hook getByInetAddress, getByName and getNetworkInterfaces?" |
about revoking permissions:
As you see, if you revoke this permission, then application automatically assume there is network connection (but hidden).. |
Loopback address: I covered this in another way. |
"Internet restricting will probably not work if an application uses IP addresses instead of domain names." In your code, if there is connection then getLocalHost will return exception (because it won't equal to loopback address) - i think it's unexpected (although valid) return of this function. SDK states, it should return loopback address in case of no connection. not exception. |
Thanks for your insights! I guess you are right about getting InetAddress, although there are no public ways to create one that is not restricted. getLocalHost is not hooked in my code. |
I will added getByInetAddress, getByName and getNetworkInterfaces to the internet category for the next release to better hide that there is a connection. |
more to restrict ;) package biz.bokhorst.xprivacy;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
public class XConnectivityManager extends XHook {
public XConnectivityManager(String methodName, String restrictionName, String[] permissions) {
super(methodName, restrictionName, permissions, null);
}
// NetworkInfo getActiveNetworkInfo()
// NetworkInfo[] getAllNetworkInfo()
// boolean getBackgroundDataSetting()
// NetworkInfo getNetworkInfo(int networkType)
// boolean requestRouteToHost(int networkType, int hostAddress)
// android.net.ConnectivityManager
@Override
protected void before(MethodHookParam param) throws Throwable {
if (isRestricted(param)) {
String methodName = param.method.getName();
if (methodName.equals("getActiveNetworkInfo") ||
methodName.equals("getAllNetworkInfo") ||
methodName.equals("getNetworkInfo"))
{
param.setResult(null);
}
else if (methodName.equals("getBackgroundDataSetting") ||
methodName.equals("requestRouteToHost"))
{
param.setResult(false);
}
}
}
@Override
protected void after(MethodHookParam param) throws Throwable
{
}
} |
It's good to block reception of ConnectivityManager.CONNECTIVITY_ACTION as well, but i don't know how. |
Can you make a pull request for this? Take a look how I have integrated both internet and network in the same class: |
Intent receives can be restricted by just a few lines of code: |
I didn't setup my repository online yet. Actually, i'm not very familiar with git.. So, forgive me ;) I will setup my repository later. |
i didn't understand this: hook(new XNetworkInterface(net, PrivacyManager.cNetwork, new String[] { "ACCESS_NETWORK_STATE" }),
"java.net.NetworkInterface"); I don't understand the role of specifying permission. Some functions of this interface marked as required permission (in SDK), some - not. So, will this hook work for all specified functions or not? Is it mandatory to specify the permission? |
It is very simple:
If you use Eclipse:
|
The permissions are used by the user interface. |
"As of ICE_CREAM_SANDWICH, availability of background data depends on several combined factors, and this method will always return true." |
I see no need to restrict requestRouteToHost to hide internet connectivity or do I miss something? getLocalHost is not hooked in my code. |
Well, i know how to use git locally. I just never pushed back :) |
No need to hook getLocalHost. Let it go alone. |
I want to have as little as possible categories, so these new functions are part of the category internet. |
Please commit all small changes you make separately to make it easier to cherry pick when needed. |
Ok. i will try my best |
Hi,
Is it possible to implement internet block that way so application will think there is no active connections at all?
Currently, it looks like application can see internet connection but cannot connect due to block. Some application refuse to work this way, some give exceptions like this:
E/Cloudcell(13711): Throwable: Permission denied (missing INTERNET permission?)
E/Cloudcell(13711): java.lang.SecurityException: Permission denied (missing INTERNET permission?)
E/Cloudcell(13711): at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
E/Cloudcell(13711): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
E/Cloudcell(13711): at java.net.InetAddress.getAllByName(InetAddress.java:214)
E/Cloudcell(13711): at libcore.net.http.HttpConnection.(HttpConnection.java:70)
E/Cloudcell(13711): at libcore.net.http.HttpConnection.(HttpConnection.java:50)
E/Cloudcell(13711): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
E/Cloudcell(13711): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
E/Cloudcell(13711): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
E/Cloudcell(13711): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
E/Cloudcell(13711): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
E/Cloudcell(13711): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
E/Cloudcell(13711): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
E/Cloudcell(13711): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
E/Cloudcell(13711): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
E/Cloudcell(13711): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
E/Cloudcell(13711): at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:281)
E/Cloudcell(13711): at com.firemonkeys.cloudcellapi.HttpThread.run(CC_HttpPost_Class.java:211)
E/Cloudcell(13711): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
E/Cloudcell(13711): at libcore.io.Posix.getaddrinfo(Native Method)
E/Cloudcell(13711): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:59)
E/Cloudcell(13711): at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
E/Cloudcell(13711): ... 16 more
E/Cloudcell(13711): Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
E/Cloudcell(13711): ... 19 more
this is from Real Racing 3 v1.2.0
Youtube has similar behaviour: It crashes if you block internet access for it (but starts fine if there are really no active connections). Of course, it's useless to block Youtube, but i've just accidentally discovered it.
The text was updated successfully, but these errors were encountered: