[英]logout date and time without login
實際上我有一個嚴重的問題:我看到有人從日本訪問過我的網站,而我沒有向未經授權的用戶提供任何登錄ID和密碼。 我將用戶ID和密碼分配給只有經過身份驗證的用戶,我正在跟蹤登錄,注銷時間以及登錄和注銷IP地址詳細信息,當經過身份驗證的用戶登錄時。但我發現在我的數據庫中沒有登錄時間,登錄用戶ID,登錄IP地址,但有注銷時間,我的數據庫中存在注銷IP地址,其中userid為null。 這怎么可能??? 一位來自日本的人已於16:20:18從我的網站退出,因為他還沒有登錄如何? 沒有登錄注銷?
我的Web應用程序是jsp,servlets,java類和oracle 10g:我給出了以下保護:
1. CSRF Protection
2. SQL Injection protection
3. XSS Protection
4. No Broken Authentication and session
我很快就會放入SSL。
HttpSession session1 = request.getSession(false);
PrintWriter out = response.getWriter();
try{
if(request.getMethod().equalsIgnoreCase("POST")){
String user="";
String timenow="";
String strQuery="";
String today="";
String tour="";
try{
String useridfinal = (String)request.getParameter("userid");
String userpassfinal = (String)request.getParameter("userpassword");
Pattern p10 = Pattern.compile("[A-Z0-9a-z]+");// XSS checking
Matcher m10 = p10.matcher(useridfinal);
boolean b10 = m10.matches();
Pattern p11 = Pattern.compile("[A-Z!_,.a-z0-9]+");// XSS checking
Matcher m11 = p11.matcher(userpassfinal);
boolean b11 = m11.matches();
if(useridfinal == null || b10==false){
session1.setAttribute("errorlogin", "Invalid Login ID or userpassword");
response.sendRedirect("login.jsp");
}
else if(userpassfinal == null || b11==false){
session1.setAttribute("errorlogin", "Invalid Login ID or userpassword");
response.sendRedirect("login.jsp");
}
else{
try {
dbconnection db= new dbconnection();
db.getConnection();
PreparedStatement ps=null;
PreparedStatement ps2=null;
ResultSet rs=null;
ResultSet rs1=null;
String ipadd="";
try {
ipadd= request.getRemoteAddr();//tracking IP address
}
catch(Exception e) {
}
SimpleDateFormat sdfDate = new SimpleDateFormat("dd-MM-yy HH:mm:ss");
Date now = new Date();
String strDate = sdfDate.format(now);
if(request.getParameter("userid")!=null &&
(request.getParameter("userid") == null ? "" != null : !request.getParameter("userid").equals("")) && request.getParameter("userpassword")!=null &&
(request.getParameter("userpassword") == null ? "" != null : !request.getParameter("userpassword").equals("")))
{
if ( session1 != null) {
session1.invalidate(); }
session1 = request.getSession(true);
String s=(String)useridfinal;
MessageDigest m=MessageDigest.getInstance("MD5");
m.update(s.getBytes(),0,s.length());
String encuseridfinal=(new BigInteger(1,m.digest()).toString(16));
String s1=(String)userpassfinal;
MessageDigest m1=MessageDigest.getInstance("MD5");
m1.update(s1.getBytes(),0,s1.length());
String encuserpassfinal=(new BigInteger(1,m1.digest()).toString(16));
ps= db.con.prepareStatement("select * from login where loginid=? and loginpass=? ");
ps.setString(1, useridfinal);
ps.setString(2, encuserpassfinal);// encrypted userpassword
try {
rs=ps.executeQuery();
} catch (SQLException ex) {
}
int count=0;
while(rs.next())
{
count++;
try {
//Initialize SecureRandom
//This is a lengthy operation, to be done only upon
//initialization of the application
SecureRandom prng = SecureRandom.getInstance("SHA1PRNG");
//generate a random number
String randomNum = new Integer( prng.nextInt() ).toString();
//get its digest
MessageDigest sha = MessageDigest.getInstance("SHA-1");
byte[] result = sha.digest( randomNum.getBytes() );
String csrf="";
csrf=hexEncode(result);
try{
Calendar calendar = new GregorianCalendar();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
today=(+hour+":"+minute+":"+second +"");
Date date = new Date();
SimpleDateFormat sdf = null;
String strDate1 = "";
sdf = new SimpleDateFormat("dd-MM-yy");
strDate1 = sdf.format(date);
tour=strDate1+" "+today;
try{
ps2 = db.con.prepareStatement("insert into logindetails (login_id, login_dt, login_ipaddress) values (?, to_date(?, 'DD-MM-YY hh24:mi:ss'),?) ");
}
catch(Exception e){
}
ps2.setString(1, useridfinal);
try{
ps2.setString(2, tour);
}
catch(Exception e){}
try{
ps2.setString(3, ipadd);
}
catch(Exception e){}
try {
rs1=ps2.executeQuery();
}
catch(SQLException ex){
}
rs1.close();
ps2.close();
}
catch(Exception e){
}
session1.setAttribute("useridfinal", useridfinal);
session1.setAttribute("csrftoken", csrf); //csrf token generation
response.sendRedirect("home.jsp");
session1.setAttribute("authenticated", true);
}
catch(Exception e){}
}
try{
rs.close();
}
catch(Exception e){}
try{
ps.close();
}
catch(Exception e){}
try{
db.removeConnection();
}
catch(Exception e){}
if(count==0)
{
session1.setAttribute("errorlogin", "Invalid Login ID or userpassword");
response.sendRedirect("login.jsp");
}
}
else {
session1.setAttribute("errorlogin", "Invalid Login ID or userpassword");
response.sendRedirect("login.jsp");
}
} catch (Exception e) {
}
}
} catch (Exception e) {
out.println("please try later");
}
}
else{
response.sendRedirect("login.jsp");
}
} catch (Exception e) {
response.sendRedirect("login.jsp");
}
processRequest(request, response);
}
function() {// For generating secure token
return token;
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META NAME="ROBOTS" CONTENT="NONE">
<META NAME="GOOGLEBOT" CONTENT="NOARCHIVE">
</head>
<body>
<%
String user="";
HttpSession session1 = request.getSession(false);
if(session1.getAttribute("useridfinal")!=null &&
session1.getAttribute("useridfinal")!="")
{
user = session1.getAttribute("useridfinal").toString();
}
String today="";
String tour="";
dbconnection db= new dbconnection();
db.getConnection();
PreparedStatement ps=null;
PreparedStatement ps2=null;
ResultSet rs=null;
ResultSet rs1=null;
try{
Calendar calendar = new GregorianCalendar();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
today=(+hour+":"+minute+":"+second +"");
Date date = new Date();
SimpleDateFormat sdf = null;
String strDate1 = "";
sdf = new SimpleDateFormat("dd-MM-yy");
strDate1 = sdf.format(date);
String useripadd="";
try {
useripadd= request.getRemoteAddr();
}
catch(Exception e) {
}
tour=strDate1+" "+today;
try{
ps2 = db.con.prepareStatement("insert into logindetails
(loginid,logoutdt,logoutipaddress) values (?,to_date(?, 'DD-MM-YY hh24:mi:ss'),?)");
}
catch(Exception e){
}
ps2.setString(1, user);
try{
ps2.setString(2, tour);
}
catch(Exception e){ }
ps2.setString(3, useripadd);
try {
rs1=ps2.executeQuery();
}
catch(SQLException ex){
out.println(ex);
}
rs1.close();
ps2.close();
db.removeConnection();
}
catch(Exception e){
}
String csrf="";
request.getSession(false).removeAttribute("useridfinal");
request.getSession(false).removeAttribute("csrftoken");
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-store");
response.setHeader("Expires","0");
response.setDateHeader("Expires",-1);
session1.invalidate();
response.sendRedirect("login.jsp");
%>
</body>
從IP地址我知道該位置是日本。 我不知道是怎么回事。 任何幫助請?????????
他們可能已經使用代理進行登錄注銷,而用戶只能是你的知名人士,他可能有權訪問你的數據庫,他想對你的系統做錯事,所以他登錄並做了一些事情錯誤。 之后他可能已經刪除了他的訪問時間細節。
假設您的應用程序托管在http://your.host.com/app
,並假設您的注銷JSP名為logout.jsp。 如果我只是使用我的瀏覽器並在地址欄中鍵入http://your.host.com/app/logout.jsp並按Enter鍵,您將在數據庫中無需登錄即可注銷。 不需要破解任何東西。
另一種可能性是,由於您基本上忽略了發生的任何異常,因此登錄成功但插入數據庫失敗。 這肯定發生了,因為要在數據庫中插入登錄,您使用executeQuery
而不是使用executeUpdate
。
你的代碼非常非常可怕。 您應該學習縮進代碼,正確使用JDBC,正確處理異常,使用事務而不是自動提交,以及關閉finally塊中的結果集,語句和連接。 JSP中的Java代碼實際上是不好的做法。
閱讀教程,永遠不要catch(Exception) {}
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.