Skip to content

Commit

Permalink
added service and tick parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Crisis82 committed Jul 11, 2023
1 parent 7da1726 commit 0e0e070
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 39 deletions.
6 changes: 4 additions & 2 deletions configs/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const got = require('got');

const SYSTEM_IP = 'http://10.10.0.1/flags';
const FLAG_SERVER = 'http://10.10.0.1/flags';
const TEAM_TOKEN = '48638b31449aef540d6e8131733bb3ed';
const TIMEOUT_MS = 5000;
const teams = require('./teams.json');
const services = require('./services.json');

module.exports = {
flagFormat: '[A-Z0-9]{31}=',
submitInterval: 120,
flagLifetime: 5 * 120,
teams,
services,
submitFlags: async (flags, onSubmit) => {
const tot = flags.length;
const chunkSize = 20;
for (let i = 0; i < tot - chunkSize; i += chunkSize) {
const answer = await got
.put(SYSTEM_IP, {
.put(FLAG_SERVER, {
headers: {
'X-Team-Token': TEAM_TOKEN
},
Expand Down
2 changes: 0 additions & 2 deletions configs/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"name": "server",
"version": "0.1.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "UNLICENSED",
"dependencies": {
"got": "^11.8.1"
}
Expand Down
5 changes: 5 additions & 0 deletions configs/services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"example service 1": "8000",
"example service 2": "3333",
"example service 3": "4123"
}
2 changes: 1 addition & 1 deletion src/api/client-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const makeClientApiRouter = async () => {
for (const flag of flags) {
flagsForInserion.push({
flag: flag.flag,
sploit: flag.sploit,
exploit: flag.exploit,
team: flag.team,
timestamp: new Date()
});
Expand Down
1 change: 1 addition & 0 deletions src/game-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class GameManager {
private game: any;
getClientConfig() {
return {
SERVICES: this.game.services,
TEAMS: this.game.teams,
FLAG_FORMAT: this.game.flagFormat,
FLAG_LIFETIME: this.game.flagLifetime,
Expand Down
10 changes: 9 additions & 1 deletion src/lib/models/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Flag extends Model<Flag> {

@Field()
@Column({ allowNull: false })
sploit!: string;
exploit!: string;

@Field()
@Column({ allowNull: false })
Expand All @@ -22,6 +22,14 @@ export default class Flag extends Model<Flag> {
@Column({ allowNull: false })
timestamp!: Date;

@Field()
@Column({ allowNull: false })
service!: string;

@Field()
@Column({ allowNull: false })
tick!: number;

@Field({ nullable: true })
@Column({ allowNull: true, defaultValue: 'QUEUED' })
@Index({
Expand Down
45 changes: 36 additions & 9 deletions src/lib/resolvers/flagResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ class GetFlagsCountArgs {

@IsOptional()
@Field({ nullable: true })
sploit?: string;
service?: string;

@IsOptional()
@Field({ nullable: true })
exploit?: string;

@IsOptional()
@Field({ nullable: true })
team?: string;

@IsOptional()
@Field({ nullable: true })
tick?: number;

@IsOptional()
@IsDate()
@Field({ nullable: true })
Expand Down Expand Up @@ -63,7 +71,10 @@ class GetFlagsArgs extends GetFlagsCountArgs {
@ObjectType()
class SearchValues {
@Field(type => [String])
sploits: string[];
service: string[];

@Field(type => [String])
exploits: string[];

@Field(type => [String])
teams: string[];
Expand All @@ -75,12 +86,14 @@ class SearchValues {
@Resolver()
export class FlagResolver {
static argumentsToQuery(args: GetFlagsCountArgs | GetFlagsArgs) {
const { flag, sploit, team, since, until, status, checksystem_response } = args;
const { flag, service, exploit, team, tick, since, until, status, checksystem_response } = args;
const search: any = {};

if (flag) search.flag = { [Op.iLike]: '%' + flag + '%' };
if (sploit) search.sploit = sploit;
if (service) search.service = service;
if (exploit) search.exploit = exploit;
if (team) search.team = team;
if (tick) search.tick = tick;
if (status) search.status = status;
if (checksystem_response)
search.checksystem_response = { [Op.iLike]: '%' + checksystem_response + '%' };
Expand Down Expand Up @@ -130,12 +143,19 @@ export class FlagResolver {

@Query(returns => SearchValues)
async getSearchValues(): Promise<SearchValues> {
const sploitRes: [{ DISTINCT: string }] = await Flag.aggregate('sploit', 'DISTINCT', {
const serviceRes: [{ DISTINCT: string }] = await Flag.aggregate('service', 'DISTINCT', {
plain: false,
raw: true
});
const sploits = [];
for (const status of sploitRes) sploits.push(status.DISTINCT);
const services = [];
for (const status of serviceRes) services.push(status.DISTINCT);

const exploitRes: [{ DISTINCT: string }] = await Flag.aggregate('exploit', 'DISTINCT', {
plain: false,
raw: true
});
const exploits = [];
for (const status of exploitRes) exploits.push(status.DISTINCT);

const teamRes: [{ DISTINCT: string }] = await Flag.aggregate('team', 'DISTINCT', {
plain: false,
Expand All @@ -144,14 +164,21 @@ export class FlagResolver {
const teams = [];
for (const status of teamRes) teams.push(status.DISTINCT);

const tickRes: [{ DISTINCT: number }] = await Flag.aggregate('tick', 'DISTINCT', {
plain: false,
raw: true
});
const ticks = [];
for (const status of tickRes) ticks.push(status.DISTINCT);

const statusRes: [{ DISTINCT: string }] = await Flag.aggregate('status', 'DISTINCT', {
plain: false,
raw: true
});
const statuses = [];
for (const status of statusRes) statuses.push(status.DISTINCT);

return { sploits, teams, statuses };
return { services, exploits, teams, statuses };
}

@Mutation(returns => Boolean)
Expand All @@ -161,7 +188,7 @@ export class FlagResolver {
for (const flag of flags) {
flagsForInserion.push({
flag: flag,
sploit: 'MANUAL',
exploit: 'MANUAL',
team: 'MANUAL',
timestamp: new Date()
});
Expand Down
4 changes: 3 additions & 1 deletion src/next/components/flagRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ interface Props {

const FlagRow: StatelessComponent<Props> = ({ flag }) => (
<tr>
<th scope="row">{flag.sploit}</th>
<th scope="row">{flag.exploit}</th>
<td>{flag.team}</td>
<td>{flag.service}</td>
<td>{flag.flag}</td>
<td>{moment(flag.timestamp).format('HH:mm:ss')}</td>
<td>{flag.tick}</td>
<td>{flag.status}</td>
<td>{flag.checksystem_response}</td>
</tr>
Expand Down
4 changes: 3 additions & 1 deletion src/next/components/flagsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class FlagsTable extends Component<Props> {
<table className="table table-hover">
<thead>
<tr className="table-secondary">
<th scope="col">Sploit</th>
<th scope="col">Exploit</th>
<th scope="col">Team</th>
<th scope="col">Service</th>
<th scope="col">Flag</th>
<th scope="col">Time</th>
<th scope="col">Tick</th>
<th scope="col">Status</th>
<th scope="col">Checksystem Response</th>
</tr>
Expand Down
73 changes: 61 additions & 12 deletions src/next/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ interface Props {
}

interface State {
sploit: string;
service: string;
exploit: string;
team: string;
status: string;
flag: string;
tick: string;
since?: Date;
until?: Date;
checksystemResponse: string;
Expand All @@ -26,17 +28,21 @@ class Search extends Component<Props, State> {
super(props);

this.state = {
sploit: props.searchParams.sploit || '',
service: props.searchParams.service || '',
exploit: props.searchParams.exploit || '',
team: props.searchParams.team || '',
status: props.searchParams.status || '',
flag: props.searchParams.flag || '',
tick: props.searchParams.tick || '',
since: props.searchParams.since && new Date(props.searchParams.since),
until: props.searchParams.until && new Date(props.searchParams.until),
checksystemResponse: props.searchParams.checksystem_response || ''
};

this.onSelectSploit = this.onSelectSploit.bind(this);
this.onSelectService = this.onSelectService.bind(this);
this.onSelectExploit = this.onSelectExploit.bind(this);
this.onSelectTeam = this.onSelectTeam.bind(this);
this.onSelectTick = this.onSelectTick.bind(this);
this.onSelectStatus = this.onSelectStatus.bind(this);
this.onTextInputChanged = this.onTextInputChanged.bind(this);
this.onResetClick = this.onResetClick.bind(this);
Expand All @@ -47,7 +53,8 @@ class Search extends Component<Props, State> {
//If searchParams object changed (needed for update on navigation)
if (this.props.searchParams !== prevProps.searchParams)
this.setState({
sploit: this.props.searchParams.sploit || '',
service: this.props.searchParams.service || '',
exploit: this.props.searchParams.exploit || '',
team: this.props.searchParams.team || '',
status: this.props.searchParams.status || '',
flag: this.props.searchParams.flag || '',
Expand All @@ -57,16 +64,27 @@ class Search extends Component<Props, State> {
});
}

onSelectSploit(event: any) {

onSelectService(event: any) {
this.setState({
service: event.target.value
});
}
onSelectExploit(event: any) {
this.setState({
sploit: event.target.value
exploit: event.target.value
});
}
onSelectTeam(event: any) {
this.setState({
team: event.target.value
});
}
onSelectTick(event: any) {
this.setState({
tick: event.target.value
});
}
onSelectStatus(event: any) {
this.setState({
status: event.target.value
Expand All @@ -84,8 +102,10 @@ class Search extends Component<Props, State> {

onResetClick() {
this.setState({
sploit: '',
service: '',
exploit: '',
team: '',
tick: '',
status: '',
flag: '',
since: undefined,
Expand All @@ -99,8 +119,10 @@ class Search extends Component<Props, State> {
onSearchClick() {
const payload: any = {};

payload.sploit = this.state.sploit;
payload.service = this.state.service;
payload.exploit = this.state.exploit;
payload.team = this.state.team;
payload.tick = this.state.tick;
payload.status = this.state.status;
payload.flag = this.state.flag;
payload.since = this.state.since ? moment(this.state.since).format('HH:mm') : '';
Expand All @@ -118,14 +140,31 @@ class Search extends Component<Props, State> {
<h4 className="card-title">Show Flags</h4>
<div className="row mb-2">
<div className="col-md-4">
<label>Sploit</label>
<label>Service</label>
<select
className="form-control form-control-sm"
onChange={this.onSelectSploit}
value={this.state.sploit}
onChange={this.onSelectService}
value={this.state.service}
>
<option value="">All</option>
{this.props.searchValues.sploits.map((value, i) => {
{this.props.searchValues.service.map((value, i) => {
return (
<option key={i} value={value}>
{value}
</option>
);
})}
</select>
</div>
<div className="col-md-4">
<label>Exploit</label>
<select
className="form-control form-control-sm"
onChange={this.onSelectExploit}
value={this.state.exploit}
>
<option value="">All</option>
{this.props.searchValues.exploits.map((value, i) => {
return (
<option key={i} value={value}>
{value}
Expand Down Expand Up @@ -191,6 +230,16 @@ class Search extends Component<Props, State> {
/>
</div>
</div>
<div className="col-md-3">
<label>Tick</label>
<input
type="text"
className="form-control form-control-sm"
value={this.state.tick}
id="tick"
onChange={this.onTextInputChanged}
/>
</div>
<div className="col-md-2">
<label>Status</label>
<select
Expand Down
Loading

0 comments on commit 0e0e070

Please sign in to comment.