D385 Software Security and Testing

studied byStudied by 9 people
2.0(1)
Get a hint
Hint

Sanitize outbound log messages

1 / 68

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

69 Terms

1

Sanitize outbound log messages

What is the primary defense against log injection attacks?

New cards
2

Access the user's data

An attacker exploits a cross-site scripting vulnerability. What is the attacker able to do?

New cards
3

eval()

Which Python function is prone to a potential code injection attack?

New cards
4

Check functional preconditions and postconditions

What are two common defensive coding techniques?

New cards
5

test

Which package is meant for internal use by Python for regression testing?

New cards
6

type()

Which Python function is used for input validation?

New cards
7

Broken access control

A security analyst has noticed a vulnerability in which an attacker took over multiple users' accounts. Which vulnerability did the security analyst encounter?

New cards
8

Implement resource and field-level access control

When creating a new user, an administrator must submit the following fields to an API endpoint:

Name
Email Address
Password
IsAdmin

What is the best way to ensure the API is protected against privilege escalation?

New cards
9

Exploiting query parameters

Which method is used for a SQL injection attack?

New cards
10

response.content

Which response method, when sent a request, returns information about the server's response and is delivered back to the console?

New cards
11

Override same starting policy for specific resources

What does cross-origin resource sharing (CORS) allow users to do?

New cards
12

MSAL

Which protocol caches a token after it has been acquired?

New cards
13

200

OK - Your request was successful

New cards
14

201

CREATED - Your request was accepted, and the resource was created

New cards
15

400

BAD REQUEST - Your request is either wrong or missing information

New cards
16

401

UNAUTHORIZED - Your request requires additional permissions

New cards
17

403

FORBIDDEN - website can be reached, but more permissions needed before accessing further

New cards
18

404

NOT FOUND - The requested resource does not exist

New cards
19

405

METHOD NOT ALLOWED - The endpoint does not allow for that specific HTTP method

New cards
20

500

INTERNAL SERVER ERROR - Your request was not expected and probably broke something on the server side

New cards
21

Content-Type (header)

What type of content the server will respond with

New cards
22

Accept (header)

What type of content the client can accept

New cards
23

Server (header)

What software the server is using to communicate with the client

New cards
24

User-Agent (header)

What software the client is using to communicate with the server

New cards
25

Authentication (header)

Who's calling the API and what credentials they have

New cards
26

validate()

Which Python function is used to protect against log injection attacks?

New cards
27

Cross Site Scripting (XSS)

A user masquerades as other users, what type of attack was used?

New cards
28

SQL Injection

Exploiting query parameters is an example of what attack?

New cards
29

Raw binary content of the HTTP response as bytes

What is returned when using response.content?

New cards
30

response.content

Which response method, when sent a request, returns information about the server's response and is delivered back to the console?

New cards
31

Injection of commands a parser can execute

What can an attacker do with a log injection attack?

New cards
32

Sanitize outbound log messages

What is the primary defense against log injection attacks?

New cards
33

test

Which package is meant for internal use by Python for regression testing?

New cards
34

Regression Testing

Which software testing method relies on using old test cases?

New cards
35

After some code changes

When should regression testing be conducted?

New cards
36

Override same starting policy for specific resources

What does cross-origin resource sharing (CORS) allow users to do?

New cards
37

ACAO client.url

Access Control Allow Origin: client request to (www.client.url) What is returned by the server?

New cards
38

help(http)

Can be used on the first (ungraded) page to view status codes

New cards
39

MSAL

Which protocol caches a token after it has been acquired?

New cards
40

API related errors

Status code 401 is common with?

New cards
41

NO HEADER is provided in the GET request

Status code 403 is common when?

New cards
42

Python Logging

try:

quotient = dividend/divisor

print (quotient)

except Exception as e:

logging.error("The exception that occurred is: " +str(e))

Memorize highlighted

New cards
43

Check a Null Setting Using Assertions

def multiply_numbers(x, y):

if x is None:

print("x is a null value")

return y

elif y is None:

print("y is a null value")

return x

else:

return x * y

Memorize highlighted

OA: They will change the variables

New cards
44

Secure Code with Template Class

if __name__ == '__main__':

name = input()

email = input()

user = User(name, email)

t = Template("Hello, my name is $name.")

print(t.substitute(name=user.name))

Memorize highlighted

OA: Instead of name the declaration was changed to something like admin_name

New cards
45

Rate Limiting

bucket = self.bucket + time_passed * (self.rate / self.per)

if (bucket > self.rate):

self.bucket = self.rate

if (bucket < 1):

pass

else:

callback_fn()

self.bucket = bucket - 1

Memorize highlighted

OA: Only asks for the if/else portion, self.rate may be called something else

New cards
46

Assertion Statement

def CelciusToFahrenheit(Temperature):

