• Lv0
    粉丝0

积分0 / 贡献0

提问1答案被采纳0文章0

作者动态

    网络抓包APP开发,报错:eth0: You don't have permission to perform this capture on that device (socket: Operation not permitted)

    yuhaoooooooo 显示全部楼层 发表于 2024-9-11 18:45:43

    【问题描述】

    1. 使用libpcap.so,编写native代码调用

    2. pcap_t *handle = pcap_open_live(device->name, BUFSIZ, 1, 1000, errbuf);
              if (handle == NULL) {
                  OH_LOG_ERROR(LOG_APP, "Open - pcap_open_live failure %{public}s", errbuf);
                  return -1;
              }
      
    3. Open - pcap_open_live failure eth0: You don't have permission to perform this capture on that device (socket: Operation not permitted)

    4. 把网络相关的权限都配置了

      "requestPermissions": [
                  {
                      "name": "ohos.permission.INTERNET", //socket权限
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.GET_NETWORK_INFO",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.GET_WIFI_INFO",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.MANAGE_NET_STRATEGY",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.CONNECTIVITY_INTERNAL",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.NETSYS_INTERNAL",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.ENTERPRISE_GET_NETWORK_INFO",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.ENTERPRISE_SET_NETWORK",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.ENTERPRISE_MANAGE_NETWORK",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.RUN_ANY_CODE",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.SET_NETWORK_INFO",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  },
                  {
                      "name" : "ohos.permission.GET_NETWORK_STATS",
                      "usedScene": {
                          "abilities": [
                              "MainAbility"
                          ],
                          "when":"always"
                      }
                  }
              ]
          }
    5. 可以正常网络包

    【运行环境】

    硬件:RK3568 ROM版本:4.0.10 DevEvoStudio版本:4.0 SDK版本:10

    您尚未登录,无法参与评论,登录后可以:
    参与开源共建问题交流
    认同或收藏高质量问答
    获取积分成为开源共建先驱

    精彩评论6

    深开鸿_王石

    沙发 发表于 2024-9-18 16:53:30
    看看 selinux 和 应用权限(是不是系统应用)

    yuhaoooooooo

    发表于 2024-9-30 15:55  IP属地: 江苏省扬州市

    回复 深开鸿_王石: selinux 是关闭的,应用权限对libpcap不起作用。感觉是linux内核机制只有root才可以抓包

    深开鸿_王石

    发表于 2024-10-14 09:26  IP属地: 山东省潍坊市

    回复 yuhaoooooooo: 你这里是直接用app去open一个设备节点,所以你要看看这个节点权限是啥,他是不是能被用户账号访问,还是只能root访问,简单改法呢就是chmod,要不就是你把应用改成系统应用

    【2 条回复】

    kuaile

    板凳 发表于 2024-9-26 15:54:58
    只有root可以使用tcpdump

    yuhaoooooooo

    发表于 2024-9-30 15:54  IP属地: 江苏省扬州市

    回复 kuaile: 但是ohos的机制,app不是root运行的,而是uid 100。改如何破局?

    深开鸿_王石

    发表于 2024-10-8 17:55  IP属地: 江苏省扬州市

    回复 yuhaoooooooo: 系统应用啊,或者自己改对应的权限:)

    【2 条回复】
    共6 条回复,点击查看

    Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

    返回顶部