linux:如何在没有root权限的情况下获得无线ssid?

时间:2012-09-01 19:29:58

标签: linux ssid iwconfig

有没有办法在没有root权限的情况下获取当前的无线SSID?

iwconfig告诉我ESSID,但前提是我以root身份运行它。

1 个答案:

答案 0 :(得分:5)

如果你看一下iwconfigwireless_tools)的源代码,你会看到这一行:

iwconfig.c:639: if(iw_get_ext(skfd, ifname, SIOCGIWESSID, &wrq) < 0)

此行负责获取ESSID(wireless.h)。我认为只有root才有权限(开箱即用)才能执行此操作,因此调用iw_get_ext的函数iwlib.h(在wireless_tools ioctl中定义)将调用EPERM返回Operation not permitted/*------------------------------------------------------------------*/ /* * Wrapper to extract some Wireless Parameter out of the driver */ static inline int iw_get_ext(int skfd, /* Socket to the kernel */ const char * ifname, /* Device name */ int request, /* WE ID */ struct iwreq * pwrq) /* Fixed part of the request */ { /* Set device name */ strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); /* Do the request */ return(ioctl(skfd, request, pwrq)); } )。

setuid

你有2个解决方案:

  1. 使用iwconfig允许用户使用sudo chmod u+s /sbin/iwconfig命令:

    CAP_NET_ADMIN

  2. 您还可以尝试使用CAP_NET_ADMIN功能进行一些黑客攻击,这些功能允许特定用户使用某些特定功能。这里有一些关于strace

  3. 的链接

    http://packetlife.net/blog/2010/mar/19/sniffing-wireshark-non-root-user/

    http://peternixon.net/news/2012/01/28/configure-tcpdump-work-non-root-user-opensuse-using-file-system-capabilities/

    http://www.lids.org/lids-howto/node48.html

    http://lwn.net/Articles/430462/

    最后,您可以使用ioctl跟踪所有系统调用,并确认root调用对此负责:

    #strace /sbin/iwconfig your_interface_name > strace_iwconfig_root.log 执行此操作:

    $strace /sbin/iwconfig your_interface_name > strace_iwconfig_normal.log
    

    普通用户

    相同
    {{1}}

    并比较结果。