$ cat writeup.md…
$ cat writeup.md…
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.
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
The file distance_matrix.npy contains a 1808×1808 (float64) matrix — a symmetric pairwise distance matrix between 1808 points:
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.
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
Classical MDS reconstructs point coordinates from a distance matrix via eigendecomposition:
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) # Sort by descending eigenvalue idx = np.argsort(eigenvalues)[::-1] eigenvalues = eigenvalues[idx] eigenvectors = eigenvectors[:, idx] # Check eigenvalues — only 2 significant ones print(f"Top 5 eigenvalues: {eigenvalues[:5]}") # ~[8225, 41, ~0, ~0, ~0] — confirms 2D data # Reconstruct 2D coordinates coords_2d = eigenvectors[:, :2] * np.sqrt(np.abs(eigenvalues[:2])) # Plot plt.figure(figsize=(20, 5)) plt.scatter(coords_2d[:, 0], coords_2d[:, 1], s=1, c='black') plt.axis('equal') plt.title('Reconstructed 2D coordinates') plt.savefig('flag.png', dpi=200, bbox_inches='tight') plt.show()
The 1808 points on the 2D plane form the text: HTB{d1st4nt_spac3}
The flag is a leet-speak version of "distant space", matching the space hacker theme of the challenge.
Multidimensional Scaling (MDS) is a dimensionality reduction method that reconstructs point coordinates from a pairwise distance matrix.
Classical MDS algorithm:
Why this works: Matrix B is the Gram matrix (inner products) of the centered points. Eigendecomposition of the Gram matrix yields the point coordinates in space.
Determining dimensionality: The number of significant (non-zero) eigenvalues equals the dimensionality of the original space. In this challenge, only 2 are significant → the data is 2D.
Use this technique when:
.npy file with a square symmetric matrix$ cat /etc/motd
Liked this one?
Pro unlocks every writeup, every flag, and API access. $9/mo.
$ cat pricing.md$ grep --similar