Exemplo n.º 1
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(PuzzleFileFns.StandardOneParamRequiredErrorMessage);
                return(1);
            }

            var allLines         = File.ReadAllLines(args[0]);
            int payloadStartLine = PuzzleFileFns.GetLinePayloadStartsAt(allLines);
            var payload          = PuzzleFileFns.GetPayloadAsOneLongString(allLines, payloadStartLine);

            Debug.Assert(payload.StartsWith(@"<~0/)?#c'P?"));
            Debug.Assert(payload.EndsWith(@"ZOG^Hi`#W@:,!~>"));
            Debug.Assert(payload.Contains("\n") == false);
            Debug.Assert(BitwiseFns.FlipEverySecondBit(180) == 225);
            Debug.Assert(BitwiseFns.RotateByteRight(225) == 240);

            Func <byte, byte> bytePostProcess =
                (inByte) => BitwiseFns.RotateByteRight(BitwiseFns.FlipEverySecondBit(inByte));

            Debug.Assert(bytePostProcess(180) == 240);

            var payloadSpan      = Ascii85Fns.DecodeAsSpan(payload, 2);
            var transformedBytes = payloadSpan.ToArray().Select(bytePostProcess).ToArray();

            Console.Write(Encoding.ASCII.GetString(transformedBytes));

            return(0);
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(PuzzleFileFns.StandardOneParamRequiredErrorMessage);
                return(1);
            }

            var allLines         = File.ReadAllLines(args[0]);
            int payloadStartLine = PuzzleFileFns.GetLinePayloadStartsAt(allLines);
            var payload          = PuzzleFileFns.GetPayloadAsOneLongString(allLines, payloadStartLine);

            Debug.Assert(payload.StartsWith("<~70!<j!!#7a+;"));
            Debug.Assert(payload.EndsWith(":j*\"<<*=Q1C=~>"));
            Debug.Assert(payload.Contains("\n") == false);

            var ipv4PacketsSpan = Ascii85Fns.DecodeAsSpan(payload, 2);
            var packetStream    = new MemoryStream(ipv4PacketsSpan.ToArray());
            var memBuffer       = new MemoryStream();

            foreach (var ipv4Frame in IPv4Fns.IterateFrames(packetStream))
            {
                if (!ipv4Frame.Header.ChecksumOK)
                {
                    continue;
                }

                var udpFrame = UDPFns.DecodeUDP(ipv4Frame.Data);

                if (!PacketFilter(ipv4Frame.Header, udpFrame))
                {
                    continue;
                }

                memBuffer.Write(udpFrame.Data, 0, udpFrame.Data.Length);
            }

            // Debugging:
            // var ipv4frame = IPv4Fns.IterateFrames(payloadStream).Last();

            // System.Console.WriteLine(
            //     UDPFns.UDPToDebugString(
            //         ipv4frame.Header.SourceAddress,
            //         ipv4frame.Header.DestinationAddress,
            //         UDPFns.DecodeUDP(ipv4frame.Data)));

            // var udpPacket = UDPFns.DecodeUDP(ipv4frame.Data);
            // var checksum = UDPFns.UDPChecksum(ipv4frame.Header.SourceAddress, ipv4frame.Header.DestinationAddress, udpPacket);
            // System.Console.WriteLine("Checksum (calc)={0:x4}", checksum);
            memBuffer.Position = 0L;
            Console.WriteLine(Encoding.ASCII.GetString(memBuffer.ToArray()));

            return(0);
        }
Exemplo n.º 3
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(PuzzleFileFns.StandardOneParamRequiredErrorMessage);
                return(1);
            }

            var allLines         = File.ReadAllLines(args[0]);
            int payloadStartLine = PuzzleFileFns.GetLinePayloadStartsAt(allLines);
            var payload          = PuzzleFileFns.GetPayloadAsOneLongString(allLines, payloadStartLine);

            Debug.Assert(payload.StartsWith("<~;&S8o%X?BS"));
            Debug.Assert(payload.EndsWith(@"uQ&0qa8h%~>"));
            Debug.Assert(payload.Contains("\n") == false);

            var cipherBytes = Ascii85Fns.DecodeAsSpan(payload, 2).ToArray();

            // We know what the plaintext should start with, so those bytes are easy to find:
            var plainText1Bytes = Encoding.ASCII.GetBytes("==[ Layer 4/5: ");
            var first15KeyBytes = ByteArrayFns.XOR(cipherBytes.Take(15).ToArray(), plainText1Bytes).ToArray();

            var partialOneTimePad = first15KeyBytes.Concat(new byte[17]).ToArray();

            // We also know the line "==[ Payload ]===============================================" should appear, and it's position is easy to find from the partially descrambled file:
            var partialDescramble = Encoding.ASCII.GetString(ByteArrayFns.OneTimePadScramble(cipherBytes, partialOneTimePad).ToArray());


            var offsetToUnscrambled = partialDescramble.IndexOf("==[ Pay") + 7;
            var stillScrambledBytes = cipherBytes.Skip(offsetToUnscrambled).Take(17).ToArray();

            var expectedPlainTextBytes = Encoding.ASCII.GetBytes("load ]===========");

            var last17KeyBytes = ByteArrayFns.XOR(stillScrambledBytes, expectedPlainTextBytes).ToArray();

            var finalOneTimePad = first15KeyBytes.Concat(last17KeyBytes).ToArray();
            var plainTextBytes  = ByteArrayFns.OneTimePadScramble(cipherBytes, finalOneTimePad).ToArray();

            Console.WriteLine(Encoding.ASCII.GetString(plainTextBytes));
            return(0);
        }
