Created
May 26, 2019 09:20
-
-
Save mimura1133/70a65e4cd5a00feb57dc65880dcd415c to your computer and use it in GitHub Desktop.
containers challenge's builder code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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