Skip to content

Instantly share code, notes, and snippets.

@mimura1133
Created May 26, 2019 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mimura1133/70a65e4cd5a00feb57dc65880dcd415c to your computer and use it in GitHub Desktop.
Save mimura1133/70a65e4cd5a00feb57dc65880dcd415c to your computer and use it in GitHub Desktop.
containers challenge's builder code.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace build
{
class Program
{
static void Main(string[] args)
{
var flag = "ctf4b{e52df60c058746a66e4ac4f34db6fc81}";
var font = new Font("Consolas", 100);
var python = "import hashlib\r\nprint('Valid flag.' if hashlib.sha1(input('Please your flag:').encode('utf-8')).hexdigest()=='"+BitConverter.ToString(SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(flag))).Replace("-","").ToLower()+"' else 'wrong.'";
File.WriteAllBytes("..\\..\\..\\..\\..\\files\\challenge",
Enumerable.Concat(
Enumerable.Concat(
Enumerable.Concat(Encoding.UTF8.GetBytes("CONTAINER."),
flag.Select(e =>
{
var img = new Bitmap(128, 128);
using (var graphics = Graphics.FromImage(img))
{
graphics.FillRectangle(Brushes.White, 0, 0, img.Width, img.Height);
graphics.DrawString(e.ToString(), font, Brushes.SeaGreen, 0, -20);
}
return img;
}).Select((e, i) =>
{
var stream = new MemoryStream();
e.Save(stream, ImageFormat.Png);
return stream.ToArray();
}).SelectMany((e, i) => Enumerable.Concat(Encoding.UTF8.GetBytes("FILE" + i + "."), e))
),
Encoding.UTF8.GetBytes("VALIDATOR."+python)),
Encoding.UTF8.GetBytes(".ENDCONTAINER")).ToArray()
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment