|
3 | 3 | import json
|
4 | 4 | import subprocess
|
5 | 5 |
|
6 |
| -from scapy.all import IP, TCP, hexdump, import_hexcap |
| 6 | +from scapy.all import IP, TCP, Ether, hexdump, import_hexcap |
7 | 7 |
|
8 | 8 | FIREWALL_COMMANDS_HELP = "\r\n( · - · · · \r\n\
|
9 | 9 | You may need to temporarily block RST output packets in your firewall.\r\n\
|
@@ -113,24 +113,30 @@ def _ask_yesno(cls, question):
|
113 | 113 |
|
114 | 114 | @classmethod
|
115 | 115 | def _supported_or_correct(cls, copied_packet):
|
116 |
| - return (copied_packet[IP].version == 4) |
| 116 | + return (copied_packet.haslayer(IP) and (copied_packet[IP].version == 4)) |
117 | 117 |
|
118 | 118 | @classmethod
|
119 | 119 | def _read_pasted_packet(cls, show=False):
|
120 | 120 | print(" ********************************************************************** ")
|
121 | 121 | print(" paste here the packet hex dump start with the IP layer and then enter :")
|
122 | 122 | print(" . . . - . . . . - . . . . - . . . . - . ")
|
123 |
| - p1 = IP(import_hexcap()) |
| 123 | + packet_string = import_hexcap() |
124 | 124 | print(" . . . - . . . . - . . . . - . . . . - . ")
|
125 |
| - if not cls._supported_or_correct(p1): |
126 |
| - raise BADPacketException( |
127 |
| - "it's not IPv4 or the hexdump is not started with IP layer") |
128 |
| - p1[IP].src = '127.1.2.7' |
| 125 | + packet_object = None |
| 126 | + if not cls._supported_or_correct(IP(packet_string)): |
| 127 | + if not cls._supported_or_correct(Ether(packet_string).payload): |
| 128 | + raise BADPacketException( |
| 129 | + "it's not IPv4 or the hexdump is not started with IP layer") |
| 130 | + else: |
| 131 | + packet_object = Ether(packet_string).payload |
| 132 | + else: |
| 133 | + packet_object = IP(packet_string) |
| 134 | + packet_object[IP].src = '127.1.2.7' |
129 | 135 | if show:
|
130 | 136 | print(" . . . - . developed view of this packet:")
|
131 |
| - p1.show() |
132 |
| - print(" . . . - . . . . - . . . . - . . . . - . ") |
133 |
| - return p1 |
| 137 | + packet_object.show() |
| 138 | + print(" . . . - . (make sure it's correct) . . . - . ") |
| 139 | + return packet_object |
134 | 140 |
|
135 | 141 | @classmethod
|
136 | 142 | def from_stdin(cls, os_name: str, trace_retransmission: bool):
|
|
0 commit comments