Update public source
This commit is contained in:
+260
-72
@@ -1603,6 +1603,169 @@ def _session_id_by_hash(
|
|||||||
|
|
||||||
return row["id"]
|
return row["id"]
|
||||||
|
|
||||||
|
def _map_existing_handshake_ids(
|
||||||
|
conn,
|
||||||
|
session_id,
|
||||||
|
session_handshakes,
|
||||||
|
):
|
||||||
|
rows = conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
handshakes.id,
|
||||||
|
access_points.bssid,
|
||||||
|
handshakes.type,
|
||||||
|
handshakes.hash22000,
|
||||||
|
handshakes.message_pair,
|
||||||
|
handshakes.captured_at,
|
||||||
|
handshakes.latitude,
|
||||||
|
handshakes.longitude,
|
||||||
|
handshakes.speed
|
||||||
|
FROM handshakes
|
||||||
|
JOIN access_points
|
||||||
|
ON access_points.id =
|
||||||
|
handshakes.access_point_id
|
||||||
|
WHERE handshakes.session_id=?
|
||||||
|
ORDER BY handshakes.id
|
||||||
|
""",
|
||||||
|
(session_id,),
|
||||||
|
).fetchall()
|
||||||
|
|
||||||
|
if len(rows) != len(session_handshakes):
|
||||||
|
raise WifitripError(
|
||||||
|
"Existing session handshake count does not "
|
||||||
|
"match the .wifitrip package."
|
||||||
|
)
|
||||||
|
|
||||||
|
handshake_ids = {}
|
||||||
|
|
||||||
|
fields = (
|
||||||
|
"bssid",
|
||||||
|
"type",
|
||||||
|
"hash22000",
|
||||||
|
"message_pair",
|
||||||
|
"captured_at",
|
||||||
|
"latitude",
|
||||||
|
"longitude",
|
||||||
|
"speed",
|
||||||
|
)
|
||||||
|
|
||||||
|
for row, handshake in zip(
|
||||||
|
rows,
|
||||||
|
session_handshakes,
|
||||||
|
):
|
||||||
|
if any(
|
||||||
|
row[field] != handshake[field]
|
||||||
|
for field in fields
|
||||||
|
):
|
||||||
|
raise WifitripError(
|
||||||
|
"Existing session handshake mapping "
|
||||||
|
"does not match the .wifitrip package."
|
||||||
|
)
|
||||||
|
|
||||||
|
handshake_ids[
|
||||||
|
handshake["handshake_key"]
|
||||||
|
] = row["id"]
|
||||||
|
|
||||||
|
return handshake_ids
|
||||||
|
|
||||||
|
|
||||||
|
def _import_session_credentials(
|
||||||
|
conn,
|
||||||
|
session_credentials,
|
||||||
|
ap_ids,
|
||||||
|
handshake_ids,
|
||||||
|
):
|
||||||
|
for credential in session_credentials:
|
||||||
|
access_point_id = ap_ids[
|
||||||
|
credential["bssid"]
|
||||||
|
]
|
||||||
|
|
||||||
|
handshake_id = None
|
||||||
|
|
||||||
|
if credential["handshake_key"] is not None:
|
||||||
|
handshake_id = handshake_ids[
|
||||||
|
credential["handshake_key"]
|
||||||
|
]
|
||||||
|
|
||||||
|
existing_verified = conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT COALESCE(MAX(verified), 0)
|
||||||
|
FROM credentials
|
||||||
|
WHERE access_point_id=?
|
||||||
|
AND password=?
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
access_point_id,
|
||||||
|
credential["password"],
|
||||||
|
),
|
||||||
|
).fetchone()[0]
|
||||||
|
|
||||||
|
effective_verified = int(
|
||||||
|
bool(existing_verified)
|
||||||
|
or bool(credential["verified"])
|
||||||
|
)
|
||||||
|
|
||||||
|
existing_credential = conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT id
|
||||||
|
FROM credentials
|
||||||
|
WHERE access_point_id=?
|
||||||
|
AND handshake_id IS ?
|
||||||
|
AND password=?
|
||||||
|
LIMIT 1
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
access_point_id,
|
||||||
|
handshake_id,
|
||||||
|
credential["password"],
|
||||||
|
),
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
if existing_credential is None:
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO credentials (
|
||||||
|
access_point_id,
|
||||||
|
handshake_id,
|
||||||
|
password,
|
||||||
|
source,
|
||||||
|
created_at,
|
||||||
|
verified
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
access_point_id,
|
||||||
|
handshake_id,
|
||||||
|
credential["password"],
|
||||||
|
credential["source"],
|
||||||
|
credential["created_at"],
|
||||||
|
effective_verified,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
if effective_verified:
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
UPDATE credentials
|
||||||
|
SET verified=1
|
||||||
|
WHERE access_point_id=?
|
||||||
|
AND password=?
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
access_point_id,
|
||||||
|
credential["password"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
conn.execute(
|
||||||
|
"""
|
||||||
|
UPDATE access_points
|
||||||
|
SET is_cracked=1
|
||||||
|
WHERE id=?
|
||||||
|
""",
|
||||||
|
(access_point_id,),
|
||||||
|
)
|
||||||
|
|
||||||
def import_wifitrip(conn, package_path):
|
def import_wifitrip(conn, package_path):
|
||||||
started = time.monotonic()
|
started = time.monotonic()
|
||||||
@@ -1687,12 +1850,97 @@ def import_wifitrip(conn, package_path):
|
|||||||
if existing_id is not None:
|
if existing_id is not None:
|
||||||
result["duplicates"] += 1
|
result["duplicates"] += 1
|
||||||
|
|
||||||
logger.info(
|
try:
|
||||||
"Skipping duplicate .wifitrip session: "
|
conn.execute("BEGIN")
|
||||||
"hash=%s local_id=%s",
|
|
||||||
session_hash,
|
calculated_hash = _session_hash(
|
||||||
existing_id,
|
conn,
|
||||||
)
|
existing_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
if calculated_hash != session_hash:
|
||||||
|
raise WifitripError(
|
||||||
|
"Existing session hash verification failed: "
|
||||||
|
f"expected {session_hash}, "
|
||||||
|
f"calculated {calculated_hash}"
|
||||||
|
)
|
||||||
|
|
||||||
|
session_handshakes = (
|
||||||
|
handshakes_by_session.get(
|
||||||
|
session_hash,
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
session_credentials = (
|
||||||
|
credentials_by_session.get(
|
||||||
|
session_hash,
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
bssids = {
|
||||||
|
handshake["bssid"]
|
||||||
|
for handshake in session_handshakes
|
||||||
|
}
|
||||||
|
|
||||||
|
bssids.update(
|
||||||
|
credential["bssid"]
|
||||||
|
for credential in session_credentials
|
||||||
|
)
|
||||||
|
|
||||||
|
created_access_points = set()
|
||||||
|
ap_ids = {}
|
||||||
|
|
||||||
|
for bssid in sorted(bssids):
|
||||||
|
ap_ids[bssid] = (
|
||||||
|
_get_or_create_import_ap(
|
||||||
|
conn,
|
||||||
|
bssid,
|
||||||
|
created_access_points,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
handshake_ids = (
|
||||||
|
_map_existing_handshake_ids(
|
||||||
|
conn,
|
||||||
|
existing_id,
|
||||||
|
session_handshakes,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
_import_session_credentials(
|
||||||
|
conn,
|
||||||
|
session_credentials,
|
||||||
|
ap_ids,
|
||||||
|
handshake_ids,
|
||||||
|
)
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"Updated duplicate .wifitrip session "
|
||||||
|
"credentials: hash=%s local_id=%s",
|
||||||
|
session_hash,
|
||||||
|
existing_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as exc:
|
||||||
|
conn.rollback()
|
||||||
|
|
||||||
|
result["failed"] += 1
|
||||||
|
result["failed_sessions"].append(
|
||||||
|
{
|
||||||
|
"session_hash": session_hash,
|
||||||
|
"error": str(exc),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.exception(
|
||||||
|
"Failed to update duplicate .wifitrip session: "
|
||||||
|
"hash=%s",
|
||||||
|
session_hash,
|
||||||
|
)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -1955,72 +2203,12 @@ def import_wifitrip(conn, package_path):
|
|||||||
f"calculated {calculated_hash}"
|
f"calculated {calculated_hash}"
|
||||||
)
|
)
|
||||||
|
|
||||||
for credential in session_credentials:
|
_import_session_credentials(
|
||||||
access_point_id = ap_ids[
|
conn,
|
||||||
credential["bssid"]
|
session_credentials,
|
||||||
]
|
ap_ids,
|
||||||
|
handshake_ids,
|
||||||
handshake_id = None
|
)
|
||||||
|
|
||||||
if credential[
|
|
||||||
"handshake_key"
|
|
||||||
] is not None:
|
|
||||||
handshake_id = handshake_ids[
|
|
||||||
credential[
|
|
||||||
"handshake_key"
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
existing_credential = conn.execute(
|
|
||||||
"""
|
|
||||||
SELECT id
|
|
||||||
FROM credentials
|
|
||||||
WHERE access_point_id=?
|
|
||||||
AND handshake_id IS ?
|
|
||||||
AND password=?
|
|
||||||
LIMIT 1
|
|
||||||
""",
|
|
||||||
(
|
|
||||||
access_point_id,
|
|
||||||
handshake_id,
|
|
||||||
credential["password"],
|
|
||||||
),
|
|
||||||
).fetchone()
|
|
||||||
|
|
||||||
if existing_credential is not None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
conn.execute(
|
|
||||||
"""
|
|
||||||
INSERT INTO credentials (
|
|
||||||
access_point_id,
|
|
||||||
handshake_id,
|
|
||||||
password,
|
|
||||||
source,
|
|
||||||
created_at,
|
|
||||||
verified
|
|
||||||
)
|
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
|
||||||
""",
|
|
||||||
(
|
|
||||||
access_point_id,
|
|
||||||
handshake_id,
|
|
||||||
credential["password"],
|
|
||||||
credential["source"],
|
|
||||||
credential["created_at"],
|
|
||||||
credential["verified"],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
conn.execute(
|
|
||||||
"""
|
|
||||||
UPDATE access_points
|
|
||||||
SET
|
|
||||||
is_cracked=1
|
|
||||||
WHERE id=?
|
|
||||||
""",
|
|
||||||
(access_point_id,),
|
|
||||||
)
|
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user