Hack This Site: Realistic Web Mission – Level 4

Hello and welcome to haxez, today we’re looking at Hack This Site Realistic Web Mission Level 4. I liked this challenge although I was confused about the syntax used to complete the mission. The mission requires you to perform a UNION ALL SQL Injection in order to grab email addresses from a database. Once you have the email address, you need to email them to the client. If you haven’t seen my other posts are the realistic series you can do so here: Part 1, Part 2 and Part 3.

Realistic 4 Fischer’s Animal Products
Fischer’s Animal Products

The mission should you chose to accept it is to hack the FAP website and steal the email addresses of everyone on the mailing list. Why?, because FAP kills animals to sell their pelts to rich customers. SaveTheWhales has kindly asked us if we can get the mailing list and send it to him so that he may “contact them”.

Realistic 4 Message From SaveTheWhales
Message From SaveTheWhales

Exploring The Realistic 4 Website

Visiting the website, you’re greeted with a fairly simple page that explains what the web application is about. There is a submission box to add your email address to the mailing list. There are also two links, one to Fur Coats and one to Alligator Accessories (poor Alligators). We could try attacking the mailing list submission system but for now, let’s continue exploring the application.

Realistic 4 Main Web Application Page
Main Web Application Page

Following the Fur Coats and Alligator Accessories links takes you to the corresponding product pages. These pages appear to be dynamic, as though they were being generated by an SQL Query. If we look at the structure of the page, it can be broken down into three database columns Picture, Description, and Price. We can also assume that there is a table for email addresses.

Web Application Product Page
Web Application Product Page

The Website Hack

Although the application didn’t error when appending a single quotation mark. We can still attempt to perm a UNION SQL injection. The syntax for the specific SQL injection to retrieve the data confuses me slightly. For example, W3Schools and Portswigger have excellent articles on UNION SELECT and UNION SQL injections. W3Schools explains that the difference between UNION SELECT and UNION ALL SELECT is that UNION ALL SELECT will include duplicate values whereas, UNION SELECT won’t. The information that we exfiltrate from the database doesn’t have duplicate values but the UNION SELECT injection doesn’t work. Furthermore, Portswigger has a number of examples and they all start with a single quotation mark to break out of the existing SQL query. Adding a single quotation mark to the UNION ALL SELECT command here doesn’t work. I’m probably misunderstanding what’s going on but feel free to leave me a comment.

Anyway, back to the hack. So we know there are likely three table columns. One for the product picture, one for the product description, and one for the product price. We also know that there is likely a table called email, or emails. With this information, we can structure our UNION ALL SELECT command.

SQL Injection

Firstly, in order to perform an SQL injection on realistic 4, we need to tell the application what type of query we’re performing.

UNION ALL SELECT

Secondly, we tell the database what columns we want and what column we want to inject our data into. This works with both columns two and three. However, if you inject it into column two your font will be normal but if you inject it into column three your font will be bold. This matches the formatting of the website.

NULL, *, NULL, NULL

Finally, we tell it where we want to query the data from. For example, we want to pull the data from the email table. We also need to end the query with a semicolon.

FROM EMAIL;

Put it all together and you should have an SQL injection that looks like the following.

UNION ALL SELECT NULL, *, NULL, NULL FROM email;

Moving forward, we need to append the SQL injection to the end of the URL after the 1. The query should look something similar to the image below depending on your injection point and the case of your characters.

UNION ALL SELECT SQL Injection
UNION ALL SELECT SQL Injection

Once you have done that, hit return on your keyboard and you should see the web application load with some additional information. The email addresses from the mailing list have been included with the product queries.

UNION ALL SELECT SQL Injection Returned Results
UNION ALL SELECT SQL Injection Returned Results

Copy the email addresses from the page and head back to the main HackThisSite website. Click your name on the left-hand side and then when your profile loads, click it again. You will now a send message box. Change the recipient to SaveTheWhales and send them the list of email addresses that you hacked from the FAP website.

