Beispiel #1
0
 public Connection(Tamir.IPLib.Packets.TCPPacket packet)
 {
     m_srcIp = packet.SourceAddress; 
     m_dstIp = packet.DestinationAddress;
     m_srcPort = (ushort)packet.SourcePort;
     m_dstPort = (ushort)packet.DestinationPort;
 }
        private static void device_PcapOnPacketArrival(object sender, Tamir.IPLib.Packets.Packet packet)
        {
            if(packet is EthernetPacket)
            {
                EthernetPacket eth = ((EthernetPacket)packet);
                Console.WriteLine("Original packet: "+eth.ToColoredString(false));

                //Manipulate ethernet parameters
                eth.SourceHwAddress = "00:11:22:33:44:55";
                eth.DestinationHwAddress = "00:99:88:77:66:55";

                if (packet is IPPacket)
                {
                    IPPacket ip = ((IPPacket)packet);

                    //manipulate IP parameters
                    ip.SourceAddress = "1.2.3.4";
                    ip.DestinationAddress = "44.33.22.11";
                    ip.TimeToLive = 11;

                    //Recalculate the IP checksum
                    ip.ComputeIPChecksum();

                    if (ip is TCPPacket)
                    {
                        TCPPacket tcp = ((TCPPacket)ip);

                        //manipulate TCP parameters
                        tcp.SourcePort = 9999;
                        tcp.DestinationPort = 8888;
                        tcp.Syn = !tcp.Syn;
                        tcp.Fin = !tcp.Fin;
                        tcp.Ack = !tcp.Ack;
                        tcp.WindowSize = 500;
                        tcp.AcknowledgementNumber = 800;
                        tcp.SequenceNumber = 800;

                        //Recalculate the TCP checksum
                        tcp.ComputeTCPChecksum();
                    }

                    if (ip is UDPPacket)
                    {
                        UDPPacket udp = ((UDPPacket)ip);

                        //manipulate UDP parameters
                        udp.SourcePort = 9999;
                        udp.DestinationPort = 8888;

                        //Recalculate the UDP checksum
                        udp.ComputeUDPChecksum();
                    }
                }
                Console.WriteLine("Manipulated packet: "+eth.ToColoredString(false));
            }
        }
    /// <summary>
    /// The main function of the class receives a tcp packet and reconstructs the stream
    /// </summary>
    /// <param name="tcpPacket"></param>
    public void ReassemblePacket(Tamir.IPLib.Packets.TCPPacket tcpPacket)
    {
        // if the paylod length is zero bail out
        ulong length = (ulong)(tcpPacket.TCPPacketByteLength - tcpPacket.TCPHeaderLength);
        if (length == 0) return;

        reassemble_tcp((ulong)tcpPacket.SequenceNumber, length,
                       tcpPacket.TCPData, (ulong)tcpPacket.TCPData.Length, tcpPacket.Syn,
                       tcpPacket.SourceAddressAsLong,tcpPacket.DestinationAddressAsLong,
                       (uint)tcpPacket.SourcePort, (uint)tcpPacket.DestinationPort);
    }
 void dev_PcapOnPacketArrival(object sender, Tamir.IPLib.Packets.Packet packet)
 {
     lock(packets) {
         packets.Add(packet);
         newpackets.Add(packet);
     }
     if(dev.PcapDumpOpened) {
         dev.PcapDump(packet);
     }
     this.Invoke(updater);
 }
Beispiel #5
0
        /// <summary>
        /// Helper function that extracts error messages from SharpSSH style exceptions and converts them into regular .Net exception messages
        /// </summary>
        /// <param name="sx">The exception to convert</param>
        /// <returns>The converted exception</returns>
        private static Exception ReshapeSharpSSHException(Tamir.SharpSsh.jsch.SftpException sx)
        {
            string idstr;
            if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_OK)
                idstr = "OK";
            else if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_EOF)
                idstr = "EOF";
            else if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_NO_SUCH_FILE)
                idstr = "NO_SUCH_FILE";
            else if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_PERMISSION_DENIED)
                idstr = "PERMISSION_DENIED";
            else if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_FAILURE)
                idstr = "FAILURE";
            else if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_BAD_MESSAGE)
                idstr = "BAD_MESSAGE";
            else if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_NO_CONNECTION)
                idstr = "NO_CONNECTION";
            else if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_CONNECTION_LOST)
                idstr = "CONNECTION_LOST";
            else if (sx.id == Tamir.SharpSsh.jsch.ChannelSftp.SSH_FX_OP_UNSUPPORTED)
                idstr = "UNSUPPORTED";
            else
                idstr = "UNKNOWN";

            return new Exception(string.Format("{0} - {1}: {2}", sx.id, idstr, sx.message), sx);
        }
		public StringBuffer append(Tamir.SharpSsh.java.String s)
		{
			return append(s.ToString());
		}
		public StringBuffer(Tamir.SharpSsh.java.String s):this(s.ToString())
		{
		}
Beispiel #8
0
 private void device_PcapOnPacketArrival(object sender, Tamir.IPLib.Packets.Packet packet)
 {
     Console.WriteLine(packet);
 }
Beispiel #9
0
        /// <summary>
        /// The main function of the class receives a tcp packet and reconstructs the stream
        /// </summary>
        /// <param name="tcpPacket"></param>
        public void ReassemblePacket(Tamir.IPLib.Packets.TCPPacket tcpPacket)
        {
            // if the paylod length is zero bail out
            ulong length = (ulong)(tcpPacket.TCPPacketByteLength - tcpPacket.TCPHeaderLength);
            if (length == 0) return;

            // Raise Events
            if (tcpPacket.Syn && tcpPacket.Ack)
                this.OnSynRecived(this);
            else if (tcpPacket.Fin && tcpPacket.Ack)
                this.OnFinRecived(this);
            else if (tcpPacket.Rst)
                this.OnRstRecived(this);

            reassemble_tcp((ulong)tcpPacket.SequenceNumber, length,
                           tcpPacket.TCPData, (ulong)tcpPacket.TCPData.Length, tcpPacket.Syn,
                           tcpPacket.SourceAddressAsLong, tcpPacket.DestinationAddressAsLong,
                           (uint)tcpPacket.SourcePort, (uint)tcpPacket.DestinationPort);
        }
Beispiel #10
0
 public void PutWithStream(Tamir.SharpSsh.java.io.InputStream stream, string toDirPath)
 {
     cancelled = false;
     SftpChannel.put(stream, toDirPath, m_monitor) ;
 }
Beispiel #11
0
 public void GetWithStream(string fromFilePath, Tamir.SharpSsh.java.io.OutputStream stream)
 {
     cancelled = false;
     SftpChannel.get(fromFilePath, stream, m_monitor);
 }
Beispiel #12
0
 public static int GenerateHashCode(Tamir.IPLib.Packets.TCPPacket packet)
 {
     return ((packet.SourceAddress.GetHashCode() ^ packet.SourcePort.GetHashCode()) as object).GetHashCode() ^
      ((packet.DestinationAddress.GetHashCode() ^ packet.DestinationPort.GetHashCode()) as object).GetHashCode();
 }