Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
665faf6c
Commit
665faf6c
authored
9 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
Fix IFACES: index by GUID instead of name (not unique)
parent
d69b5b7e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scapy/arch/windows/__init__.py
+44
-43
44 additions, 43 deletions
scapy/arch/windows/__init__.py
with
44 additions
and
43 deletions
scapy/arch/windows/__init__.py
+
44
−
43
View file @
665faf6c
...
@@ -231,6 +231,7 @@ class NetworkInterface(object):
...
@@ -231,6 +231,7 @@ class NetworkInterface(object):
self
.
name
=
data
[
"
name
"
]
self
.
name
=
data
[
"
name
"
]
self
.
description
=
data
[
'
description
'
]
self
.
description
=
data
[
'
description
'
]
self
.
win_index
=
data
[
'
win_index
'
]
self
.
win_index
=
data
[
'
win_index
'
]
self
.
guid
=
data
[
'
guid
'
]
# Other attributes are optional
# Other attributes are optional
self
.
_update_pcapdata
()
self
.
_update_pcapdata
()
...
@@ -258,8 +259,10 @@ class NetworkInterface(object):
...
@@ -258,8 +259,10 @@ class NetworkInterface(object):
raise
PcapNameNotFoundError
raise
PcapNameNotFoundError
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"
<%s: %s %s %s pcap_name=%s description=%s>
"
%
(
self
.
__class__
.
__name__
,
return
"
<%s %s: %s %s %s description=%r>
"
%
(
self
.
name
,
self
.
ip
,
self
.
mac
,
repr
(
self
.
pcap_name
),
repr
(
self
.
description
))
self
.
__class__
.
__name__
,
self
.
name
,
self
.
guid
,
self
.
ip
,
self
.
mac
,
self
.
description
,
)
from
UserDict
import
UserDict
from
UserDict
import
UserDict
...
@@ -269,7 +272,7 @@ class NetworkInterfaceDict(UserDict):
...
@@ -269,7 +272,7 @@ class NetworkInterfaceDict(UserDict):
for
i
in
get_windows_if_list
():
for
i
in
get_windows_if_list
():
try
:
try
:
interface
=
NetworkInterface
(
i
)
interface
=
NetworkInterface
(
i
)
self
.
data
[
interface
.
name
]
=
interface
self
.
data
[
interface
.
guid
]
=
interface
except
(
KeyError
,
PcapNameNotFoundError
):
except
(
KeyError
,
PcapNameNotFoundError
):
pass
pass
...
@@ -278,30 +281,29 @@ class NetworkInterfaceDict(UserDict):
...
@@ -278,30 +281,29 @@ class NetworkInterfaceDict(UserDict):
"
You probably won
'
t be able to send packets.
"
"
You probably won
'
t be able to send packets.
"
"
Deactivating unneeded interfaces and restarting Scapy might help.
"
"
Deactivating unneeded interfaces and restarting Scapy might help.
"
"
Check your winpcap and powershell installation, and access rights.
"
)
"
Check your winpcap and powershell installation, and access rights.
"
)
def
pcap_name
(
self
,
devname
):
"""
Return pcap device name for given Windows device name.
"""
try
:
def
dev_from_name
(
self
,
name
):
pcap_name
=
self
.
data
[
devname
].
pcap_name
"""
Return the first pcap device name for a given Windows
except
KeyError
:
device name.
raise
ValueError
(
"
Unknown network interface %r
"
%
devname
)
else
:
"""
return
pcap_name
for
iface
in
self
.
itervalues
():
if
iface
.
name
==
name
:
def
devname
(
self
,
pcap_name
):
return
iface
raise
ValueError
(
"
Unknown network interface %r
"
%
name
)
def
dev_from_pcapname
(
self
,
pcap_name
):
"""
Return Windows device name for given pcap device name.
"""
"""
Return Windows device name for given pcap device name.
"""
for
iface
in
self
.
itervalues
():
for
devname
,
iface
in
self
.
items
():
if
iface
.
pcap_name
==
pcap_name
:
if
iface
.
pcap_name
==
pcap_name
:
return
iface
.
name
return
iface
raise
ValueError
(
"
Unknown pypcap network interface %r
"
%
pcap_name
)
raise
ValueError
(
"
Unknown pypcap network interface %r
"
%
pcap_name
)
def
dev
name
_from_index
(
self
,
if_index
):
def
dev_from_index
(
self
,
if_index
):
"""
Return interface name from interface index
"""
"""
Return interface name from interface index
"""
for
devname
,
iface
in
self
.
items
():
for
devname
,
iface
in
self
.
items
():
if
iface
.
win_index
==
if_index
:
if
iface
.
win_index
==
str
(
if_index
)
:
return
iface
.
name
return
iface
raise
ValueError
(
"
Unknown network interface index %r
"
%
if_index
)
raise
ValueError
(
"
Unknown network interface index %r
"
%
if_index
)
def
show
(
self
,
resolve_mac
=
True
):
def
show
(
self
,
resolve_mac
=
True
):
...
@@ -317,31 +319,34 @@ class NetworkInterfaceDict(UserDict):
...
@@ -317,31 +319,34 @@ class NetworkInterfaceDict(UserDict):
IFACES
=
NetworkInterfaceDict
()
IFACES
=
NetworkInterfaceDict
()
IFACES
.
load_from_powershell
()
IFACES
.
load_from_powershell
()
def
pcap_name
(
devname
):
def
pcapname
(
dev
):
"""
Return pypcap device name for given libdnet/Scapy device name
"""
"""
Return pypcap device name for given interface or libdnet/Scapy
if
type
(
devname
)
is
NetworkInterface
:
device name.
return
devname
.
pcap_name
"""
if
type
(
dev
)
is
NetworkInterface
:
return
dev
.
pcap_name
try
:
try
:
pcap_name
=
IFACES
.
pcap
_name
(
devname
)
return
IFACES
.
dev_from
_name
(
dev
).
pcap_
name
except
ValueError
:
except
ValueError
:
# pcap.pcap() will choose a sensible default for sniffing if
iface=None
# pcap.pcap() will choose a sensible default for sniffing if
pcap_name
=
None
# iface=
None
return
pcap_name
return
None
def
devname
(
pcap_name
):
def
dev
_from_pcap
name
(
pcap_name
):
"""
Return libdnet/Scapy device name for given pypcap device name
"""
"""
Return libdnet/Scapy device name for given pypcap device name
"""
return
IFACES
.
devname
(
pcap_name
)
return
IFACES
.
dev
_from_pcap
name
(
pcap_name
)
def
dev
name
_from_index
(
if_index
):
def
dev_from_index
(
if_index
):
"""
Return Windows adapter name for given Windows interface index
"""
"""
Return Windows adapter name for given Windows interface index
"""
return
IFACES
.
dev
name
_from_index
(
if_index
)
return
IFACES
.
dev_from_index
(
if_index
)
def
show_interfaces
(
resolve_mac
=
True
):
def
show_interfaces
(
resolve_mac
=
True
):
"""
Print list of available network interfaces
"""
"""
Print list of available network interfaces
"""
return
IFACES
.
show
(
resolve_mac
)
return
IFACES
.
show
(
resolve_mac
)
_orig_open_pcap
=
pcapdnet
.
open_pcap
_orig_open_pcap
=
pcapdnet
.
open_pcap
pcapdnet
.
open_pcap
=
lambda
iface
,
*
args
,
**
kargs
:
_orig_open_pcap
(
pcap
_
name
(
iface
),
*
args
,
**
kargs
)
pcapdnet
.
open_pcap
=
lambda
iface
,
*
args
,
**
kargs
:
_orig_open_pcap
(
pcapname
(
iface
),
*
args
,
**
kargs
)
_orig_get_if_raw_hwaddr
=
pcapdnet
.
get_if_raw_hwaddr
_orig_get_if_raw_hwaddr
=
pcapdnet
.
get_if_raw_hwaddr
pcapdnet
.
get_if_raw_hwaddr
=
lambda
iface
,
*
args
,
**
kargs
:
(
pcapdnet
.
get_if_raw_hwaddr
=
lambda
iface
,
*
args
,
**
kargs
:
(
...
@@ -355,11 +360,10 @@ def read_routes_7():
...
@@ -355,11 +360,10 @@ def read_routes_7():
for
line
in
exec_query
([
'
Get-WmiObject
'
,
'
win32_IP4RouteTable
'
],
for
line
in
exec_query
([
'
Get-WmiObject
'
,
'
win32_IP4RouteTable
'
],
[
'
Name
'
,
'
Mask
'
,
'
NextHop
'
,
'
InterfaceIndex
'
]):
[
'
Name
'
,
'
Mask
'
,
'
NextHop
'
,
'
InterfaceIndex
'
]):
try
:
try
:
iface
=
dev
name
_from_index
(
int
(
line
[
3
])
)
iface
=
dev_from_index
(
line
[
3
])
except
ValueError
:
except
ValueError
:
continue
continue
routes
.
append
((
atol
(
line
[
0
]),
atol
(
line
[
1
]),
line
[
2
],
iface
,
routes
.
append
((
atol
(
line
[
0
]),
atol
(
line
[
1
]),
line
[
2
],
iface
,
iface
.
ip
))
IFACES
[
iface
].
ip
))
return
routes
return
routes
def
read_routes
():
def
read_routes
():
...
@@ -393,19 +397,16 @@ def read_routes_post2008():
...
@@ -393,19 +397,16 @@ def read_routes_post2008():
match
=
re
.
search
(
pattern
,
l
)
match
=
re
.
search
(
pattern
,
l
)
if
match
:
if
match
:
try
:
try
:
iface
=
devname_from_index
(
int
(
match
.
group
(
1
)))
iface
=
dev_from_index
(
match
.
group
(
1
))
addr
=
IFACES
[
iface
].
ip
except
:
except
:
continue
continue
dest
=
atol
(
match
.
group
(
2
))
mask
=
itom
(
int
(
match
.
group
(
3
)))
gw
=
match
.
group
(
4
)
# try:
# try:
# intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
# intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
# except OSError:
# except OSError:
# log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest)
# log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest)
# continue
# continue
routes
.
append
((
dest
,
mask
,
gw
,
iface
,
addr
))
routes
.
append
((
atol
(
match
.
group
(
2
)),
itom
(
int
(
match
.
group
(
3
))),
match
.
group
(
4
),
iface
,
iface
.
ip
))
return
routes
return
routes
def
read_routes6
():
def
read_routes6
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment