HackTheBox Challenge Low Logic (Hardware)
Writeup for HackTheBox Challenge Low Logic
HackTheBox Challenge Low Logic (Hardware)
Challenge Synopsis
I have this simple chip, I want you to understand how it’s works and then give me the output. (Source)
Enumeration
In this challenge, we are given 2 files - chip.jpg
and input.csv
.
1
2
3
4
5
6
7
8
9
10
11
❯ head input.csv
in0,in1,in2,in3
1,0,0,1
1,1,0,0
0,1,1,0
0,0,1,0
1,1,0,1
1,0,0,1
0,0,0,0
0,0,1,0
0,0,0,0
Analysing the diagram in chip.jpg
, we can observe that there are 2 AND Gates and 1 OR Gate.
Exploitation
We can craft our script to take in the values from input.csv
and find out the outputs using the logical gates.
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
❯ cat solve.py
#!/usr/bin/python3
import csv
def solve(input_file):
results = []
with open(input_file, mode='r') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',')
next(csvreader) # start from second row
# Read inputs from input.csv
for row in csvreader:
input1 = int(row[0])
input2 = int(row[1])
input3 = int(row[2])
input4 = int(row[3])
and_output1 = input1 & input2
and_output2 = input3 & input4
final_output = and_output1 | and_output2
results.append(str(final_output))
return ''.join(results)
input_file = 'input.csv'
output = solve(input_file)
print(output)
❯ ./solve.py
010010000101010001000010011110110011010001011111010001110011000000110000011001000101111101000011011011010011000000110101010111110011001101111000001101000110110101110000011011000011001101111101
Take the binary output and convert it to ASCII in CyberChef.
Flag: HTB{4_G00d_Cm05_3x4mpl3}
This post is licensed under CC BY 4.0 by the author.