Replying to SaveTheWhales
Replying to SaveTheWhales

That’s it, you should now have completed this mission. This was a fun mission that uses a practical exploitation technique in the form of a UNION-based SQL injection. While I argue that the syntax is a bit odd and will wait for someone to correct me before changing my mind, it is a good example. What we can learn from this is that queries to back-end databases should use prepared statements. Use prepared statements!!!

Anyway, thats Realistic 4 hacked and that’s it for today. I hope you enjoyed it. Please check out the video and I will see you next time.

Hack This Site: Realistic Web Mission – Level 3

Hello world, welcome to haxez where today we are looking at Hack This Site Realistic Mission number 3. This mission requires knowledge of website structures and how web forms work. To summarise, It’s a fun mission but some of the syntax is incorrect unless I’m mistaken. If you haven’t seen my other posts are the realistic series you can do so here: Part 1, and Part 2.

Realistic 3 Peace Poetry Mission

Upon navigating to realistic mission 4, you are greeted with the following message from PeacePoetry. The message explains that she has built her own site to submit and share peace-related poetry. However, someone has hacked her website and posted pro-war propaganda. She has asked whether we can hack her website to restore the original content.

Realistic 3 Message From PeacePoetry
Message From PeacePoetry

Exploring The Realistic 3 Website

Upon visiting the website, we’re presented with a title that says the page has been hacked. There is a picture of a majestic and patriotic eagle. The website doesn’t have much functionality other than that.

Realistic 3 Defaced Web Application
Defaced Web Application

There isn’t much going on at the surface level. Let’s dig a little deeper and see what is going on in the page source. As shown below, the image shows the page source and that the hackers kindly left a message to inform us where the old site was located. As a result, the old site can be found at oldindex.html.

Defaced Web Application Page Source
Defaced Web Application Page Source

If we navigate to the oldindex.html, we find the original website. Furthermore, It has a bit of dynamic functionality that allows you to submit and read poems. The Poem submission system appears to write the poems directly to the directory where the website is located. We can use the Poem submission system to restore the hacked website.

Original Web Application
Original Web Application

Restore Website Hack

If you head back to the oldindex.html page, you can view the page source. Select all of the page source and copy it to your clipboard or save it in a notepad document. Once you have it copied, head back to the poem submission system.

Original Web Application Page Source
Original Web Application Page Source

Paste the page source for the oldindex.html page into the Poem content box. In addition, name your Poem ../index.html. I’m not sure why we need to step up a directory to overwrite the current index.html page. Looking through the website content, everything appears to be stored in the /3/ directory. It shouldn’t require directory traversal to overwrite the page. I digress, with the name of the poem as ../index.html, it should overwrite the currently hacked index.html with the page source of the original website. This won’t fix the vulnerability. However, it will bring the old site back as the primary page.

Poem Submission System
Poem Submission System

Clicking submit will solve the challenge

Hack This Site: Realistic Web Mission – Level 2

Hello world, welcome to haxez where today we are looking at Hack This Site Realistic Mission level 2 where we need to hack the Nazis. Personally, I loved this mission. It’s much more immersive than the basic challenges as the website you need to hack could be real. While the web application only has two pages, the main page sets the tone instantly. In order to complete this mission, we need to perform an SQL Injection on the login page of the Nazi Web Application. Please check out my article on Realistic 1 if you haven’t already done so.

Realistic 2 Chicago American Nazi Party Web Application
Chicago American Nazi Party Web Application

Navigating to Realistic 2 presents you with a message from someone called DestroyFacism. They have heard we are a good hacker and want our assistance taking care of the Nazis. The Nazis are organizing a hate rally against immigration. We can’t have that, let’s take them down.

Realistic 2 Message from DestroyFacism
Message from DestroyFacism

Exploring The Realistic 2 Web Application

Loading their web application, the symbolism is strong. If you’re easily offended by Nazi symbolism then maybe this one isn’t for you. Personally, I love the fact that I’m getting to hack the Nazis, it feels so freaking cool. Anyway, back to the technical stuff. The website appears to be basic, there is no interaction other than the images. I don’t recommend clicking on them as they do link to a real Nazi website.

