wraith-wireless / PyRIC

Python wireless library for Linux
http://wraith-wireless.github.io/PyRIC
Other
93 stars 51 forks source link

MAC on monitor interface #15

Closed mchwalisz closed 8 years ago

mchwalisz commented 8 years ago

I have troubles running the example code ( pentest.py). I was able to get to the following statement.

In [11]: pyw.macget(pcard)
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-11-b54fc24bf362> in <module>()
----> 1 pyw.macget(pcard)

.virtualenvs/venv/lib/python2.7/site-packages/pyric/pyw.pyc in macget(card, *argv)
    280         iosock = argv[0]
    281     except IndexError:
--> 282         return _iostub_(macget, card)
    283 
    284     try:

.virtualenvs/venv/lib/python2.7/site-packages/pyric/pyw.pyc in _iostub_(fct, *argv)
   1547     try:
   1548         argv = list(argv) + [iosock]
-> 1549         return fct(*argv)
   1550     except pyric.error:
   1551         raise # catch and rethrow

.virtualenvs/venv/lib/python2.7/site-packages/pyric/pyw.pyc in macget(card, *argv)
    289             return _hex2mac_(ret[18:24])
    290         else:
--> 291             raise pyric.error(errno.EAFNOSUPPORT, "Invalid return addr family {0}".format(fam))
    292     except AttributeError:
    293         raise pyric.error(errno.EINVAL, "Invalid Card object")

error: [Errno 97] Invalid return addr family 803

With standard tools I get:

ifconfig pent0        
pent0     Link encap:UNSPEC  HWaddr 24-77-03-D2-E4-E8-70-C2-00-00-00-00-00-00-00-00 

iwconfig pent0      
pent0     IEEE 802.11abgn  Mode:Monitor  Frequency:2.437 GHz  Tx-Power=15 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off

Setting doesn't work either:

In [6]: pyw.macset(d,'00:03:93:57:54:46')
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-6-40f960911357> in <module>()
----> 1 pyw.macset(d,'00:03:93:57:54:46')

.virtualenvs/venv/lib/python2.7/site-packages/pyric/pyw.pyc in macset(card, mac, *argv)
    308         iosock = argv[0]
    309     except IndexError:
--> 310         return _iostub_(macset, card, mac)
    311 
    312     try:

.virtualenvs/venv/lib/python2.7/site-packages/pyric/pyw.pyc in _iostub_(fct, *argv)
   1547     try:
   1548         argv = list(argv) + [iosock]
-> 1549         return fct(*argv)
   1550     except pyric.error:
   1551         raise # catch and rethrow

.virtualenvs/venv/lib/python2.7/site-packages/pyric/pyw.pyc in macset(card, mac, *argv)
    312     try:
    313         flag = sioch.SIOCSIFHWADDR
--> 314         ret = io.io_transfer(iosock, flag, ifh.ifreq(card.dev, flag, [mac]))
    315         fam = struct.unpack_from(ifh.sa_addr, ret, ifh.IFNAMELEN)[0]
    316         if fam == ifh.ARPHRD_ETHER or fam == ifh.AF_UNSPEC: # confirm we got a hwaddr back

.virtualenvs/twist-netter/lib/python2.7/site-packages/pyric/lib/libio.pyc in io_transfer(iosock, flag, ifreq)
     71         # permissions etc, catch and reraise as our own
     72         if e.errno is not None: # just in case we have a none 2-tuple error
---> 73             raise pyric.error(e.errno,e.strerror)
     74         else:
     75             raise pyric.error(pyric.EUNDEF,e)

error: [Errno 22] Invalid argument

I suspect it is due to the monitor interface as it by default has different mac address format.

Setting MAC on managed card is fine:

In [15]: wl = pyw.devinfo('wlan2')['card']

In [16]: pyw.macset(wl,'00:03:93:57:54:46')
Out[16]: '00:03:93:57:54:46'

In [17]: pyw.macget(wl)#,'00:03:93:57:54:46')
Out[17]: '00:03:93:57:54:46'
wraith-wireless commented 8 years ago

Looking into it now. My code currently has a lot of changes in that I have debug before I can proceed with this issue. I think you're right "I suspect it is due to the monitor interface as it by default has different mac address format" I need to track down what family name 803 corresponds to - pretty sure the mac address will be the same with additional hex characters tacked on to the end.

wraith-wireless commented 8 years ago

@mchwalisz You were right. After switching to monitor mode, the card returns a family address of 803 which is defined in if_arp.h as IEEE80211_RADIOTAP. Please clone the latest. I've tested on my system and it works.