测试apk-异常管控NetTraffic攻击者开发

1. 目的

基于《软件绿色联盟应用体验标准》中 NetTraffic 资源的定义,对 NetTraffic 后台多次小流量数据包的行为模拟。旨在触发手机中异常功耗管控机制。

netTrafiic异常

本次灭屏NetTraffic使用次数至少超过的二个等级:30次,60次,执行如下判断:
绿线不管控标准:重要可感知场景,不限于且包含系统应用白名单、第三方应用白名单、CTS、充电、默认输入法、默认时钟、音频场景、计步场景
红线要管控标准:本次灭屏非下载和上传的小流量次数超过30次,超过5分钟的非可感知场景
注意:针对的是小数据包,规避下载行为场景,防止误判
第一个等级:通知提醒或耗电标签化
第二个等级:限制或拦截


2022-06-22 15:00:40.459 2630-23738/com.huawei.iaware I/DownloadState: singleUid: 10175 [com.sufadi.blocknettraffic] speed: 7830 real speed: 7800 (rxB:34116 txB:5036 rxP:73 txP:77)
2022-06-22 15:00:40.474 2630-23738/com.huawei.iaware I/DownloadState: shareUid: 0 /system/bin/netd transmitting data speed : 35 bytes/s (rxB:118 txB:59 rxP:1 txP:1 iface:1)
2022-06-22 15:00:44.711 2630-3079/com.huawei.iaware I/APwActAnalysis: net traffic high power app: com.sufadi.blocknettraffic trafficCount: 30 duration:150180

2. 测试步骤

H手机和T手机、其他手机进行安装该apk.
所有手机都需要设置应用为白名单。

2.1 手机白名单设置方法:

手机管家->应用启动设置:允许自启动、允许关联启动、允许后台启动

H手机白名单

2.2 测试环境

开启网络

2.3 运行本apk

灭屏后台的数据包使用行为检测

2.4 运行本apk

测试:加白名单后,运行本apk后,按home键,灭屏,30分钟后亮屏查看,是否有高耗电异常提醒

3. apk 源码

本apk作用:后台无限制的WiFi扫描行为

3.1 UI

NetTrafiic UI界面

3.2 核心逻辑

3.2.1 MainActivity
package com.sufadi.blocknettraffic

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        startService(Intent(this, BlockNetTrafficService::class.java))
    }
}

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="本次灭屏NetTraffic使用次数至少超过的二个等级:30次,60次,执行如下判断:\n
\n绿线不管控标准:重要可感知场景,不限于且包含系统应用白名单、第三方应用白名单、CTS、充电、默认输入法、默认时钟、音频场景、计步场景
\n红线要管控标准:本次灭屏非下载和上传的小流量次数超过30次,超过5分钟的非可感知场景
\n注意:针对的是小数据包,规避下载行为场景,防止误判
\n第一个等级:通知提醒或耗电标签化
\n第二个等级:限制或拦截
\n测试方法:
\n加白名单后,运行本apk后,按home键,灭屏,30分钟后亮屏查看,是否有高耗电异常提醒
"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
3.3.2 权限配置

保活和联网

    <!-- 前台服务属性权限 -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <!-- 网络权限 -->
    <uses-permission android:name="android.permission.INTERNET" />
3.3.3 核心逻辑

后台一直定时联网百度和常驻服务

package com.sufadi.blocknettraffic

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import android.os.Bundle
import android.os.Handler
import android.os.IBinder
import android.os.Message
import android.util.Log
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.IOException
import java.lang.ref.WeakReference

class BlockNetTrafficService: Service() {

    companion object {
        val TAG = "BlockNetTrafficService"
        val FORGROUND_ID = 0x11
        val MSG_UPDATE_NETWORK = 1
    }

    var mMainHandle: MainHandle? = null


    override fun onBind(p0: Intent?): IBinder? {
        return null
    }