Realistic 2 Main Web Application Page
Main Web Application Page

As there isn’t much going on at the surface, let’s look at what’s going on under the hood. There isn’t much to see except for a URL which we didn’t see on the main page. The URL references a page called update.php, as the main page is likely index.html or index.php we can assume this is a different page.

Main Web Application Page Source
Main Web Application Page Source

Navigating to update.php, we get a login form. This is going to be the method we use to hack the application. There could be a number of techniques used to hack it (such as brute-forcing), but we should test if the application is vulnerable to SQL injection. In order to do this, we can use a single quotation mark to escape the login forms SQL query and append our own data to the query.

Application Admin Login Page
Application Admin Login Page

Web Application Hack

Submitting a single quotation mark to the application caused it to error. This means the application isn’t using prepared statements for SQL queries. To elaborate, prepared statements use placeholders such as question marks to reference SQL queries. This means that the SQL query can’t be escaped because it is being called by the placeholder. However, as this application produced an SQL error it most definitely isn’t using prepared statements which means we can hack it.

SQL Error On Admin Login Page
SQL Error On Admin Login Page

By entering a value and escaping it with a single quotation mark, we can append our own SQL query to the current query. The value we are going to append is:

'or 1=1 --

This value will help us bypass the authentication because the answer is true. 1 does equal 1 so the SQL server will allow us to access the area of the application that the login form was protecting.

SQL Injection On Admin Login Page
SQL Injection On Admin Login Page

After submitting the value you will have completed the mission. This is by far one of the best missions I’ve come across doing labs. It’s an easy lab but the theme of it is brilliant, who wouldn’t love to hack Nazis. It also uses a practical exploit which is still common in the wild. Injection attacks were number 1 on the OWASP top ten up until recently. The lesson that can be learned from this is to use prepared statements when your web application needs to query a SQL server.

Hack This Site: Realistic Web Mission – Level 1

Hello world, welcome to haxez where today today we are looking at the Hack This Site Realistic Web Mission level 1. This mission requires the hacker to modify the source of the web application to modify its behavior. The reason behind the hack is to increase the rank of the band Raging Inferno. This hack uses a similar technique to one of the basic missions where we had to modify Sam’s email address to send the email to ourselves. If you want to read my posts about the basic missions, you can do so here.

Realistic 1 Uncle Arnold’s Local Band Review
Uncle Arnold’s Local Band Review

Navigating to realistic mission 1, you are presented with a message from HeavyMetalRyan who explains that he made a bet that his band would be ranked first. Unfortunately, two of his band members died in an accident but the person he made the bet with insists the bet is still on. HeavyMetalRyan would like us to hack the web application so that his band is at the top of the chart.

Realistic 1 Message from HeavyMetalRyan
Message from HeavyMetalRyan

Exploring The Realistic 1 Web Application

The functionality of the application appears to be basic. Each band is listed and has a voting option next to them. The voting option allows the user to submit a score between one and five. There doesn’t appear to be any other functionality on the application other than links to the band.

Exploring The Application
Exploring The Application

HeavyMetalRyan said in his message, that his band is called Raging Inferno. So far, they don’t appear to have the most rave reviews. Using the voting system appears to submit the value of the selected number back to the server. In order to hack the application, we will need to view the page source.

Web Application Hack

In order to “hack” the application, we need to look at the page source and make some modifications before submitting the vote. This can be done in many browsers by right-clicking on the page and selecting view source from the context menu. The image below shows the page source before modification. You can see that option 5 has a value of 5. When the vote button is pressed, the value 5 will be recorded as the vote.

Web Application Source Code
Web Application Source Code

In order to complete this challenge, we need to modify the value of 5 to a significantly higher value. This means that when the vote button is clicked, the higher value will be submitted rather than the value of 5. The image below shows the page source after the modification has taken place.

Manipulating The Source Code
Manipulating The Source Code

