Practical Coding in Cyber Security | HackTheBox Coding Challenges
In this article, I present a collection of practical programming solutions tailored to cybersecurity challenges from HackTheBox. It focuses…
In this article, I present a collection of practical programming solutions tailored to cybersecurity challenges from HackTheBox. It focuses on coding-driven CTFs, especially those that require careful parsing, algorithmic logic, or exploit proof-of-concepts. The challenges I solve in this post are retired challenges and are listed below:
- HackTheBox Threat Index
- HackTheBox Oddly Even
- HackTheBox Reversal
- HackTheBox Addition
- HackTheBox Triple Knock
- HackTheBox MiniMax
- HackTheBox Honeypot
- HackTheBox BlackWire
- HackTheBox Insane Bolt
- HackTheBox Ghost Path
HackTheBox Threat Index Description
Volnayan APTs are exfiltrating data through TOR nodes, embedding attack signals in plain sight. Your job is to scan each outbound stream and identify known malicious keywords linked to Operation Blackout. Each keyword has a threat level — the more hits you find, the higher the danger. Analyze the stream, tally the signals, and calculate the overall threat score.

Walkthrough
We’ll solve this problem using Python3. To start, we’ll transfer the provided keywords and their corresponding weights into a dictionary for easy lookup.
KEYWORD_WEIGHTS = {
"scan": 1,
"response": 2,
"control": 3,
"callback": 4,
"implant": 5,
"zombie": 6,
"trigger": 7,
"infected": 8,
"compromise": 9,
"inject": 10,
"execute": 11,
"deploy": 12,
"malware": 13,
"exploit": 14,
"payload": 15,
"backdoor": 16,
"zeroday": 17,
"botnet": 18,
}Next, we’ll read the input stream into a variable called data and initialize a variable ans to 0. This variable will store the final calculated threat score.
n = input()
ans = 0Then, we’ll loop through each keyword and its weight from the dictionary. For each keyword, we’ll count how many times it appears in the data and multiply that count by its weight, adding the result to ans:
for keyword, weight in KEYWORD_WEIGHTS.items():
keyword_count = n.count(keyword)
ans += keyword_count * weightFinally, we print the result, which gives us the flag:
print(ans)
Full working script
KEYWORD_WEIGHTS = {
"scan": 1,
"response": 2,
"control": 3,
"callback": 4,
"implant": 5,
"zombie": 6,
"trigger": 7,
"infected": 8,
"compromise": 9,
"inject": 10,
"execute": 11,
"deploy": 12,
"malware": 13,
"exploit": 14,
"payload": 15,
"backdoor": 16,
"zeroday": 17,
"botnet": 18,
}# take in the number
n = input()
ans = 0
# calculate answer
for keyword, weight in KEYWORD_WEIGHTS.items():
keyword_count = n.count(keyword)
ans += keyword_count * weight
# print answer
print(ans)

HackTheBox Oddly Even Description
The ghostly clock ticks strangely. Determine whether its chimes are even or odd to calm the restless spirits.

Walkthrough
- Get User Input
We start by asking the user to enter a number. The input() function reads the input as a string, so we wrap it with int() to convert it into an integer:
a = int(input("Enter a number: "))- Determine Even or Odd
To check whether the number is even, we use the modulo operator %. This operator gives the remainder after division. If a number divided by 2 leaves no remainder (a % 2 == 0), it’s even. Otherwise, it’s odd:
if a % 2 == 0:
print("even")
else:
print("odd")Example
If the user enters 7, the output will be:
oddIf the user enters 12, the output will be:
even
Why It Works
- Even numbers are divisible by 2 with no remainder (e.g., 0, 2, 4, 6).
- Odd numbers leave a remainder of 1 when divided by 2 (e.g., 1, 3, 5, 7).
This simple program is often one of the first exercises given to beginners because it teaches input handling, conditionals, and basic arithmetic operations in Python.