Back to the Lab 3
LabVIEW

Problem

I think you just have to unzip it and open up _main.vi. ... Oh god, what... what is this?
Author: nb

Solution

First things first, it's pretty annoying that you only get one try, and we need to debug this multiple times later on. We can patch the program and make sure that the checker always allows the rest of the program to run by replacing it with 1.

First 14 Chars

The bytearray with each number rotated left by 3 bits and 4 bits respectively is compared with two constant bytearrays. But note that the bytes are treated as 8-bit unsigned integers, so our implementation needs to consider that.

Second 14 Chars

The bytearray is represented as RGB values.
  • R = byte value
  • G = 5 (constant)
  • B = array index
We can inspect the RGB values:

Third 14 Chars

The input is split into the first 7 and last 7 bytes, then interleaved.

Fourth 14 Chars

Every 2 characters in the array are concatenated and used as the "group name" to read the TDMS file. The Y-value is compared to the array index. Use the probe watch window to debug the program.
Y-value for "ru" is 0
Y-value for "ct" is 1
"3_" is 3
"ur" is 2
"th" is 4
"r1" is 6
"e_" is 5
Then, rearrange so that we go from 0 to 6.

Fifth 14 Chars

There are multiple parts to this.
First, we know it starts with 'd', since other options give us False immediately.
One of the parts is password protected. If we drag the comment out we can see the hidden password.
This unlocks the block diagram.
The input is first converted to their ASCII values, then multiplied with 7927.
Then, 0x49 is subtracted.
Then it goes through some redundant enqueuing, and is compared to some constants.
But we get some weird results. 990802 = 1187410?
Then I realised that the last 16 bits are equal. We are probably comparing 16 bit numbers!

Final Script

Finally!
1
import string
2
​
3
INT_BITS = 8
4
​
5
def leftRotate(n, d):
6
result = bin(n << d)
7
if len(result) - 2 > 8:
8
result = result[-8:-1 * (len(result) - 2 - 8)] + result[2:-8]
9
​
10
return int(result, 2)
11
​
12
rotated_left_3 = [34, 11, 187, 59, 26, 162, 0, 0, 0, 0, 147, 153, 250, 179]
13
rotated_left_4 = [68, 22, 119, 118, 52, 69, 100, 183, 119, 19, 0, 0, 0, 0]
14
​
15
flag = ''
16
​
17
for i in range(14):
18
for char in string.ascii_letters + string.digits + '-_{}':
19
if leftRotate(ord(char), 3) == rotated_left_3[i] or leftRotate(ord(char), 4) == rotated_left_4[i]:
20
flag += char
21
​
22
i += 1
23
​
24
print(flag)
25
assert len(flag) == 14
26
​
27
r_values = [49, 95, 99, 108, 117, 53, 116, 51, 114, 95, 52, 114, 114, 97]
28
flag += ''.join([chr(x) for x in r_values])
29
​
30
print(flag)
31
assert len(flag) == 28
32
​
33
flag += 'y_l00p_ca53_5t'
34
print(flag)
35
assert len(flag) == 42
36
​
37
flag += 'ructur3_the_r1'
38
print(flag)
39
assert len(flag) == 56
40
​
41
fragment = ''
42
results = [1187410, 616666, 989235, 1068505, 600812, 949600, 1100213, 600812, 1131921, 600812, 1068505, 949600, 997162]
43
for result in results:
44
for char in string.ascii_letters + string.digits + '-_{}':
45
output = ord(char) * 7927 - 0x49
46
if int(bin(output)[-16:], 2) == int(bin(result)[-16:], 2):
47
fragment += char
48
break
49
​
50
flag += 'd'
51
flag += fragment[::-1]
52
print(flag)
Copied!