Once the value has been modified, we can select the option that we have modified and click the vote button. This should send the modified value back to the server instead of the originally intended value.

Casting The Vote
Casting The Vote

With the vote submitted you should have now completed the challenge. I hope you enjoyed this post but please check out the video if you would prefer to watch a demonstration.

Hack This Site: Basic Web Challenges – Level 11

Hello world and welcome to haxez where today we are solving Basic 11. This the final challenge in the Hack This Site Basic web series. The series as a whole has been fun and I recommend giving it a go. This challenge doesn’t require any form of exploitation. Instead, it relies on the user’s knowledge, whit, and exploration skills. It’s a bit of a cheeky challenge as the last part had me scratching my head for a bit. If you haven’t seen my previous posts in this series then you can do so here: Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 7, Part 8, and Part 9.

Hack This Site Basic 11
Hack This Site Basic 11

Navigating to the Basic 11 page shows a sentence that includes a song title. After a bit of research, it turns out that the song was sung by Elton John. Not knowing what to do with that information, I continued exploring the Web Application. The way I solved this challenge was to brute-force the directories. However, that isn’t the intended approach and would probably be frowned upon by the Hack This Site server admins. Sorry guys.

Basic 11 Elton John Song Titles
Elton John Song Titles

Exploring The Basic 11 Web Application – The Hard Way

The proper way to solve this challenge is to use your whit and deductive skills. We know the song was sung by Elton John so let’s see if there is an E directory.

Basic 11 L directory listing
L directory listing

The ‘e’ directory exists and even better, directory listing is enabled on the server. We can see that the next directory is the ‘l’ directory. I can see where this is going.

T directory listing
T directory listing

Tumbling, tumbling, tumbling further down the rabbit hole we go.

O Directory
O Directory

Almost there

N directory listing
N directory listing

One final directory to check and we will have the password.

Empty Directory Listing
Empty Directory Listing

Or not, after all that, the directory is empty. Or is it? dotfiles are hidden files on a Linux system. One particular dot file used within web environments is the .htaccess. If we navigate to the .htaccess file we can see the following data. Normally, .htaccess files are protected so they can’t be read by everyone. However, it looks like the file permissions are wrong on this one.

.htaccess File
.htaccess File

The .htaccess file shows some information, the most important part is the DaAnswer directory. We can append DaAnswer to the current URL and it produces the page below.

DaAnswer directory listing
Empty Directory Listing

I must admit that this had me scratching my head for a while. I viewed the source code, I checked other directories, I was stumped at this point but the answer was right in front of me. The sentence literally tells you the password. The answer is available. I can’t believe how long it took me to realize this. I feel that this is cheating slightly. With the password in hand, you can head to the /11/ directory followed by index.php. That should allow you to submit the password and complete the challenge.

Password Submission System
Password Submission System

Exploring The Application — The Easy Way

Normally once a challenge is complete I wouldn’t explore it further. However, I feel that I need to be honest about how I actually solved this challenge. I cheated. I was stumped on the song titles. As this challenge didn’t require any form of exploitation I didn’t know where to go next. I used a brute force tool to learn the location of the directories. The brute force tool also found the .htaccess file and the DaAnswer directory. I believe doing it this way was quicker than it would have been if I had done it manually.

Basic 11 Brute Forcing Directories
Brute Force Directories

That’s it from me. I have really enjoyed this series and can’t wait to start the realistic missions.

Hack This Site: Basic Web Challenges – Level 10

Hello world and welcome to haxez, where today, we’re looking at Hack This Site Basic Web Challenges level 10. This challenge requires us to manipulate cookies in order to authenticate against the application. A cookie is a small file that contains data, the data is utilised by the applications to make decisions. For example, if you add an item to your shopping basket then the website could issue a cookie which contains that information. That way, when you revisit the application, the item is still in your basket. If you haven’t see my previous posts in this series then you can do so here: Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 7, Part 8, and Part 9.

Hack This Site Basic 10
Hack This Site Level 10

