Capture The Flag is a console application challenge runner.
- Create
QuickStart
Console App (.NET Core). - Add Janda.CTF nuget package.
- Add CTF.Run to
Program.cs
.
using Janda.CTF;
namespace QuickStart
{
class Program
{
static void Main(string[] args) => CTF.Run(args);
}
}
- Run program with
Add
profile to createC001
challenge
CTF nuget package provides Help and Add profiles
{
"profiles": {
"Add": {
"commandName": "Project",
"commandLineArgs": "add --name C001"
},
"Help": {
"commandName": "Project",
"commandLineArgs": "--help"
}
}
}
- Implement Run for
C001
challenge.
The challenge class was added by CTF challenge runner.
using Microsoft.Extensions.Logging;
namespace Janda.CTF
{
public class C001 : IChallenge
{
private readonly ILogger<C001> _logger;
public C001(ILogger<C001> logger)
{
_logger = logger;
}
public void Run()
{
_logger.LogInformation("I will capture the flag!");
}
}
}
- Run the challenge with
C001
profile
C001 profile was added by CTF runner
{
"profiles": {
"Add": {
"commandName": "Project",
"commandLineArgs": "add --name C001"
},
"Help": {
"commandName": "Project",
"commandLineArgs": "--help"
},
"C001": {
"commandName": "Project",
"commandLineArgs": "--name C001"
}
}
}
[22:24:33 VRB] Using CTF runner 1.0.0
[22:24:33 VRB] Running challange C001
[22:24:33 INF] I will get the flag!
[22:24:33 VRB] Challenge C001 completed
- Create your services. For example
FlagFinder
service.
namespace QuickStart
{
public interface IFlagFinder
{
void FindFlag();
}
}
using Microsoft.Extensions.Logging;
namespace QuickStart
{
public class FlagFinder : IFlagFinder
{
readonly ILogger<FlagFinder> _logger;
public FlagFinder(ILogger<FlagFinder> logger)
{
_logger = logger;
}
public void FindFlag()
{
_logger.LogInformation("Looking for a flag...");
}
}
}
- Add your service to CTF runner
using Janda.CTF;
using Microsoft.Extensions.DependencyInjection;
namespace QuickStart
{
class Program
{
static void Main(string[] args) => CTF.Run(args, (services) =>
{
services.AddTransient<IFlagFinder, FlagFinder>();
});
}
}
- Add your service to the challenge service
using Microsoft.Extensions.Logging;
using QuickStart;
namespace Janda.CTF
{
public class C001 : IChallenge
{
readonly ILogger<C001> _logger;
readonly IFlagFinder _flagFinder;
public C001(ILogger<C001> logger, IFlagFinder flagFinder)
{
_logger = logger;
_flagFinder = flagFinder;
}
public void Run()
{
_logger.LogInformation("I will capture the flag!");
_flagFinder.FindFlag();
}
}
}
- Run
C001
challenge withIFlagFinder
service
[23:01:20 VRB] Using CTF runner 1.0.0
[23:01:20 VRB] Running challange C001
[23:01:20 INF] I will capture the flag!
[23:01:20 INF] Looking for a flag...
[23:01:20 VRB] Challenge C001 completed