Ctssecuritytestcases - listeningportstest locates tcp port and pid

Ctssecuritytestcases - listeningportstest locates tcp port and pid

[problem description]

cts failures
armeabi-v7a CtsSecurityTestCases
android.security.cts.ListeningPortsTest#testNoListeningLoopbackTcpPorts
Tool: 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)

[Conclusion]

Go to the subtitle port to listen for a submission and test pass after fallback

AuthBlog: Autumn City https://www.cnblogs.com/houser0323

[analysis details]

1. Locate node inode
port=10100 is decimal, and port in / proc/net/tcp is hexadecimal. Do the conversion 10110 -- > 2774, as shown in 2: below, the corresponding inode is 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. Find pid according to inode
Enter ls-l in the directory / proc/[pid]/fd / to check the socket port number. Since we don't know which pid directory we are in, let's go through it
sh script or terminal input shell command for loop traversal to find pid of 32905 node:

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

The result shows that pid is 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. Check the program corresponding to 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

At this point, the positioning is completed and the feedback is sent to the corresponding module for processing

[References]

1. How to locate the process through the port number on the embedded device
https://blog.csdn.net/daizhongyin/article/details/90031132

2. Obtain the process pid corresponding to the tcp/udp port
https://blog.csdn.net/ChrisNiu1984/article/details/7022745

Keywords: Android socket Java shell

Added by tibiz on Thu, 07 May 2020 19:59:45 +0300