|
29 | 29 | from kasa.protocol import DEFAULT_CREDENTIALS, get_default_credentials
|
30 | 30 |
|
31 | 31 |
|
| 32 | +def _is_http_response_for_packet(response, packet): |
| 33 | + """Return True if the *response* contains a response for request in *packet*. |
| 34 | +
|
| 35 | + Different tshark versions use different field for the information. |
| 36 | + """ |
| 37 | + if not hasattr(response, "http"): |
| 38 | + return False |
| 39 | + if hasattr(response.http, "response_for_uri") and ( |
| 40 | + response.http.response_for_uri == packet.http.request_full_uri |
| 41 | + ): |
| 42 | + return True |
| 43 | + # tshark 4.4.0 |
| 44 | + if response.http.request_uri == packet.http.request_uri: |
| 45 | + return True |
| 46 | + |
| 47 | + return False |
| 48 | + |
| 49 | + |
32 | 50 | class MyEncryptionSession(KlapEncryptionSession):
|
33 | 51 | """A custom KlapEncryptionSession class that allows for decryption."""
|
34 | 52 |
|
@@ -222,7 +240,7 @@ def main(
|
222 | 240 | while True:
|
223 | 241 | try:
|
224 | 242 | packet = capture.next()
|
225 |
| - # packet_number = capture._current_packet |
| 243 | + packet_number = capture._current_packet |
226 | 244 | # we only care about http packets
|
227 | 245 | if hasattr(
|
228 | 246 | packet, "http"
|
@@ -267,18 +285,16 @@ def main(
|
267 | 285 | message = bytes.fromhex(data)
|
268 | 286 | operator.local_seed = message
|
269 | 287 | response = None
|
| 288 | + print( |
| 289 | + f"got handshake1 in {packet_number}, " |
| 290 | + f"looking for the response" |
| 291 | + ) |
270 | 292 | while (
|
271 | 293 | True
|
272 | 294 | ): # we are going to now look for the response to this request
|
273 | 295 | response = capture.next()
|
274 |
| - if ( |
275 |
| - hasattr(response, "http") |
276 |
| - and hasattr(response.http, "response_for_uri") |
277 |
| - and ( |
278 |
| - response.http.response_for_uri |
279 |
| - == packet.http.request_full_uri |
280 |
| - ) |
281 |
| - ): |
| 296 | + if _is_http_response_for_packet(response, packet): |
| 297 | + print(f"found response in {packet_number}") |
282 | 298 | break
|
283 | 299 | data = response.http.get_field_value("file_data", raw=True)
|
284 | 300 | message = bytes.fromhex(data)
|
|
0 commit comments