加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 01:00:32 所属栏目:Linux 来源:网络整理
导读:有没有办法在没有root权限的情况下获得当前的无线SSID? iwconfig告诉我ESSID,但前提是我以root身份运行它. 解决方法 如果你看一下iwconfig( wireless_tools)的源代码,你会看到这一行: iwconfig.c:639: if(iw_get_ext(skfd,ifname,SIOCGIWESSID,wrq) 0) 该
有没有办法在没有root权限的情况下获得当前的无线SSID?

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

解决方法

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

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

该行负责获取ESSID(wireless.h).我认为只有root才有权限(开箱即用)来执行此操作,因此调用ioctl的函数iw_get_ext(在wireless_tools包的iwlib.h中定义)将返回EPERM(不允许操作).

/*------------------------------------------------------------------*/
/*
 * 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,IFNAMSIZ);
  /* Do the request */
  return(ioctl(skfd,request,pwrq));
}

你有2个解决方案:

>使用setuid允许用户使用iwconfig命令:

sudo chmod u s / sbin / iwconfig
>您还可以尝试使用CAP_NET_ADMIN功能进行一些黑客操作,该功能允许特定用户使用某些特定功能.这里有一些关于CAP_NET_ADMIN的链接:

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/

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

以root身份执行此操作:

#strace /sbin/iwconfig your_interface_name > strace_iwconfig_root.log

和普通用户一样:

$strace /sbin/iwconfig your_interface_name > strace_iwconfig_normal.log

并比较结果.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读