0

security Online Quiz - 9

Description: security Online Quiz - 9
Number of Questions: 20
Created by:
Tags: security
Attempted 0/20 Correct 0 Score 0

Data returned by which of the following methods should be validated before using it

  1. getParameter ()
  2. getQueryString ()
  3. getCookies ()
  4. getHeaders ()
  1. 1

  2. 1 and 2

  3. 1,2 and 3

  4. 1,2,3 and 4


Correct Option: D

AI Explanation

To answer this question, we need to understand the purpose of each method and determine whether the data returned by each method should be validated before using it.

Option A) 1 - The getParameter() method is used to retrieve a specific parameter from a request, such as a query string parameter or a form parameter. Since the data is user-supplied and can be manipulated, it is important to validate the data returned by this method before using it.

Option B) 1 and 2 - In addition to the getParameter() method, the getQueryString() method is used to retrieve the query string portion of a URL. Similar to the getParameter() method, the data returned by the getQueryString() method should also be validated before using it.

Option C) 1, 2, and 3 - In addition to the getParameter() and getQueryString() methods, the getCookies() method is used to retrieve the cookies sent by the client. Since cookies can contain user-supplied data, it is important to validate the data returned by this method as well.

Option D) 1, 2, 3, and 4 - In addition to the methods mentioned above, the getHeaders() method is used to retrieve the headers of a request. While headers typically contain metadata and not user-supplied data, it is still important to validate the data returned by this method to ensure its integrity and prevent any potential security vulnerabilities.

Based on the above analysis, the correct answer is D. All of the mentioned methods should have their returned data validated before using it to ensure the security and integrity of the application.

Which of the following are countermeasures for XSS

  1. Releasing Resources after use
  2. Input Validation
  3. Running with least privilege
  4. URL based access control
  5. Output Encoding
  1. 1 and 4

  2. 2 and 4

  3. 2 and 5

  4. 3 and 5


Correct Option: C
  1. Since the file name is hard coded, fopen() will fail if the file already exists.

  2. 0600 is not a secure option. The parameter 0600 should be changed to 0666

  3. Attackers can exploit by creating a symboling link /tmp/cache_data that points to a system file.

  4. Attackers can exploit the application's cache by writing directly to /tmp/cache_data


Correct Option: C

Is writing to an already freed memory a vulnerability?

x = malloc(200); /* do something with x */ 
free (x); /* do something else */  
strcpy(x, “somedata”);  
  1. Overwriting freed memory is a security vulnerability

  2. Depends on the application and how important “somedata” is

  3. This will result in a buffer overflow since the freed memory location cannot handle 8 characters of data “somedata”

  4. strcpy() will fail as it cannot write to already freed memory, and the application will crash.


Correct Option: A

AI Explanation

To answer this question, let's go through each option:

Option A) Overwriting freed memory is a security vulnerability - This option is correct. Writing to an already freed memory is a security vulnerability. When memory is freed using the free() function, the operating system marks that memory as available for other allocations. If you try to write to that memory after it has been freed, it can lead to undefined behavior, including potential security vulnerabilities such as buffer overflows or information disclosure.

Option B) Depends on the application and how important "somedata" is - This option is not the correct answer. While the importance of "somedata" may impact the severity of the vulnerability, the act of writing to already freed memory itself is a security vulnerability.

Option C) This will result in a buffer overflow since the freed memory location cannot handle 8 characters of data "somedata" - This option is incorrect. A buffer overflow occurs when more data is written to a buffer than it can handle, exceeding its allocated size. In this case, the issue is not specifically a buffer overflow, but rather writing to already freed memory.

Option D) strcpy() will fail as it cannot write to already freed memory, and the application will crash - This option is incorrect. The behavior of writing to already freed memory is undefined. It might crash the application, or it might not. It is not guaranteed to fail or crash in all cases.

The correct answer is A) Overwriting freed memory is a security vulnerability. This option is correct because writing to already freed memory can lead to security vulnerabilities and should be avoided.

In the following code, which is the location of vulnerability?

1  bIsAdmin = true; 
2  try  
3  { 
4  function (); 
5   bIsAdmin = isAdminUser(userName); 
6  } 
7  catch (Exception ex)  
8  { 
9   log.write(ex.toString()); 
10 }
  1. Line 9

  2. Line 5

  3. Line 7

  4. Line 1


