Tags: programming 

Rating:

The website ```http://challs.dvc.tf:6002/home``` presents a 9 by 9 sudoku field. Each number is an input field of a html form. Input fields that contain initial numbers are disabled and the values are set. From top left to bottom right the fields are numbered 1 to 81. We have to solve the puzzle quickly to get the flag and it is obvious that we have to automate the whole process.
The script below will return the flag for us.
```
import requests
from bs4 import BeautifulSoup
from sudoku import Sudoku
import numpy as np

url = 'http://challs.dvc.tf:6002/home'
response = requests.get(url)
cookies = response.cookies
soup = BeautifulSoup(response.text)
fields = list(range(1, 82))
field_values = []
for field_num in fields:
input_field = soup.find('input', attrs={'name': str(field_num)})
if input_field.get('value'):
field_values.append(int(input_field.get('value')))
else:
field_values.append(0)

board = []
count = 0
for i in range(9):
row = []
for j in range(9):
row.append(field_values[count])
count += 1
board.append(row)

puzzle = Sudoku(3, 3, board=board)
solved_sudoku = puzzle.solve()
numpy_board = np.array(solved_sudoku.board)
solved_field = numpy_board.flatten()
post_data = {}
for field in fields:
post_data[str(field)] = str(solved_field[field-1])

flag_url = 'http://challs.dvc.tf:6002/flag'
response = requests.post(flag_url, post_data, cookies=cookies)
print(response.text)
```