Testing injection attacks
Any inputs into your system are a possible way for a hacker to gain access or inject malicious data. Everything entered into your system should be checked, and as a tester, you get to play the role of the hacker, probing your application’s defenses. We met some of these attacks in Chapter 5, Black-Box Functional Testing, and the different input types users can enter. In text fields, the primary attacks are SQL injection, HTML injection, code injection, and Cross-Site Scripting (XSS) attacks.
SQL injection
SQL injection involves entering a string that, if naively copied into a line of code, will perform unauthorized database changes instigated by an attacker. Consider this snippet of Python that uses a string without validating it first:
SQLCommand = 'INSERT INTO users VALUES (username);'
This works fine if username
is "
Simon Amey"
:
SQLCommand = 'INSERT INTO users VALUES ("Simon Amey");'
However...