HeroCTF v3 2021: White Market

White Market

Category: Prog

chal

100 points

Welcome to the year 2080, you have just finished shopping and you set yourself a challenge.

A robot scans barcodes at a phenomenal speed, you tell yourself that with a little programming, you can beat it.

Calculate the price of your shopping before the robot does!

Challenge : nc chall0.heroctf.fr 7005

Format : Hero{}
Author : Worty

market.txt

1669187413837:aroma:21
8989511479050:bagel:82
1657443751533:batter:25
4801019678275:beans:52
5174854543756:beer:92
6058469685690:biscuit:39
5961153113052:bread:90
1894436354337:broth:92
1694638064870:burger:49
9520525899565:butter:69
1194538623592:cake:73
5049110058179:candy:67
9006345377815:caramel:75
9051982111629:caviar:46
4356498652822:cheese:90
7513265447600:chili:55
8130136665346:chocolate:43
3233534838864:cider:60
8544790511503:cobbler:50
3244531913645:cocoa:35
8129003865163:coffee:86
2213180222553:cookie:47
5968873604709:cream:35
5855375508546:croissant:59
2070442482106:crumble:68
9841783680567:cuisine:82
5431428792829:curd:56
6534945748016:dessert:28
1293704889258:dish:99
3549973150789:drink:48
8791182112996:eggs:58
6950207780004:entree:20
1686664828410:filet:49
8252969815634:fish:83
1821361323473:flour:48
4677810993561:foie gras:46
4017039220442:food:76
8558505702261:glaze:20
8126631269783:grill:41
6257462652511:hamburger:36
6068044423807:ice:53
5101352540413:juice:72
9898990609300:ketchup:36
3699825430375:kitchen:36
5896995240454:lard:44
7773016687512:liquor:50
2558833734855:margarine:29
1305631269574:marinade:64
4811718623681:mayo:51
2789301531090:mayonnaise:97
9317967006114:meat:57
5588167258472:milk:44
7641306614107:mousse:99
3298639654047:muffin:46
2814541950049:mushroom:66
5031485534037:noodle:51
6729608369763:nut:95
1148435371087:oil:71
6097743923028:olive:25
2639656983580:omelette:63
2272105834318:pan:53
5616889871836:pasta:52
1571761157054:paste:53
6359833869655:pastry:83
3992400484788:pie:82
3545687760016:pizza:95
3113929658096:plate:84
8225414384528:pot:85
7775390432849:poutine:95
1406605796031:pudding:48
9190536545135:raclette:50
1434512330598:recipe:31
8323507206099:rice:28
3000153926025:salad:24
2305994050610:salsa:24
6204207636350:sandwich:84
2526141995404:sauce:30
3286175026107:seasoning:44
1795081286731:skillet:20
4408463530946:soda:50
3384320198720:soup:91
2342103565658:soy:45
2830144995188:spice:21
2242078742033:steak:25
8059539815694:stew:95
6220850596155:syrup:47
5738198066342:tartar:77
1741852268499:taste:53
5079324565750:tea:80
5392169993022:toast:79
5911286071989:vinegar:89
2387817501592:waffle:92
5791282736651:water:68
4702775820277:wheat:46
2560625364195:wine:47
8300425667584:wok:100
6552294157808:yeast:64
6555320829663:yogurt:48
2029107661387:apple:27
1420703904402:apricot:78
5099181737701:avocado:94
8813720112937:banana:75
2365004650803:berry:46
5184007535514:cantaloupe:82
3169330863956:cherry:37
2972069810914:citron:49
1570465338653:citrus:80
5326111656765:coconut:94
1503475804016:date:73
6137235816329:fig:29
7974686706309:grape:86
8735052735816:guava:49
2682247548125:kiwi:34
8565081239012:lemon:39
9184294234578:lime:57
5600444789971:mango:84

Solution

The solution is to get png barcodes (which are delivered base64 encoded), scan them and return their prices. Solution in Python.

from pyzbar import pyzbar
import base64
from io import BytesIO
from PIL import Image
from pwn import *

f = open('market.txt', 'rt')
market = {}
for line in f.readlines():
    item = line.split(':')
    market[item[0]] = {'name': item[1], 'prize': item[2].strip()}
f.close()

# context.log_level = 'DEBUG'
conn = remote('chall0.heroctf.fr', 7005)
conn.recvuntil(b'Do you want to try?(y/n)')
conn.sendline(b'y')
while True:
    try:
        msg = conn.recvuntil(b'Here is the barcode of the current article: ')
        img = BytesIO(base64.b64decode(conn.recvline().decode('utf-8')))
        barcode_decode = pyzbar.decode(Image.open(img))
        barcode = barcode_decode[0].data.decode('utf-8')
        conn.sendline(market[barcode]['prize'])
    except EOFError:
        print(conn.recvall().decode('utf-8'))
        break
conn.close()

Output:

Ooooh... It's a little embarrassing, you're done calculating before me.
WELL DONE ! You deserve a reward, take it: Hero{u_4r3_b3tt3r_th4n_4_r0b0t_!!}

Flag

Hero{u_4r3_b3tt3r_th4n_4_r0b0t_!!}

Privacy Policy
luc © 2021