安卓逆向环境检测--抓包

一、代理检测

一般是通过getProperty方法拿到 http.proxyHost 和 http.proxyPort 字段的值,代码如下

UNEXPORT void AntiCapture::check_proxy(JNIEnv *env) {
    jstring jsproxyHost = env->NewStringUTF(GlobalString::encrypt(GlobalString::str_AntiCapture_proxyHost));
    jstring jsproxyPort = env->NewStringUTF(GlobalString::encrypt(GlobalString::str_AntiCapture_proxyPort));

    jstring proxyHost = static_cast<jstring>(Method::callStaticMethodObject(env, GlobalString::encrypt(GlobalString::str_AntiCapture_System),
                                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_getProperty),
                                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_SiggetProperty),
                                                                            jsproxyHost));
    jstring proxyPort = static_cast<jstring>(Method::callStaticMethodObject(env, GlobalString::encrypt(GlobalString::str_AntiCapture_System),
                                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_getProperty),
                                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_SiggetProperty),
                                                                            jsproxyPort));


    char* cproxyHost = const_cast<char *>(env->GetStringUTFChars(proxyHost, nullptr));
    char* cproxyPort = const_cast<char *>(env->GetStringUTFChars(proxyPort, nullptr));

    LOGI("native http.proxyHost = %s", cproxyHost);
    LOGI("native http.proxyPort = %s", cproxyPort);

    if (Str::strlen(const_cast<char *>(cproxyHost)) >= 2 && Str::strlen(const_cast<char *>(cproxyPort)) >= 2){
        //TODO 开启代理
        LOGI("check_proxy find proxy");
    }

    env->ReleaseStringUTFChars(proxyHost, cproxyHost);
    env->ReleaseStringUTFChars(proxyPort, cproxyPort);
    env->DeleteLocalRef(jsproxyHost);
    env->DeleteLocalRef(jsproxyPort);
}

二、VPN检测

一般是遍历NetworkInterface的name,判断是否为tun0或者ppp0,代码如下:

UNEXPORT void AntiCapture::check_VPN(JNIEnv *env) {
    jobject objEnumeration = Method::callStaticMethodObject(env,
                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_NetworkInterface),
                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_getNetworkInterfaces),
                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_Enumeration));
    LOGI("check_VPN objEnumeration %p", objEnumeration);
    if (objEnumeration != 0){
        jobject objArrayList = Method::callStaticMethodObject(env,
                                                              GlobalString::encrypt(GlobalString::str_AntiCapture_Collections),
                                                              GlobalString::encrypt(GlobalString::str_AntiCapture_list),
                                                              GlobalString::encrypt(GlobalString::str_AntiCapture_Siglist),
                                                              objEnumeration);
        LOGI("check_VPN objArrayList %p", objArrayList);

        jint len = Method::callMethodInt(env, objArrayList,
                                         GlobalString::encrypt(GlobalString::str_AntiCapture_ArrayList),
                                         GlobalString::encrypt(GlobalString::str_AntiCapture_size),
                                         GlobalString::encrypt(GlobalString::str_AntiCapture_Sigsize));
        LOGI("check_VPN len %d", len);

        for (int i = 0; i < len; i++){
            jobject objNetworkInterface = Method::callMethodObject(env, objArrayList,
                                                                   GlobalString::encrypt(GlobalString::str_AntiCapture_ArrayList),
                                                                   GlobalString::encrypt(GlobalString::str_AntiCapture_get),
                                                                   GlobalString::encrypt(GlobalString::str_AntiCapture_Object),
                                                                   i);
            LOGI("check_VPN objNetworkInterface %p  i=%d", objNetworkInterface, i);

            jboolean bIsUp = Method::callMethodBoolean(env, objNetworkInterface,
                                                       GlobalString::encrypt(GlobalString::str_AntiCapture_NetworkInterface),
                                                       GlobalString::encrypt(GlobalString::str_AntiCapture_isUp),
                                                       GlobalString::encrypt(GlobalString::str_AntiCapture_SigisUp));
            if (!bIsUp){
                continue;
            }

            jobject objInterfaceAddresses = Method::callMethodObject(env, objNetworkInterface,
                                                                     GlobalString::encrypt(GlobalString::str_AntiCapture_NetworkInterface),
                                                                     GlobalString::encrypt(GlobalString::str_AntiCapture_getInterfaceAddresses),
                                                                     GlobalString::encrypt(GlobalString::str_AntiCapture_List));
            LOGI("check_VPN objInterfaceAddresses %p", objInterfaceAddresses);

            jint size = Method::callMethodInt(env, objInterfaceAddresses,
                                                GlobalString::encrypt(GlobalString::str_AntiCapture_List),
                                                GlobalString::encrypt(GlobalString::str_AntiCapture_size),
                                                GlobalString::encrypt(GlobalString::str_AntiCapture_Sigsize));
            LOGI("check_VPN size %d", size);
            if (size == 0){
                continue;
            }

            jstring jsName = static_cast<jstring>(Method::callMethodObject(env,
                                                                            objNetworkInterface,
                                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_NetworkInterface),
                                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_getName),
                                                                            GlobalString::encrypt(GlobalString::str_AntiCapture_String)));
            LOGI("check_VPN jsName %p", jsName);

            jboolean jb = false;
            const char* charName = (env->GetStringUTFChars(jsName, &jb));
            LOGI("check_VPN charName  ------------------------> < %s >", charName);

            if (Str::strcmp(const_cast<char *>(charName), const_cast<char *>(GlobalString::encrypt(GlobalString::str_AntiCapture_tun0))) == 0 ||
                    Str::strcmp(const_cast<char *>(charName), const_cast<char *>(GlobalString::encrypt(GlobalString::str_AntiCapture_ppp0))) == 0){
                // TODO 发现开启VPN
                LOGI("check_VPN   ----------------------------------> 发现开启VPN");
            }

            env->ReleaseStringUTFChars(jsName, charName);
        }
    }
    LOGI("check_VPN over");
}

