Documentation ¶
Overview ¶
Package models contains the types for schema 'cyboard'.
Package models contains the types for schema 'cyboard'.
Package models contains the types for schema 'cyboard'.
Package models contains the types for schema 'cyboard'.
Package models contains the types for schema 'cyboard'.
Package models contains the types for schema 'cyboard'.
Index ¶
- Constants
- Variables
- func EnableChallenge(db DB, flagID int) error
- func GetPublicChallengeDescription(db DB, flagID int) (string, error)
- func LatestScoreChange(db DB) (time.Time, error)
- func LatestServiceCheckRun(db DB) (time.Time, error)
- type BlueTeamStore
- type BlueTeamStoreSlice
- type BlueteamView
- type CTFProgress
- type CapturedChallenge
- type Challenge
- type ChallengeCaptureCount
- type ChallengeGuess
- type ChallengeSlice
- type ChallengeView
- type ChallengeViewGroup
- type CtfSolve
- type CtfSolveResult
- type DB
- type DBClient
- type Deleter
- type ExitStatus
- type FlagState
- type Inserter
- type ManyInserter
- type MonitorTeamService
- type OtherPoints
- type OtherPointsSlice
- type OtherPointsView
- type Service
- type ServiceCheck
- type ServiceCheckSlice
- type ServiceSlice
- type TXer
- type Team
- type TeamCapturedChallenges
- type TeamRole
- type TeamServiceStatusesView
- type TeamsScoresResponse
- type Tx
- type Updater
Constants ¶
const ( // ExitStatusPass is the 'pass' ExitStatus. ExitStatusPass = ExitStatus(1) // ExitStatusFail is the 'fail' ExitStatus. ExitStatusFail = ExitStatus(2) // ExitStatusPartial is the 'partial' ExitStatus. ExitStatusPartial = ExitStatus(3) // ExitStatusTimeout is the 'timeout' ExitStatus. ExitStatusTimeout = ExitStatus(4) )
const ( // ValidFlag is for successful guesses of flags which were not previously submitted ValidFlag FlagState = 0 // InvalidFlag is for bad guesses InvalidFlag = 1 // AlreadyCaptured is for flags that were claimed by the team already AlreadyCaptured = 2 )
const ( // TeamRoleUnspecified is an invalid TeamRole, likely bad user input. TeamRoleUnspecified = TeamRole(0) // TeamRoleAdmin is the 'admin' TeamRole. TeamRoleAdmin = TeamRole(1) // TeamRoleCtfCreator is the 'ctf_creator' TeamRole. TeamRoleCtfCreator = TeamRole(2) // TeamRoleBlueteam is the 'blueteam' TeamRole. TeamRoleBlueteam = TeamRole(3) )
Variables ¶
var ( // DatabaseTables is a list of every table for the schema 'cyboard' DatabaseTables = []string{ "challenge", "challenge_category", "challenge_file", "ctf_solve", "exit_status", "other_points", "service", "service_check", "team", "team_role", } )
Functions ¶
func EnableChallenge ¶ added in v0.2019.11
EnableChallenge updates a challenge, ensuring it is active for submission. Right now, this means it will definitely be visible on the CTF display page, ready to guess against.
func GetPublicChallengeDescription ¶
GetPublicChallengeDescription fetches a non-hidden challenge's description/body column. This field has a separate call due to how long it may get.
func LatestScoreChange ¶
LatestScoreChange retrieves the timestamp of the last event that changed any team's score. This is a lightweight way of checking if other pieces of info need updating. If the timestamp changes between calls, then that means other score or status related data should be queried for again.
Types ¶
type BlueTeamStore ¶
type BlueTeamStore struct { Name string `json:"name"` // name Hash []byte `json:"-"` // hash BlueteamIP int16 `json:"blueteam_ip"` // blueteam_ip }
BlueTeamStore contains the fields used to insert new blue teams into the database.
type BlueTeamStoreSlice ¶
type BlueTeamStoreSlice []BlueTeamStore
BlueTeamStoreSlice is a list of blue teams, ready to be batch inserted.
func (BlueTeamStoreSlice) Insert ¶
func (teams BlueTeamStoreSlice) Insert(db TXer) error
Insert a batch of new blue teams into the database. Blue teams must have a unique name and ip from all other blueteams.
type BlueteamView ¶
type BlueteamView struct { ID int `json:"id"` // id Name string `json:"name"` // name BlueteamIP int16 `json:"blueteam_ip"` // blueteam_ip }
BlueteamView has the Team fields needed by the service monitor.
func AllBlueteams ¶
func AllBlueteams(db DB) ([]BlueteamView, error)
AllBlueteams fetches all non-disabled contestants from the database, along with their significant IP octet (the one octet that changes between teams, all the other octets are assumed to be the same).
type CTFProgress ¶
type CTFProgress struct { Category string `json:"category"` Amount int `json:"count"` Max int `json:"max"` }
CTFProgress holds a team's status for a ctf category. Represents e.g. `completed 4 out of 5 challenges in the reversing category`
func GetTeamCTFProgress ¶
func GetTeamCTFProgress(db DB, teamID int) ([]CTFProgress, error)
GetTeamCTFProgress retrieves the given team's status in each ctf category, by counting the number of solved challenges out of the total amount of them.
type CapturedChallenge ¶
type CapturedChallenge struct { Designer string `json:"designer"` // challenge.designer Category string `json:"category"` // challenge.category Name string `json:"name"` // challenge.name Timestamp time.Time `json:"time"` // ctf_solve.created_at }
CapturedChallenge contains enough to identify a solved challenge.
type Challenge ¶
type Challenge struct { ID int `json:"id"` // id Name string `json:"name"` // name Category string `json:"category"` // category Designer string `json:"designer"` // designer Flag string `json:"flag"` // flag Total float32 `json:"total"` // total Body string `json:"body"` // body Hidden bool `json:"hidden"` // hidden CreatedAt time.Time `json:"created_at"` // created_at ModifiedAt time.Time `json:"modified_at"` // modified_at }
Challenge represents a row from 'cyboard.challenge'.
func AllChallenges ¶
AllChallenges fetches all ctf challenges from the database, to be displayed to staff.
func ChallengeByFlag ¶
ChallengeByFlag retrieves a row from 'cyboard.challenge' as a Challenge.
func ChallengeByID ¶
ChallengeByID retrieves a row from 'cyboard.challenge' as a Challenge.
func ChallengeByName ¶
ChallengeByName retrieves a row from 'cyboard.challenge' as a Challenge.
type ChallengeCaptureCount ¶
type ChallengeCaptureCount struct { Designer string `json:"designer"` // challenge.designer Category string `json:"category"` // challenge.category Name string `json:"name"` // challenge.name Count int `json:"count"` // --- (calculated column) FirstTeam *string `json:"first_team,omitempty"` // team.name Timestamp *time.Time `json:"timestamp,omitempty"` // ctf_solve.created_at }
ChallengeCaptureCount holds the number of teams that have beaten a CTF challenge, and the first team w/ timestamp to solve it.
func ChallengeCapturesPerFlag ¶
func ChallengeCapturesPerFlag(db DB) ([]ChallengeCaptureCount, error)
ChallengeCapturesPerFlag gets the number of times each flag was captured, sorted by designer, then category, then name. This includes flags that remain unsolved, which will have a Count of 0, and team/timestamp of nil.
type ChallengeGuess ¶
type ChallengeGuess struct { Name string `json:"name"` // name Category string `json:"category"` // category Flag string `json:"flag"` // flag Points float32 `json:"points"` // total }
ChallengeGuess is a blueteam's attempt to captured a flag. Only the Flag field is required to be set. Leaving Name empty causes the guess to checked against all hidden flags. The Category, Name, and points are filled in on a successful guess.
type ChallengeSlice ¶
type ChallengeSlice []Challenge
ChallengeSlice is an array of challenges, suitable to insert many of at once.
func (ChallengeSlice) Insert ¶
func (cs ChallengeSlice) Insert(db TXer) error
Insert many ctf challenges into the database at once.
func (ChallengeSlice) Sum ¶ added in v0.2019.11
func (cs ChallengeSlice) Sum() float32
type ChallengeView ¶
type ChallengeView struct { ID int `json:"id"` // id Name string `json:"name"` // name Points int `json:"points"` // points (rounded down to nearest int) Captured bool `json:"captured"` // Whether the viewing team has already got this flag }
ChallengeView is a safe-for-public-display subset of fields over a CTF challenge.
type ChallengeViewGroup ¶ added in v0.2019.11
type ChallengeViewGroup struct { Category string `json:"category"` Challenges []ChallengeView `json:"challenges"` }
ChallengeViewGroup wraps a set of ChallengeViews, by their category (crypto, web, etc.)
func AllPublicChallenges ¶
func AllPublicChallenges(db DB, teamID int) ([]ChallengeViewGroup, error)
AllPublicChallenges fetches all non-hidden ctf challenges from the database, to be displayed to constestants.
type CtfSolve ¶
type CtfSolve struct { CreatedAt time.Time `json:"created_at"` // created_at TeamID int `json:"team_id"` // team_id ChallengeID int `json:"challenge_id"` // challenge_id }
CtfSolve represents a row from 'cyboard.ctf_solve'.
type CtfSolveResult ¶ added in v0.2019.11
type CtfSolveResult struct { Timestamp time.Time `json:"timestamp"` // ctf_solve.created_at TeamID int `json:"team_id"` // team.id TeamName string `json:"team_name"` // team.name ChallengeID int `json:"challenge_id"` // challenge.id ChallengeName string `json:"challenge_name"` // challenge.name Category string `json:"category"` // challenge.category Points float32 `json:"points"` // challenge.total }
CtfSolveResult represents a solved challenge, associated with the solving team, via the pivot table 'ctf_solve'
func ChallengeCapturesByTime ¶ added in v0.2019.11
func ChallengeCapturesByTime(db DB, cutoffTime time.Time) ([]CtfSolveResult, error)
ChallengeCapturesByTime fetches all `ctf_solve` rows with their ctf name/info and solving team's name & id, and orders them by time. A `cutoffTime` threshold will exclude any solves older than the date.
type DB ¶
type DB interface { Exec(string, ...interface{}) (pgx.CommandTag, error) Query(string, ...interface{}) (*pgx.Rows, error) QueryRow(string, ...interface{}) *pgx.Row CopyFrom(tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int, error) }
DB is the common interface for database operations that can be used with types from schema 'cyboard'.
type DBClient ¶
DBClient is a postgres session/engine/client. This is the main interface for doing database related stuff. It can be used to query, insert, and start transactions.
type ExitStatus ¶
type ExitStatus uint16
ExitStatus is the 'exit_status' enum type from schema 'cyboard'.
func (ExitStatus) MarshalText ¶
func (es ExitStatus) MarshalText() ([]byte, error)
MarshalText marshals ExitStatus into text.
func (*ExitStatus) Scan ¶
func (es *ExitStatus) Scan(src interface{}) error
Scan satisfies the database/sql.Scanner interface for ExitStatus.
func (ExitStatus) String ¶
func (es ExitStatus) String() string
String returns the string value of the ExitStatus.
func (*ExitStatus) UnmarshalText ¶
func (es *ExitStatus) UnmarshalText(text []byte) error
UnmarshalText unmarshals ExitStatus from text.
type FlagState ¶
type FlagState int
FlagState represents the possibilities when user submits a flag guess
func CheckFlagSubmission ¶
func CheckFlagSubmission(db TXer, ctx context.Context, team *Team, chal *ChallengeGuess) (FlagState, error)
CheckFlagSubmission will award the team with a captured flag if their flag string guess is correct. No points will be given on a repeat flag, or obviously if the flag submitted is simply wrong.
type ManyInserter ¶
type MonitorTeamService ¶
type MonitorTeamService struct { Team struct { ID int // id Name string // name IP int16 // blueteam_ip } Service struct { ID int // id Name string // name Script string // script Args []string // args StartsAt time.Time // starts_at } }
func MonitorTeamsAndServices ¶
func MonitorTeamsAndServices(db DBClient) ([]MonitorTeamService, error)
MonitorTeamsAndServices fetches every active service and blueteam from the database, at the same time. Returns an empty array for no rows, or an error if there is a problem fetching data from postgres.
type OtherPoints ¶
type OtherPoints struct { CreatedAt time.Time `json:"created_at"` // created_at TeamID int `json:"team_id"` // team_id Points float32 `json:"points"` // points Reason string `json:"reason"` // reason }
OtherPoints represents a row from 'cyboard.other_points'.
func (*OtherPoints) Insert ¶
func (op *OtherPoints) Insert(db DB) error
Insert a bonus point award/deduction into the database.
type OtherPointsSlice ¶
type OtherPointsSlice []OtherPoints
OtherPointsSlice is an array of bonus points, suitable to insert many of at once.
func (OtherPointsSlice) Insert ¶
func (ops OtherPointsSlice) Insert(db TXer) error
Insert many bonus point scores into the database at once. The incoming slice should have the CreatedAt field set to the same value on each struct, allowing a batch of bonus points to 'come in' at exactly the same time.
type OtherPointsView ¶ added in v0.2019.11
type OtherPointsView struct { CreatedAt time.Time `json:"created_at"` // created_at Teams []string `json:"teams"` // array of team names Points float32 `json:"points"` // points Reason string `json:"reason"` // reason }
OtherPointsView groups together a row of other_points by timestamp
func AllBonusPoints ¶ added in v0.2019.11
func AllBonusPoints(db DB) ([]OtherPointsView, error)
AllBonusPoints returns all the bonus point totals, grouped by timestamp.
type Service ¶
type Service struct { ID int `json:"id"` // id Name string `json:"name"` // name Category string `json:"category"` // category Description string `json:"description"` // description TotalPoints float32 `json:"total_points"` // total_points Points *float32 `json:"points"` // points Script string `json:"script"` // script Args []string `json:"args"` // args Disabled bool `json:"disabled"` // disabled StartsAt time.Time `json:"starts_at"` // starts_at CreatedAt time.Time `json:"created_at"` // created_at ModifiedAt time.Time `json:"modified_at"` // modified_at }
Service represents a row from 'cyboard.service'.
func AllActiveServices ¶
AllActiveServices retrieves all monitored services from 'cyboard.service'.
func AllServices ¶
AllServices retrieves all monitored services from 'cyboard.service'.
func ServiceByID ¶
ServiceByID retrieves a row from 'cyboard.service' as a Service.
func ServiceByName ¶
ServiceByName retrieves a row from 'cyboard.service' as a Service.
type ServiceCheck ¶
type ServiceCheck struct { CreatedAt time.Time `json:"created_at"` // created_at TeamID int `json:"team_id"` // team_id ServiceID int `json:"service_id"` // service_id Status ExitStatus `json:"status"` // status ExitCode int16 `json:"exit_code"` // exit_code }
ServiceCheck represents a row from 'cyboard.service_check'.
type ServiceCheckSlice ¶
type ServiceCheckSlice []ServiceCheck
ServiceCheckSlice is an array of ServiceChecks, suitable to insert many of at once.
func (ServiceCheckSlice) Insert ¶
func (sc ServiceCheckSlice) Insert(db DB) error
Insert a batch of service monitor results efficiently into the database.
type ServiceSlice ¶ added in v0.2019.11
type ServiceSlice []Service
func (ServiceSlice) Sum ¶ added in v0.2019.11
func (ss ServiceSlice) Sum() float32
type Team ¶
type Team struct { ID int `json:"id"` // id Name string `json:"name"` // name RoleName TeamRole `json:"role_name"` // role_name Hash []byte `json:"-"` // hash Disabled bool `json:"disabled"` // disabled BlueteamIP *int16 `json:"blueteam_ip"` // blueteam_ip }
Team represents a row from 'cyboard.team'.
func AllTeams ¶
AllTeams fetches all teams (users) from the database. Used by the admin dashboard to view & modify all added users.
func TeamByName ¶
TeamByName retrieves a row from 'cyboard.team' as a Team.
type TeamCapturedChallenges ¶
type TeamCapturedChallenges struct { Team string `json:"team"` // team.name Challenges []CapturedChallenge `json:"challenges"` }
TeamCapturedChallenges holds the flags a team has captured.
func ChallengeCapturesPerTeam ¶
func ChallengeCapturesPerTeam(db DB) ([]TeamCapturedChallenges, error)
ChallengeCapturesPerTeam retrieves each team with the flags they've captured.
type TeamRole ¶
type TeamRole uint16
TeamRole is the 'team_role' enum type from schema 'cyboard'.
func (TeamRole) MarshalText ¶
MarshalText marshals TeamRole into text.
func (*TeamRole) UnmarshalText ¶
UnmarshalText unmarshals TeamRole from text.
type TeamServiceStatusesView ¶
type TeamServiceStatusesView struct { ServiceID int `json:"service_id"` ServiceName string `json:"service_name"` Statuses []ExitStatus `json:"statuses"` }
TeamServiceStatusesView represents the current, calculated service's status (pass, fail, timeout), for all teams.
func TeamServiceStatuses ¶
func TeamServiceStatuses(db DB) ([]TeamServiceStatusesView, error)
TeamServiceStatuses gets the current service status (pass, fail, timeout) for each team, for each service that has started and isn't disabled.