欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

CtsSecurityTestCases#ListeningPortsTest定位tcp端口与pid

程序员文章站 2022-03-18 16:57:59
CtsSecurityTestCases ListeningPortsTest定位tcp端口与pid 【问题描述】 cts失败项 armeabi v7a CtsSecurityTestCases android.security.cts.ListeningPortsTest testNoListen ......

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:秋城

【分析详细】

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.嵌入式设备上如何通过端口号定位到进程

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