HTB Hack The Boo Practice: Hexoding64
Challenge Information
| Attribute | Details |
|---|---|
| Event | Hack The Boo Practice |
| Category | Cryptography |
| Challenge | Hexoding64 |
| Difficulty | Very Easy |
Summary
In this challenge, a ghost named Caspersky needs to join the Applied Cryptography Academy of Ghosts. The challenge provides source code that encodes a flag using two different methods: the first half is encoded in hexadecimal, while the second half is encoded in base64. The task is to decode both halves and retrieve the original flag.
Analysis
The source code reveals the encryption process:
def main(): first_half = FLAG[:len(FLAG)//2] second_half = FLAG[len(FLAG)//2:]
hex_encoded = to_hex(first_half) base64_encoded = to_base64(second_half)
with open('output.txt', 'w') as f: f.write(f'{hex_encoded}\n{base64_encoded}')The flag is split into two parts:
- First half: converted to hexadecimal using a custom function
- Second half: converted to base64 using a custom implementation
The output file contains:
- Line 1:
4854427b6b6e3077316e675f6830775f74305f3164336e743166795f336e633064316e675f736368336d33735f31735f6372756331346c5f6630725f615f - Line 2:
Y3J5cHQwZ3I0cGgzcl9fXzRsczBfZDBfbjB0X2MwbmZ1czNfZW5jMGQxbmdfdzF0aF9lbmNyeXA1MTBuIX0=
Solution
The key observation is that the challenge can be solved without understanding the source code. Both encoding schemes used are standard and reversible:
Step 1: Decode the first line from hexadecimal
The first line is a hexadecimal string. Convert it from hex to ASCII:
4854427b... → HTB{kn0w1ng_h0w_t0_1d3nt1fy_3nc0d1ng_sch3m3s_1s_cruci4l_f0r_a_Step 2: Decode the second line from base64
The second line is a base64 string. Decode it to ASCII:
Y3J5cHQwZ3I0cGgzcl9fXzRsczBfZDBfbjB0X2MwbmZ1czNfZW5jMGQxbmdfdzF0aF9lbmNyeXA1MTBuIX0=→ crypt0gr4ph3r___4ls0_d0_n0t_c0nfus3_enc0d1ng_w1th_encrypt510n!}Step 3: Combine both halves
Concatenate the decoded first and second halves:
HTB{kn0w1ng_h0w_t0_1d3nt1fy_3nc0d1ng_sch3m3s_1s_cruci4l_f0r_a_crypt0gr4ph3r___4ls0_d0_n0t_c0nfus3_enc0d1ng_w1th_encrypt510n!}Recommended Tool: CyberChef can be used to quickly decode both hex and base64 without requiring any Python scripting.
Key Takeaways
- Encoding is NOT encryption; it’s just a transformation of data representation
- Common encoding schemes include hexadecimal, base64, URL encoding, and others
- These schemes are easily reversible and provide no security
- It’s important to distinguish between encoding (for data representation) and encryption (for confidentiality)
- Tools like CyberChef can identify and decode multiple encoding schemes automatically