Correct Option: D

In the following code, which is the location of vulnerability?

1 String username = req.getParameter("loginID"); 
2 String password = req.getParameter("loginPassword"); 
3 String sql = "SELECT UserID from Employee WHERE Emp_ID = ? AND Password=?"; 
4 pstmt = con.prepareStatement(sql); 
5 pstmt.setString(1,username); 
6 pstmt.setString(2,password); 
7 pstmt.execute(); 
8 user = pstmt.getResultSet(); 
9 if(user!=null)  
10 { 
11  while (user.next()) 
12  { 
13   userInfo.add(user.getString(1)); 
14  }  
15 } 
16 else 
17 { 
18  log.debug(“Invalid Login: Login ID-”+ username+” Password-”+ password); 
19 }
  1. Line 5

  2. Line 4

  3. Line 18

  4. Line 11


Correct Option: C

Identify the line on which the vulnerability exists:

1 public class performSearchAction extends HttpServlet{ 
2 // Servlet for Search Action  
3  public void doPost(HttpServletRequest req, HttpServletResponse res)  
4  { 
5   try 
6   { 
7       ArrayList arrSearch =  Util.performSearchAction(req, res); 
8       req.setAttribute(“SearchResults”,arrSearch); 
9       RequestDispatcher rd = getServletContext().getRequestDispatcher("/SearchResult.jsp"); 
10      rd.forward(req,res); 
11  } catch (Exception e) { 
12               log.debug(“Exception occurred:”+e); 
13               } 
14  } //End of doPost method 
15  public void doGet(HttpServletRequest req, HttpServletResponse res) 
16  { 
17    doPost(req,res); 
18  } //End of doGet method 
19 } //End of Class
  1. Line # 12

  2. Line # 9

  3. Line # 17

  4. Line # 8


Correct Option: C

Give the name of the vulnerability resides in the below code:

... 
Runtime rt = Runtime.getRuntime(); 
Process proc = rt.exec("cmd.exe /c type "+request.getParameter("path")); //path is an Input Parameter and contains the file name. 
InputStream stdin = proc.getInputStream(); 
InputStreamReader isr = new InputStreamReader(stdin); 
BufferedReader br = new BufferedReader(isr);              
...
  1. Race Condition

  2. Command Injection

  3. Denial of Service

  4. Cross Site Request Forgery


Correct Option: B

Are there any memory issues in the following code? Please assume that variable inputsize has the correct size.

