Linux: How to get wireless ssid without root permission?

Is there a way to get the current SSID without root permission?

iwconfig tells me the ESSID, but only if I run it as root.

+5
source share
1 answer

If you look at the source code iwconfig( wireless_tools ), you will see this line:

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

This line is responsible for obtaining the ESSID ( wireless.h ). And I think that only root has permissions (out of the box) for this, so the function iw_get_ext(defined in the package iwlib.hfrom wireless_tools) that calls ioctlwill return 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));
}

You have 2 solutions:

  • Use setuidso that the user can use the command 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

.

+4

All Articles