V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
pmispig
V2EX  ›  程序员

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

  •  
  •   pmispig · 2020-09-14 15:38:32 +08:00 · 818 次点击
    这是一个创建于 1523 天前的主题,其中的信息可能已经有所发展或是发生改变。
    [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)
    
    
    1 条回复    2020-09-14 15:50:28 +08:00
    pmispig
        1
    pmispig  
    OP
       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
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2676 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:01 · PVG 13:01 · LAX 21:01 · JFK 00:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.