atx0mg's Fortress.

K3RN3LCTF 2021

Word count: 363Reading time: 2 min
2021/11/15

Kiddie Pool

Vieta's Poly


Read More →

Python Code:

  • You have to solve 100 math problems to get the flag
    • There are three types of math problems
      1. sum of the roots
      2. sum of the reciprocals of the roots
      3. sum of the squares of the roots
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        31
        32
        33
        34
        35
        36
        37
        38
        39
        40
        41
        42
        43
        44
        from pwn import *
        import re
        import sympy
        import numpy as np
        port = 2236
        # context.log_level = 'debug' #will print all input and output for debugging purposes
        conn = remote("ctf.k3rn3l4rmy.com",port) #enter the address and the port here as strings. For example nc 0.0.0.0 5000 turns into remote('0.0.0.0', 5000)
        def get_input(): #function to get one line from the netcat
        input = conn.recvline().strip().decode()
        return input
        def parse(my_poly):
        '''
        TODO: Parse polynomial
        For example, parse("x^3 + 2x^2 - x + 1") should return [1,2,-1,1]
        '''
        # my_poly = "2*x**2+7*x-3"
        my_poly = my_poly.replace("^", "**").replace(my_poly[0], "*x").replace("*x", my_poly[0], 1)
        x = sympy.Symbol('x')
        my_poly = sympy.polys.polytools.poly_from_expr(my_poly)[0]
        coeffs = my_poly.coeffs()
        return coeffs
        for _ in range(4): get_input() #ignore challenge flavortext
        for i in range(100):
        type = get_input()
        coeffs = parse(get_input())
        print(coeffs)

        ans = 0
        if 'sum of the roots' in type:
        #TODO: Find answer
        print("sum of the roots")
        ans = -1*coeffs[1]
        elif 'sum of the reciprocals of the roots' in type:
        #TODO: Find answer
        print("sum of the reciprocals of the roots")
        ans = -1*coeffs[-2]//coeffs[-1]
        elif 'sum of the squares of the roots' in type:
        #TODO: Find answer
        print("sum of the squares of the roots")
        ans = coeffs[1]**2-2*coeffs[2]
        print(ans)
        conn.sendline(str(ans)) #send answer to server
        get_input()
        conn.interactive() #should print flag if you got everything right

Result: Got flag

Formula that can make the math easier to solve

  1. sum of the roots
  2. sum of the reciprocals of the roots
  3. sum of the squares of the roots

Resources

sum of the root
sum of the squares of roots of a polynomial

Author:atx0mg

Link:https://jeff14994.github.io/2021/11/15/K3RN3LCTF-2021/

Publish date:November 15th 2021, 9:54:02 pm

Update date:April 22nd 2022, 5:18:14 am

License:This article is licensed under CC BY-NC 4.0

CATALOG
  1. 1. Kiddie Pool
    1. 1.1. Vieta's Poly
      1. 1.1.1. Python Code:
      2. 1.1.2. Result: Got flag
      3. 1.1.3. Formula that can make the math easier to solve
    2. 1.2. Resources