Exemplo n.º 4
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(PuzzleFileFns.StandardOneParamRequiredErrorMessage);
                return(1);
            }

            var allLines         = File.ReadAllLines(args[0]);
            int payloadStartLine = PuzzleFileFns.GetLinePayloadStartsAt(allLines);
            var payload          = PuzzleFileFns.GetPayloadAsOneLongString(allLines, payloadStartLine);

            Debug.Assert(payload.StartsWith("<~$O=cdK]PkWZ"));
            Debug.Assert(payload.EndsWith("/UHOHO4@~>"));
            Debug.Assert(payload.Contains("\n") == false);

            var payloadSpan = Ascii85Fns.DecodeAsSpan(payload, 2);

            var kekSpan              = payloadSpan.Slice(0, 32);
            var ivWrapSpan           = payloadSpan.Slice(32, 8);
            var encryptedKeySpan     = payloadSpan.Slice(40, 40);
            var ivSpan               = payloadSpan.Slice(80, 16);
            var encryptedPayloadSpan = payloadSpan.Slice(96);

            Debug.Assert(HexFns.ToHex(kekSpan.ToArray()) == "0b07c91284e54bd5b3a356451eda9d38e9770f505fef14f0e62c74f3fd1f286a");
            Debug.Assert(HexFns.ToHex(ivWrapSpan.ToArray()) == "badc0ffeebadc0de");
            Debug.Assert(HexFns.ToHex(ivSpan.ToArray()) == "8c2e487274dbebe699677f1b54ebbeb4");

            var plainTextKeyBytes = CryptoFns.DecryptKey(kekSpan.ToArray(),
                                                         ivWrapSpan.ToArray(), encryptedKeySpan.ToArray());

            Debug.Assert(HexFns.ToHex(plainTextKeyBytes) == "c68cade3c9c973067b383b77713ddac8072e05d2bb54a8a2d45b312ce8817024");

            var plainText = CryptoFns.Decrypt(plainTextKeyBytes, ivSpan.ToArray(),
                                              encryptedPayloadSpan.ToArray());

            Console.WriteLine(Encoding.ASCII.GetString(plainText));
            return(0);
        }
Exemplo n.º 5
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("\nRequired params:\nparam 1: path to original TDO file");
                Console.WriteLine("\nLinux tips: dotnet run -p layer0 `realpath toms-data-onion.txt`");
                return(1);
            }

            var allLines         = File.ReadAllLines(args[0]);
            int payloadStartLine = PuzzleFileFns.GetLinePayloadStartsAt(allLines);
            var payload          = PuzzleFileFns.GetPayloadAsOneLongString(allLines, payloadStartLine);

            Debug.Assert(payload.StartsWith(@"<~4[!!l9OW3XEZ"));
            Debug.Assert(payload.EndsWith(@"\d<,?I,k/0TI+$46~>"));
            Debug.Assert(payload.Contains("\n") == false);

            var payloadSpan = Ascii85Fns.DecodeAsSpan(payload, 2);

            Console.Write(Encoding.ASCII.GetString(payloadSpan.ToArray()));

            return(0);
        }
Exemplo n.º 6
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(PuzzleFileFns.StandardOneParamRequiredErrorMessage);
                return(1);
            }

            var allLines         = File.ReadAllLines(args[0]);
            int payloadStartLine = PuzzleFileFns.GetLinePayloadStartsAt(allLines);
            var payload          = PuzzleFileFns.GetPayloadAsOneLongString(allLines, payloadStartLine);

            Debug.Assert(payload.StartsWith("<~4J,Yc\"_331o4>"));
            Debug.Assert(payload.EndsWith(@"<Y),nDu&4~>"));
            Debug.Assert(payload.Contains("\n") == false);

            Debug.Assert(ParityFns.OneBitParityCheck(178));
            Debug.Assert(ParityFns.OneBitParityCheck(0b01000001));
            Debug.Assert(ParityFns.OneBitParityCheck(0b00000001) == false);
            Debug.Assert(ParityFns.OneBitParityCheck(0b01001010) == false);

            var bsbTest = new BitStreamBuilder();

            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            bsbTest.Add7Bits(128);
            var bytesTest = bsbTest.MaterializeStream().ToArray();

            Debug.Assert(bytesTest[0] == 129);
            Debug.Assert(bytesTest[1] == 2);
            Debug.Assert(bytesTest[2] == 4);
            Debug.Assert(bytesTest[3] == 8);
            Debug.Assert(bytesTest[4] == 16);
            Debug.Assert(bytesTest[5] == 32);
            Debug.Assert(bytesTest[6] == 64);
            Debug.Assert(bytesTest[7] == 129);

            var payloadSpan = Ascii85Fns.DecodeAsSpan(payload, 2);
            var builder     = new BitStreamBuilder();

            foreach (var aByte in payloadSpan.ToArray())
            {
                if (!ParityFns.OneBitParityCheck(aByte))
                {
                    continue;
                }
                builder.Add7Bits(aByte);
            }

            var decoded = builder.MaterializeStream().ToArray();

            Console.Write(Encoding.ASCII.GetString(decoded));
            return(0);
        }