3
선생님과 저는 준비된 문으로 SQL 주입이 가능한지 여부에 대한 토론을하고 있습니다. 나는 보통 당신이 할 수 없다는 것을 이해하지만, 교수는 (?) 대신에 SQL 연결을 사용하라고 주장한다.SQL 삽입 및 준비된 문
이제 코드를 해독하려고하는데 행운이 없습니다.
public Users getUserByUsername(String username) throws SQLException {
StringBuffer sql = new StringBuffer();
sql.append("select * from users as u, user_type_lookup as l, user_types as t ");
sql.append("where u.users_id=l.user_id and l.type_id=t.user_types_id and u.username='");
sql.append(username);
sql.append("';");
System.out.println(sql.toString());
PreparedStatement ps = conn.prepareStatement(sql.toString());
ResultSet rs = ps.executeQuery(sql.toString());
if (!rs.next()) {
return null;
}
String password = rs.getString("password");
String type = rs.getString("description");
int id = rs.getInt("users_id");
int incorrect_logins = rs.getInt("incorrect_logins");
Time wait_time = rs.getTime("wait_time");
Users u = new Users(id, username, password, type, incorrect_logins,
wait_time);
return u;
}
삽입 나는 시도했다 :
string: '; DELETE FROM users WHERE 1 or users_id = '
string: ';delete from users where username<>'
//The only one that worked
string: stan' or 'a'<>'b
SQL 출력 (자바 오류가 발생) : (의도 된 작품으로)
select * from users as u, user_type_lookup as l, user_types as t where u.users_id=l.user_id and l.type_id=t.user_types_id and u.username=''; DELETE FROM users WHERE 1 or users_id = '';
SQL 출력 :
select * from users as u, user_type_lookup as l, user_types as t where u.users_id=l.user_id and l.type_id=t.user_types_id and u.username='stan';
을
오류 메시지 :
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near 'DELETE FROM users WHERE 1 or users_id = ''' at line 1
서버 : 톰캣 7
데이터베이스 : MySQL의
IDE : 언어
이클립스 : 자바그래서 내 암호를 해독 도와주세요! 예를 들어,
준비된 문은 일반적으로 값을 이스케이프 처리합니다. 값이 이미 이스케이프 된 경우 연결을 사용해야합니다. – kirilloid
나는 이것이 "Prep Prepared Statements를 SQL Injection으로 공격 할 수 있는가?"라는 측면에서 좋은 질문이라고 생각하지만, 실제로는 그런 말로 표현되지 않습니다 ... 당신은 대답 을 제공 할 수있다. – scunliffe
SQL을 해당 명령문에 삽입 할 수 있다고하더라도 코드를 작성한 방식 덕분에 SQL을 삽입 할 수있었습니다. 그건 준비된 진술이 아닙니다. – NullUserException