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
339dfb39
Commit
339dfb39
authored
8 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
Add a tcpdump-based L2listen socket
This also includes some fixes for tcpdump()
parent
94bab875
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/supersocket.py
+26
-0
26 additions, 0 deletions
scapy/supersocket.py
scapy/utils.py
+18
-9
18 additions, 9 deletions
scapy/utils.py
with
44 additions
and
9 deletions
scapy/supersocket.py
+
26
−
0
View file @
339dfb39
...
@@ -13,6 +13,7 @@ from scapy.config import conf
...
@@ -13,6 +13,7 @@ from scapy.config import conf
from
scapy.data
import
*
from
scapy.data
import
*
from
scapy.error
import
warning
,
log_runtime
from
scapy.error
import
warning
,
log_runtime
import
scapy.packet
import
scapy.packet
from
scapy.utils
import
PcapReader
,
tcpdump
class
_SuperSocket_metaclass
(
type
):
class
_SuperSocket_metaclass
(
type
):
def
__repr__
(
self
):
def
__repr__
(
self
):
...
@@ -174,5 +175,30 @@ class SSLStreamSocket(StreamSocket):
...
@@ -174,5 +175,30 @@ class SSLStreamSocket(StreamSocket):
self
.
_buf
=
self
.
_buf
[
x
:]
self
.
_buf
=
self
.
_buf
[
x
:]
return
pkt
return
pkt
class
L2ListenTcpdump
(
SuperSocket
):
desc
=
"
read packets at layer 2 using tcpdump
"
def
__init__
(
self
,
iface
=
None
,
promisc
=
None
,
filter
=
None
,
nofilter
=
False
,
prog
=
None
,
*
arg
,
**
karg
):
self
.
outs
=
None
args
=
[
'
-w
'
,
'
-
'
,
'
-s
'
,
'
65535
'
]
if
iface
is
not
None
:
args
.
extend
([
'
-i
'
,
iface
])
if
not
promisc
:
args
.
append
(
'
-p
'
)
if
not
nofilter
:
if
conf
.
except_filter
:
if
filter
:
filter
=
"
(%s) and not (%s)
"
%
(
filter
,
conf
.
except_filter
)
else
:
filter
=
"
not (%s)
"
%
conf
.
except_filter
if
filter
is
not
None
:
args
.
append
(
filter
)
self
.
ins
=
PcapReader
(
tcpdump
(
None
,
prog
=
prog
,
args
=
args
,
getfd
=
True
))
def
recv
(
self
,
x
=
MTU
):
return
self
.
ins
.
recv
(
x
)
if
conf
.
L3socket
is
None
:
if
conf
.
L3socket
is
None
:
conf
.
L3socket
=
L3RawSocket
conf
.
L3socket
=
L3RawSocket
This diff is collapsed.
Click to expand it.
scapy/utils.py
+
18
−
9
View file @
339dfb39
...
@@ -804,7 +804,10 @@ class RawPcapNgReader(RawPcapReader):
...
@@ -804,7 +804,10 @@ class RawPcapNgReader(RawPcapReader):
self
.
endian
=
"
<
"
self
.
endian
=
"
<
"
else
:
else
:
raise
Scapy_Exception
(
"
Not a pcapng capture file (bad magic)
"
)
raise
Scapy_Exception
(
"
Not a pcapng capture file (bad magic)
"
)
self
.
f
.
seek
(
0
)
try
:
self
.
f
.
seek
(
0
)
except
:
pass
def
read_packet
(
self
,
size
=
MTU
):
def
read_packet
(
self
,
size
=
MTU
):
"""
Read blocks until it reaches either EOF or a packet, and
"""
Read blocks until it reaches either EOF or a packet, and
...
@@ -1139,11 +1142,19 @@ To get a JSON representation of a tshark-parsed PacketList(), one can:
...
@@ -1139,11 +1142,19 @@ To get a JSON representation of a tshark-parsed PacketList(), one can:
u
'
64
'
u
'
64
'
"""
"""
if
isinstance
(
pktlist
,
basestring
):
if
prog
is
None
:
prog
=
[
conf
.
prog
.
tcpdump
]
elif
isinstance
(
prog
,
basestring
):
prog
=
[
prog
]
if
pktlist
is
None
:
proc
=
subprocess
.
Popen
(
proc
=
subprocess
.
Popen
(
[
conf
.
prog
.
tcpdump
if
prog
is
None
else
prog
,
"
-r
"
,
pktlist
]
prog
+
(
args
if
args
is
not
None
else
[]),
+
([
"
-n
"
]
if
args
is
None
else
args
),
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stdin
=
subprocess
.
PIPE
,
stderr
=
open
(
os
.
devnull
),
)
elif
isinstance
(
pktlist
,
basestring
):
proc
=
subprocess
.
Popen
(
prog
+
[
"
-r
"
,
pktlist
]
+
(
args
if
args
is
not
None
else
[]),
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stderr
=
open
(
os
.
devnull
),
stderr
=
open
(
os
.
devnull
),
)
)
...
@@ -1158,16 +1169,14 @@ u'64'
...
@@ -1158,16 +1169,14 @@ u'64'
else
:
else
:
tmpfile
.
close
()
tmpfile
.
close
()
proc
=
subprocess
.
Popen
(
proc
=
subprocess
.
Popen
(
[
conf
.
prog
.
tcpdump
if
prog
is
None
else
prog
,
"
-r
"
,
prog
+
[
"
-r
"
,
tmpfile
.
name
]
+
(
args
if
args
is
not
None
else
[]),
tmpfile
.
name
]
+
([
"
-n
"
]
if
args
is
None
else
args
),
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stderr
=
open
(
os
.
devnull
),
stderr
=
open
(
os
.
devnull
),
)
)
conf
.
temp_files
.
append
(
tmpfile
.
name
)
conf
.
temp_files
.
append
(
tmpfile
.
name
)
else
:
else
:
proc
=
subprocess
.
Popen
(
proc
=
subprocess
.
Popen
(
[
conf
.
prog
.
tcpdump
if
prog
is
None
else
prog
,
"
-r
"
,
"
-
"
]
prog
+
[
"
-r
"
,
"
-
"
]
+
(
args
if
args
is
not
None
else
[]),
+
([
"
-n
"
]
if
args
is
None
else
args
),
stdin
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stderr
=
open
(
os
.
devnull
),
stderr
=
open
(
os
.
devnull
),
...
...
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