Beispiel #1
0
        public byte[] MakeLoginPacket(byte[] salt, out byte[] data, out int len)
        {
            int pwlen = Password.Length;

            byte[] mac = MAC.GetAddressBytes();
            byte[] md5_src;
            data = new byte[400];

            int i = 0;

            // Begin
            data[i++] = 0x03;
            data[i++] = 0x01;
            data[i++] = 0x00;
            data[i++] = (byte)(Username.Length + 20);

            // MD5 A
            md5_src    = new byte[6 + pwlen];
            md5_src[0] = 3;
            md5_src[1] = 1;
            Buffer.BlockCopy(salt, 0, md5_src, 2, 4);
            Buffer.BlockCopy(Encoding.Default.GetBytes(Password), 0, md5_src, 6, pwlen);
            md5a = MD5(md5_src);
            Buffer.BlockCopy(md5a, 0, data, 4, 16);
            i += 16;

            // Username
            Buffer.BlockCopy(Encoding.Default.GetBytes(Username), 0, data, i, Username.Length);
            i += Username.Length > 36 ? Username.Length : 36;

            // CONTROLCHECKSTATUS ADAPTERNUM
            data[i++] = 0x20;
            data[i++] = 0x03;

            /* (data[4:10].encode('hex'),16)^mac */
            Buffer.BlockCopy(md5a, 0, data, i, 6);
            for (int j = 0; j < 6; j++)
            {
                data[i + j] ^= mac[j];
            }
            i += 6;

            // MD5 B
            md5_src    = new byte[9 + pwlen];
            md5_src[0] = 1;
            Buffer.BlockCopy(Encoding.Default.GetBytes(Password), 0, md5_src, 1, pwlen);
            Buffer.BlockCopy(salt, 0, md5_src, 1 + pwlen, 4);
            Buffer.BlockCopy(MD5(md5_src), 0, data, i, 16);
            i += 16;

            // Ip number, 1, 2, 3, 4
            data[i++] = 0x01;
            Buffer.BlockCopy(ClientIP.GetAddressBytes(), 0, data, i, 4);
            i += 16;

            // MD5 C
            md5_src = new byte[i + 4];
            Buffer.BlockCopy(data, 0, md5_src, 0, i);
            md5_src[i + 0] = 0x14;
            md5_src[i + 1] = 0x00;
            md5_src[i + 2] = 0x07;
            md5_src[i + 3] = 0x0b;
            Buffer.BlockCopy(MD5(md5_src), 0, data, i, 8);
            i += 8;

            // IPDOG(0x01) 0x00*4
            data[i++] = 0x01;
            i        += 4;

            // Host Name
            md5_src = Encoding.Default.GetBytes(HostName);
            Buffer.BlockCopy(md5_src, 0, data, i, md5_src.Length > 32 ? 32 : md5_src.Length);
            i += 32;

            // primary dns
            Buffer.BlockCopy(PrimaryDNS.GetAddressBytes(), 0, data, i, 4);
            i += 4;

            // DHCP Server
            Buffer.BlockCopy(DefaultDHCP.GetAddressBytes(), 0, data, i, 4);
            i += 4;

            // secondary dns
            Buffer.BlockCopy(SecondaryDNS.GetAddressBytes(), 0, data, i, 4);
            i += 4;

            // delimeter
            i += 8;

            // unknown os_major os_minor OS_build os_unknown
            data[i++] = 0x94;
            i        += 3;
            data[i++] = 0x06;
            i        += 3;
            data[i++] = 0x02;
            i        += 3;
            data[i++] = 0xf0;
            data[i++] = 0x23;
            i        += 2;
            data[i++] = 0x02;
            i        += 3;

            // unknown string
            data[i++] = 0x44;
            data[i++] = 0x72;
            data[i++] = 0x43;
            data[i++] = 0x4f;
            data[i++] = 0x4d;
            i++;
            data[i++] = 0xcf;
            data[i++] = 0x07;
            data[i++] = 0x68;
            i        += 55;

            // unknown string 2
            data[i++] = 0x33;
            data[i++] = 0x64;
            data[i++] = 0x63;
            data[i++] = 0x37;
            data[i++] = 0x39;
            data[i++] = 0x66;
            data[i++] = 0x35;
            data[i++] = 0x32;
            data[i++] = 0x31;
            data[i++] = 0x32;
            data[i++] = 0x65;
            data[i++] = 0x38;
            data[i++] = 0x31;
            data[i++] = 0x37;
            data[i++] = 0x30;
            data[i++] = 0x61;
            data[i++] = 0x63;
            data[i++] = 0x66;
            data[i++] = 0x61;
            data[i++] = 0x39;
            data[i++] = 0x65;
            data[i++] = 0x63;
            data[i++] = 0x39;
            data[i++] = 0x35;
            data[i++] = 0x66;
            data[i++] = 0x31;
            data[i++] = 0x64;
            data[i++] = 0x37;
            data[i++] = 0x34;
            data[i++] = 0x39;
            data[i++] = 0x31;
            data[i++] = 0x36;
            data[i++] = 0x35;
            data[i++] = 0x34;
            data[i++] = 0x32;
            data[i++] = 0x62;
            data[i++] = 0x65;
            data[i++] = 0x37;
            data[i++] = 0x62;
            data[i++] = 0x31;
            i        += 24;

            // auth version
            data[i++] = 0x68;
            data[i++] = 0x00;

            data[i++] = 0x00;
            data[i++] = (byte)(pwlen);

            // ror password
            for (int k = 0, x; k < pwlen; k++)
            {
                x         = md5a[k] ^ Password[k];
                data[i++] = (byte)(((x << 3) & 0xFF) + (x >> 5));
            }

            data[i++] = 0x02;
            data[i++] = 0x0c;

            // checksum point
            int check_point = i;

            data[i++] = 0x01;
            data[i++] = 0x26;
            data[i++] = 0x07;
            data[i++] = 0x11;

            // 0x00 0x00 mac
            i += 2;
            Buffer.BlockCopy(mac, 0, data, i, 6);
            i += 6;

            // checksum
            ulong sum   = 1234;
            ulong check = 0;

            for (int k = 0; k < i; k += 4)
            {
                check = 0;
                for (int j = 0; j < 4; j++)
                {
                    check = (check << 2) + data[k + j];
                }
                sum ^= check;
            }
            sum = (1968 * sum) & 0xFFFFFFFF;
            for (int j = 0; j < 4; j++)
            {
                data[check_point + j] = (byte)(sum >> (j * 8) & 0x000000FF);
            }


            if (pwlen / 4 != 4)
            {
                i += (pwlen / 4);
            }
            i        += 4;
            data[i++] = 0x60;
            data[i++] = 0xa2;
            i        += 28;
            len       = i;

#if DEBUG
            OnLog.Invoke("mkpkt", data, true);
#else
            OnLog.Invoke("login", "Making login packet...", false);
#endif
            return(data);
        }
Beispiel #2
0
 private void OnWakeOnLan(object parameter)
 {
     WakeOnLan(MAC.GetAddressBytes());
     Task.Run(() => { CheckStatus(1000, 10); });
 }