Testing The Basic 10 Web Application

After logging in to the application, you will be presented with the following page. There aren’t any hints this time, this time it’s just a password submission form. The image for the challenge mentions having to know your way around Javascript. I’ve looked at the source and didn’t find anything interesting.

Basic 10 Web Application Password Submission System
Web Application Password Submission System

I then fed the application some test data to see how it would respond. I tested a number of characters associated with various types of attacks but they were all sanitised. Submitting generic strings to the password input box results in an authorisation error.

Authorisation Failure
Authorisation Failure

Exploiting The Web Application

In order to investigate the application further, I used Burp Suite to intercept the request. The image below shows that the request is setting a cookie called “level10_authorized”. The cookie is set to no, but it can be manipulated through Burp Suite.

Burp Proxy Request Interception
Burp Proxy Request Interception

Burp Suite allows you to intercept the request and modify it before forwarding the data to the application. As we have captured the request, let’s change the value of the “level10_authorized” cookie from no to yes and forward the request. You will also need to forward any subsequent requests too.

Burp Proxy Request Modification
Burp Proxy Request Modification

Completing The Challenge

After changing the value to yes and forwarding the requests, you should have completed the challenge. This was a fun challenge that shows the importance properly implementing cookies. Using yes/no cookies for authentication is not a good method for authenticating users. Cookies are used for user sessions to keep users logged in. However, those cookies are set after the user has successfully authenticated with a password.

Congratulations
Congratulations

Hack This Site: Basic Web Challenges – Level 9

Welcome to haxez, today we’re looking at Hack This Site Basic Web Challenge Level 9. This challenge is similar to level 8 and you have to use the level 8 application in order to complete it. It requires thinking outside the box and using level 8 as the platform to launch the attack. If you haven’t see my previous posts in this series then you can do so here: Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 7, and Part 8

Hack This Site: Basic Web Challenges - Level 9
Hack This Site: Basic Web Challenges — Level 9

Testing The Basic 9 Web Application

After logging in and navigating to level 9 you will be greeted with the following page. It looks like Sam has been up to his old tricks. Instead of implementing a strong password system, Sam has decided to continue obscuring the file. The only form on this box is the password form which isn’t injectable.

Web Application Password Submission System
Web Application Password Submission System

Exploiting The Web Application

As there is no form to inject on level 9, we should head back to level 8 and inject that form. We use the same injection that we did last time but we modify it to list out the contents of the 9 directory. The script below performs the same Server Side Include Injection but this time it traverses up two directories in to the 9 directory.

<!--#exec cmd="ls ../../9"-->
Web Application Exploitation Basic 9
Web Application Exploitation

Retrieving The Password

As with level 8, executing this payload will tell the php script to execute the command and write the output to the shtml file. When clicking view on the following page you will see the listed files including the PHP file containing the password.

Listing Files
Listing Files

Grab the file name and append it to the level 9 url. This should then show you the password which you can copy and paste it in to the level 9 password submission system to complete the challenge.

Password Retrieved
Password Retrieved
Congratulations
Congratulations

Hack This Site: Basic Web Challenges – Level 8

Hello and welcome to haxez, today we are looking at Hack This Site Basic Web Challenge level 8. This challenge requires you to perform a Server Side Include injection in order to retrieve the password. A server side include is a chunk of code in a separate file that you can include in different pages. For example, if you had a website with a header and a side menu. You could put the header and side menu in separate files and then include them on other pages with a single line such as “<!–#include virtual=”includes/header.shtml” –>“. A Server Side Include Injection attack exploits web forms that accept user input to generate files.

If you haven’t see my previous posts in this series then you can do so here: Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, and Part 7.

Hack This Site Basic 8
Level 8

Testing The Basic 8 Web Application

Once you’ve logged in and navigated to level 8 you will see the page below. The information reads as follows:

Sam remains confident that an obscured password file is still the best idea, but he screwed up with the calendar program. Sam has saved the unencrypted password file in /var/www/hackthissite.org/html/missions/basic/8/

