mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2025-01-17 18:34:03 -05:00
WPS: Use alternating poll/listen for NFC peer discovery with nfcpy
This is needed to find the NFC peer to avoid cases where both devices could be using the same operation. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
8140ae969b
commit
dc6bda1123
@ -185,6 +185,34 @@ def wps_write_password_tag(clf):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
def find_peer(clf):
|
||||||
|
while True:
|
||||||
|
if nfc.llcp.connected():
|
||||||
|
print "LLCP connected"
|
||||||
|
general_bytes = nfc.llcp.startup({})
|
||||||
|
peer = clf.listen(ord(os.urandom(1)) + 200, general_bytes)
|
||||||
|
if isinstance(peer, nfc.DEP):
|
||||||
|
print "listen -> DEP";
|
||||||
|
if peer.general_bytes.startswith("Ffm"):
|
||||||
|
print "Found DEP"
|
||||||
|
return peer
|
||||||
|
print "mismatch in general_bytes"
|
||||||
|
print peer.general_bytes
|
||||||
|
|
||||||
|
peer = clf.poll(general_bytes)
|
||||||
|
if isinstance(peer, nfc.DEP):
|
||||||
|
print "poll -> DEP";
|
||||||
|
if peer.general_bytes.startswith("Ffm"):
|
||||||
|
print "Found DEP"
|
||||||
|
return peer
|
||||||
|
print "mismatch in general_bytes"
|
||||||
|
print peer.general_bytes
|
||||||
|
|
||||||
|
if peer:
|
||||||
|
print "Found tag"
|
||||||
|
return peer
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clf = nfc.ContactlessFrontend()
|
clf = nfc.ContactlessFrontend()
|
||||||
|
|
||||||
@ -200,25 +228,18 @@ def main():
|
|||||||
while True:
|
while True:
|
||||||
print "Waiting for a tag or peer to be touched"
|
print "Waiting for a tag or peer to be touched"
|
||||||
|
|
||||||
while True:
|
tag = find_peer(clf)
|
||||||
general_bytes = nfc.llcp.startup({})
|
if isinstance(tag, nfc.DEP):
|
||||||
tag = clf.poll(general_bytes)
|
wps_handover_init(tag)
|
||||||
if tag == None:
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
if isinstance(tag, nfc.DEP):
|
if tag.ndef:
|
||||||
wps_handover_init(tag)
|
wps_tag_read(tag)
|
||||||
break
|
continue
|
||||||
|
|
||||||
if tag.ndef:
|
print "Not an NDEF tag - remove tag"
|
||||||
wps_tag_read(tag)
|
while tag.is_present:
|
||||||
break
|
time.sleep(0.1)
|
||||||
|
|
||||||
if tag:
|
|
||||||
print "Not an NDEF tag - remove tag"
|
|
||||||
while tag.is_present:
|
|
||||||
time.sleep(0.1)
|
|
||||||
break
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
@ -127,6 +127,34 @@ def wps_tag_read(tag):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
def find_peer(clf):
|
||||||
|
while True:
|
||||||
|
if nfc.llcp.connected():
|
||||||
|
print "LLCP connected"
|
||||||
|
general_bytes = nfc.llcp.startup({})
|
||||||
|
peer = clf.listen(ord(os.urandom(1)) + 200, general_bytes)
|
||||||
|
if isinstance(peer, nfc.DEP):
|
||||||
|
print "listen -> DEP";
|
||||||
|
if peer.general_bytes.startswith("Ffm"):
|
||||||
|
print "Found DEP"
|
||||||
|
return peer
|
||||||
|
print "mismatch in general_bytes"
|
||||||
|
print peer.general_bytes
|
||||||
|
|
||||||
|
peer = clf.poll(general_bytes)
|
||||||
|
if isinstance(peer, nfc.DEP):
|
||||||
|
print "poll -> DEP";
|
||||||
|
if peer.general_bytes.startswith("Ffm"):
|
||||||
|
print "Found DEP"
|
||||||
|
return peer
|
||||||
|
print "mismatch in general_bytes"
|
||||||
|
print peer.general_bytes
|
||||||
|
|
||||||
|
if peer:
|
||||||
|
print "Found tag"
|
||||||
|
return peer
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clf = nfc.ContactlessFrontend()
|
clf = nfc.ContactlessFrontend()
|
||||||
|
|
||||||
@ -134,25 +162,18 @@ def main():
|
|||||||
while True:
|
while True:
|
||||||
print "Waiting for a tag or peer to be touched"
|
print "Waiting for a tag or peer to be touched"
|
||||||
|
|
||||||
while True:
|
tag = find_peer(clf)
|
||||||
general_bytes = nfc.llcp.startup({})
|
if isinstance(tag, nfc.DEP):
|
||||||
tag = clf.poll(general_bytes)
|
wps_handover_init(tag)
|
||||||
if tag == None:
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
if isinstance(tag, nfc.DEP):
|
if tag.ndef:
|
||||||
wps_handover_init(tag)
|
wps_tag_read(tag)
|
||||||
break
|
continue
|
||||||
|
|
||||||
if tag.ndef:
|
print "Not an NDEF tag - remove tag"
|
||||||
wps_tag_read(tag)
|
while tag.is_present:
|
||||||
break
|
time.sleep(0.1)
|
||||||
|
|
||||||
if tag:
|
|
||||||
print "Not an NDEF tag - remove tag"
|
|
||||||
while tag.is_present:
|
|
||||||
time.sleep(0.1)
|
|
||||||
break
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
Loading…
Reference in New Issue
Block a user