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.