Avatar
Part time CTF Player learn every day!!
🌠 I Love Hoshimachi Suisei!! 🌠
🌠 I Love Hoshimachi Suisei!! 🌠

OverTheWire Krypton Level 6 → 7 tutorial!!

Login

ssh krypton6@krypton.labs.overthewire.org -p 2231
# password: RANDOM

Why? Each level uses a different UNIX account. The password is passed forward from Level 5 → 6.

Task

Task placeholder

This level introduces a stream cipher. You are given an encrypt6 binary that uses a hidden keyfile.dat plus a weak “random” generator. Your target is /krypton/krypton6/krypton7, which is encrypted with the same mechanism.

Hints in the level suggest:

  • The random generator is periodic (8‑bit LFSR).
  • You can run chosen‑plaintext attacks (encrypt6 lets you encrypt any file).
  • With the pattern, you can replicate the keystream and decrypt the password.

Solution

1. Setup workspace

cd /tmp
mkdir -p kr6 && cd kr6
ln -s /krypton/krypton6/keyfile.dat .

Why? Working in /tmp is clean and safe; the symlink lets encrypt6 read the original keyfile.

setup placeholder


2. Create a file of 'A's and encrypt (to leak the keystream)

python3 - <<'PY'
open('a.txt','w').write('A'*50)
PY

/krypton/krypton6/encrypt6 a.txt outA.txt
cat outA.txt

You should see a repeating keystream block (~30 chars):

EICTDGYIYZKTHNSIRFXYCPFUEOCKRNEICTDGYIYZKTHNSIRFXY...

Why? With plaintext all 'A', ciphertext directly equals the keystream for each position.

A-experiment


3. (Optional) Confirm with 'B's

python3 - <<'PY'
open('b.txt','w').write('B'*50)
PY

/krypton/krypton6/encrypt6 b.txt outB.txt
cat outB.txt

The pattern is identical but shifted by +1 (classic Caesar-on-top behavior).

B-experiment


4. Decrypt the target file

Extract the keystream period and apply it to krypton7.

python3 - <<'PY'
import string

# 1) load keystream from 50 'A's
A = open('outA.txt').read().strip()

def find_period(s, lo=2, hi=60):
    for p in range(lo, min(hi, len(s)//2)+1):
        if s[:p] == s[p:2*p]:
            return p
    return None

period = find_period(A) or 30
keystream = A[:period]

# 2) decrypt krypton7
C = open('/krypton/krypton6/krypton7').read().strip()
plain = []
j = 0
for ch in C:
    if ch not in string.ascii_uppercase:
        plain.append(ch); continue
    shift = ord(keystream[j % period]) - ord('A')
    p = (ord(ch) - ord('A') - shift) % 26
    plain.append(chr(p + ord('A')))
    j += 1

print("PLAINTEXT:", ''.join(plain))
PY

Result:

PLAINTEXT: LFSRISNOTRANDOM

decrypt placeholder


Password

LFSRISNOTRANDOM

Troubleshooting

  • “Command ‘import’ not found” → You pasted Python into bash. Run it via a here‑doc: python3 - <<'PY' ... PY.
  • No repeating pattern in outA.txt → Ensure you encrypted 50× ‘A’ from the same directory that has the keyfile.dat symlink.
  • Mixed case / spaces → The mapping assumes uppercase A–Z only. Strip spaces/newlines when comparing.
  • Wrong plaintext → Recreate outA.txt and rerun the decrypt step; verify period is around 30.
  • “File exists” when linking → Harmless. The symlink is already there; proceed.
  • Ciphertext longer than your keystream → The keystream repeats; the code already indexes with modulo period.

Congrats 🎉 You just broke the weak stream cipher using chosen‑plaintext analysis and keystream repetition. Krypton solved up to Level 7 (final)!


Cinema

all tags

GOT-overwrite aboutme aead ai alphanumeric-shellcode apt argc0 argon2 aslr assembly asymmetric atoi automation backbox bandit base64 bash beginner behemoth binary binary-exploitation binary-to-ascii blackarch blind blind-sqli blogging blue-team bruteforce buffer-overflow buffer-overwrite c caesar canary capabilities checksec command-injection commonmark cookie cron crypto cryptography ctf cutter cyberchef cybersecurity defenders detection dev directory-traversal dnf docs drifter ecc education elf env envp exploitation finale forensics format-string formulaone frequency frequency-analysis gcc gdb getchar gfm ghidra github-pages governance gpg guide hashing hkdf http jekyll jmpbuf kali kasiski kdf kernel keylength kramdown krypton lab ld_preload leviathan lfi lfsr linux linux-syscall llmops log-poisoning ltrace manpage markdown maze memcpy mitigations mitmproxy mlops narnia natas networking newline-injection nonce nop-sled nx object-injection obsidian openssl osint overflow overthewire package-manager pacman parrot path path-hijacking pathname php pie pkc pki pointer-trick pqc priv-esc privilege-escalation provable-security pwn pwntools pyshark python race-condition radare2 rag randomness recon red-team redirect relro requests ret2env ret2libc reverse-engineering reversing ricing roadmap rop rot13 rsa scapy security seed seo serialization session setjmp-longjmp setuid shell shellcode smoke soc sockets sprintf sql-injection srop stack-canary stack-overflow strace strcmp strcpy streamcipher strings strncpy strtoul substitution suid suisei symlink symmetric terminal test threat-intel time-based tls troubleshooting tshark type-juggling ubuntu udp utumno vigenere virtualbox virtualization vmware vortex walkthrough web windows wireshark writing wsl x86
dash theme for Jekyll by bitbrain made with