assert Temperature >= 0, "Colder than zero degrees Celsius!"

return ((Temperature*9)/5)+32

Memorize highlighted

OA: Changed delclaration of Temperature to something like temp_check and the string text is different.

New cards
47

Check Data to Verify Values

def check_numeric_value(wg_int):

return isinstance(wg_int, int)

def check_null_string (wg_string):

return wg_string is not None

Memorize highlighted

New cards
48

Hashing

def hash_password(pwd):

enc_pwd = pwd.encode()

d = hashlib.sha3_256(enc_pwd)

hash = d.hexdigest()

return hash

Memorize highlighted

OA: add 3_ to sha256 and hex to d.digest()

New cards
49

Validate Data for Deserialization

def safe_deserialize(key, serialized_data):

new_key = generate_key(serialized_data)

try:

if key == new_key:

return deserialize(serialized_data)

else:

raise Exception('New key does not match old key')

except Exception as error:

print('Error:', error)

return False

Memorize highlighted

OA: The test has you create and if/else statement instead of fixing this code. Also memorize the raise Exception string! The test does not tell you what it wants the string to say so it will get marked wrong no matter what

New cards
50

Verify Data is Valid (Numeric)

if __name__ == '__main__':

zipCode = input()

try:

zip_check = int(zipCode)

print(f'Your zip code is {zipCode}.')

except:

print('Please use numeric digits for the zip code.')

Memorize highlighted

OA: Instead of zipCode its something like zip_Code_Input

New cards
51

Verify Data is Valid (Length)

if __name__ == '__main__':

password = input()

if (len(password) >= 8):

print("Your password is long enough.")

else:

print("Your password is too short.")

Memorize highlighted

OA: Same on test but the string text is different

New cards
52

Verify Data is Valid (Range)

if __name__ == '__main__':

r = range(1,10)

num = int(input())

if num in r:

print("The number input is in the range from 1 and 10.")

else:

print("The number input is not in the range from 1 and 10.")

Memorize highlighted

OA: num and r may have different names and the string text is different

New cards
53

AES Encryption

def encrypt(self, plain_text):

plain_text = self.__pad(plain_text)

counter = Counter.new(self.block_size * 8)

cipher = AES.new(self.key, AES.MODE_CTR, counter=counter)

encrypted_text = cipher.encrypt(plain_text.encode("utf-8"))

return b64encode(encrypted_text).decode("utf-8")

Memorize highlighted

OA: Instead of encrypted_text its something like encrypted_plain_text

New cards
54

Least Privilege Permission Levels

def grant_permission(name_list, filename):

if result:

os.chmod(filename, stat.S_IRWXU)

else:

os.chmod(filename, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)

check_permission(filename)

Memorize highlighted

OA: this was the exact same

New cards
55

Broken Object Level Authorization

ownerID = 4567

def ShowData():

if(GetUserID() == ownerID):

print("This is the user data")

def Redirect():

print("Redirecting to homepage")

def GetUserID():

return 1234

Memorize highlighted

OA: the string text in the print function will be different. GetUserID and OwnerID may have different names

New cards
56

Type and Range check

A security analyst is reviewing code for improper input validation.

Which type of input validation does this code show?

isValidNumber = False

while not isValidNumber:

try:

pickedNumber = int(input('Pick a number from 1 to 10'))

if pickedNumber >= 1 and pickedNumber <= 10:

isValidNumber = True

except:

print('You must enter a valid number from 1 to 10')

print('You picked the number ' + str(pickedNumber))

New cards
57

Man-in-the-Middle

Consider the following penetration test:

import requests

urls = open("websites.txt", "r")

for url in urls:

url = url.strip()

req = requests.get(url)

