mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 11:13:34 +00:00
parse_pcap_klap: use request_uri for matching the response (#1136)
tshark 4.4.0 does not have response_for_uri, this fixes response detection by using request_uri, too.
This commit is contained in:
parent
d897503b58
commit
130e1b6023
@ -29,6 +29,24 @@ from kasa.klaptransport import KlapEncryptionSession, KlapTransportV2
|
|||||||
from kasa.protocol import DEFAULT_CREDENTIALS, get_default_credentials
|
from kasa.protocol import DEFAULT_CREDENTIALS, get_default_credentials
|
||||||
|
|
||||||
|
|
||||||
|
def _is_http_response_for_packet(response, packet):
|
||||||
|
"""Return True if the *response* contains a response for request in *packet*.
|
||||||
|
|
||||||
|
Different tshark versions use different field for the information.
|
||||||
|
"""
|
||||||
|
if not hasattr(response, "http"):
|
||||||
|
return False
|
||||||
|
if hasattr(response.http, "response_for_uri") and (
|
||||||
|
response.http.response_for_uri == packet.http.request_full_uri
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
# tshark 4.4.0
|
||||||
|
if response.http.request_uri == packet.http.request_uri:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class MyEncryptionSession(KlapEncryptionSession):
|
class MyEncryptionSession(KlapEncryptionSession):
|
||||||
"""A custom KlapEncryptionSession class that allows for decryption."""
|
"""A custom KlapEncryptionSession class that allows for decryption."""
|
||||||
|
|
||||||
@ -222,7 +240,7 @@ def main(
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
packet = capture.next()
|
packet = capture.next()
|
||||||
# packet_number = capture._current_packet
|
packet_number = capture._current_packet
|
||||||
# we only care about http packets
|
# we only care about http packets
|
||||||
if hasattr(
|
if hasattr(
|
||||||
packet, "http"
|
packet, "http"
|
||||||
@ -267,18 +285,16 @@ def main(
|
|||||||
message = bytes.fromhex(data)
|
message = bytes.fromhex(data)
|
||||||
operator.local_seed = message
|
operator.local_seed = message
|
||||||
response = None
|
response = None
|
||||||
|
print(
|
||||||
|
f"got handshake1 in {packet_number}, "
|
||||||
|
f"looking for the response"
|
||||||
|
)
|
||||||
while (
|
while (
|
||||||
True
|
True
|
||||||
): # we are going to now look for the response to this request
|
): # we are going to now look for the response to this request
|
||||||
response = capture.next()
|
response = capture.next()
|
||||||
if (
|
if _is_http_response_for_packet(response, packet):
|
||||||
hasattr(response, "http")
|
print(f"found response in {packet_number}")
|
||||||
and hasattr(response.http, "response_for_uri")
|
|
||||||
and (
|
|
||||||
response.http.response_for_uri
|
|
||||||
== packet.http.request_full_uri
|
|
||||||
)
|
|
||||||
):
|
|
||||||
break
|
break
|
||||||
data = response.http.get_field_value("file_data", raw=True)
|
data = response.http.get_field_value("file_data", raw=True)
|
||||||
message = bytes.fromhex(data)
|
message = bytes.fromhex(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user