← Back to Writeups
HTBEasyMisc

Primed for Action

XESXOR9/10/20261 min read
#misc#htb#easy#primality_test

Primed for Action

Platform: HackTheBox | Category: Misc | Type: Challenge | Difficulty: Easy | OS: NA | Author: XESXOR | Date: 2026-01-26 | Status: Solved Techniques: primality_test

Summary

Task: Find two prime numbers in a list and output their product. Solution: Implement primality check and multiply the two primes found.

Primed for Action — Hack The Box

Description

The task provided a web interface with a code editor. The goal was to write a script that reads a list of numbers from stdin, identifies the two prime numbers in the list, and outputs their product.

Analysis

This is a classic coding challenge. We are given a list of numbers, among which we need to find exactly two prime numbers and multiply them. The main difficulty lies in correctly implementing the primality check and handling the input data.

Solution

python
#!/usr/bin/env python3
import sys

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def solve():
    try:
        # Read all input data
        input_data = sys.stdin.read().split()
        numbers = [int(x) for x in input_data]
        
        primes = []
        for num in numbers:
            if is_prime(num):
                primes.append(num)
        
        if len(primes) == 2:
            print(primes[0] * primes[1])
        else:
            # If there are not exactly 2 primes, output something or nothing
            pass
    except Exception as e:
        pass

if __name__ == "__main__":
    solve()

The script is submitted to the /run endpoint via a POST request (or through the editor interface on the website), after which the server executes it on test data and returns the flag.