From ec37d317c9087eb08cc7cdaa9f96f356a81526ae Mon Sep 17 00:00:00 2001 From: Meitar M Date: Sat, 14 Mar 2020 02:45:50 -0400 Subject: [PATCH] Bitwise AND should be with decimal 31 to also compare QR flag. The original version of pyminifakedns ignored the value of the Query/Response Flag ("QR flag"), which is the bit immediately prior to the DNS opcode field. The value of the QR flag should be checked for the value 0 along with the opcode bits, which should also be zero. --- src/core/minifakedns.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/minifakedns.py b/src/core/minifakedns.py index 27e53fcd5..cf39ec246 100644 --- a/src/core/minifakedns.py +++ b/src/core/minifakedns.py @@ -96,15 +96,15 @@ class DNSQuery: # 000 0 0000 # # To test for this reliably, we do a bitwise AND with a value - # of decimal 15, which is 1111 in binary, exactly four bits: + # of decimal 31, which is 11111 in binary, exactly five bits: # # 00000000 (Remember, 0 AND 1 equals 0.) - # AND 00001111 + # AND 00011111 # ------------ # 00000000 = decimal 0 # # In one line of Python code, we get the following: - kind = (flags[0] >> 3) & 15 # Opcode is in bits 4, 5, 6, and 7 of first byte. + kind = (flags[0] >> 3) & 31 # Opcode is in bits 4, 5, 6, and 7 of first byte. # QR bit is 8th bit, but it should be 0. # And now, we test to see if the result if 0 == kind: # was a standard query.