challenges

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License: Unlicense Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SortByChallenge   = v4Client.GetChallengesParamsSortBy("Challenge")
	SortByCatagory    = v4Client.GetChallengesParamsSortBy("Catagory")
	SortByRating      = v4Client.GetChallengesParamsSortBy("Rating")
	SortByUsersSolves = v4Client.GetChallengesParamsSortBy("Solves")
	SortByReleaseDate = v4Client.GetChallengesParamsSortBy("ReleaseDate")
)
View Source
const (
	StateActive     = "active"
	StateRetired    = "retired"
	StateUnreleased = "unreleased"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityResponse

type ActivityResponse struct {
	Data         []ChallengeActivity
	ResponseMeta common.ResponseMeta
}

type CategoriesListInfo added in v0.1.0

type CategoriesListInfo = v4Client.CategoriesListInfo

type CategoriesListInfoResponse added in v0.1.0

type CategoriesListInfoResponse struct {
	Data         CategoriesListInfo
	ResponseMeta common.ResponseMeta
}

type Challenge

type Challenge = v4Client.Challenge

type ChallengeActivity

type ChallengeActivity = v4Client.ChallengeActivity

type ChallengeList

type ChallengeList = v4Client.ChallengeList

type ChallengeListResponse

type ChallengeListResponse struct {
	Data         []ChallengeList
	ResponseMeta common.ResponseMeta
}

type ChallengeQuery

type ChallengeQuery struct {
	// contains filtered or unexported fields
}

func (*ChallengeQuery) AllResults

AllResults executes the query and returns all pages of challenges. This method automatically paginates through all available results. Use with caution for large datasets as it may consume significant memory.

Example:

allChallenges, err := client.Challenges.List().
	ByDifficulty("Hard").
	AllResults(ctx)

func (*ChallengeQuery) Ascending

func (q *ChallengeQuery) Ascending() *ChallengeQuery

Ascending sets the sort order to ascending. Must be called after SortedBy(). Returns a new ChallengeQuery that can be further chained.

Example:

challenges := query.SortedBy("Rating").Ascending().Results(ctx)

func (*ChallengeQuery) ByCategory

func (q *ChallengeQuery) ByCategory(val ...int) *ChallengeQuery

ByCategory filters challenges by category ID. Category IDs are typically obtained from category listings. Returns a new ChallengeQuery that can be further chained.

Example:

webChallenges := query.ByCategory(1).Results(ctx)
cryptoChallenges := query.ByCategory(2).Results(ctx)

func (*ChallengeQuery) ByCategoryList

func (q *ChallengeQuery) ByCategoryList(val ...int) *ChallengeQuery

ByCategoryList filters challenges by multiple category IDs. Category IDs are typically obtained from category listings. Returns a new ChallengeQuery that can be further chained.

Example:

challenges := query.ByCategoryList(1, 2, 3).Results(ctx)

func (*ChallengeQuery) ByDifficulty

func (q *ChallengeQuery) ByDifficulty(val string) *ChallengeQuery

ByDifficulty filters challenges by difficulty level. Valid values are "VeryEasy", "Easy", "Medium", "Hard", and "Insane". Returns a new ChallengeQuery that can be further chained.

Example:

hardChallenges := query.ByDifficulty("Hard").Results(ctx)
easyChallenges := query.ByDifficulty("Hard").ByDifficulty("Easy").Results(ctx)

func (*ChallengeQuery) ByDifficultyList

func (q *ChallengeQuery) ByDifficultyList(val ...string) *ChallengeQuery

ByDifficultyList filters challenges by multiple difficulty levels. Valid values are "Easy", "Medium", "Hard", and "Insane". Returns a new ChallengeQuery that can be further chained.

Example:

challenges := query.ByDifficultyList("Hard", "Insane").Results(ctx)

func (*ChallengeQuery) ByKeyword added in v0.1.0

func (q *ChallengeQuery) ByKeyword(keyword string) *ChallengeQuery

ByKeyword filters Challenge name Returns a new ChallengeQuery that can be further chained.

Example:

challenges := query.ByKeyword("spo").Results(ctx)

func (*ChallengeQuery) ByState

func (q *ChallengeQuery) ByState(val string) *ChallengeQuery

ByState filters challenges by state. Valid values are "active", "retired", and "unreleased". Returns a new ChallengeQuery that can be further chained.

Example:

activeChallenges := query.ByState("active").Results(ctx)
retiredChallenges := query.ByState("retired").Results(ctx)

func (*ChallengeQuery) ByStateList

func (q *ChallengeQuery) ByStateList(val ...string) *ChallengeQuery

ByStateList filters challenges by multiple states. Valid values are "active", "retired", and "unreleased". Returns a new ChallengeQuery that can be further chained.

Example:

challenges := query.ByStateList("active", "retired").Results(ctx)

func (*ChallengeQuery) Descending

func (q *ChallengeQuery) Descending() *ChallengeQuery

Descending sets the sort order to descending. Must be called after SortedBy(). Returns a new ChallengeQuery that can be further chained.

Example:

challenges := query.SortedBy("Rating").Descending().Results(ctx)

func (*ChallengeQuery) First

First executes the query and returns only the first challenge. Returns an error if no results are found.

Example:

firstChallenge, err := client.Challenges.List().
	ByDifficulty("Insane").
	SortedBy("Rating").Descending().
	First(ctx)

func (*ChallengeQuery) Next

func (q *ChallengeQuery) Next() *ChallengeQuery

Next moves to the next page in the pagination sequence. Returns a new ChallengeQuery that can be further chained.

Example:

nextPage := query.Next().Results(ctx)

func (*ChallengeQuery) Page

func (q *ChallengeQuery) Page(n int) *ChallengeQuery

Page sets the specific page number for pagination. Returns a new ChallengeQuery that can be further chained.

Example:

challenges := query.Page(3).Results(ctx)

func (*ChallengeQuery) PerPage

func (q *ChallengeQuery) PerPage(n int) *ChallengeQuery

PerPage sets the number of results per page. Returns a new ChallengeQuery that can be further chained.

Example:

challenges := query.PerPage(50).Results(ctx)

func (*ChallengeQuery) Previous

func (q *ChallengeQuery) Previous() *ChallengeQuery

Previous moves to the previous page in the pagination sequence. If already on the first page, it remains on page 1. Returns a new ChallengeQuery that can be further chained.

Example:

prevPage := query.Previous().Results(ctx)

func (*ChallengeQuery) Results

Results executes the query and returns the current page of challenges. This method should be called last in the query chain to fetch the actual data.

Example:

challenges, err := client.Challenges.List().
	ByDifficulty("Hard").
	ByState("active").
	SortedBy("Rating").Descending().
	Results(ctx)

func (*ChallengeQuery) SortedBy

func (q *ChallengeQuery) SortedBy(field string) *ChallengeQuery

SortedBy sets the field to sort results by. Valid values include "Challenge", "Catagory", "Rating", "Solves", and "ReleaseDate". Returns a new ChallengeQuery that can be further chained with Ascending() or Descending().

Example:

challenges := query.SortedBy("Rating").Descending().Results(ctx)
challenges := query.SortedBy("ReleaseDate").Ascending().Results(ctx)

type DownloadResponse

type DownloadResponse struct {
	Data         []byte
	ResponseMeta common.ResponseMeta
}

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

func (*Handle) Activity

func (h *Handle) Activity(ctx context.Context) (ActivityResponse, error)

Activity retrieves the recent activity history for the challenge. This includes recent solves, attempts, and other challenge-related activities.

Example:

activity, err := client.Challenges.Challenge(12345).Activity(ctx)
if err != nil {
	log.Fatal(err)
}
for _, act := range activity.Data {
	fmt.Printf("Activity: %s at %s\n", act.Type, act.Date)
}

func (*Handle) Download

func (h *Handle) Download(ctx context.Context) (DownloadResponse, error)

Download retrieves the challenge files for download. This returns the challenge's downloadable zip. Note: Not all challenges have downloadable files. Check Info() first to verify availability.

Example:

challenge := client.Challenges.Challenge(12345)

// Get challenge info first to check if files are available
info, err := challenge.Info(ctx)
if err != nil {
	log.Fatal(err)
}

// Check if the challenge has downloadable files
if info.Data.FileName == "" {
	fmt.Println("This challenge has no downloadable files")
	return
}

// Download the challenge files
download, err := challenge.Download(ctx)
if err != nil {
	log.Fatal(err)
}

// Write to file
err = os.WriteFile(info.Data.FileName, download.Data, 0644)
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Downloaded challenge files to: %s (%d bytes)\n", info.Data.FileName, len(download.Data))

func (*Handle) Info

func (h *Handle) Info(ctx context.Context) (InfoResponse, error)

Info retrieves detailed information about the challenge. This includes comprehensive challenge details such as name, difficulty, category, description, and other metadata.

Example:

info, err := client.Challenges.Challenge(12345).Info(ctx)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Challenge: %s (%s, %s)\n", info.Data.Name, info.Data.Difficulty, info.Data.Category)

func (*Handle) Own

func (h *Handle) Own(ctx context.Context, flag string) (common.MessageResponse, error)

Own submits a flag for the challenge to claim ownership. This is used to submit the solution flag to complete the challenge.

Example:

result, err := client.Challenges.Challenge(12345).Own(ctx, "HTB{example_flag_here}")
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Flag submission: %s\n", result.Data.Message)

func (*Handle) Start

func (h *Handle) Start(ctx context.Context) (common.MessageResponse, error)

Start initiates a new instance of the challenge. This creates and starts a challenge instance for solving.

Example:

result, err := client.Challenges.Challenge(12345).Start(ctx)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Challenge started: %s\n", result.Data.Message)

func (*Handle) Stop

Stop terminates the running challenge instance. This stops and destroys the active challenge instance.

Example:

result, err := client.Challenges.Challenge(12345).Stop(ctx)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Challenge stopped: %s (Success: %t)\n", result.Data.Message, result.Data.Success)

func (*Handle) ToDo

ToDo toggles the challenge's todo status for the current user. This adds or removes the challenge from the user's todo list.

Example:

result, err := client.Challenges.Challenge(12345).ToDo(ctx)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Todo updated: %+v\n", result.Data)

type InfoResponse

type InfoResponse struct {
	Data         Challenge
	ResponseMeta common.ResponseMeta
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(client service.Client, product string) *Service

func (*Service) Categories added in v0.1.0

func (s *Service) Categories(ctx context.Context) (CategoriesListInfoResponse, error)

func (*Service) Challenge

func (s *Service) Challenge(id int) *Handle

Challenge returns a handle for a specific challenge with the given ID. This handle can be used to perform operations on the challenge such as retrieving information, starting/stopping instances, or submitting flags.

func (*Service) ChallengeName added in v0.0.24

func (s *Service) ChallengeName(name string) *Handle

func (*Service) List

func (s *Service) List() *ChallengeQuery

List creates a new query for challenges. This returns a ChallengeQuery that can be chained with filtering and pagination methods. Use this to search and filter challenges based on various criteria.

Example:

query := client.Challenges.List()
challenges, err := query.ByDifficulty("Hard").ByState("active").Results(ctx)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL