Sub topic 1
How exchange accounts get taken over
This chapter explains how attackers gain control of crypto exchange accounts and which login protections stop them. It covers passwords, SMS codes and authenticator apps.
Prerequisites
You should have an account on a centralized crypto exchange, know what a password is, and have seen a two-factor authentication (2FA) prompt at login. The code example needs Python 3.
How exchange accounts get taken over
Attackers rarely break the exchange's servers. They usually get in through the user. Common routes include:
- Phishing: a fake login page collects your password and one-time code, then uses them within seconds.
- Credential stuffing: attackers try email and password pairs leaked from other sites, because people reuse passwords.
- SIM swapping: an attacker convinces your phone carrier to move your number to their SIM card, then receives your SMS codes.
- Session theft: malware copies a logged-in browser session, so the attacker never needs your password.
Authentication factors: something you know, have and are
An authentication factor is a way to prove who you are. There are three kinds: something you know (a password), something you have (a phone or security key) and something you are (a fingerprint or face). Multi-factor authentication (MFA) asks for at least two kinds at once.
Why passwords alone fail
A password is weak when it is reused, short, or typed into a fake page. Once a password leaks, it works anywhere the same password is used. A password also proves only that someone typed the right text, not that the person is you.
Why SMS codes are a weak second factor
An SMS code is a one-time code sent to your phone. It is better than nothing, but a SIM swap or a phishing page can capture it. Because the attacker can relay the code in real time, the code protects you only until someone else gets it.
Authenticator apps and time-based codes
An authenticator app stores a secret key and produces a six-digit code that changes every 30 seconds. This is called a time-based one-time password (TOTP). The code comes from the shared secret and the current time, so no message is sent over the phone network.
import base64
import hashlib
import hmac
import struct
import time
def totp(secret_b32, step=30, digits=6, at=None):
key = base64.b32decode(secret_b32.upper() + "=" * (-len(secret_b32) % 8))
now = time.time() if at is None else at
counter = int(now // step)
mac = hmac.new(key, struct.pack(">Q", counter), hashlib.sha1).digest()
offset = mac[-1] & 0x0F
value = struct.unpack(">I", mac[offset:offset + 4])[0] & 0x7FFFFFFF
return str(value % 10 ** digits).zfill(digits)
if __name__ == "__main__":
print(totp("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", at=59))Running this prints 287082, the RFC 6238 test value for that secret at time 59.
> Note: an authenticator code is only safe while the secret stays on your device. Anyone who sees the secret can produce valid codes.
Replace the > in the note above is not needed; the callout below is the correct form.
Exercise
Why does a SIM swap defeat SMS codes but not a TOTP code stored in an authenticator app?
Show answer
An SMS code is delivered over the phone network, so whoever controls the number receives it. A TOTP code is computed on your device from a secret that never travels over the network, so moving your phone number gives the attacker nothing.