┌───────────────────────┐
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
└───────────────────────┘
CVE-2017-9048: libxml2
~ CuB3y0nd
# CVE-2017-9048

## Description

CVE: https://www.cve.org/CVERecord?id=CVE-2017-9048

# Compile

## Download

```shellsession
git clone https://github.com/GNOME/libxml2.git && cd libxml2
git checkout v2.9.4
```

## Build

 `valid.c`  `xmlSnprintfElementContent` 
西 fuzzing 

```shellsession
./autogen.sh
AFL_USE_ASAN=1 
CC=afl-clang-lto 
CXX=afl-clang-lto++ 
./configure 
  --prefix="$(realpath ../libxml2-fuzz-asan)" 
  --disable-shared 
  --without-debug 
  --without-ftp 
  --without-http 
  --without-legacy 
  --without-python
make clean && 
AFL_USE_ASAN=1 make -j`nproc` && 
AFL_USE_ASAN=1 make install
```

……
 `invalid token at start of a preprocessor expressio
n` `.in`  `@@`  `@WITH_PUS
H @`

使 `grug-far.nvim` `@([^@s]+)s+@` `@$1@` 


……线
 fuzz 
使 `ASAN_OPTIONS=help=1 ../libxml2-fuzz-asan/bin/xml
lint``nm ../libxml2-fuzz-asan/bin/xmllint | rg -i asan`

 ASAN  2x - 10x  ASAN 线
线

 [Notes for using ASAN with afl-fuzz](https://aflplus.plus/docs/no
tes_for_asan/) 



```shellsession
CC=afl-clang-lto 
CXX=afl-clang-lto++ 
./configure 
  --prefix="$(realpath ../libxml2-fuzz-lite)" 
  --disable-shared 
  --without-debug 
  --without-ftp 
  --without-http 
  --without-legacy 
  --without-python
make clean && 
make -j`nproc` && 
make install
```

# Samples

 xml tag,  fuzzer 
AFL++ 
 corpus, libxml2  test  `<!DOCTYPE
 a []>`  `<a b="c">d</a>`

# Fuzzing

`xmllint` 便
线 fuzz 便

```bash
#!/bin/bash

MASTER_BIN="../libxml2-fuzz-asan/bin/xmllint"
SLAVE_BIN="../libxml2-fuzz-lite/bin/xmllint"
INPUT_CORPUS="corpus"
OUTPUT_DIR="outs"
SHM_BASE="/dev/shm/fuzz"

# Arguments for the Master instance
MASTER_ARGS="--debug --valid"

# Argument pool for Slave instances
SLAVE_ARGS_POOL=(
  "--memory --oldxml10"
  "--postvalid"
)

# --- Dictionary Support ---
DICT_PATH="./dict/xml.dict"
DICT_OPT=""
if [ -d "$DICT_PATH" ] || [ -f "$DICT_PATH" ]; then
  DICT_OPT="-x $DICT_PATH"
fi

# --- Environment Check ---
if [ ! -f "$MASTER_BIN" ] || [ ! -f "$SLAVE_BIN" ]; then
  echo "[-] Error: Fuzzing binaries not found. Check your paths."
  exit 1
fi

TOTAL_THREADS=${1:-4}
if [ "$TOTAL_THREADS" -lt 1 ]; then
  echo "Usage: $0 [total_threads]"
  exit 1
fi

# --- Resume Logic ---
if [ -d "$OUTPUT_DIR/master" ]; then
  echo "[*] Existing output detected. Resuming fuzzing session..."
  INPUT_OPT="-i -"
else
  echo "[*] First run. Using input corpus: $INPUT_CORPUS"
  mkdir -p "$OUTPUT_DIR"
  INPUT_OPT="-i $INPUT_CORPUS"
fi

mkdir -p "$SHM_BASE"

# --- Launch Master (ASAN) ---
echo "[+] Launching Master (ASAN) | Args: $MASTER_ARGS @@"
mkdir -p "$SHM_BASE/master"
AFL_TMPDIR="$SHM_BASE/master" 
  afl-fuzz $INPUT_OPT 
  -o "$OUTPUT_DIR" 
  -m none 
  $DICT_OPT 
  -M master 
  -- "$MASTER_BIN" $MASTER_ARGS @@ >"$OUTPUT_DIR/master.log" 2>&1 &

# Brief sleep to let Master initialize
sleep 2

# --- Launch Slaves (Non-ASAN) ---
NUM_VARIANTS=${#SLAVE_ARGS_POOL[@]}

for i in $(seq 1 $((TOTAL_THREADS - 1))); do
  SLAVE_NAME="slave_$i"
  ARG_INDEX=$(((i - 1) % NUM_VARIANTS))
  CURRENT_ARGS=${SLAVE_ARGS_POOL[$ARG_INDEX]}

  echo "[+] Launching $SLAVE_NAME | Args: $CURRENT_ARGS @@"
  mkdir -p "$SHM_BASE/$SLAVE_NAME"

  AFL_TMPDIR="$SHM_BASE/$SLAVE_NAME" 
    afl-fuzz $INPUT_OPT 
    -o "$OUTPUT_DIR" 
    -m none 
    $DICT_OPT 
    -S "$SLAVE_NAME" 
    -- "$SLAVE_BIN" $CURRENT_ARGS @@ >/dev/null 2>&1 &
done

echo "------------------------------------------------------"
echo "[!] Successfully started $TOTAL_THREADS instances with @@ input mode."
echo "[!] Check status: afl-whatsup $OUTPUT_DIR"
echo "[!] Stop all:     pkill afl-fuzz"
echo "------------------------------------------------------"
```

线 fuzz,  chall  crashes
 

~ crashes ~
 ASAN  _uwu_