Challenge : ASSS

Enoncé :

Welcome to the Amazing SSS! Join now to get your share of the secret. Flag is 66 bytes long.

Un service SSL écoute sur asss.atreides.b01lersc.tf:8443. À chaque connexion, il génère :

Here is a ^_^: a
Here is your share ^_^: (x, y)
  • a est un nombre premier de 64 bits

  • (x, y) est un point sur un polynôme f(x) = s + a·P(x)

  • s est le flag encodé en entier (66 octets ≃ 528 bits)

L’objectif est de récupérer s.

Solve :

solve.py :

#!/usr/bin/env python3
import socket, ssl
from sympy.ntheory.modular import crt

HOST = 'asss.atreides.b01lersc.tf'
PORT = 8443
NUM_SHARES = 9

def get_share():
    ctx = ssl.create_default_context()
    with ctx.wrap_socket(socket.socket(), server_hostname=HOST) as s:
        s.connect((HOST, PORT))
        data = b''
        while True:
            chunk = s.recv(4096)
            if not chunk:
                break
            data += chunk
    text = data.decode()
    part = text.splitlines()[1].split("share ^_^: (")[1].rstrip(")")
    x_str, y_str = part.split(", ")
    x = int(x_str)
    y = int(y_str)
    return x, y % x


def main():
    ns, rs = [], []
    for i in range(NUM_SHARES):
        print(f"[*] Récupération du partage #{i+1}")
        n, r = get_share()
        ns.append(n)
        rs.append(r)
    S, _ = crt(ns, rs)
    flag = S.to_bytes((S.bit_length() +7)//8, 'big')
    print("\n=== FLAG ===")
    print(flag.decode())

if __name__ == '__main__':
    main()
Python

4. Flag

$ chmod +x solve.py
$ ./solve.py

=== Partage #1 ===  
Here is a ^_^: 17331394011252040163  
Here is your share ^_^: (13879353900949580717, 1360979011148826339122449446945499488921276102389208091012591  
419883269902678185111324003260448002896780697966156809692964232063515241454134378331255665767947755387813961  
364953791641272211411940961930640576609641744794045479793089312197894931798650155573111125146201956898244865  
016277498706984791927440784238397948891872895750450147001810971514232220359740617850070938231288211660932326  
744829982807693700)  
  
  
=== Partage #2 ===  
Here is a ^_^: 11915893396480981657  
Here is your share ^_^: (9305384857153767619, 55829982159652998690387016786290701417737029008819876372094123  
076979868219707434628108214464024250100459684530772168394277426168014085715048803428630631980716798276919713  
373507501228584390677350035205917978230395392175598724431751684171601630994091419567813565398364751025549679  
679894192400722876599652790389882768707544854192266205570507929535383224258902492390300156867166850113483688  
744829982807693700)  
  
  
=== Partage #3 ===  
Here is a ^_^: 16709034437593251511  
Here is your share ^_^: (14124968809395651301, 2115059928820191746433422041701819055178594056467872586524173  
789747105130856740311026246147467076237998590884378818914519320977246250660360779986004757632739346236950606  
456207025985009430362805985518263961162287901841927525675367412262064371366259891641959444737681787708089287  
795076160612222625490016243988504069528088045091559868930450838860856118589909725361603661935988359022488754  
7095703689129)  
  
  
=== Partage #4 ===  
Here is a ^_^: 16176553675199909377  
Here is your share ^_^: (13124087598866836897, 5057006413193965747851205132463486134553678358936358473430646  
685358173329926421449349359275877477988877254903926482757009755035313913949047857841505241757442457937501554  
517884706728502786124258579951038954406917972498908309993478482932750890448890853020955814589912990199612463  
132425282704438979947589749249077509849477245369641281666046720560369955704906698055981932878092565810367091  
864525081753506700)  
  
  
=== Partage #5 ===  
Here is a ^_^: 17715948856564031111  
Here is your share ^_^: (15433417544629723811, 1156995086657146465203209635618667508261480636518836011310236  
459667748701276359336475148493554088045164259643550208757992921859555235890612765768989490229050532735238291  
831743694241803122550101754586185105072462552674524355820850623987006507078566914451157049266986826522518013  
984125103874031320940558379914842057464818660972258992211395926206545425995781088607116747682637176233215668  
45324165228169600)  
  
  
=== Partage #6 ===  
Here is a ^_^: 17190505269303297247  
Here is your share ^_^: (15051597768804250151, 5156540948946189073594659552089965782355896006557646966772800  
187470579156379071633966341039300060761336290212026320763461235922452333703019497935413359873824302586810339  
214462207313375647589116396376112887841260261711273184309547202476393272615270879970829671647947834880808211  
533792200076868215026907530940473771108413313093698781303998260813037347256250418797770512094884572808437813  
3342065889012783600)  
  
  
=== Partage #7 ===  
Here is a ^_^: 16543838624252269061  
Here is your share ^_^: (9666538905010101859, 11623362341291757546301350595657051677439057888579340031967374  
509518801584821137523261928883994599620346449781162893361781493575584537521310839599409928264275816270881031  
767436095422065968827241673809917782465029272306325543937951045867060161926597887937667799251549523149537495  
269430757182876009565266411156124246970342111734866457085694074744292674553870574441735513069510487500522970  
538476688955436700)  
  
  
=== Partage #8 ===  
Here is a ^_^: 10675631503496763379  
Here is your share ^_^: (17605059603882583733, 5811984943960297530574621719712989675004670581384768045807001  
026233857685055447945616236142174385142480100650343343744565400891757541842794920057382206062686400820979983  
917879234978822791509299821772344577795873483865035594233101554196869156839015596959711221136536645020737167  
295387321538506369633488609218134914245122281100686066500733815399260283420762030885648372432925557597881202  
23330442648357)  
  
  
=== Partage #9 ===  
Here is a ^_^: 15395765934269798629  
Here is your share ^_^: (12359332530505106801, 8690010393196251825747088480655634846460344245230435717219297  
058240295397240065906950772936955455778020175609175007775865635373010941188576204622951318469979559268702550  
278586350336963407656079660830965941051052010907342801127836414703733046276249074409010236631244374964079718  
306041902560587424833699846709550484897690968038052139498802870346804334433614182904341476828490370882063808  
4774508983905204000)  
  
  
----- FLAG -----  
b"bctf{shamir_secret_sharing_isn't_ass_but_this_implementation_isXD}"
Bash