The open window
A shop locks its front door every night, but a back window stays open.
A thief needs only one open window. Software is the same. One weak place is enough.
Security testing looks for the weak places before a thief does.
Key words
| Word | What it means | Example |
|---|---|---|
| Security testing | Tests that look for weak places a thief could use. | Is the password safe? |
| Vulnerability | A weak place in software that an attacker could use. | A password in the code |
| Vulnerability scanning | Using a tool to check software for known weak places. | A scanner finds an old part with a known fault |
| Static analysis | Checking code by reading it, without running it. | Search the code for a password |
| Dynamic analysis | Checking the software while it runs. | Type strange text into a form |
| Integration analysis | Checking the joins between parts are safe. | Is data checked when it moves from one part to another? |
| Database | A store of organised data. | A list of users |
| Attacker | A person who tries to break in or do harm. | A thief online |
| Hard-coded | Written inside the code, not kept safely elsewhere. | password = "abc" |
The cells students fill in are left blank in this preview.
Four tests look for weak places
| Test | How it works | Does the code run? | Example |
|---|---|---|---|
| Vulnerability scanning | A tool checks for known weak places | Sometimes | Finds an old part with a known fault |
| Static analysis | A person or tool reads the code | No | Finds a password written in the code |
| Dynamic analysis | A tester uses the running software | Yes | Types strange text into the login box |
| Integration analysis | A tester checks where parts join | Yes | Is data checked when it goes from the page to the database? |
The cells students fill in are left blank in this preview.
Match each test to its story
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Static analysis: spot the problems
password = "letmein123"
def check(text):
return eval(text)
site = "http://my-shop.example"
print("This code was only read, not trusted.")
# Read the code. There are 3 problems. Do not run it to find them.
# Line 1: a password in the code.
# Line 4: eval runs any text as code.
# Line 6: http is not secure.
Make a free account to save your work and track your progress.
Never write a password in code
Warning
Many people think a password in the code is safe because only the team reads it. Code is copied and shared, so anyone who reads it can see the password. Keep passwords in a safe place outside the code.
Write a tiny analyser
Write a tiny static analyser. It gets the lines of a program as a list of text. It gives back the line numbers that have a problem. The first line is number 1. A problem is a line with password =, eval( or http:// in it. A line with two problems is listed only once. Press Run Tests.
# A tiny static analyser. It reads code as text. It never runs it.
# Each line of the code is one string in the list "lines".
def find_problems(lines):
# Give back a list of the line numbers (the first line is 1) that have a problem.
# A line has a problem if it contains any of these:
# a password written in the code: the text password =
# the dangerous function: the text eval(
# an address that is not secure: the text http://
return []
Make a free account to save your work, or press Start lab to work through the whole lesson.
Dynamic analysis uses the running software
With dynamic analysis you use the running software, as an attacker would.
You type unusual things into forms. You try very long text. You try to open a page without logging in. You watch what the software does.
SQL injection changes the question
A database answers questions written in SQL (the language of databases).
Some programs put what you typed straight into the question. Then you can change the question. SQL injection means that your own text becomes part of the question. Run the code and see how it works.
Try it: why odd input matters
name = "Sam"
query = "SELECT * FROM users WHERE name = '" + name + "'"
print(query)
# Now change the name to: x' OR '1'='1
# Run again. The question now matches every user.
# This is why a tester tries odd input.
Make a free account to save your work and track your progress.
Attack only your own lab
Warning
The next lab runs a shop that is weak on purpose. Attack it, and nothing else. It is your own private copy. Never try these things on a site that is not yours. In the UK that is a crime under the Computer Misuse Act 1990.
Start the lab first
Note
Press Start the lab on the bar at the top of this lesson. Wait until it says it is running. Each Run button types its command into your lab terminal.
Lab 1. Static analysis: read the code
The shop is a small program. Show its code and read it. Do not run anything yet. Find the line that starts with rows. It joins your search text to the SQL question with a plus sign (+). That is a weak place, and you found it by reading.
docker exec app cat /tmp/app/app.pyA command for the lesson’s lab terminal. It is shown here and not run.
Lab 2. Dynamic analysis: a normal search
Now use the running shop. Search for pen. A good shop gives one line: the name and the price.
curl -s -G --data-urlencode "q=pen" http://app:8000/searchA command for the lesson’s lab terminal. It is shown here and not run.
Lab 3. Dynamic analysis: odd input
Now type odd text, like an attacker. The quote mark (') ends the search text early. OR 1=1 is true for every row. The two dashes (--) make the computer ignore the rest of the question. Look at the answer: the shop lists products that are not for sale.
curl -s -G --data-urlencode "q=x' OR 1=1 --" http://app:8000/searchA command for the lesson’s lab terminal. It is shown here and not run.
Check: name the test you used
Have a go
Check: name the test you used
3 questionsIntegration analysis checks every join
flowchart LR
user[User types in a form] -->|1 check here| page[Web page]
page -->|2 check here| api[API]
api -->|3 check here| db[(Database)]
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Final check
Have a go