Implement kCTF strategy
This implementation is pretty scuffed, but its more exploratory than anything else.
This commit is contained in:
@@ -4,12 +4,13 @@ import * as z from 'zod';
|
||||
import { outstandingChallenges } from '~~/server/utils/pow';
|
||||
|
||||
const challengeSchema = z.object({
|
||||
challenge: z.string(),
|
||||
nonce: z.string()
|
||||
challenge: z.string().startsWith("s."),
|
||||
solution: z.string().startsWith("s.")
|
||||
})
|
||||
|
||||
// post handler that takes in the challenge, and the nonce
|
||||
export default defineEventHandler(async (event) => {
|
||||
console.log(await readBody(event));
|
||||
const body = await readValidatedBody(event, challengeSchema.safeParse);
|
||||
|
||||
if (!body.success) {
|
||||
@@ -19,19 +20,25 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
}
|
||||
|
||||
let target = body.data.challenge;
|
||||
let nonce = body.data.nonce;
|
||||
let { challenge, solution } = body.data;
|
||||
|
||||
const outstanding_challenge = outstandingChallenges.get(challenge);
|
||||
if (outstanding_challenge === undefined) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Challenge not found'
|
||||
})
|
||||
}
|
||||
|
||||
// check if the challenge is valid
|
||||
let challenge_valid = await validate_challenge(outstandingChallenges.get(target)!.challenge, {
|
||||
challenge: target,
|
||||
nonce: nonce
|
||||
});
|
||||
const challenge_valid = await validate_challenge(outstanding_challenge.challenge, solution);
|
||||
|
||||
console.log("CHALLENGE VALID", challenge_valid);
|
||||
|
||||
if (challenge_valid) {
|
||||
// clear the challenge
|
||||
clearTimeout(outstandingChallenges.get(target)!.timeout);
|
||||
outstandingChallenges.delete(target);
|
||||
clearTimeout(outstandingChallenges.get(challenge)!.timeout);
|
||||
outstandingChallenges.delete(challenge);
|
||||
|
||||
return {
|
||||
message: 'Challenge solved'
|
||||
|
||||
Reference in New Issue
Block a user