10. 音屎SQL猟の嘛
なぜパスワ`ドが燕幣されたのか
SELECT * FROM articles A JOIN users U ON U.id=user_id WHERE title LIKE '%'
UNION SELECT 0,0,name,pass,0,'a','a','a' from users where name like '%%' ORDER BY 1
+----+---------+-------+---------+----+------+----------+------------------+
| id | user_id | title | body | id | name | pass | email |
+----+---------+-------+---------+----+------+----------+------------------+
| 5 | 1 | sss | dfdsfsa | 1 | hata | hatahata | h.hata@olt.tokyo |
+---+---+--------------+----------+---+---+---+---+
| 0 | 0 | name | pass | 0 | a | a | a |
+---+---+--------------+----------+---+---+---+---+
| 0 | 0 | hata | hatahata | 0 | a | a | a |
| 0 | 0 | hiro | hiro | 0 | a | a | a |
| 0 | 0 | hata2 | hahata | 0 | a | a | a |
| 0 | 0 | hata2 | hahata | 0 | a | a | a |
| 0 | 0 | hata2 | hahata | 0 | a | a | a |
1朕のSELECTで伏撹された燕┐發箸發頒蹐靴討い娠蹌州献ラムを隔ち、うち3カラムを聞う
2朕のSELECTで伏撹された燕
+----+---------+---------+------------+----+------+----------+-----------+
| id | user_id | title | body | id | name | pass | email |
+----+---------+---------+------------+----+------+----------+-----------+
| 0 | 0 | hata | hatahata | 0 | a | a | a |
| 0 | 0 | hiro | hiro | 0 | a | a | a |
| 0 | 0 | hata2 | hahata | 0 | a | a | a |
| 0 | 0 | rrr | 8888 | 0 | a | a | a |
| 0 | 0 | trew | 5555 | 0 | a | a | a |
| 0 | 0 | hhaat | 11111 | 0 | a | a | a |
UNION
10
14. プログラミング貨
String sql = "SELECT * FROM articles A JOIN users U ON U.id=user_id"+" WHERE title LIKE '%" + word +"%' ORDER BY 1";
ResultSet rs = st.executeQuery(sql);
String sql = "SELECT * FROM articles JOIN users ON user_id=users.id"+" WHERE title LIKE ? ORDER BY 1";
PreparedStatement st = con.prepareStatement(sql);
st.setString(1, "%" + word + "%");
ResultSet rs = st.executeQuery();
俐屎されたコ`ド
冱Zで喘吭されているSQLインジェクション貨C嬬を旋喘する
StringのY栽ではなく、PreparedStatementクラスのsetStringを聞う
廣吭PreparedStatementを聞えばいいのではなく、
プレ`スホルダに、鬟札奪箸垢襪里setStringを聞うことで兜めて貨になる
蒙歩猟忖をエスケ`プする。ただし、返咾任呂覆冱Zごとに喘吭されている
PreparedStatementクラスを聞う
14