print (url, 'report😂

try:

transport_security = req.headers['Strict-Transport-Security']

except:

print ('HSTS header not set properly')

Which security vulnerability is shown?

New cards
58

AssertionError: no admin found

Consider the following assertion statement:

def authorizeAdmin(usr):

assert isinstance(usr, list) and usr != [], "No user found"

assert 'admin' in usr, "No admin found."

print("You are granted full access to the application.")

If __name__ == '__main__':

authorizeAdmin(['user'])

What should be the response after running the code?

New cards
59

403 - FORBIDDEN

Consider the following API code snippet:

import requests

url = 'https://website.com/'

# Get request

result = requests.get(url)

# Print request

print(result.content.decode())

Which status code will the server return?

New cards
60

404 - NOT FOUND

The user submits the following request to an API endpoint that requires a header:

import requests

url = 'https://api.github.com/invalid'

try:

request_response = requests.get(url)

# If the response was successful, no Exception will be raised

request_response.raise_for_status()

except Exception as err:

print(f'Other error occurred: {err}')

else:

print('Success!')

Which response code will the user most likely be presented with?

New cards
61

400 - Bad Request

Indicates that the server could not understand or process the request due to invalid syntax or bad formatting

This could happen due to:

malformed URL, missing required parameters, or incorrect data

<p></p><p>Indicates that the server could not understand or process the request due to <span class="bgP">invalid syntax</span> or <span class="bgP">bad formatting</span></p><p></p><p>This could happen due to: </p><p><span class="bgB">malformed URL</span>, <span class="bgB">missing required parameters</span>, or <span class="bgB">incorrect data</span></p>
New cards
62

401 - Unauthorized

Indicates that the request lacks valid authentication credentials and often occurs when an API requires authentication

This could happen due to:

API key, token, session or other credentials are either missing, invalid, or expired

<p>Indicates that the request lacks valid authentication credentials and often occurs <span class="bgP">when an API requires authentication</span> </p><p></p><p>This could happen due to: </p><p><span class="bgB">API key</span>, <span class="bgB">token</span>, <span class="bgB">session</span> or other <span class="bgB">credentials</span> are either <span class="bgB">missing, invalid, or expired</span></p>
New cards
63

403 - Forbidden

Indicates that the server understands the request but refuses to authorize it. This often occurs when the client has the correct credentials but lacks the necessary permissions to access the requested resource

This could happen due to:

Insufficient permissions, such as their user role or other access restrictions. (e.g. IP Blacklisting)

* headers and cookies provide that data which is validated for requests

New cards
64

404 - Not Found

Indicates that the server could not find the requested resource. This typically happens when the URL is incorrect or the resource does not exist on the server.

New cards
65

401 vs. 403

Authentication vs. Authorization:

401: focuses on invalid or missing authentication credentials

403: pertains to valid authentication but inadequate authorization

New cards
66

Cross-origin Resource Sharing (CORS) - Example
(Malicious Attacks)

Allows or restricts web applications running at one origin (domain) to make requests for resources hosted on a different origin

<p>Allows or restricts web applications running at one origin (domain) to <span class="bgP">make requests for resources hosted on a different origin</span></p>
New cards
67

Denial of Service (DoS) - Example
(Malicious Attacks)

An attempt to overload a website or network, with the aim of degrading its performance or even making it completely inaccessible

<p>An attempt to overload a website or network, with the aim of <span class="bgP">degrading its performance</span> or even making it <span class="bgP">completely inaccessible</span></p>
New cards
68

Code Injection - Example
(Malicious Attacks)

An attacker is able to insert malicious code into a program. This code is then executed by the system

Potentially leading to unauthorized actions, data breaches, or other harmful outcomes.

<p>An attacker is able to <span class="bgP">insert malicious code into a program</span>. This code is then <span class="bgP">executed by the system</span></p><p></p><p>Potentially leading to <span class="bgP">unauthorized actions</span>, <span class="bgP">data breaches</span>, or other harmful outcomes.</p>
New cards
69

Cross-Site Scripting (XSS) - Example
(Malicious Attacks)

An attacker inserts malicious script (generally through input fields or url parameters not properly sanitized) that is executed by other users who visit the site

The users are then prey to cookie theft, redirection to phishing sites, or their webpage may be manipulated

<p>An attacker inserts malicious script (generally through <span class="bgP">input fields</span> or <span class="bgP">url parameters</span> not properly sanitized) that is <span class="bgP">executed by other users who visit the site</span></p><p></p><p>The users are then prey to <span class="bgP">cookie theft</span>, <span class="bgP">redirection to phishing sites</span>, or their <span class="bgP">webpage may be manipulated</span></p>
New cards

Explore top notes

note Note
studied byStudied by 7 people
... ago
5.0(1)
note Note
studied byStudied by 12 people
... ago
5.0(1)
note Note
studied byStudied by 21 people
... ago
4.0(1)
note Note
studied byStudied by 32 people
... ago
5.0(1)
note Note
studied byStudied by 8 people
... ago
5.0(1)
note Note
studied byStudied by 9 people
... ago
5.0(1)
note Note
studied byStudied by 31 people
... ago
5.0(1)
note Note
studied byStudied by 357 people
... ago
5.0(5)

Explore top flashcards

flashcards Flashcard (24)
studied byStudied by 21 people
... ago
5.0(1)
flashcards Flashcard (51)
studied byStudied by 28 people
... ago
4.0(1)
flashcards Flashcard (198)
studied byStudied by 7 people
... ago
5.0(1)
flashcards Flashcard (34)
studied byStudied by 2 people
... ago
5.0(1)
flashcards Flashcard (39)
studied byStudied by 4 people
... ago
5.0(1)
flashcards Flashcard (61)
studied byStudied by 379 people
... ago
4.6(28)
flashcards Flashcard (116)
studied byStudied by 13 people
... ago
5.0(1)
flashcards Flashcard (65)
studied byStudied by 2352 people
... ago
4.6(14)
robot