From d148fd555ddcdcefa9fb9c4ec24bedc752df9941 Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Fri, 8 Nov 2024 21:42:46 +0100 Subject: [PATCH 1/3] Fix #4547: Change hashret of DoIP --- scapy/contrib/automotive/doip.py | 5 +---- test/contrib/automotive/doip.uts | 22 +++++++++++++++++++++ test/pcaps/doip_functional_request.pcap.gz | Bin 0 -> 818 bytes 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 test/pcaps/doip_functional_request.pcap.gz diff --git a/scapy/contrib/automotive/doip.py b/scapy/contrib/automotive/doip.py index b9d279bcf6b..3fcbdc5dad4 100644 --- a/scapy/contrib/automotive/doip.py +++ b/scapy/contrib/automotive/doip.py @@ -239,10 +239,7 @@ def answers(self, other): def hashret(self): # type: () -> bytes - if self.payload_type in [0x8001, 0x8002, 0x8003]: - return bytes(self)[:2] + struct.pack( - "H", self.target_address ^ self.source_address) - return bytes(self)[:2] + return bytes(self)[:3] def post_build(self, pkt, pay): # type: (bytes, bytes) -> bytes diff --git a/test/contrib/automotive/doip.uts b/test/contrib/automotive/doip.uts index 9a7d61e3b7d..0bda4f17f2f 100644 --- a/test/contrib/automotive/doip.uts +++ b/test/contrib/automotive/doip.uts @@ -10,6 +10,8 @@ = Load Contrib Layer +from test.testsocket import TestSocket, cleanup_testsockets, UnstableSocket + load_contrib("automotive.doip", globals_dict=globals()) load_contrib("automotive.uds", globals_dict=globals()) @@ -406,6 +408,26 @@ assert pkts[0][DoIP].payload_length == 2 assert pkts[0][DoIP:2].payload_length == 7 assert pkts[1][DoIP].payload_length == 103 += Doip logical addressing + +filename = scapy_path("/test/pcaps/doip_functional_request.pcap.gz") +tx_sock = TestSocket(DoIP) +rx_sock = TestSocket(DoIP) +tx_sock.pair(rx_sock) + +for pkt in PcapReader(filename): + if pkt.haslayer(DoIP): + tx_sock.send(pkt[DoIP]) + +ans, unans = rx_sock.sr(DoIP(bytes(DoIP(payload_type=0x8001, source_address=0xe80, target_address=0xe400) / UDS() / UDS_TP())), multi=True, timeout=0.01, verbose=False) + +cleanup_testsockets() + +assert len(ans) == 8 +ans.summary() +assert len(unans) == 0 + + + DoIP Communication tests = Load libraries diff --git a/test/pcaps/doip_functional_request.pcap.gz b/test/pcaps/doip_functional_request.pcap.gz new file mode 100644 index 0000000000000000000000000000000000000000..c2b9e9cf35f8eedc1ea7c610b4c57b6372cda4e1 GIT binary patch literal 818 zcmV-21I_#&iwFp+=m%#217vS$a9?J1Zew(5Z*F01Uvgz}b!BsOE^uREZ~%SOT}abW z7{~Fm|2Fq`#`-5-2xTBa)J2*xx=OLddQoySA!Zkr67D7{5QT1JG>LAaLVLGzLeL<) zh~A430;5{m%M6*!R3w9T(Yjd8+Uj}EIA?e~9$`bg_&y(g9E`ra7t)A@aCDtLb6Y2FLbk>FYDsND`cF9Pa)q;FiNv7OS8=C1h>Zbl z;Ya%cLNtr@zD3jRTYblO;@?eXvkl94i}U4NGuO|R3Bhvo99FUJ^d$y|+WIu8_Y4$g zPuI8R%fXtKBUoqUIFwybb;-=m*aa*vXo9&1>gIr9O119;qltQVVHt}XR@+G<)EZ^Q z9kGjag`d)5DHL0IaSs-?46#DU<_OTS@j(BYJbB3&&g5%6Fgq%YVTL2UK+bgC${m3C zQ9Odh;W9gEf?AWT=uW<&#plvusVTEAy|@VE0tgj40#!DHp`&HWoiEXyiLgp9oGB4@ zuER48Q1p%H#0xdAtmukeraLF4McnxiD|W=NsAU59j0+rrIZ{KgKm1Bp&HR>*5)noz zfg2&5`PgALO6xzofyMB+PCQWa$co#O5n6m9EyB#{5ms!|un1xeLe@C~Z-auzb=AaI z=pb2PkPw_GUp#Tg6rR9hVj@5B60j@zPWmp&8MtDIgUwiF6Ia1w?xy0*gi?H!iZc>% zr6B%-H?TN9sT7Y=@iReO$;GF**n(9qUdzPulS=V5D*h`GS4+eeEUu3$#bZ?bR1jA) zvFD^*Y?LtZmbg;fFa4*C;(9?m&BXIlO7VLtejw5~8Kw9m6+aThelBiXMyxY& z%ZyTdlZt;!#GQh8hKUcRl;TfR{7?{gGI7H!7Z+ibzlshfK9N$22dMa$L>v^vU-1SO wjiN%8I7-D21aXjyKXb8xRW9~3@kZz?#33q9NyO&`@pruOAB1&*VtEMw06RvAHUIzs literal 0 HcmV?d00001 From 177b60b6b9fe3bbe7ef7cdb86239e91f0ecc7e1a Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Sat, 9 Nov 2024 07:51:52 +0000 Subject: [PATCH 2/3] debug --- test/contrib/automotive/doip.uts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/contrib/automotive/doip.uts b/test/contrib/automotive/doip.uts index 0bda4f17f2f..a371d411ad8 100644 --- a/test/contrib/automotive/doip.uts +++ b/test/contrib/automotive/doip.uts @@ -423,6 +423,10 @@ ans, unans = rx_sock.sr(DoIP(bytes(DoIP(payload_type=0x8001, source_address=0xe8 cleanup_testsockets() +ans.summary() +if unans: + unans.summary() + assert len(ans) == 8 ans.summary() assert len(unans) == 0 From 25a651749bb585e25814000c0474609df724370e Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Sat, 9 Nov 2024 19:18:17 +0000 Subject: [PATCH 3/3] update timeout --- test/contrib/automotive/doip.uts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/contrib/automotive/doip.uts b/test/contrib/automotive/doip.uts index a371d411ad8..b5963a0d817 100644 --- a/test/contrib/automotive/doip.uts +++ b/test/contrib/automotive/doip.uts @@ -419,7 +419,7 @@ for pkt in PcapReader(filename): if pkt.haslayer(DoIP): tx_sock.send(pkt[DoIP]) -ans, unans = rx_sock.sr(DoIP(bytes(DoIP(payload_type=0x8001, source_address=0xe80, target_address=0xe400) / UDS() / UDS_TP())), multi=True, timeout=0.01, verbose=False) +ans, unans = rx_sock.sr(DoIP(bytes(DoIP(payload_type=0x8001, source_address=0xe80, target_address=0xe400) / UDS() / UDS_TP())), multi=True, timeout=0.1, verbose=False) cleanup_testsockets()