However, Sam’s young daughter Stephanie has just learned to program in PHP. She’s talented for her age, but she knows nothing about security. She recently learned about saving files, and she wrote a script to demonstrate her ability.

Security Sam

There are two pieces of important information hidden in the text. Firstly, the full file path is mentioned. This suggests to me, that we will need to know the structure of the application in order to exploit it. Secondly, Sam’s daughter has been learning PHP but doesn’t know anything about security. This is likely going to be the part of the application that we need to attack. So first, we are going to submit a basic value to the application and see what happens.

Basic 8 Web Application Functionality
Web Application Functionality

As you can see from the image below, submitting the test string has written it to a shtml file. The script appears to doing same basic arithmetic to calculate the number of letters in the submitted value. However, the thing to notice here is that it’s writing to an shtml file. This suggests, that the application could be vulnerable to a Server Side Include Injection attack. It is also worth nothing that the files are written to the tmp directory but the location of the password is one directory above that.

Basic 8 Web Application Results
Web Application Results

Exploiting The Web Application

In order to exploit the application, we can submit a basic Server Side Include Injection payload. The payload is going to use the cmd directive to execute the ls Linux command. Additionally, we are going to tell the ls command to list out the files of the directory above it. When we submit the payload, the application will include it in the script that generates the shtml page. It will execute the payload and store the results in the shtml file.

<!--#exec cmd="ls ../"-->
Web Application Server Side Include Injection
Web Application Server Side Include Injection

As you can see from the image below, the payload has been executed by the PHP script and the results have been stored in the shtml file. The au12ha39vc.php file appears to be the one we are looking for.

Web Application Server Side Include Injection Results
Web Application Server Side Include Injection Results

Recovering The Passowrd

Copy the file name of the php file and append it to the URL and you will be able to recover the password.

Password Retrieved
Password Retrieved

You can then go and submit the password and you will have solved the challenge.

Congratulations
Congratulations

Hack This Site: Basic Web Challenges – Level 7

Hello world, welcome to haxez where today we’re looking at Hack This Site Basic Web Challenge 7. This challenge requires performing command injection to complete it. If you haven’t see my previous posts in this series then you can do so here: Part 1, Part 2, Part 3, Part 4, Part 5, and Part 6. Command injection is a type of attack that allows the malicious threat actor to execute arbitrary commands on the host system.

Hack This Site Basic 7

Let’s begin, after navigating to Basic 7 you will be greeted with the following text.

“This time Network Security sam has saved the unencrypted level7 password in an obscurely named file saved in this very directory. In other unrelated news, Sam has set up a script that returns the output from the UNIX cal command. Here is the script. Enter the year you wish to view and hit ‘view’.”
Security Sam — HackThisSite.org

What we can infer from this, is that the script is running the UNIX cal command directly on the host system. Once the user inputs a value, that value is likely being appended to the script as a variable.

Basic Web 7 Calendar Mechanism and Password Submission System
Calendar Mechanism and Password Submission System

Testing Basic 7 Web Application Functionality

While we can’t confirm the exact syntax of the script, we can test the functionality to see what it’s doing. I submitted the value 1 to the submission box to see how the script behaves. After clicking the view button, we are presented with page showing all the months for the year 1. From this, I can assume that the Perl script (identified with the .pl extension in the URL) is running the command cal -y $year. The $year value is the variable that is taking the user input from the web application, and running it on the host operating system.

Hack This Site Basic 7 Testing Calendar Mechanism
Testing Calendar Mechanism

Exploiting Web Application Functionality

It is essential, that all user input submitted to a web application is treated as untrusted. What this means, is that the web application should check and sanitise the user input before executing it. Otherwise, this could have a detrimental impact on the server. For example, if I was to escape the cal command using a semi-colon and inject the following characters “:(){ :|:& };:” the web-server is going to have a bad time (it’s a fork bomb). However, you should never do that, not even to test. Instead we’re going to use the “ls” command which will list out the current directory.

