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
55392dc3
Commit
55392dc3
authored
16 years ago
by
Phil
Browse files
Options
Downloads
Patches
Plain Diff
Added IP options support
* * *
parent
2d0ef27e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/base_classes.py
+1
-1
1 addition, 1 deletion
scapy/base_classes.py
scapy/layers/inet.py
+155
-12
155 additions, 12 deletions
scapy/layers/inet.py
with
156 additions
and
13 deletions
scapy/base_classes.py
+
1
−
1
View file @
55392dc3
...
@@ -189,7 +189,7 @@ class NewDefaultValues(Packet_metaclass):
...
@@ -189,7 +189,7 @@ class NewDefaultValues(Packet_metaclass):
except
:
except
:
f
,
l
=
"
??
"
,
-
1
f
,
l
=
"
??
"
,
-
1
raise
raise
log_loading
.
warning
(
"
Deprecated use of NewDefaultValues (%s l. %i).
"
%
(
f
,
l
))
log_loading
.
warning
(
"
Deprecated
(no more needed)
use of NewDefaultValues (%s l. %i).
"
%
(
f
,
l
))
return
super
(
NewDefaultValues
,
cls
).
__new__
(
cls
,
name
,
bases
,
dct
)
return
super
(
NewDefaultValues
,
cls
).
__new__
(
cls
,
name
,
bases
,
dct
)
...
...
This diff is collapsed.
Click to expand it.
scapy/layers/inet.py
+
155
−
12
View file @
55392dc3
...
@@ -34,18 +34,160 @@ class IPTools:
...
@@ -34,18 +34,160 @@ class IPTools:
return
self
.
ottl
()
-
self
.
ttl
-
1
return
self
.
ottl
()
-
self
.
ttl
-
1
_ip_options_names
=
{
0
:
"
end_of_list
"
,
1
:
"
nop
"
,
2
:
"
security
"
,
3
:
"
loose_source_route
"
,
4
:
"
timestamp
"
,
5
:
"
extended_security
"
,
6
:
"
commercial_security
"
,
7
:
"
record_route
"
,
8
:
"
stream_id
"
,
9
:
"
strict_source_route
"
,
10
:
"
experimental_measurement
"
,
11
:
"
mtu_probe
"
,
12
:
"
mtu_reply
"
,
13
:
"
flow_control
"
,
14
:
"
access_control
"
,
15
:
"
encode
"
,
16
:
"
imi_traffic_descriptor
"
,
17
:
"
extended_IP
"
,
18
:
"
traceroute
"
,
19
:
"
address_extension
"
,
20
:
"
router_alert
"
,
21
:
"
selective_directed_broadcast_mode
"
,
23
:
"
dynamic_packet_state
"
,
24
:
"
upstream_multicast_packet
"
,
25
:
"
quick_start
"
,
30
:
"
rfc4727_experiment
"
,
}
class
_IPOption_HDR
(
Packet
):
fields_desc
=
[
BitField
(
"
copy_flag
"
,
0
,
1
),
BitEnumField
(
"
optclass
"
,
0
,
2
,{
0
:
"
control
"
,
2
:
"
debug
"
}),
BitEnumField
(
"
option
"
,
0
,
5
,
_ip_options_names
)
]
class
IPOption
(
Packet
):
fields_desc
=
[
_IPOption_HDR
,
FieldLenField
(
"
length
"
,
None
,
fmt
=
"
B
"
,
# Only option 0 and 1 have no length and value
length_of
=
"
value
"
,
adjust
=
lambda
pkt
,
l
:
l
+
2
),
StrLenField
(
"
value
"
,
""
,
length_from
=
lambda
pkt
:
pkt
.
length
-
2
)
]
def
extract_padding
(
self
,
p
):
return
""
,
p
registered_ip_options
=
{}
@classmethod
def
register_variant
(
cls
):
cls
.
registered_ip_options
[
cls
.
option
.
default
]
=
cls
@classmethod
def
dispatch_hook
(
cls
,
pkt
=
None
,
*
args
,
**
kargs
):
if
pkt
:
opt
=
ord
(
pkt
[
0
])
&
0x1f
if
opt
in
cls
.
registered_ip_options
:
return
cls
.
registered_ip_options
[
opt
]
return
cls
class
IPOption_EOL
(
IPOption
):
option
=
0
fields_desc
=
[
_IPOption_HDR
]
class
IPoptionsField
(
StrField
):
class
IPOption_NOP
(
IPOption
):
def
i2m
(
self
,
pkt
,
x
):
option
=
1
return
x
+
"
\x00
"
*
(
3
-
((
len
(
x
)
+
3
)
%
4
))
fields_desc
=
[
_IPOption_HDR
]
def
getfield
(
self
,
pkt
,
s
):
opsz
=
(
pkt
.
ihl
-
5
)
*
4
class
IPOption_Security
(
IPOption
):
if
opsz
<
0
:
copy_flag
=
1
warning
(
"
bad ihl (%i). Assuming ihl=5
"
%
pkt
.
ihl
)
option
=
2
opsz
=
0
fields_desc
=
[
_IPOption_HDR
,
return
s
[
opsz
:],
s
[:
opsz
]
ByteField
(
"
length
"
,
11
),
def
randval
(
self
):
ShortField
(
"
security
"
,
0
),
return
RandBin
(
RandNum
(
0
,
39
))
ShortField
(
"
compartment
"
,
0
),
ShortField
(
"
handling_restrictions
"
,
0
),
StrFixedLenField
(
"
transmission_control_code
"
,
"
xxx
"
,
3
),
]
class
IPOption_LSRR
(
IPOption
):
name
=
"
IP Option Loose Source and Record Route
"
copy_flag
=
1
option
=
3
fields_desc
=
[
_IPOption_HDR
,
FieldLenField
(
"
length
"
,
None
,
fmt
=
"
B
"
,
length_of
=
"
routers
"
,
adjust
=
lambda
pkt
,
l
:
l
+
3
),
ByteField
(
"
pointer
"
,
4
),
# 4 is first IP
FieldListField
(
"
routers
"
,[],
IPField
(
""
,
"
0.0.0.0
"
),
length_from
=
lambda
pkt
:
pkt
.
length
-
3
)
]
def
get_current_router
(
self
):
return
self
.
routers
[
self
.
pointer
/
4
-
1
]
class
IPOption_RR
(
IPOption_LSRR
):
name
=
"
IP Option Record Route
"
option
=
7
class
IPOption_SSRR
(
IPOption_LSRR
):
name
=
"
IP Option Strict Source and Record Route
"
option
=
9
class
IPOption_Stream_Id
(
IPOption
):
name
=
"
IP Option Stream ID
"
option
=
8
fields_desc
=
[
_IPOption_HDR
,
ByteField
(
"
length
"
,
4
),
ShortField
(
"
security
"
,
0
),
]
class
IPOption_MTU_Probe
(
IPOption
):
name
=
"
IP Option MTU Probe
"
option
=
11
fields_desc
=
[
_IPOption_HDR
,
ByteField
(
"
length
"
,
4
),
ShortField
(
"
mtu
"
,
0
),
]
class
IPOption_MTU_Reply
(
IPOption_MTU_Probe
):
name
=
"
IP Option MTU Reply
"
option
=
12
class
IPOption_Traceroute
(
IPOption
):
copy_flag
=
1
option
=
18
fields_desc
=
[
_IPOption_HDR
,
ByteField
(
"
length
"
,
12
),
ShortField
(
"
id
"
,
0
),
ShortField
(
"
outbound_hops
"
,
0
),
ShortField
(
"
return_hops
"
,
0
),
IPField
(
"
originator_ip
"
,
"
0.0.0.0
"
)
]
class
IPOption_Address_Extension
(
IPOption
):
name
=
"
IP Option Address Extension
"
copy_flag
=
1
option
=
19
fields_desc
=
[
_IPOption_HDR
,
ByteField
(
"
length
"
,
10
),
IPField
(
"
src_ext
"
,
"
0.0.0.0
"
),
IPField
(
"
dst_ext
"
,
"
0.0.0.0
"
)
]
class
IPOption_Router_Alert
(
IPOption
):
name
=
"
IP Option Router Alert
"
copy_flag
=
1
option
=
20
fields_desc
=
[
_IPOption_HDR
,
ByteField
(
"
length
"
,
4
),
ShortEnumField
(
"
alert
"
,
0
,
{
0
:
"
router_shall_examine_packet
"
}),
]
class
IPOption_SDBM
(
IPOption
):
name
=
"
IP Option Selective Directed Broadcast Mode
"
copy_flag
=
1
option
=
21
fields_desc
=
[
_IPOption_HDR
,
FieldLenField
(
"
length
"
,
None
,
fmt
=
"
B
"
,
length_of
=
"
addresses
"
,
adjust
=
lambda
pkt
,
l
:
l
+
2
),
FieldListField
(
"
addresses
"
,[],
IPField
(
""
,
"
0.0.0.0
"
),
length_from
=
lambda
pkt
:
pkt
.
length
-
2
)
]
TCPOptions
=
(
TCPOptions
=
(
...
@@ -181,9 +323,10 @@ class IP(Packet, IPTools):
...
@@ -181,9 +323,10 @@ class IP(Packet, IPTools):
#IPField("src", "127.0.0.1"),
#IPField("src", "127.0.0.1"),
Emph
(
SourceIPField
(
"
src
"
,
"
dst
"
)),
Emph
(
SourceIPField
(
"
src
"
,
"
dst
"
)),
Emph
(
IPField
(
"
dst
"
,
"
127.0.0.1
"
)),
Emph
(
IPField
(
"
dst
"
,
"
127.0.0.1
"
)),
IPoptions
Field
(
"
options
"
,
""
)
]
PacketList
Field
(
"
options
"
,
[],
IPOption
,
length_from
=
lambda
p
:
p
.
ihl
*
4
-
20
)
]
def
post_build
(
self
,
p
,
pay
):
def
post_build
(
self
,
p
,
pay
):
ihl
=
self
.
ihl
ihl
=
self
.
ihl
p
+=
"
\0
"
*
((
-
len
(
p
))
%
4
)
# pad IP options if needed
if
ihl
is
None
:
if
ihl
is
None
:
ihl
=
len
(
p
)
/
4
ihl
=
len
(
p
)
/
4
p
=
chr
(((
self
.
version
&
0xf
)
<<
4
)
|
ihl
&
0x0f
)
+
p
[
1
:]
p
=
chr
(((
self
.
version
&
0xf
)
<<
4
)
|
ihl
&
0x0f
)
+
p
[
1
:]
...
...
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