• CtsSecurityTestCases#ListeningPortsTest定位tcp端口与pid


    CtsSecurityTestCases#ListeningPortsTest定位tcp端口与pid

    【问题描述】

    cts失败项
    armeabi-v7a CtsSecurityTestCases
    android.security.cts.ListeningPortsTest#testNoListeningLoopbackTcpPorts
    工具:9.0_r11

    05-06 17:11:28.649 17375 17391 E TestRunner: android.security.cts.ListeningPortsTest$ListeningPortsAssertionError: 
    05-06 17:11:28.649 17375 17391 E TestRunner: Found port listening on addr=127.0.0.1, port=10100, UID=1000 [com.android.keychain, com.itv.android.iptv, com.android.location.fused, com.android.providers.settings,com.launcher.idn, android, com.itv.android.iptv.tvclient,com.droidlogic, com.android.wallpaperbackup, com.droidlogic.BluetoothRemote, ] in /proc/net/tcp
    05-06 17:11:28.649 17375 17391 E TestRunner: 	at android.security.cts.ListeningPortsTest.assertNoAccessibleListeningPorts(ListeningPortsTest.java:250)
    05-06 17:11:28.649 17375 17391 E TestRunner: 	at android.security.cts.ListeningPortsTest.testNoListeningLoopbackTcpPorts(ListeningPortsTest.java:138)
    

    【问题结论】

    定位到subtitle端口监听某次提交,回退后测试pass

    AuthBlog:秋城https://www.cnblogs.com/houser0323

    【分析详细】

    1.定位节点inode
    port=10100是十进制,/proc/net/tcp中port是十六进制,做一下转换10110-->2774,见下面2:处,对应inode为32905。

    console:/ # cat proc/net/tcp
      sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
       0: 7632A8C0:EA60 00000000:0000 0A 00000000:00000000 00:00000000 00000000  1000        0 58215 1 00000000 100 0 0 10 0
       1: 00000000:1A85 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 33635 1 00000000 100 0 0 10 0
       2: 0100007F:2774 00000000:0000 0A 00000000:00000000 00:00000000 00000000  1000        0 32905 1 00000000 100 0 0 10 0
    

    2.根据inode查找pid
    进入/proc/[pid]/fd/目录下ls -l 查看socket端口号,由于我们不知道在哪个pid目录下,所以遍历一下
    sh脚本或者终端输入shell命令for循环遍历查找32905节点的pid:

    # for dir in `find /proc -name "fd" 2>/dev/null`
    > do
    > ls -l $dir | grep "socket:[32905]" && echo $dir
    > done
    

    结果查找到pid为4085

    lrwx------ 1 root root 64 2020-05-07 11:03 46 -> socket:[32905]
    /proc/4085/task/4085/fd
    lrwx------ 1 root root 64 2020-05-07 11:03 46 -> socket:[32905]
    /proc/4085/task/4094/fd
    ......
    lrwx------ 1 root root 64 2020-05-07 10:47 46 -> socket:[32905]
    /proc/4085/fd
    
    

    3.查看pid对应的程序

    console:/ # ps 4085
    USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME
    system        4085  3024 1124392  82892 SyS_epoll_wait      0 S com.droidlogic.SubTitleService
    

    至此定位结束,反馈给相应模块处理

    【参考资料】

    1.嵌入式设备上如何通过端口号定位到进程
    https://blog.csdn.net/daizhongyin/article/details/90031132

    2.获取tcp/udp端口对应的进程pid
    https://blog.csdn.net/ChrisNiu1984/article/details/7022745

  • 相关阅读:
    COOKIE和SESSION有什么区别?
    JSP中三大指令
    JSP中out.print()、out.println()以及out.write()的区别
    Linux实战教学笔记06:Linux系统基础优化
    Linux实战教学笔记05:远程SSH连接服务与基本排错(新手扫盲篇)
    Linux实战教学笔记04:Linux命令基础
    Linux实战教学笔记03:操作系统发展历程及系统版本选择
    Linux实战教学笔记02:计算机系统硬件核心知识
    Linux实战教学笔记01:计算机硬件组成与基本原理
    从零开始学Python第八周:网络编程基础(socket)
  • 原文地址:https://www.cnblogs.com/houser0323/p/12843865.html
Copyright © 2020-2023  润新知