Understanding Source Code
Hey everyone and welcome to this article on understanding source code. First, let me start by explaining that this article will not teach you to hack anything specifically, but it will give you the understanding you need to start to learn to hack.
Okay, first let me tell you a little about what source code is. Source code is the code behind every webpage. It is all the HTML and CSS and various other types of code that make up a website. A little knowledge of HTML would be helpful in understanding source code, but it is not entirely necessarry.
The next thing you will need to know is how to access the source code. With most web browsers it is as simple as a right click->View source code. If your browser does not have this option I suggest googling how to access source code on (your browser). There are also different shortcuts for accessing the source code quickly for example in Google Chrome the shortcut is "CTRL + U"
Now there are numerous add-ons to your browser that allow more advanced access to the source code such as "firebug" but for now I will just be teaching you the basics.
Okay so now we know how to access the source code go ahead and do it. I will wait here while you scratch your head trying to figure out what all this code means.... Back yet? Good! Ok now I know this looks very confusing but trust me, once you have got your head around it, it will all become much clearer!
First lets open up another tab and go to the [hackthis.co.uk] home page and access the source code. It should look something like this:
The first thing we see is a piece of code like this:
This small piece of code is just defining the document type and some protocols and doesn't really yield much information that is relevent at this moment in time.
Next is the head section of the source code. You can tell this by what is known as the 'Head tag'. In html every section is tagged with an open and closed tag.
<head> is the opening tag and is the beginning of the head section.
</head> is the close tag and signifies the closing of the head section.
Next comes some code that helps the webpage work better with different versions of internet explorer (this is necersary as internet explorer sucks and isn't compatible with some code. If you are using internet explorer then I suggest you upgrade to firefox or google chrome).
Now I can't sit here all day and explain what every part of this source code means but I will briefly explain what the most important parts mean.
Divs are what makes a webpage modular. Each div, like most other tags in the source code is opened by <div> and closed by </div>. Each "part" of the website is usually made up
The titles "hackthis" will be in one div, then the navigation bar will be in another div etc etc. Divs run like a book, left to right, so if there are 2 two different "parts" next to each ther the one on the left will usually come first in the source code. Divs are usually defined by either "class=" or "id=" after the word div like this:
This would show that the div you are looking at would be the title div.
A very important thing to look for in the source code is a chunk called a "comment" these look this in HTML:
When you put anything in the source code in these tags, it will be ignored by the browser. Web developers use this to remind them about things in the code or to leave bits of information on the webpage without actually displaying them. Keep your eye out for these as sometimes they contain information that the coder didn't mean for you to see!
The last bit of code I shall mention in called "href". This is simply a link. So if you see:
it will display a link on the page that says "Google" and when you click it, it would go to http://www.google.com
Ok, so thats about all that I will be saying about the coding of the source code.
So to recap:
To open the source code, right click anywhere on the website and click view source. The head section contains information such and style sheets(CSS) and meta info. Divs are what makes the webpage modular and easier to understand in the source code. Comments are used for information that is not meant to be seen by the end user href's are used to make hyperlinks to other websites or another part of the website.
So now that you know what source code is, go out there and start looking at other websites source code! Like I said, there usually is much to hack within the source code but it may point you in the right direction. Now having read this, you should have enough knowledge to complete the first few main level challenges. So what are you waiting for?! Get in there and HACK!