Kabinet's GitBook
  • 🚩Kabinet CTF's Writeups
  • Page
  • 2025
    • Thuderdome
      • Emerge through the breach
      • Pulled from the sky
      • An absent defense
      • A new wave (web of deceit)
      • Crossing the great divide
      • Joining forces as one
      • Infiltrate (open the gate)
      • Jaeger
      • Victory
  • 2024
    • GreyCTF 2024
      • Markdown Parser
      • Fearless Concurrency
      • GreyCTF Survey
      • Baby Web
      • Beautiful Styles
      • All About Timing
      • Poly Playground
    • TetCTF 2024
      • Hello from API GW
      • Microservices
  • 2023
    • BSidesSF Cloud Village CTF
      • Tony Tony Tony
      • Plain Sight
      • A Suit of Armor Around The World
      • Sharing is Caring + Sequel
      • Photo Drive
    • DART CTF
      • Flag 1
      • Flag 2
      • Flag 3
      • Flag 4
      • Flag 5
      • Flag 6
      • Flag 7
      • Flag 8
      • Flag 9
      • Flag 10
    • EKS Cluster Games
    • Big IAM Challenge
  • 2022
    • Stack The Flag
      • Secret of Meow Olympurr
  • Authored
    • Cyber League 2025 Major 1
      • Perfect Storage
      • catalog commits
      • pawtainer hub
    • Lag and Crash 2023
      • Managed Secrets
      • Pickle Rick
      • Cloudy with a chance of meatball
    • NYP InfoSec December CTF 2022
      • Super Secure Technology Infrastructure
      • Self Introduction
      • Aww Cuter Cat
      • Obligatory Calc
      • BreadSecurity
  • NYP InfoSec Introduction to Pentesting Workshop
Powered by GitBook
On this page
  • Description
  • Solve

Was this helpful?

  1. 2024
  2. GreyCTF 2024

Poly Playground

PreviousAll About TimingNextTetCTF 2024

Last updated 1 year ago

Was this helpful?

Description

Magicians love to create things out of thin air. This time our secret wizards have created a playground. Test out your wizardry here! Comment Suggest edit

Author: jloh02

nc challs.nusgreyhats.org 31113


Solve

Basicailly its a math question, finding cofficients of quadratic, cubic and quintic equation. I used chatgpt to write the script ot calculate the cofficient.

Note, I dont fully understand the math behind this, was just solving cause my team were busy with other challenges.

Script

from pwn import *

host, port = "challs.nusgreyhats.org", 31113

conn = remote(host,port)
conn.recvuntil(b"Here's your first problem...\n")


def level1(root1, root2):
    sum_of_roots = root1 + root2
    product_of_roots = root1 * root2

    b_over_a = -sum_of_roots
    c_over_a = product_of_roots

    b = b_over_a
    c = c_over_a

    a = 1

    return a, b, c

def level2(roots):
    sum_of_roots = sum(roots)
    product_of_pairs = roots[0] * roots[1] + roots[0] * roots[2] + roots[1] * roots[2]
    product_of_all = roots[0] * roots[1] * roots[2]

    b_over_a = -sum_of_roots
    c_over_a = product_of_pairs
    d_over_a = -product_of_all

    b = b_over_a
    c = c_over_a
    d = d_over_a

    a = 1

    return a, b, c, d

def level3(roots):
    sum_of_roots = sum(roots)
    product_of_pairs = sum(roots[i] * roots[j] for i in range(len(roots)) for j in range(i + 1, len(roots)))
    product_of_triples = sum(roots[i] * roots[j] * roots[k] for i in range(len(roots)) for j in range(i + 1, len(roots)) for k in range(j + 1, len(roots)))
    product_of_all = roots[0] * roots[1] * roots[2] * roots[3]

    b_over_a = -sum_of_roots
    c_over_a = product_of_pairs
    d_over_a = -product_of_triples
    e_over_a = product_of_all

    b = b_over_a
    c = c_over_a
    d = d_over_a
    e = e_over_a

    a = 1

    return a, b, c, d, e

def level4(roots):
    sum_of_roots = sum(roots)
    product_of_pairs = sum(roots[i] * roots[j] for i in range(len(roots)) for j in range(i + 1, len(roots)))
    product_of_triples = sum(roots[i] * roots[j] * roots[k] for i in range(len(roots)) for j in range(i + 1, len(roots)) for k in range(j + 1, len(roots)))
    product_of_quadruples = sum(roots[i] * roots[j] * roots[k] * roots[l] for i in range(len(roots)) for j in range(i + 1, len(roots)) for k in range(j + 1, len(roots)) for l in range(k + 1, len(roots)))
    product_of_all = roots[0] * roots[1] * roots[2] * roots[3] * roots[4]

    b_over_a = -sum_of_roots
    c_over_a = product_of_pairs
    d_over_a = -product_of_triples
    e_over_a = product_of_quadruples
    f_over_a = -product_of_all

    b = b_over_a
    c = c_over_a
    d = d_over_a
    e = e_over_a
    f = f_over_a

    a = 1

    return a, b, c, d, e, f


while True:
    p = ''
    p = conn.recvuntil(b'Present the coefficients of your amazing equation: ')
    p = p.split(b'\n')
    roots = p[2]
    levels = int(p[1].strip(b':').split(b' ')[1])
    numbers = roots.split(b' ')[1].split(b',')

    if levels < 21 :
        conn.sendline(f'1,{int(numbers[0]) * -1}')

    elif 20 < levels < 41:
        a,b,c = level1(int(numbers[0]),int(numbers[1]))
        conn.sendline(f'{a},{b},{c}')

    elif 40 < levels < 61:
        a,b,c,d = level2([int(numbers[0]),int(numbers[1]),int(numbers[2])])
        conn.sendline(f'{a},{b},{c},{d}')
    elif 60 < levels < 81:
        a,b,c,d,e = level3([int(numbers[0]),int(numbers[1]),int(numbers[2]),int(numbers[3])])
        conn.sendline(f'{a},{b},{c},{d},{e}')
    elif 80 < levels < 100:
        test = [int(numbers[0]),int(numbers[1]),int(numbers[2]),int(numbers[3]),int(numbers[4])]
        a,b,c,d,e,f = level4(test)
        conn.sendline(f'{a},{b},{c},{d},{e},{f}')
    
    if levels == 100:
        test = [int(numbers[0]),int(numbers[1]),int(numbers[2]),int(numbers[3]),int(numbers[4])]
        a,b,c,d,e,f = level4(test)
        conn.sendline(f'{a},{b},{c},{d},{e},{f}')
        conn.recvuntil(b"Here's your flag!\n")
        print(conn.recvline())
        quit()

Flag: grey{l0oks_lik3_sOm3one_c4n_b3_a_po1ynomia1_w1z4rd}