Bird
Raised Fist0
Computer Networksknowledge~10 mins

SQL injection via network in Computer Networks - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to identify the type of attack shown in the network log.

Computer Networks
if packet.payload.contains('[1]'):
    alert('Possible SQL injection detected')
Drag options to blanks, or click blank then click option'
AUPDATE
BDROP
CINSERT
DSELECT
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing DROP or UPDATE which are less commonly the first sign of injection.
Confusing INSERT with SELECT in detection.
2fill in blank
medium

Complete the code to block SQL injection attempts by filtering input containing {{BLANK_1}}.

Computer Networks
def is_safe(input_string):
    return '[1]' not in input_string.upper()
Drag options to blanks, or click blank then click option'
ASELECT
BDROP
CDELETE
DINSERT
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering only DROP or DELETE but missing SELECT.
Not converting input to uppercase before checking.
3fill in blank
hard

Fix the error in the network filter rule to detect SQL injection containing {{BLANK_1}}.

Computer Networks
if '[1]' in packet.payload.lower():
    log('SQL injection attempt')
Drag options to blanks, or click blank then click option'
AselECT
BSELECT
Cselect
DSeLeCt
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase SELECT when payload is lowercase.
Using mixed case which won't match.
4fill in blank
hard

Fill both blanks to create a network rule that detects SQL injection attempts with keywords and logical operators.

Computer Networks
if '[1]' in packet.payload and '[2]' in packet.payload:
    alert('SQL injection detected')
Drag options to blanks, or click blank then click option'
ASELECT
BOR
CAND
DDROP
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing AND instead of OR which is less common in injections.
Using DROP which is a command but not a logical operator.
5fill in blank
hard

Fill all three blanks to complete the network detection code for SQL injection using keyword, operator, and comment syntax.

Computer Networks
if '[1]' in packet.payload and '[2]' in packet.payload and '[3]' in packet.payload:
    block(packet)
Drag options to blanks, or click blank then click option'
ASELECT
BOR
C--
DDROP
Attempts:
3 left
💡 Hint
Common Mistakes
Using DROP instead of comment syntax --.
Missing the comment syntax which is crucial in injections.

Practice

(1/5)
1. What is SQL injection via network in simple terms?
easy
A. A way to backup database data remotely
B. A method to speed up database queries over the network
C. An attack where harmful commands are sent to a database through a network connection
D. A network protocol for secure database communication

Solution

  1. Step 1: Understand the meaning of SQL injection

    SQL injection means sending harmful commands to a database to manipulate or steal data.
  2. Step 2: Connect SQL injection with network

    When these harmful commands are sent through a network connection, it is called SQL injection via network.
  3. Final Answer:

    An attack where harmful commands are sent to a database through a network connection -> Option C
  4. Quick Check:

    SQL injection via network = harmful commands sent over network [OK]
Hint: Think: harmful commands sent through network to database [OK]
Common Mistakes:
  • Confusing SQL injection with normal database queries
  • Thinking it is a backup or speed method
  • Mixing it up with network security protocols
2. Which of the following is a correct way to prevent SQL injection via network?
easy
A. Use input validation and parameterized queries
B. Send raw SQL commands directly over the network
C. Disable network connections to the database
D. Allow all user inputs without checks

Solution

  1. Step 1: Identify safe practices against SQL injection

    Input validation checks user data, and parameterized queries separate data from commands, preventing injection.
  2. Step 2: Evaluate other options

    Sending raw commands or allowing unchecked inputs increases risk; disabling network is impractical.
  3. Final Answer:

    Use input validation and parameterized queries -> Option A
  4. Quick Check:

    Safe coding = input validation + parameterized queries [OK]
Hint: Prevent injection by validating inputs and using safe queries [OK]
Common Mistakes:
  • Thinking disabling network is practical
  • Believing raw SQL commands are safe
  • Ignoring input validation importance
3. Consider this SQL query sent over a network: SELECT * FROM users WHERE username = '' OR '1'='1';. What is the likely result?
medium
A. Causes the database to crash
B. Returns no users because of syntax error
C. Returns only users with empty username
D. Returns all users because the condition is always true

Solution

  1. Step 1: Analyze the SQL condition

    The condition username = '' OR '1'='1' means either username is empty or '1' equals '1'. Since '1'='1' is always true, the whole condition is true for all rows.
  2. Step 2: Understand query effect

    Because the WHERE clause is always true, the query returns all users from the table.
  3. Final Answer:

    Returns all users because the condition is always true -> Option D
  4. Quick Check:

    Always true condition returns all rows [OK]
Hint: Look for always true conditions like '1'='1' [OK]
Common Mistakes:
  • Assuming syntax error due to quotes
  • Thinking it returns no rows
  • Believing it crashes the database
4. A developer wrote this query to get user info: "SELECT * FROM users WHERE id = " + user_input; sent over network. What is the main problem?
medium
A. It concatenates user input directly, risking SQL injection
B. It uses prepared statements safely
C. It uses parameterized queries correctly
D. It encrypts user input before sending

Solution

  1. Step 1: Examine how user input is used

    The query concatenates user input directly into the SQL string, which can allow attackers to insert harmful commands.
  2. Step 2: Identify risk of SQL injection

    Direct concatenation without validation or parameterization is a common cause of SQL injection vulnerabilities.
  3. Final Answer:

    It concatenates user input directly, risking SQL injection -> Option A
  4. Quick Check:

    Direct input concatenation = injection risk [OK]
Hint: Avoid direct string concatenation with user input [OK]
Common Mistakes:
  • Thinking concatenation is safe
  • Confusing with parameterized queries
  • Assuming encryption is done automatically
5. You receive a network log showing this suspicious query: SELECT * FROM accounts WHERE user = 'admin'--' AND password = 'anything'; What does the -- do in this SQL injection attempt?
hard
A. Encrypts the password part of the query
B. Comments out the rest of the query, bypassing password check
C. Ends the SQL statement safely
D. Causes a syntax error and stops execution

Solution

  1. Step 1: Understand the role of -- in SQL

    The -- sequence starts a comment in SQL, ignoring everything after it on the same line.
  2. Step 2: Analyze the effect on the query

    By commenting out the password check, the attacker bypasses authentication, gaining access as 'admin'.
  3. Final Answer:

    Comments out the rest of the query, bypassing password check -> Option B
  4. Quick Check:

    -- = comment to skip code [OK]
Hint: Remember -- starts a comment in SQL [OK]
Common Mistakes:
  • Thinking -- encrypts or ends query safely
  • Assuming it causes syntax error
  • Not realizing it bypasses checks
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard