O Servlet abaixo possui uma brecha de segurança bastante grave. O ambiente
onde a brecha foi testada é o Tomcat com SQLServer.
Só por curiosidade, alguém consegue ver aonde está essa brecha?
public class BadServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doPost(request,response);
}
private Connection getConnection() throws Exception {
// retorna conexao com o SQLServer...
}
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
// Mostra o nome do usuário a partir do usuario_id...
String userid = request.getParameter("userid");
String nome = null;
try {
Connection conn = getConnection();
Statement query = conn.createStatement();
StringBuffer sql = new StringBuffer();
sql.append("SELECT Nome FROM Users WHERE userid = ");
sql.append(userid);
ResultSet results = query.executeQuery(sql.toString());
if (results.next()) nome = results.getString(1);
query.close();
conn.close();
} catch(Exception e) {
throw new IOException("Problemas: " + e.getMessage());
}
PrintWriter pw = response.getWriter();
if (nome != null) pw.println("<h1>" + nome + "</h1>");
else pw.println("<h1>Nao achei!!!</h1>");
}
}
------------------------------
Sergio Oliveira Jr.
Sun Certified Java Programmer
Desenvolvedor e Consultor Java
------------------------------
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------