Esempio n. 1
0
        //internal static string CreateHash(Packet p)
        //{
        //    string hash = "";
        //    string preIPHash = "";
        //    string preTCPHash = "";
        //    string preUDPHash = "";
        //    IPpacket ip = p.IpPacket;
        //    TCPpacket tcp = p.TcpPacket;
        //    UDPpacket udp = p.UdpPacket;

        //    preIPHash = ip.DesIP + ip.Flags + ip.FragmentationOffset + ip.HeaderLength + ip.Identification + ip.MessageLength + ip.Protocol + ip.SrcIP + ip.Tos + ip.TotalLength + ip.Ttl + ip.Version;
        //    if (p.Type == "TCP")
        //        preTCPHash = tcp.AckNumber + tcp.Checksum + tcp.DataOffset + tcp.DesPort + tcp.HeaderLength + tcp.MessageLength + tcp.SeqNumber + tcp.SrcPort + tcp.UrgentPointer + tcp.Window;
        //    else
        //        preUDPHash = udp.Checksum + udp.DesPort + udp.Length_Header_and_Data + udp.SrcPort;
        //    hash += preIPHash + preTCPHash + preUDPHash;
        //    hash = GetMd5Hash(hash);
        //    return hash;
        //}

        internal static string CreateHash(Packet p, byte[] payload)
        {
            string    stringToBeHashed = "";
            IPpacket  ip  = p.IpPacket;
            TCPpacket tcp = p.TcpPacket;
            UDPpacket udp = p.UdpPacket;

            stringToBeHashed = ip.SrcIP + ip.DesIP + ip.Identification + ip.TotalLength;
            if (tcp != null)
            {
                stringToBeHashed += tcp.DesPort;
            }
            else
            {
                stringToBeHashed += udp.DesPort;
            }
            byte[] indexBuffer = Encoding.UTF8.GetBytes(stringToBeHashed);

            if (payload != null && payload.Length != 0)
            {
                byte[] totalBuffer = new byte[indexBuffer.Length + payload.Length];
                Buffer.BlockCopy(indexBuffer, 0, totalBuffer, 0, indexBuffer.Length);
                Buffer.BlockCopy(payload, 0, totalBuffer, indexBuffer.Length, payload.Length);
                return(GetMd5Hash(totalBuffer, totalBuffer.Length));
            }
            else
            {
                return(GetMd5Hash(indexBuffer, indexBuffer.Length));
            }
        }
Esempio n. 2
0
        internal static UDPpacket CreateUDPpacket(UDPHeader udpHeader)
        {
            UDPpacket udp = new UDPpacket();

            udp.Checksum = udpHeader.RawChecksum;
            udp.DesPort  = udpHeader.DestinationPort;
            udp.Length_Header_and_Data = udpHeader.Length;
            udp.SrcPort = udpHeader.SourcePort;
            return(udp);
        }