Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enowars8 #61

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,8 @@ MigrationBackup/
/scoreboard
/sessions
docker-compose.yml


/firstblood-discord-bot/venv
/firstblood-discord-bot/config.py
/firstblood-discord-bot/cache.json
4 changes: 2 additions & 2 deletions EnoLandingPageBackend/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async Task<ActionResult> Info()
team.Id,
team.Confirmed,
team.Name,
System.IO.File.Exists($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{team.Id}{Path.DirectorySeparatorChar}client.conf"),
System.IO.File.Exists($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{team.Id}{Path.DirectorySeparatorChar}client.ovpn"),
gameHasStarted ? team.Vulnbox.RootPassword : null,
gameHasStarted ? team.Vulnbox.ExternalAddress : null,
Utils.VulnboxIpAddressForId(team.Id), // internal ip
Expand All @@ -105,7 +105,7 @@ public async Task<ActionResult> Info()
public async Task<ActionResult> VpnConfig()
{
var team = await this.db.GetTeamAndVulnbox(this.GetTeamId(), this.HttpContext.RequestAborted);
var config = System.IO.File.ReadAllText($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{team.Id}{Path.DirectorySeparatorChar}client.conf");
var config = System.IO.File.ReadAllText($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{team.Id}{Path.DirectorySeparatorChar}client.ovpn");
var contentType = "application/force-download";
return this.File(Encoding.ASCII.GetBytes(config), contentType, "client.ovpn");
}
Expand Down
4 changes: 2 additions & 2 deletions EnoLandingPageBackend/Hetzner/HetznerCloudApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private async Task DoGetServer(long teamId, HetznerCloudApiScheduledCall call, C
try
{
// TODO refactor this into always reading the file?
var rootPassword = File.ReadAllText($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{teamId}{Path.DirectorySeparatorChar}root.pw");
var rootPassword = File.ReadAllText($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{teamId}{Path.DirectorySeparatorChar}password.txt");

// Call "Get Servers" endpoint.
this.logger.LogInformation($"{nameof(this.DoGetServer)} for team {teamId}");
Expand Down Expand Up @@ -176,7 +176,7 @@ await LandingPageDatabase.UpdateTeamVulnbox(

// Call "Create Server" endpoint.
var user_data = File.ReadAllText($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{teamId}{Path.DirectorySeparatorChar}user_data.sh");
var rootPassword = File.ReadAllText($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{teamId}{Path.DirectorySeparatorChar}root.pw");
var rootPassword = File.ReadAllText($"{LandingPageBackendUtil.TeamDataDirectory}{Path.DirectorySeparatorChar}teamdata{Path.DirectorySeparatorChar}team{teamId}{Path.DirectorySeparatorChar}password.txt");
dynamic createVmRequest = new JObject();
createVmRequest.name = $"team{teamId}";
createVmRequest.server_type = this.landingPageSettings.HetznerVulnboxType;
Expand Down
14 changes: 7 additions & 7 deletions EnoLandingPageFrontend/Pages/ContactView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
<h1>Contact</h1>
<hr />
<div>
<h4>Email</h4>
<p>bambi@@enoflag.de</p>
<!--<h4>Email</h4>
<p>bambi@@enoflag.de</p>-->

<h4>Twitter</h4>
<p><a href="https://twitter.com/enoflag">@@ENOFLAG</a></p>
<!--<h4>Twitter</h4>
<p><a href="https://twitter.com/enoflag">@@ENOFLAG</a></p>-->

<h2>Communication Channels</h2>
<!--<h4>IRC</h4>
<p><a href="https://web.libera.chat/#enowars">#enowars on libera.chat</a></p>-->

<h4>Matrix</h4>
bambictf:matrix.tu-berlin.de
<!--<h4>Matrix</h4>
bambictf:matrix.tu-berlin.de-->

<h4>Discord</h4>
<p><a href="https://discord.gg/62TqF38x3M">Invite-Link</a></p>
<p><a href="https://discord.gg/jQHj8d3zHE">Invite-Link</a></p>
</div>
</div>

Expand Down
31 changes: 26 additions & 5 deletions EnoLandingPageFrontend/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
@page "/"


<div class="bg">
<div>
<h1>Bambi CTF #7</h1>
<h2>Attack/Defense CTF by ENOFLAG / TU Berlin</h2>
<center>
<div style="display: flex;flex-wrap: wrap;justify-content: center;align-items: center;">
<img src="/images/logo.png" width="40%">
<div>
<p style="font-weight: bolder;font-size: 6rem;height: 100%;margin: auto;">
8$*
</p>
</div>
</div>
</center>
<div>
<center>
<h5 style="margin: auto;">
*payment is not non-optional and definetly the opposite of not unrequired
</h5>
</center>
</div>
<div>
<h2>
Attack/Defense CTF by ENOFLAG / TU Berlin
</h2>
</div>
</div>
</div>

Expand All @@ -16,9 +37,9 @@
<p>We have updated our contact page. We have changed our email address, and may drop Matrix support for this year.</p>
-->

<h3>Bambi CTF #7</h3>
<!--<p>ENOFLAG will host another ENOWARS CTF on the 16th of July. Registration is open, don't hesitate to sign up!</p>-->
<p>ENOFLAG will host another Bambi CTF event on the 5th of November 2022 at 2PM UTC! Like every year we invite beginner teams to participate, so you can practice playing Attack/Defense CTFs against opponents with a similar skill level. If you are interested, check out our <a href="/setup">setup page</a> and <a href="/login">sign up</a>!</p>
<h3>ENOWARS 8</h3>
<p>ENOFLAG will host another ENOWARS CTF on the 20th of July. Registration is open, don't hesitate to sign up!</p>
<!--<p>ENOFLAG will host another Bambi CTF event on the 5th of November 2022 at 2PM UTC! Like every year we invite beginner teams to participate, so you can practice playing Attack/Defense CTFs against opponents with a similar skill level. If you are interested, check out our <a href="/setup">setup page</a> and <a href="/login">sign up</a>!</p>-->
<p>This year's event is sponsored by IABG<!-- and Hetzner-->.</p>
<center><img src="/images/sponsors/iabg-logo.png" width="30%" /></center>
<br />
Expand Down
132 changes: 125 additions & 7 deletions EnoLandingPageFrontend/Pages/ScoreboardView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,134 @@
@inject AuthenticationStateProvider authenticationStateProvider
@inject ILogger<ScoreboardView> logger

@functions {
private bool showAdvancedScoreboard = false;

private void ToggleAdvancedScoreboard()
{
showAdvancedScoreboard = !showAdvancedScoreboard;
}

private string HslToHex(double h, double s, double l)
{
// Normalize h, s, l
l /= 100.0;
s /= 100.0;

// Edge case where saturation is 0 (gray)
if (s == 0)
{
int gray = (int)Math.Round(l * 255.0);
return $"#{gray:X2}{gray:X2}{gray:X2}";
}

double a = s * Math.Min(l, 1 - l);
int ToHex(double value)
{
// Clamp value to the range 0-255 and convert to an integer
int clampedValue = (int)Math.Round(Math.Max(0.0, Math.Min(255.0, value)));
return clampedValue;
}

double f(int n)
{
double k = (n + h / 30.0) % 12.0;
double color = l - a * Math.Max(Math.Min(k - 3.0, 9.0 - k), -1.0);
return 255.0 * color;
}

// Convert to 2-digit hex values
string ToHexString(int value) => value.ToString("X2");

// Ensure HEX color is properly formatted
return $"#{ToHexString(ToHex(f(0)))}{ToHexString(ToHex(f(8)))}{ToHexString(ToHex(f(4)))}";
}

private double Clamp(double value, double min, double max)
{
return Math.Max(min, Math.Min(max, value));
}
}



@if (currentScoreboard != null)
{
var orderedTeams = currentScoreboard.Teams.OrderByDescending(t => t.TotalScore).ToArray();
var orderedServices = currentScoreboard.Services.OrderBy(t => t.ServiceId).ToArray();

@if (showAdvancedScoreboard)
{
// Advanced Scoreboard Calculation
var states = new[] { "OK", "RECOVERING", "MUMBLE", "OFFLINE", "INTERNAL_ERROR", "EXPLOITED" };
var serviceNames = orderedServices.Select(s => s.ServiceName).ToArray();
var advancedScoreboardData = new double[orderedServices.Length, states.Length];

@for (int t = 0; t < currentScoreboard.Teams.Length; t++)
{
var team = orderedTeams[t];
var orderedTeamServiceDetails = team.ServiceDetails.OrderBy(sd => sd.ServiceId).ToArray();
@for (int s = 0; s < team.ServiceDetails.Length; s++)
{
var serviceDetails = orderedTeamServiceDetails[s];
var service = orderedServices[s];
var state = serviceDetails.ServiceStatus;
var stateName = Enum.GetName(state);
var dataStateIndex = Array.IndexOf(states, stateName);
advancedScoreboardData[s, dataStateIndex] += 1.0;

// check if team exploited this service
if (serviceDetails.AttackScore > 0)
{
advancedScoreboardData[s, 5] += 1.0;
}
}
}


// Advanced Scoreboard display
<table class="adv-scoreboard">
<tr class="adv-scoreboard-header">
<th class="adv-scoreboard-header-cell">Service</th>
@foreach (var state in states)
{
<th class="adv-scoreboard-header-cell">@state</th>
}
</tr>
@for (int s = 0; s < orderedServices.Length; s++)
{
var service = orderedServices[s];
<tr class="adv-scoreboard-row">
<td class="adv-scoreboard-row-cell">@service.ServiceName</td>
@for (int stateIndex = 0; stateIndex < states.Length; stateIndex++)
{
var value = advancedScoreboardData[s, stateIndex];
var proportion = value / currentScoreboard.Teams.Length * 100;
var brightness = 100 - (proportion / 2 + 10);
var saturation = proportion * 0.5 + 50;
var hue = stateIndex switch
{
0 => 110, // OK
1 => 210, // RECOVERING
2 => 40, // MUMBLE
3 => 0, // OFFLINE
4 => 240, // INTERNAL_ERROR
5 => 300, // EXPLOITED
_ => 0
};
var bgColor = HslToHex(hue, saturation, brightness);
<td class="adv-scoreboard-row-cell" style="background-color: @bgColor;">
@value
</td>
}
</tr>
}
</table>


}

// Normal Scoreboard
<table class="scoreboard">
<colgroup>
<col class="team-rank" style="width:40px;" />
Expand All @@ -41,7 +165,7 @@
<i class="p-2 fas fa-angle-left" />
}
</div>
<div class="p-1">Round @currentScoreboard.CurrentRound</div>
<div class="p-1" @onclick="ToggleAdvancedScoreboard">Round @currentScoreboard.CurrentRound</div>
<div>
@if (currentScoreboard.CurrentRound < ScoreboardService.LatestScoreboard?.CurrentRound)
{
Expand Down Expand Up @@ -193,12 +317,6 @@
// We are in "show old round" mode.
currentScoreboard = await ScoreboardService.TryGetOrRequest(roundId);
previousScoreboard = await ScoreboardService.TryGetOrRequest(roundId - 1);

// Also request the neighbouring rounds
var a = ScoreboardService.TryGetOrRequest(roundId - 2);
var b = ScoreboardService.TryGetOrRequest(roundId + 1);
var c = ScoreboardService.TryGetOrRequest(roundId - 3);
var d = ScoreboardService.TryGetOrRequest(roundId + 2);
}
else
{
Expand Down
24 changes: 24 additions & 0 deletions EnoLandingPageFrontend/Pages/ScoreboardView.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,27 @@
.service-INACTIVE {
background-color: gray;
}

.adv-scoreboard {
width: 100%;
border-collapse : 'collapse';
margin-top: 20px;
font-family: Arial, sans-serif;
}

.adv-scoreboard-header {
background-color: #f2f2f2;
color: #333;
}

.adv-scoreboard-header-cell {
font-weight: bold;
text-align: center;
}

.adv-scoreboard-row, .adv-scoreboard-row-cell {
padding: 10px;
text-align: center;
border: 1px solid #ddd;
}

4 changes: 2 additions & 2 deletions EnoLandingPageFrontend/Pages/TeamsView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
<div>
<hr />
<h4>Confirmed</h4>
<h4>Confirmed (@teams.ConfirmedTeams.Count)</h4>
@foreach (var team in teams.ConfirmedTeams)
{
@if (team.CtftimeId is long ctftimeId)
Expand Down Expand Up @@ -38,7 +38,7 @@
}

<hr />
<h4>Registered</h4>
<h4>Registered (@teams.RegisteredTeams.Count)</h4>
@foreach (var team in teams.RegisteredTeams)
{
@if (team.CtftimeId is long ctftimeId)
Expand Down
2 changes: 1 addition & 1 deletion EnoLandingPageFrontend/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="">Bambi CTF #7</a>
<a class="navbar-brand" href="">ENOWARS 8</a>
<button class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
Expand Down
48 changes: 33 additions & 15 deletions EnoLandingPageFrontend/wwwroot/css/app.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
html, body {
html,
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

a, .btn-link {
a,
.btn-link {
color: #0366d6;
}

Expand Down Expand Up @@ -56,18 +58,34 @@ a, .btn-link {
padding-top: 200px;
padding-bottom: 200px;
}
.bg div {
background-color: rgba(211, 211, 211, 0.8);
}

.bg div h1 {
font-size: 80px;
font-weight: bolder;
text-align: center;
}
.bg div {
background-color: rgba(211, 211, 211, 0.8);
}

.bg div h1 {
font-size: 80px;
font-weight: bolder;
text-align: center;
}

.bg div h2 {
font-size: 50px;
font-weight: bold;
text-align: center;
}

.bg div h2 {
font-size: 50px;
font-weight: bold;
text-align: center;
}
.free-flags {
background-color: red;
color: white;
padding: 5px;
border-radius: 5px;
font-size: 12px;
font-weight: bold;
position: absolute;
width: 100px;
height: 50px;
top: 0;
left: 0;
z-index: 1000;
}
Binary file modified EnoLandingPageFrontend/wwwroot/images/deers-88991.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EnoLandingPageFrontend/wwwroot/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading