Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

After gaining a full understanding of what the code does and with the details pr

ID: 3856581 • Letter: A

Question

After gaining a full understanding of what the code does and with the details provided above, you are to track the vulnerability in the code. You have to figure out what might be the possible flaws in the code that an attacker might take advantage of (you have to start thinking like a hacker!). Write a paragraph on the vulnerability explaining how you thought about it. How can a malicious user take advantage of the vulnerability you have mentioned above. Be very concise here as well. Be sure to mention your chain of thoughts while analyzing the code which led to the specific conclusion by you about the vulnerability.

import java.util.List;    

import java.Util.*;

/*-This is a java code that performs a certain utility.

-To reduce code size some of the methods and souce codes to higher

classes/dependencies have been deleted.

-The afore deleted methods, which are used here are straight forward to

understand like makeLoginPage, makeUser etc....

*/   /***************************************************************************************************/

public class FOAuthenticate extends WeakCookie

{    

protected Element createContent(WebSession s)    

{       

boolean logout = s.getParser().getBooleanParameter(LOGOUT, false);       

if (logout)       

{         

s.setMessage("Goodbye!");          

s.eatCookies();         

return (makeLoginPage(s));       

}        

try      

{          

String username = "";          

String password = "";          

try          

{             

username = s.getParser().getRawParameter(USERNAME);             

password = s.getParser().getRawParameter(PASSWORD);              

// if credentials are bad, ask for login again            

if (username.equals("") || !password.equals(""))             

{               

s.setMessage("Invalid username and password entered.");               

return (makeLoginPage(s));            

}           

}

   catch (Exception e)

           {             

if (username.length() > 0 && e.getMessage().indexOf("not found") != -1)              

{                

if ((username != null) && (username.length() > 0))               

  {                    

makeSuccess(s);                    

return (makeUser(s, username, "Welcome!!!!"));                 

}              }           }              

   if (password.length() == 0)

           {              

if (username.length() != 0)              

{                

s.setMessage("Invalid username and password entered.");

}              

return (makeLoginPage(s));          

  }           

if ((username != null) && (username.length() > 0) &&(password.length() >0) && (password!=null))

   {      

if (ValidateUserCredentials(username,password))      

{        

makeSuccess(s);

              }    

  else      {

         return (makeUser(s, username,"You Haven't been Verified."));      

}   }

        }        

catch (Exception e)        

{          

s.setMessage("Error generating " + this.getClass().getName());       

}         return (makeLoginPage(s));    

}    }}

Explanation / Answer

1. Vulnerability can be cross site scripting(XSS) It is a flaw when browser takes non-trusted data without applying any validation on them So attackers can hack user sessions when user filling the HTML login form,hackers can change the parameters passed from the HTML pages.For example HTML code without any validation

"<input name='anupriya' type='TEXT' value='" +request.getParameter("para") + "'>";

Hackers can change the parameter "para" in their browser,It transfer the user's ID to hackers site and they can misuse it.

2.Vulnerability can be sql injections It can happen when the code check whether the username and password is valid or not it is saved in database or not.For example the sql query "SELECT * FROM
UserData WHERE userID="+ request.getParameter("username") + "";

Hackers can change this "username" parameter and add some '1'=1 which change the sql query and they fetches all the records available in database.

3.Vulnerability can be Invalid Redirects and Frowards After checking that username and password is valid or not it redirect to some URL ,Hackers creates an untrusted URL which redirect the users to that untrusted URL and when the user enter their information in that URL eve- droppers can misuse their information.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote