⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 packetnbns.cs

📁 一个抓包工具
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Windows.Forms;

namespace MyClasses
{

	public class PacketNBNS
	{

		public struct QUESTION_ITEM
		{
			public string Name;
			public ushort Type;
			public ushort Class;
		}

		public struct QUESTIONS
		{
			public QUESTION_ITEM [] Items;
		}

		public struct ANSWER_ITEM
		{
			public string Name;
			public ushort Flags;
		}

		
		public struct ANSWERS
		{
			public string Name;
			public ushort Type;
			public ushort Class;
			public uint TimeToLive;
			public ushort DataLength;
			public byte NumberOfNames;
			public ANSWER_ITEM [] Items;
			public string UnitId;
			public byte Jumpers;
			public byte TestResult;
			public ushort VersionNumber;
			public ushort PeriodOfStatistics;
			public ushort CRCs;
			public ushort NumberOfAlignmentErrors;
			public ushort NumberOfCollisions;
			public ushort NumberOfSendAborts;
			public uint NumberOfGoodSends;
			public uint NumberOfReceives;
			public ushort NumberOfRetransmits;
			public ushort NumberOfNoResourceConditions;
			public ushort NumberOfCommandBlocks;
			public ushort NumberOfPendingSessions;
			public ushort MaxNumberOfPendingSessions;
			public ushort MaxTotalSessionPossible;
			public ushort SessionDataPacketSize;
		}

		public struct AUTHORITY_ITEM
		{
			public string Name;
			public ushort Type;
			public ushort Class;
		}

		public struct AUTHORITIES
		{
			public AUTHORITY_ITEM [] Items;
		}

		public struct ADDITIONAL_ITEM
		{
			public string Name;
			public ushort Type;
			public ushort Class;
			public uint TimeToLive;
			public ushort DataLength;
			public ushort Flags;
			public string Address;
		}

		public struct ADDITIONALS
		{
			public ADDITIONAL_ITEM [] Items;
		}


		public struct PACKET_NBNS
		{
			public ushort TransactionId;
			public ushort Flags;
			public ushort QuestionRRS;
			public ushort AnswerRRS;
			public ushort AuthorityRRS;
			public ushort AdditionalRRS;
			public QUESTIONS Questions;
			public ANSWERS Answers;
			public AUTHORITIES Authorities;
			public ADDITIONALS Additionals;

		}


		public PacketNBNS()
		{
		}


		public static string GetTypeString( ushort u )
		{
			string Tmp = "";

			switch( u )
			{
				case Const.TYPE_NB	 : Tmp = "NB"; break;
				case Const.TYPE_NBSTAT :  Tmp = "NBSTAT"; break;
				default : Tmp = "Unknown"; break;
			}

			return Tmp;
		}


		public static string GetClassString( ushort u )
		{
			string Tmp = "";

			switch( u )
			{
				case Const.CLASS_INET	: Tmp = "inet"; break;
				case ( Const.CLASS_INET | Const.CLASS_FLUSH ) : Tmp = "inet ( data flush )"; break;
				case Const.CLASS_CSNET : Tmp = "Csnet"; break;				case Const.CLASS_CHAOS : Tmp = "Chaos"; break;				case Const.CLASS_HESIOD : Tmp = "Hesiod"; break;				case Const.CLASS_NONE	 : Tmp = "None"; break;				case Const.CLASS_ANY	 : Tmp = "Any"; break;			}

			return Tmp;
		}


		public static string GetErrorCodeString( byte b )
		{
			int i = 0;
			string [] ErrorCodeList = new string[16];

			for( i = 0; i < 16; i ++ )
				ErrorCodeList[i] = "Unknown";

			ErrorCodeList[0x00] = "Not listening on called name";			ErrorCodeList[0x01] = "Not listening for called name";			ErrorCodeList[0x02] = "Called name not present";			ErrorCodeList[0x03] = "Called name present, but insufficient resources";			ErrorCodeList[0x0F] = "Unspecified error";
			return ErrorCodeList[ b - 0x80 ];
		}

