Week 7 - Web Security and Malware Flashcards
Learn about security on the Internet and they type of attacks that occur on there. Includes SQL injection, Cross site scripting, malware taxonomy etc.
What is a SQL injection attack?
When an attack users input maliciously to deploy SQL queries rather than an expected data input. This attack only words for application that use a sql database.
What could and attacker use an SQL injection to do?
They could ‘drop’ all tables or records in the database.
They could modify a record or multiple records.
They could select and display row data to themselves.
They could attempt to disrupt validation.
What is password spraying?
When an attacker refers to a list of common passwords to attempt to attack a large number of accounts. An attacker might use sql injection to disrupt validation so that instead of looking for and account with a certain username or password, the sql only looks for an account with the specified password. If the attacker uses the list of common passwords they will likely gain access to at least one account.
How do you do comments in SQL?
You use –
How would you inject mutple SQL statements at once?
You would use batch sql would allow you to execute mutple SQL statements by separating the statements with a ; or joining them using UNION. Separating with a ; typically doesn’t work as application do not normally deal with a second set of data return from a second sql statement.
Why might using ; to execute more sql statements to get a second set of data not work as compared to a UNION statement?
Separating with a ; typically doesn’t work as applications do not normally deal with a second set of data returned from a second sql statement, thus the second set of data will be dropped in favour of dealing with the first commands data.
A UNION statement on the other hand join statements together and allows for the data returned from those statements to be joined as one result table.
How might one prevent an SQL injection?
Prepared statements/parameterised queries
Stored procedures
What is a prepared statement?
It is a way of executing sql in Web application that allows the sql command and the parameters to be defined separately so that the application can tell what is code and what is not. The command is defined first and the parameters and passed in afterwards. This means that any parameter inouts will never be considered code and thus cannot inject sql.
How would you implement a prepared statement?
You would first get the parameters from the input data.
Next you would defined the sql command as a string, with a placeholder value that goes where parameters should go (in java this placeholder is ?).
Next you create a prepared statement object which let’s the application know that that the sql command string is a command, and convert it as such.
Finally we can pass in the input parameters to this prepared statement and it will add them in order to all the placeholders, knowing not to treat the parameters as sql code (In java we use the prepared statement method setString(…) to add the parameters).
What is a stored procedure?
Stored procedures are used to prevent sql injections by defining an SQL query and the parameters separately, and passing the parameters in later so that the application does not recognise parameters as code. This is very similar to prepared statements, but the difference is that stored procedures are defined in the database itself, not the application. The application must retrieve the stored procedure to use it.
What is the difference between a stored procedure and a prepared statement?
Stored procedures are defined and stored in the database rather than defined in the code of the application.
How would you implement a stored procedure?
First, you get the parameters from the I out data.
Next you retrieve the procedure from the database and stored it is as a stored procedure in the code (In java it is stored as a CallableStatement).
Next you pass the parameters and add them into the statement in order (in java CallableStatement has a method setString(…) for this purpose) .
Now execute the statement.
What is cross site scripting?
It’s when an attacker takes advantage of unsanitised inputs to embed client side scripting (Normally java script) into a legitimate website.
What are the dangers of cross site scripting?
Once the script has eebn embedded in the site, all users that view the page with that script will have the script be executed for them, and depending on the purpose of the script it could potentially cause harm.
Give an example of cross site scripting?
A website has an inout like a comment box. If the comment box input is not sanitised, then script (e.g. Java script) entered into the comment will be registered as code rather than text. This means that the comment entered will be executed for users who view the comment.
What are the 2 categories of cross site scripting?
Stored cross site scripting attack
Reflected cross site scripting attack
What happens during a stored cross site scripting attack?
An attacker inouts malicious script into a website.
The site stores this data on its servers, without sanitising the input.
When a user accesses this data, the script is executed because the script is registered as code rather than text.
What are some uses for cross site scripting?
To open an unsafe website for the user.
To download an unsafe file onto the users pc.
To send data from the users session back to the attacker.
To comment out the rest of the Web page.
What happens during a Reflected cross site scripting attack?
In this type of scripting attacker, the malicious script is not inputed into inout fields on a Web page but rather variables in the Web page url. If the variable is not sanitised, then the script can be executed. This type of attacker only affects the user who enters the script.
E.g. Url:
https://www.example.co.uk/index?variablename=Insert script here
How might an attacker weaponise a Reflected cross site scripting attack, when the script is only executed for the person how enters it?
The attacker could send the link to an end user with the script as part of it in a url variable. If the user clicks the link then the script is executed for them.
An attackwr might use a url shortener to hide the fact that script is in the url, or link is on an online forum where the link shows as a title rather than the url.
What methods could you use to prevent a cross site scripting attack?
Being careful about what untrusted inputs you are injecting into your html and Web page code and clearly define sections fo your code that will refer to untrusted inputs.
Encoding inputs before injecting the data into your Web page.
What does Encoding your inouts do?
It ensures that inputs are not executed, by making sure that are not recognised as script/code. It goes through the inout and encodes characters that might result in the inout being executed e.g. Html <> tags. These characters may be encoded, but when displayed as text on screen they show as the original character.
What is broken authentication?
When authentication is not implemented properly. A company might implement their own password and session management, but this may not adhere to good security protocols.
For example, if a user logs into their bank account from a public company and the session time out is ey to an hour, someone else might be able to use that public computer to access the account before the session times out.
What is sensitive data exposure?
It is when unauthorised access is gained to sensitive data, and this data is copied, retrieved or stolen etc..
This could happen in different ways, e.g. Sql injection attacks, or compromised data servers.
How should you mitigate sensitive data exposure?
Only store sensitive data which you need to carry out your service.
Ensure that there is appropriate security and effective authentication and authorisation on the data. You might use encryption or hashing.
What are XML external entities?
It is when you use XML within a Web application to retrieve external data from another source.
How to mitigate attacks that take advantage of XML external entities?
Using the latest version of JSON or something similar.
Upgrading older XML processors.
Disabling the processing of external entities.
How might an attacker take advantage of XML external entities?
A malicious url could be provided as the source of the external entities, and thus retrieving and evaluating this data could result in a security incident e.g. Remote request for access, DoS,, scanning if the Web app system…
What is security Misconfiguration?
When security controls and protocols are poorly implemented, inaccurately configured or left insecure, putting your data at risk.
What is an example of security Misconfiguration?
Poor password management - allowing users to choose weak passwords, or storing passwords in physical locations.
Default account management - using default names for usernames and passwords and not changing them e.g. Admin.
Lack of maintenance of software - not updating software such as antiviruses and or other software or hardware.
What is broken access control?
It is the failure to uphold proper authentication of users and authorisation of permissions. Broken access control can main that users could act outside of their intended permissions and do things they otherwise couldn’t do.
What are examples of broken access control?
Insecure direct object references
Missing function level access control
What is insecure direct object references?
When an object is directly referenced from the url as a url parameter. These are insecure because the user could change the data being retrieved to data they cannot access by changing the parameter data in the url. It allows users to bypass permissions and authorisations. It only works if improper authentication is in place that doesn’t check that the user should have access to the data.
How would you mitigate insecure direct object references?
Implementing better authentication,by checking whether or not a user should have access to the data being referenced.
This could be done with session variables that check which user is logged in, and check whether that user can access the data.
Another option is to remove direct object references from url, and use indirect object references using input fields. E.g. A drop down inout that shows the ONLY the data that the user can access.
What is missing function level access control?
When improper authentication is in place that allows a user to request functionality they don’t have access to and are given access because their authorisation is not checked. Authentication is only happening at the presentation level, not the function level.
How would you mitigate the vulnerability of missing function level access control?
By implementing better authorisation. This authorisation must be at function level, rather than presentation level.
What is insecure deserialisation?
When there is no validation for editing a serialised object, thus introducing insecurities when derialisation of that object occurs if the deserialisation process does not valid the object either.
What is serialisation?
When a piece of data is converted into a format that can be stored more efficiently. Normally into a string that can be stored easily.
What is deserialisation?
The reverse process of serialisation. When you convert data from its stored form back to its original form.