int add_num_array(int inputsize, int num) {
    int *newnum = malloc (inputsize * sizeof(int));  /* 1 */
    int i;   
    for (i=0; i
  1. No vulnerabilities are present

  2. Line 1 should only use malloc(inputsize);

  3. Line 2 should be for (i=0; i<=n, i++)

  4. Line 1 should use calloc() instead of malloc()


Correct Option: D

What is the vulnerability in this code?

    char output[20];  
    /*   Assume data is a character array with value %200d asdf   */  
    sprintf(output, data);
  1. Buffer overflow

  2. Off by one error

  3. Format string vulnerability

  4. No vulnerabilities are present in this code


Correct Option: C

What is the vulnerability in this code?

int main(int argc, char * argv[]) {   
    printf (argv[1]);  
}
  1. Buffer overflow

  2. Off by one error

  3. Format string vulnerability

  4. No vulnerabilities are present in this code


Correct Option: C

What is the possible vulnerability in this code?

    unsigned int total, userinput1, userinput2;  
    userinput1 = receiveInput();  
    userinput2 = receiveInput();  
    total = userinput1 + userinput2;
  1. Integer overflow

  2. Buffer overflow

  3. Stack overflow

  4. Data type mismatch


Correct Option: A

Which Compilation switch will you use to check Buffer Overflows?

  1. /GS on Visual C++ and -fmudflap -fmudflapth -fmudflapir on GCC

  2. /O in Vc++ and -O2 in GCC

  3. /S in Vc++ and -fcrossjumping in GCC

  4. /S in VC++ and -fno-function-cse in GCC


Correct Option: A

What can go wrong in following code?

#include   
int main(int argc, char *argv[]) {

if(argc != 3) {
        printf("usage: %s [source] [dest]\n", argv[0]);
        exit(1);

    }

    char x;
    FILE *file[2];
    file[0] = fopen(argv[1],"r+");
    file[1] = fopen(argv[2],"w+");
    for(x = 0; x &lt; 2; x++) { 
        if(file[x] == NULL) {
            printf("error opening file.\n");
            exit(1);
        }
    }

    do {
        x = fgetc(file[0]);
        fputc(x,file[1]);
    } while(x != EOF);

     for(x = 0; x &lt; 2; x++)
        fclose(file[x]);
     return 0; 
}
  1. SQL Injection

  2. Arc Injection

  3. Buffer Overflow

  4. both 2 and 3


Correct Option: C

Which compilation switch should be enabled for stack protection? Choose the best and most secure option.

  1. fstack-protector

  2. fstack-protector-all

  3. fdelete-null-pointer-checks

  4. Both a and b


Correct Option: B

unsigned char j,k; j=getchar(); k=getchar(); unsigned char result = j + k; What vulnerability is present in this code:

  1. Heap Overflow

  2. Integer overflow

  3. Buffer overflow

  4. No Vulnerability


Correct Option: B

AI Explanation

To answer this question, we need to understand the code and the potential vulnerabilities associated with it.

In the given code snippet:

unsigned char j,k;
j = getchar();
k = getchar();
unsigned char result = j + k;

The vulnerability present in this code is an integer overflow.

Explanation:

  1. The getchar() function reads a character from the standard input and returns its ASCII value as an int.
  2. The ASCII values of characters can range from 0 to 255, which can be represented by an unsigned char in C.
  3. The unsigned char type has a range of 0 to 255.
  4. When adding j and k, the result will be stored in the result variable.
  5. If the sum of j and k exceeds 255, an integer overflow occurs.
  6. An integer overflow happens when the result of an arithmetic operation exceeds the maximum value that can be represented by the data type.
  7. In this case, if the sum of j and k is greater than 255, the result will wrap around and be stored as the remainder of the value modulo 256.
  8. This can lead to unexpected behavior and potential security vulnerabilities if the overflow is not handled properly.

Therefore, the correct answer is B) Integer overflow.

Which statement creates a buffer over flow? (Line numbers are marked using comments /* */)

#include   
#include   
#include   
int main (int argc, char *argv[])  {   
    int i=0,j=1;   
    char ipstring[80];   
    for (;i&lt;=3;i++){    
        cout&lt;
  1. 1

  2. 2

  3. Both

  4. None


Correct Option: B

What is the vulnerability ?

int main (int argc, char *argv[]) { 
     char k[3]; 
     int i=0,j=1; 
     char buffer[50]; 
     strncpy(buffer, argv[1], sizeof(buffer) - 1); 
     buffer[49]='/0'; 
     unsigned char ch='a'; 
     k[0]=1; 
     do{   
        i++;   
        k[i]=ch+i; 
    } while(i&lt;3); 

    return 0; 
}  
  1. Heap overflow

  2. Integer overflow

  3. Off by one error

  4. None of the above


Correct Option: C

Which attack(s) are possible in the below code:


  1. Content Spoofing

  2. HTTP Response Splitting

  3. Directory Listing

  4. a & b


Correct Option: D

Identify the name of the vulnerability exist in the below code:

1 ...   
2 public class ShowUserDetailsAction extends HttpServlet   
3 {   
4 private String currentUser;     
5 public void doPost(HttpServletRequest req, HttpServletResponse res)   
6 {   
7 try   
8 {   
9  currentUser = req.getParameter("userID");  
10  RequestDispatcher rd = getServletContext().getRequestDispatcher ("/ShowDetails.jsp");  
11  if (!"".equals(currentUser))  
12  {  
13     
14   ArrayList userInfo = new ArrayList();  
15   LoginDAO objLoginDAO = new LoginDAO();  
16   userInfo = objLoginDAO.getUserInfo(currentUser);  
17     
18   if (userInfo!=null &amp;&amp; (userInfo.size()!= 0))  
19   {  
20    req.setAttribute("UserInfo", userInfo);  
21   }  
22   else  
23   {  
24    req.setAttribute("NoUser", "true");  
25   }  
26  }  
27  rd.forward(req,res);  
28 } catch (Exception e)  
29 {  
30  log.debug(“Error Occurred:”+ e);  
31 }  
32 }  
33 }   
34 ...
  1. URL Tampering

  2. Brute Forcing

  3. Race Condition

  4. HTML Injection


Correct Option: C
- Hide questions