静态分析二进制文件系统调用,请问 Python 为什么找不到 socket

2020-09-14 15:38:32 +08:00
 pmispig
[root@f96be0f450a4 tmp]# ldd /usr/bin/python2.7 
	linux-vdso.so.1 =>  (0x00007ffc63f78000)
	libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0 (0x00007fb2b7efc000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb2b7ce0000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fb2b7adc000)
	libutil.so.1 => /lib64/libutil.so.1 (0x00007fb2b78d9000)
	libm.so.6 => /lib64/libm.so.6 (0x00007fb2b75d7000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fb2b7209000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fb2b82c8000)


[root@f96be0f450a4 tmp]# readelf  /usr/lib64/libpython2.7.so.1.0  -a |grep sock
[root@f96be0f450a4 tmp]# readelf  /usr/bin/python2.7  -a |grep socket
[root@f96be0f450a4 tmp]# readelf  /usr/lib64/libpython2.7.so.1.0  -a |grep open
00000037f7f8  002e00000007 R_X86_64_JUMP_SLO 0000000000000000 opendir@GLIBC_2.2.5 + 0
000000380140  007300000007 R_X86_64_JUMP_SLO 0000000000000000 fopen64@GLIBC_2.2.5 + 0
000000380278  007d00000007 R_X86_64_JUMP_SLO 0000000000000000 openpty@GLIBC_2.2.5 + 0
0000003803e8  008400000007 R_X86_64_JUMP_SLO 0000000000000000 dlopen@GLIBC_2.2.5 + 0
000000380810  00a400000007 R_X86_64_JUMP_SLO 0000000000000000 fdopen@GLIBC_2.2.5 + 0
000000380900  00ad00000007 R_X86_64_JUMP_SLO 0000000000000000 open64@GLIBC_2.2.5 + 0
000000380a80  00bc00000007 R_X86_64_JUMP_SLO 0000000000000000 popen@GLIBC_2.2.5 + 0
    46: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND opendir@GLIBC_2.2.5 (3)
   115: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND fopen64@GLIBC_2.2.5 (3)
   125: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND openpty@GLIBC_2.2.5 (9)
   132: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND dlopen@GLIBC_2.2.5 (10)
   164: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND fdopen@GLIBC_2.2.5 (3)
   173: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND open64@GLIBC_2.2.5 (4)
   188: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND popen@GLIBC_2.2.5 (3)


[root@f96be0f450a4 tmp]# readelf  /usr/bin/ssh  -a |grep socket
0000002b8548  002b00000007 R_X86_64_JUMP_SLO 0000000000000000 socket@GLIBC_2.2.5 + 0
0000002b8918  00b400000007 R_X86_64_JUMP_SLO 0000000000000000 socketpair@GLIBC_2.2.5 + 0
    43: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND socket@GLIBC_2.2.5 (5)
   180: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND socketpair@GLIBC_2.2.5 (5)

818 次点击
所在节点    程序员
1 条回复
pmispig
2020-09-14 15:50:28 +08:00
通过 strace 知道了,python 动态加载了 so
```
readelf -a /usr/lib64/python2.7/lib-dynload/_socketmodule.so |grep socket
00000020f1f0 004500000007 R_X86_64_JUMP_SLO 0000000000000000 socketpair@GLIBC_2.2.5 + 0
00000020f3b8 008200000007 R_X86_64_JUMP_SLO 0000000000000000 socket@GLIBC_2.2.5 + 0
69: 0000000000000000 0 FUNC GLOBAL DEFAULT UND socketpair@GLIBC_2.2.5 (2)
130: 0000000000000000 0 FUNC GLOBAL DEFAULT UND socket@GLIBC_2.2.5 (2)
137: 0000000000008d10 5379 FUNC GLOBAL DEFAULT 11 init_socket
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/706901

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX