Writeups OverTheWireNatasWeb ExploitationXORCookie Manipulation

Natas 11 Writeup - OverTheWire

Writeup for Natas level 11 from OverTheWire: XOR cookie known-plaintext attack.

Contents

Wargame: Natas

Level: 11

Category: Web Exploitation

Description

The page stores preferences in a cookie named data. The value is XOR-encrypted with a secret key then base64-encoded. The goal is to forge a cookie that sets showpassword to yes.

Overview

Background: Known-Plaintext XOR Attack

Solution

Step 2: Recover the XOR Key

import base64, json

default = json.dumps({"showpassword": "no", "bgcolor": "#ffffff"}, separators=(',', ':'))
ciphertext = base64.b64decode("MGw7JCQ5OC04PT8jOSpqdmkgJ25gbCorKCEkIzlscm5oKC4qLSgubjY=")

key_stream = "".join(chr(ord(p) ^ c) for p, c in zip(default, ciphertext))
# key_stream repeats "qw8J"
key = "qw8J"
target = json.dumps({"showpassword": "yes", "bgcolor": "#ffffff"}, separators=(',', ':'))
cipher = bytes(ord(c) ^ ord(key[i % len(key)]) for i, c in enumerate(target))
forged = base64.b64encode(cipher).decode()

Password

YWqo0pjpcXzSIl5NMAVxg12QxeC1w9QG

← Back to Blog