		public static bool Parser( ref TreeNodeCollection mNode, 
			byte [] PacketData , 
			ref int Index , 
			ref ListViewItem LItem )
		{
			TreeNode mNodex;
			TreeNode mNode1;
			TreeNode mNode2;
			TreeNode mNode3;
			string Tmp = "";
			int kk = 0 , kkk = 0;
			int i = 0;
			byte NNumber = 0;
			PACKET_NBNS PNbns;
			string [] NBFlagsNodeTypeList = new string[4];
			string [] NameFlagsNodeTypeList = new string[3];
			string [] OpCodeList = new string[16];
			string [] ReplyList = new string[8];

			for( i = 0; i < 8; i ++ )
				ReplyList[i] = "Unknown";

			for( i = 0; i < 16; i ++ )
				OpCodeList[i] = "Unknown";

			NBFlagsNodeTypeList[0] = "B-mode node";
			NBFlagsNodeTypeList[1] = "P-mode node";
			NBFlagsNodeTypeList[2] = "M-mode node";
			NBFlagsNodeTypeList[3] = "H-mode node";

			NameFlagsNodeTypeList[Const.NAME_FLAGS_B_NODE] = "B-mode node";
			NameFlagsNodeTypeList[Const.NAME_FLAGS_P_NODE] = "P-mode node";
			NameFlagsNodeTypeList[Const.NAME_FLAGS_M_NODE] = "M-mode node";

			OpCodeList[Const.OPCODE_QUERY] = "Name query";			OpCodeList[Const.OPCODE_REGISTRATION] = "Registration";			OpCodeList[Const.OPCODE_RELEASE] = "Release";			OpCodeList[Const.OPCODE_WACK] = "Wait for acknowledgment";			OpCodeList[Const.OPCODE_REFRESH] = "Refresh";			OpCodeList[Const.OPCODE_REFRESHALT] = "Refresh (alternate opcode)";			OpCodeList[Const.OPCODE_MHREGISTRATION] = "Multi-homed registration";
			ReplyList[Const.RCODE_NOERROR] = "No error";			ReplyList[Const.RCODE_FMTERROR] = "Request was invalidly formatted";			ReplyList[Const.RCODE_SERVFAIL] = "Server failure";			ReplyList[Const.RCODE_NAMEERROR] = "Requested name does not exist";			ReplyList[Const.RCODE_NOTIMPL] = "Request is not implemented";			ReplyList[Const.RCODE_REFUSED] = "Request was refused";			ReplyList[Const.RCODE_ACTIVE] = "Name is owned by another node";			ReplyList[Const.RCODE_CONFLICT] = "Name is in conflict";
			mNodex = new TreeNode();
			mNodex.Text = "NBNS ( Netbios Name Service )";
			kk = Index;

			try
			{
				PNbns.TransactionId = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				Tmp = "Transaction Id :" + Function.ReFormatString( PNbns.TransactionId , null );
				mNodex.Nodes.Add( Tmp );
				Function.SetPosition( ref mNodex , Index - 2 , 2 , false );

				PNbns.Flags = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				mNode1 = new TreeNode();
				mNode1.Text = "Flags :" + Function.ReFormatString( PNbns.Flags , null );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , true );
				mNode1.Nodes.Add( Function.DecodeBitField( PNbns.Flags , 0x8000 , "Message is a response", "Message is a query" ) );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
				mNode1.Nodes.Add( Function.DecodeBitField( PNbns.Flags , 0x7800 , OpCodeList ) );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
				mNode1.Nodes.Add( Function.DecodeBitField( PNbns.Flags , 0x0400 , "Authoritative : Server is an authority for domain", "Authoritative : Server is not an authority for domain" ) );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
				mNode1.Nodes.Add( Function.DecodeBitField( PNbns.Flags , 0x0200 , "Truncated : Message is truncated", "Truncated : Message is not truncated" ) );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
				mNode1.Nodes.Add( Function.DecodeBitField( PNbns.Flags , 0x0100 , "Recursion Desired : Do query recursively", "Recursion Desired : Don't do query recursively" ) );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
				mNode1.Nodes.Add( Function.DecodeBitField( PNbns.Flags , 0x0080 , "Recursion Available : Server can do recursive queries", "Recursion Available : Server cann't do recursive queries" ) );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
				mNode1.Nodes.Add( Function.DecodeBitField( PNbns.Flags , 0x0010 , "Broadcast : Packet is broadcast", "Broadcast : Packet is not broadcast" ) );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
				mNode1.Nodes.Add( Function.DecodeBitField( PNbns.Flags , 0x000f , ReplyList ) );
				Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
				mNodex.Nodes.Add( mNode1 );

				PNbns.QuestionRRS = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				Tmp = "Question RRS :" + Function.ReFormatString( PNbns.QuestionRRS , null );
				mNodex.Nodes.Add( Tmp );
				Function.SetPosition( ref mNodex , Index - 2 , 2 , false );

				PNbns.AnswerRRS = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				Tmp = "Answer RRS :" + Function.ReFormatString( PNbns.AnswerRRS , null );
				mNodex.Nodes.Add( Tmp );
				Function.SetPosition( ref mNodex , Index - 2 , 2 , false );

				PNbns.AuthorityRRS = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				Tmp = "Authority RRS :" + Function.ReFormatString( PNbns.AuthorityRRS , null );
				mNodex.Nodes.Add( Tmp );
				Function.SetPosition( ref mNodex , Index - 2 , 2 , false );

				PNbns.AdditionalRRS = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				Tmp = "Additional RRS :" + Function.ReFormatString( PNbns.AdditionalRRS , null );
				mNodex.Nodes.Add( Tmp );
				Function.SetPosition( ref mNodex , Index - 2 , 2 , false );

				if( PNbns.QuestionRRS > 0 )
				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -