Code Monkey home page Code Monkey logo

Comments (5)

wraith-wireless avatar wraith-wireless commented on July 19, 2024

Sorry for the delay. I can see your point hope the below helps.

First, so I don't confuse you or myself, we'll call "interface" the logical device however we refer to it, i.e. by device name, physical index etc.

Second, the reason that I generally delete all associated interfaces in my example is because I have found that by doing so, network manager, wpa_supplicant etc will no longer interfere with the interface and I don't have to kill them prior to doing anything and remember to restart them afterward.

Each interface can be reference by dev (the device name) i.e. wlan0, or by phy (the physical index) i.e. the 0 in phy0 or by ifindex (interface index) and depending on what you want to do, you may need to refer to one or other. For example. changing the mac address requires the dev, enabling/disabling the powersave feature requires the ifindex and setting the current channel requires the physical index. The

The Card object collates these three reference values into one object. An interface's phy is always the same (in theory - a usb card may have a new phy everytime it is plugged in) while the other two may change. And a phy may have multiple interfaces (while dev and ifindex are unique to each interface). As long as you "remember" the phy, you can add interfaces or restore the original even if there are no current interfaces.

Let's assume that I only have one wireless interface, wlan0 and look at pentest.py in the examples folder. On line 53, every interface sharing a phy with wlan0 (including wlan0 is deleted). If we ran ifconfig or iwconfig at this point, there would not be any wireless interfaces present. The same situation occurs on line 81 where the monitor interface is deleted. To answer the first question, there is no way to check that wiphy interfaces exist because in essence they don't and the onus is on the programmer or program to recall prior instances. (The only to way, at this point, to check for interfaces would be to iterate through a list of integers and check each one) . As a check, assume you have
card = Card(dev='wlan0',phy=0,idx=1) and you call

pyw.devdel(card) 

In a separate console try:

> iw dev wlan0 info

command failed: No such device (-19)

iw phy phy0 info
Wiphy phy0
max # scan SSIDs: 20
....

Yes, there are no interfaces, but the phy is still present.

To answer the second implied question: devadd is one of a few pyw functions that will accept either a Card object or a phy. Since, the phy is always present even if no interfaces are "attached" to it we can always add interfaces. And an artifact of Cards is that even though it may be invalid in the since that given Card(dev='wlan0',phy=0,idx=1) the interface associated with dev=wlan0 and ifindex=1 no longer exists, the underlying phy still does and in line 84 of pentest.py that is what is happening. You have to remember that after adding an interface as we do in line 84, the returned card is what we to use in future operations.

Hope this rambling provides the answer you were looking for.

I haven't gotten around to it yet but plan on added a function nameset which replicates iw. phy set name which will then allow you to do what airmon-ng does, namely change the device name and mode of the card. But, once again this assumes there are not any other interfaces associted with the phy that network manager may be using.

from pyric.

mchwalisz avatar mchwalisz commented on July 19, 2024

This shows that my understanding was not off. However, there is still one (in my case common) case where you do not "remember" (as you have nicely explained) any phy.

You can still discover it with:

# iw list | grep Wiphy
Wiphy phy0

but you don't have any dev's to start with:

# iw dev
#

In that situation there is no easy way to start using your library.

from pyric.

wraith-wireless avatar wraith-wireless commented on July 19, 2024

Let me see if I understand. You have a situation where you may begin with no devs present i.e. your not deleting them like I do?

If you know the phy you could create a Card from that. devadd supports both a Card object or a phy so in your case it would be

card = pyw.devadd(0, 'wlan0', 'managed')

where 0 is the phy number.

Now would you like to see something implemented where you could list phy's as well? I can take at look at iw list if that is the case.

from pyric.

wraith-wireless avatar wraith-wireless commented on July 19, 2024

alright, I added a function phylist which should help you help.

No devices

# iw dev
# 

List phys and create an interface

>>> phys = pyw.phylist()
>>> phys
[(0,'phy0')]
>>> card = pyw.devadd(phys[0][0],'wlan0','managed')
>>>  card
Card(phy=0,dev=wlan0,ifindex=7)
>>>

And you're good to go

from pyric.

mchwalisz avatar mchwalisz commented on July 19, 2024

That was exactly what I was looking for. Thanks.

from pyric.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.