D385 Software Security And Testing - Questions With
Verified Solutions
What is the primary defense against log injection attacks?
A. Do not use parameterized stored procedures in the database
B. Allow all users to write to these logs
C. Sanitize outbound log messages
D. Use API calls to log actions Correct Answer - C. Sanitize outbound log
messages.
The primary defense against log injection attacks is to sanitize outbound log
messages. Log injection is a type of security vulnerability where an attacker
manipulates log messages to inject malicious code or exploit system
vulnerabilities. By sanitizing outbound log messages, you ensure that any
user-supplied input or potentially dangerous characters are properly escaped
or removed before being included in the log.
Sanitizing log messages involves applying input validation and output
encoding techniques to prevent the injection of malicious content. It typically
involves validating the input data, such as user inputs, and sanitizing or
encoding it appropriately to ensure it does not contain any harmful characters
or constructs.
Some common techniques for sanitizing log messages include:
Input validation: Validate and restrict user input to ensure it conforms to
expected formats and does not contain any unauthorized or dangerous
characters.
Output encoding: Encode the log messages in a way that prevents the
interpretation of special characters or malicious constructs. For example, you
can use HTML entity encoding, URL encoding, or database-specific encoding
techniques, depending on the log storage and processing mechanisms.
By properly sanitizing outbound log messages, you can minimize the risk of
log injection attacks and ensure that the logs remain a reliable and secure
source of information for monitoring and analysis purposes.
import logging
import sys
#log division by zero error to the log, the output is printed to the screen
def divideByZeroError(dividend, divisor):
, logging.basicConfig(stream=sys.stdout,format='%(levelname)s:%
(message)s')
try:
quotient = dividend/divisor
print (quotient)
except Exception as e:
#logging error here, use str(e) as part of the output
if __name__ == '__main__':
dividend = int(input())
divisor = int(input())
divideByZeroError(dividend,divisor) Correct Answer - logging.error(' The
exception that occurred is: ' + str(e))
An attacker exploits a cross-site scripting vulnerability. What is the attacker
able to do?
A. Access the user's data
B. Execute a shell command or script
C. Discover other users' credentials
D. Gain access to sensitive files on the server Correct Answer - The
question is about a specific security vulnerability called "cross-site scripting"
(XSS). Cross-site scripting is a type of security flaw in web applications where
an attacker can inject malicious scripts into web pages that are viewed by
other users. These scripts are then executed by the users' web browsers,
allowing the attacker to perform various actions on behalf of the victim.
Let's break down the answer options:
A. Access the user's data This option is correct. With a successful cross-site
scripting attack, the attacker can gain unauthorized access to the user's data,
including personal information, login credentials, cookies, and any other
sensitive information that the user has on the affected website. (CORRECT)
B. Execute a shell command or script This option is not directly related to
cross-site scripting. Executing shell commands or scripts typically involves
other types of security vulnerabilities like command injection or remote code
execution.
C. Discover other users' credentials While cross-site scripting can potentially
allow an attacker to access other users' credentials if they are stored on the
same vulnerable website, it's not the primary purpose of XSS attacks. The
primary goal is to target individual users and steal their data.
Verified Solutions
What is the primary defense against log injection attacks?
A. Do not use parameterized stored procedures in the database
B. Allow all users to write to these logs
C. Sanitize outbound log messages
D. Use API calls to log actions Correct Answer - C. Sanitize outbound log
messages.
The primary defense against log injection attacks is to sanitize outbound log
messages. Log injection is a type of security vulnerability where an attacker
manipulates log messages to inject malicious code or exploit system
vulnerabilities. By sanitizing outbound log messages, you ensure that any
user-supplied input or potentially dangerous characters are properly escaped
or removed before being included in the log.
Sanitizing log messages involves applying input validation and output
encoding techniques to prevent the injection of malicious content. It typically
involves validating the input data, such as user inputs, and sanitizing or
encoding it appropriately to ensure it does not contain any harmful characters
or constructs.
Some common techniques for sanitizing log messages include:
Input validation: Validate and restrict user input to ensure it conforms to
expected formats and does not contain any unauthorized or dangerous
characters.
Output encoding: Encode the log messages in a way that prevents the
interpretation of special characters or malicious constructs. For example, you
can use HTML entity encoding, URL encoding, or database-specific encoding
techniques, depending on the log storage and processing mechanisms.
By properly sanitizing outbound log messages, you can minimize the risk of
log injection attacks and ensure that the logs remain a reliable and secure
source of information for monitoring and analysis purposes.
import logging
import sys
#log division by zero error to the log, the output is printed to the screen
def divideByZeroError(dividend, divisor):
, logging.basicConfig(stream=sys.stdout,format='%(levelname)s:%
(message)s')
try:
quotient = dividend/divisor
print (quotient)
except Exception as e:
#logging error here, use str(e) as part of the output
if __name__ == '__main__':
dividend = int(input())
divisor = int(input())
divideByZeroError(dividend,divisor) Correct Answer - logging.error(' The
exception that occurred is: ' + str(e))
An attacker exploits a cross-site scripting vulnerability. What is the attacker
able to do?
A. Access the user's data
B. Execute a shell command or script
C. Discover other users' credentials
D. Gain access to sensitive files on the server Correct Answer - The
question is about a specific security vulnerability called "cross-site scripting"
(XSS). Cross-site scripting is a type of security flaw in web applications where
an attacker can inject malicious scripts into web pages that are viewed by
other users. These scripts are then executed by the users' web browsers,
allowing the attacker to perform various actions on behalf of the victim.
Let's break down the answer options:
A. Access the user's data This option is correct. With a successful cross-site
scripting attack, the attacker can gain unauthorized access to the user's data,
including personal information, login credentials, cookies, and any other
sensitive information that the user has on the affected website. (CORRECT)
B. Execute a shell command or script This option is not directly related to
cross-site scripting. Executing shell commands or scripts typically involves
other types of security vulnerabilities like command injection or remote code
execution.
C. Discover other users' credentials While cross-site scripting can potentially
allow an attacker to access other users' credentials if they are stored on the
same vulnerable website, it's not the primary purpose of XSS attacks. The
primary goal is to target individual users and steal their data.