mlfreeeasy

AI SPACE

hackthebox

Task: Given a symmetric pairwise distance matrix (1808×1808) in a .npy file. Solution: Applied Classical MDS (Multidimensional Scaling) with eigendecomposition to reconstruct 2D coordinates from the distance matrix; plotting the points revealed the flag text.

$ ls tags/ techniques/
classical_mdseigendecompositioncoordinate_reconstruction

$ cat /etc/rate-limit

Rate limit reached (20 reads/hour per IP). Showing preview only — full content returns at the next hour roll-over.

AI SPACE — HackTheBox

Description

You are assigned the important mission of locating and identifying the infamous space hacker. Your investigation begins by analyzing the data patterns and breach points identified in the latest cyber-attacks. Use the provided coordinates of the last known signal origins to narrow down his potential hideouts. Utilize advanced tracking algorithms to follow the digital footprint left by the hacker.

Files: challenge.zip (password: hackthebox) → distance_matrix.npy

Analysis

The file distance_matrix.npy contains a 1808×1808 (float64) matrix — a symmetric pairwise distance matrix between 1808 points:

  • Zeros on the diagonal
  • No negative values
  • Values range from 0 to ~7.2
  • This is a valid distance matrix

Key observation: Given a distance matrix, we can reconstruct the original point coordinates using Multidimensional Scaling (MDS). If the points were in 2D, eigendecomposition of matrix B will yield only 2 significant eigenvalues.

Solution

Step 1: Loading and analyzing the matrix

import numpy as np dm = np.load('distance_matrix.npy') print(f"Shape: {dm.shape}") # (1808, 1808) print(f"Symmetric: {np.allclose(dm, dm.T)}") # True print(f"Min: {dm.min()}, Max: {dm.max()}") # 0.0, ~7.2

Step 2: Classical MDS — coordinate reconstruction

Classical MDS reconstructs point coordinates from a distance matrix via eigendecomposition:

  1. Squared distances: D² = dm²
  2. Centering: B = -0.5 * H * D² * H, where H = I - (1/n) * 11ᵀ (centering matrix)
  3. Eigendecomposition: B = VΛVᵀ
  4. Coordinates: X = V[:, :k] * √Λ[:k] (take the k largest eigenvalues)
import numpy as np import matplotlib.pyplot as plt dm = np.load('distance_matrix.npy') n = dm.shape[0] # Centering matrix H = np.eye(n) - np.ones((n, n)) / n # Double centering B = -0.5 * H @ (dm ** 2) @ H # Eigendecomposition eigenvalues, eigenvectors = np.linalg.eigh(B) ...

$ grep --similar

Similar writeups