web安全之資料庫相關知識
web安全
MySQL注入常用函式
system_user() 系統使用者名稱 concat() 沒有分隔符地連線字串 user() 使用者名稱 concat_ws() 含有分隔符地連結字串 current_user() 當前使用者名稱 group_concat() 連線一個組的所有字串,並以逗號分割一條資料 session_user() 連結資料庫使用者名稱 load_file() 讀取本地檔案 database() 資料庫名 into outfile 寫檔案 version() 資料庫版本 ascii() 字串的ASCII程式碼值 @@datadir 資料庫路徑 ord() 返回字串第一個字元發ASCII值 @@basedir 資料庫安裝路徑 mid() 返回一個字串的一部分 @@version_compile_os 作業系統 substr() 返回一個字串的一部分 count() 返回執行結果數量 length() 返回字串的長度 left() 返回字串最左面的幾個字元 sleep() 讓此語句執行N秒 floot() 返回小於或等於x的最大整數 if()>SELECT(1>2,2,3);->3 rand() 返回0和1之間的一個整數 char() 返回整數ASCII程式碼字元組成的字串 extractvalue() 第一個引數:XML document是string格式 第二個引數:XPath string(XPath格式的字串) 作用:從目標XML中返回包含所查詢的字串 updatexml() 第一個引數:XML document是String格式 第二個引數:Xpath string 第三個引數:new value,String格式,醍醐你查詢到的符合條件的資料 作用:改變文件中符合條件的節點的值 STRCMP() 比較字串內容 IFNULL() 加入引數1不為NULL,返回值為引數1,否則返回值為引數2 exp() 返回e的x次方
MySQL運算子
in:
mysql> select id ,username from users where username in ('admin','tesdt');
+----+----------+
| id | username |
+----+----------+
| 8 | admin |
+----+----------+
not in:
mysql> select id ,username from users where username not in ('admin','tesdt'); +----+----------+ | id | username | +----+----------+ | 1 | Dumb | | 2 | Angelina | | 3 | Dummy | | 4 | secure | | 5 | stupid | | 6 | superman | | 7 | batman | | 9 | admin1 | | 10 | admin2 | | 11 | admin3 | | 12 | dhakkan | | 14 | admin4 | +----+----------+
like
mysql> select id ,username from users where username like 'admin'; +----+----------+ | id | username | +----+----------+ | 8 | admin | +----+----------+ 1 row in set (0.00 sec) mysql> select id ,username from users where username like '%admin%'; +----+----------+ | id | username | +----+----------+ | 8 | admin | | 9 | admin1 | | 10 | admin2 | | 11 | admin3 | | 14 | admin4 | +----+----------+ 5 rows in set (0.00 sec)
regexp
mysql> select user();
+----------------+
| user() |
+----------------+
| [email protected] |
+----------------+
1 row in set (0.00 sec)
mysql> select user() regexp 'root';
+----------------------+
| user() regexp 'root' |
+----------------------+
| 1 |
+----------------------+
1 row in set (0.00 sec)
mysql> select user() regexp 'root0';
+-----------------------+
| user() regexp 'root0' |
+-----------------------+
| 0 |
+-----------------------+
1 row in set (0.00 sec)
MySQL邏輯運算
and or
mysql> select * from users where id =1 and 1=2;
Empty set (0.00 sec)
mysql> select * from users where id =1 and 1=1;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)
mysql> select * from users where id =1 or 1=2;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | Dumb | Dumb |
+----+----------+----------+
1 row in set (0.00 sec)
萬能密碼: ‘or ‘1’ ='1
登入處的SQL語句:select * from users where username= ‘admin’ and pwd= ‘pass’;
加入萬能密碼後語句:select * from users where username=’ ‘or ‘1’ =‘1’ and pwd =’’ or’1’=‘1’;