Hack This Site Basic 7 Command Injection
Command Injection

Stealing the Password

The screenshot below shows the result of escaping the cal command with a semi-colon and running the “ls” command. As you can see, it has listed a number of files including index.php, level7.php, cal.pl and k1kh31b1n55h.php. We already know what the other files do but what is the k1kh31b1n55h.php file for?

Command Injection Directory Listing
Command Injection Directory Listing

If you copy the filename and append it to the URL in your browser, you will be taken to a page containing a string. You guessed it, the string is the password required to complete this challenge.

Hack This Site Basic 7 Password Retrieved
Password Retrieved
Congratulations
Congratulations

Hack This Site: Basic Web Challenges – Level 6

Hello and welcome to haxez where I try to simplify CyberSecurity. This post is a walkthrough of the Hack This Site Basic 6 web challenge . If this is your first time here you can read the previous posts here: Part 1, Part 2, Part 3, Part 4, and Part 5. This challenge is about reverse-engineering the Basic 6 encryption mechanism that Sam is using to encrypt his password.

Hack This Site Basic Web 6

After logging in, you will see the following screen which reads. “Network Security Sam has encrypted his password. The encryption system is publically available and can be accessed with this form”. There is also an input box, which lets you test out the encryption mechanism. In order to test the mechanism, we need to feed it some data to see how it transforms it.

Password Encryption Mechanism
Password Encryption Mechanism

Basic 6 Web Encryption Mechanism

As you can see from the output below, the mechanism has converted 11111111 to 12345678. This allows us to deduce, that the encryption mechanism is adding 1 to a base value of 0. It is then incrementing that value and applying it to the submitted value. Essentially, the first character remains the same. The second character is increased by 1. Then, the third character is increased by 2 and so on and so forth.

Basic 6 Encrypted String
Encrypted String

However, the password contains non-alphanumeric characters such as semicolons and an equals sign. These non-alphanumeric characters, can’t be increased using simple arithmetic. They must be being converted to their ASCII decimal values before being put through the algorithm. We can test this by feeding the mechanism some special characters and seeing what happens.

Basic 6 Password Encryption Mechanism
Password Encryption Mechanism

As you can see from the results below, it is incrementing the non-alphanumerical characters too.

Encrypted String
Encrypted String

The inputted value of ‘!!!!!!‘ becomes ‘!"#$%&‘(‘. This does appear to confirm my theory, that it is converting the inputted value to the ASCII decimal value. Then, for every character in the string, the value is incremented by its position in the string starting from 0. It then converts it back from ASCII decimal to a human-readable format.

Bash Scripting the Solution

In order to solve this challenge, I wrote a basic bash script that reverses the encryption process. It takes the string and converts each character to its ASCII decimal value. It then subtracts 0 from the first character and loops around increasing the value to be subtracted by 1. Once the subtraction is complete, it converts the ASCII decimal back into a human-readable format, giving you the original password.

#!/bin/bash
# This is a script that will solve the password challenge of Hack This Site basic level 6.
# The password is dynamically generated so please replace the value of MyString with the password.
MyString='62cf4;j=' #replace this value
i=0
base=0
echo "Converting to ascii value"
while (( i++ < ${#MyString} ))
do
char=$(expr substr "$MyString" $i 1)
for j in `printf "%d" \'$char` ; do
j=$((j+base))
printf \\$(printf '%03o' $j)
base=$((base-1))
done;
done;

You can copy the script below and save it as decrypt.sh. You will then need to modify the permissions so that the script is executable. This can be done by running chmod +x decrypt.sh. You can then run the script by typing ./decrypt.sh in your terminal and it will output the correct password as you can see below.

─[joe@parrot]─[~]
└──╼ [★]$ ./decrypt.sh
Converting to ascii value
61ac06d6

All you now need to do is to take the output string and paste it into the password submission system and you will complete the challenge.

Congratulations
Congratulations

That’s all from me today. I apologise if my explanation of the encryption and decryption mechanism was a bit hard to follow.