    override fun onCreate() {
        super.onCreate()
        Log.d(TAG, "onCreate")
        startMyForeground()

        mMainHandle = MainHandle(this)
        sendRequestWithHttpClient()
    }

    override fun onDestroy() {
        super.onDestroy()
        stopForeground(true)
    }


    class MainHandle(serviceTct: BlockNetTrafficService) : Handler() {

        private val mRefServiceTct: WeakReference<BlockNetTrafficService>

        init {
            mRefServiceTct = WeakReference(serviceTct)
        }

        override fun handleMessage(msg: Message) {
            val service = mRefServiceTct.get() ?: return

            when (msg.what) {
                MSG_UPDATE_NETWORK -> {
                    service?.sendRequestWithHttpClient()
                }
            }
        }
    }

    private fun startMyForeground() {
        Log.d(TAG, "startMyForeground show notification")
        Log.d(TAG, "PhoneDataService startMyForeground sdk :" + android.os.Build.VERSION.SDK_INT)
        val nb = Notification.Builder(this)

        if (android.os.Build.VERSION.SDK_INT >= 26) {
            val CHANNEL_ONE_ID = "channel_id_foreground"
            val CHANNEL_ONE_NAME = "Channel One"
            var notificationChannel: NotificationChannel? = null

            notificationChannel = NotificationChannel(
                CHANNEL_ONE_ID,
                CHANNEL_ONE_NAME, NotificationManager.IMPORTANCE_LOW
            )

            nb.setChannelId(CHANNEL_ONE_ID)

            val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            manager.createNotificationChannel(notificationChannel)
        }

        nb.setSmallIcon(R.mipmap.ic_launcher)
        nb.setContentTitle(getString(R.string.notification_title))
        nb.setContentText(getString(R.string.notification_Content))

        try {
            startForeground(FORGROUND_ID, nb.build())
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }

    //方法:发送网络请求,获取百度首页的数据。在里面开启线程
    private fun sendRequestWithHttpClient() {
        Thread(Runnable {
            val requestUrl =
                "https://www.baidu.com/"
            val okHttpClient = OkHttpClient()
            val request = Request.Builder()
                .url(requestUrl)
                .build()

            val call = okHttpClient.newCall(request)
            Log.v(TAG, "okHttpClient.newCall")
            try {
                val response = call.execute()
                if (response.isSuccessful()) {
                    //The call was successful.print it to the log
                    val msg = Message()
                    msg.what = MSG_UPDATE_NETWORK
                    msg.obj = response.body().string()
                    Log.v(TAG, response.body().string())
                    mMainHandle?.sendMessageDelayed(msg, 1000)
                }
            } catch (e: IOException) {
                e.printStackTrace()
            }
        }).start()

    }
}
3.3.4 华为异常检测日志

netTrafiic异常

本次灭屏NetTraffic使用次数至少超过的二个等级:30次,60次,执行如下判断:
绿线不管控标准:重要可感知场景,不限于且包含系统应用白名单、第三方应用白名单、CTS、充电、默认输入法、默认时钟、音频场景、计步场景
红线要管控标准:本次灭屏非下载和上传的小流量次数超过30次,超过5分钟的非可感知场景
注意:针对的是小数据包,规避下载行为场景,防止误判
第一个等级:通知提醒或耗电标签化
第二个等级:限制或拦截


2022-06-22 15:00:40.459 2630-23738/com.huawei.iaware I/DownloadState: singleUid: 10175 [com.sufadi.blocknettraffic] speed: 7830 real speed: 7800 (rxB:34116 txB:5036 rxP:73 txP:77)
2022-06-22 15:00:40.474 2630-23738/com.huawei.iaware I/DownloadState: shareUid: 0 /system/bin/netd transmitting data speed : 35 bytes/s (rxB:118 txB:59 rxP:1 txP:1 iface:1)
2022-06-22 15:00:44.711 2630-3079/com.huawei.iaware I/APwActAnalysis: net traffic high power app: com.sufadi.blocknettraffic trafficCount: 30 duration:150180

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

法迪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值