说明:我整个项目的代码都是用native实现,还加了字符串解密,上面两部分代码中的原字符串如下:

    static ENCRYPTSTRING str_AntiCapture_proxyHost;            // http.proxyHost
    static ENCRYPTSTRING str_AntiCapture_proxyPort;            // http.proxyPort
    static ENCRYPTSTRING str_AntiCapture_System;               // java/lang/System
    static ENCRYPTSTRING str_AntiCapture_getProperty;          // getProperty
    static ENCRYPTSTRING str_AntiCapture_SiggetProperty;       // (Ljava/lang/String;)Ljava/lang/String;
    static ENCRYPTSTRING str_AntiCapture_NetworkInterface;     // java/net/NetworkInterface
    static ENCRYPTSTRING str_AntiCapture_getNetworkInterfaces; // getNetworkInterfaces
    static ENCRYPTSTRING str_AntiCapture_Enumeration;          // ()Ljava/util/Enumeration;
    static ENCRYPTSTRING str_AntiCapture_Collections;          // java/util/Collections
    static ENCRYPTSTRING str_AntiCapture_list;                 // list
    static ENCRYPTSTRING str_AntiCapture_Siglist;              // (Ljava/util/Enumeration;)Ljava/util/ArrayList;
    static ENCRYPTSTRING str_AntiCapture_ArrayList;            // java/util/ArrayList
    static ENCRYPTSTRING str_AntiCapture_size;                 // size
    static ENCRYPTSTRING str_AntiCapture_Sigsize;              // ()I
    static ENCRYPTSTRING str_AntiCapture_get;                  // get
    static ENCRYPTSTRING str_AntiCapture_Object;               // (I)Ljava/lang/Object;
    static ENCRYPTSTRING str_AntiCapture_isUp;                 // isUp
    static ENCRYPTSTRING str_AntiCapture_SigisUp;              // ()Z
    static ENCRYPTSTRING str_AntiCapture_getInterfaceAddresses;// getInterfaceAddresses
    static ENCRYPTSTRING str_AntiCapture_List;                 // ()Ljava/util/List;
    static ENCRYPTSTRING str_AntiCapture_getName;              // getName
    static ENCRYPTSTRING str_AntiCapture_String;               // ()Ljava/lang/String;
    static ENCRYPTSTRING str_AntiCapture_tun0;                 // tun0
    static ENCRYPTSTRING str_AntiCapture_ppp0;                 // ppp0

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值