SYNOPSIS int getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count); int getdents64(unsigned int fd, struct linux_dirent64 *dirp, unsigned int count);
Note: There are no glibc wrappers for these system calls; see NOTES.
#!/usr/bin/env python3 from Crypto.Util.number import * from tqdm import tqdm
classSolver: def__init__(self, x, n): self.x = x self.n = n self.pq = [(0, 0)]
defadd(self, b, p, q): if p * q <= n and (p | (b - 1)) * (q | (b - 1)) >= n: self.pq.append((p, q))
defsolve(self): for shift in tqdm(range(4095, -1, -1)): b = 1 << shift pq, self.pq = self.pq, [] for p, q in pq: if self.x & b: self.add(b, p | b, q) self.add(b, p, q | b) else: self.add(b, p, q) self.add(b, p | b, q | b) return self.pq[0]
exec(open('flag.enc').read().lower()) solver = Solver(x, n) p, q = solver.solve() r = (p - 1) * (q - 1) d = inverse(e, r) m = pow(c, d, n) print(long_to_bytes(m))
Kernel challs are always a bit painful. No internet access, no SSH, no file copying. You’re stuck with copy pasting base64’d (sometimes static) ELFs. But what if there was another solution? We’ve created a lightweight, simple binary format for your pwning pleasure. It’s time to prove your skills. nc p4fmt.zajebistyc.tf 30002
nokaslr 關掉 kernel 的位址隨機化,方便我們除錯 -gdb 開一個 gdb server 讓我們可以連上去除錯
如何跳出 qemu-system
Ctrl-A X
gdb
1 2 3 4 5 6 7 8
(gdb) target remote :7777 (gdb) set auto-load safe-path . (gdb) file ./linux-5.0.9/vmlinux (gdb) apropos lx # 顯示包含 lx 的指令 ( 從 vmlinux-gdb.py 載入的輔助函式 ) lx-cmdline -- Report the Linux Commandline used in the current kernel lx-cpus -- List CPU status arrays lx-dmesg -- Print Linux kernel log buffer ...
structQ { int l, r, b, i; booloperator < (const Q &q) { return b == q.b ? (r < q.r) : b < q.b; } } q[MAXM];
1 2 3 4 5 6 7 8 9 10 11
int block = ceil(sqrt(MAXN));
for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; q[i].l = l; q[i].r = r; q[i].b = q[i].l / block; q[i].i = i; }
sort(q, q + m);
1 2 3 4 5 6 7
for (int i = 0, L = 0, R = -1; i < m; i++) { while (R < q[i].r) add(a[++R]); while (q[i].l < L) add(a[--L]); while (q[i].r < R) sub(a[R--]); while (L < q[i].l) sub(a[L++]); ans[q[i].i] = cur; }