THM – How Websites Work – Part 9

Last Updated on January 25, 2022 by aghanim

Photo by Erik Mclean on Unsplash

How websites work 

When you visit a website, your browser makes a request to a web server asking for information about the page you’re visiting and will respond with data that your browser uses to show you the page; a web server is just a dedicated computer that handles your requests.  

There are two major components that make up a website:  

  1. Front End (Client-side) – the way your browser renders a website 
  2. Back End (Server-side) – a server that processes your request and returns a response 

HTML 

Websites are primarily created using: 

  • HTML, to build websites and define their structure 
  • CSS, to make websites look pretty by adding styling options 
  • JavaScript, implement complex features on pages using interactivity 

HyperText Markup Language (HTML) is the language websites are written in. Elements  (or tags) are the building blocks of HTML pages and tells the browser how to display content. Code snippet of HTML Code: 

The HTML structure (as shown in the screenshot) has the following components: 

  • The <!DOCTYPE html> defines that the page is a HTML5 document. This helps with standardisation across different browsers and tells the browser to use HTML5 to interpret the page. 
  • The <html> element is the root element of the HTML page – all other elements come after this element. 
  • The <head> element contains information about the page (such as the page title) 
  • The <body> element defines the HTML document’s body, only content inside of the body is shown in the browser. 
  • The <h1> element defines a large heading 
  • The <p> element defines a paragraph 
  • There are many other elements (tags) used for different purposes. For example, there are tags for: buttons (<button>), images (<img>), lists, and much more. 

You can view the HTML of any website by right-clicking, and selecting “View Page Source”.  

JavaScript 

JavaScript (JS) allows pages to become interactive . HTML is used to create a the website structure and content, while JavaScript is used to control the functionality of webpages. JS can dynamically update the page in real-time.  

JavaScript is added within the page source code and ca be either loaded within <script> tags or can be included remotely with the src attribute: 

<script src="/location/of/javascript_file.js"></script> 

This JavaScript code finds a HTML element on the page with the ID “demo” and changes the elements contents to “Hack the planet”: 

document.getElementById("demo").innerHTML = "Hack the Planet"; 

HTML elementes can also have events, such as “onclick” that execute JavaScript when the event occurs. This code changes the text of the element with the demo ID to Button Clicked: 

<button onclick='document.getElementById("demo").innerHTML = "Button Clicked";'>Click Me!</button> 

Sensitive Data Exposure 

Sensitive Data Exposure is when a website dosent properly protect (or remove) sensitive clear-text information to the end-user; which is found in the frontend source code of sites.  

Everyone can look at the page source code, so when a website developer forget to remove login credentials, hidden links to private parts of the webiste or other sensitive data showin in HTML or Javascript, everyone can look at them.  

HTML Injection 

HTML Injection is a vulnerability that occurs when unfiltered user input is displayed on the page. If a website fails to sanitize user input (Filter any “malicious text” that a user inputs into a website), and that input is used on the page, an attacker can inject HTML code into a vulnerable website.  

Input sanitization is very important in keeping a website secure, as information user inputs into a websites often used in other frontend and backend functionality.  

The above image show how a form outputs text to the page.  

General rule is to never trust user input – to prevent malicious input the website developer should sanitize everything the user enters before using it in the JavaScript function.

Similar Posts

  • THM – Metasploit Complete Documentation – Part 14

    Last Updated on January 25, 2022 by aghanim This is my notes from the Junior Pentesting course at TryHackMe. This course takes you through the basics and some advanced topics regarding penetration testing. Table Of ContentsMetasploit: IntroductionMain Components of MetasploitMsfconsole exploit rankMetasploit: ExploitationTopicsScanningThe Metasploit DatabaseVulnerability ScanningExploitationWorking with sessionsMsfvenomOutput formatsEncodersOther PayloadsMeterpreterPost-Exploitation with MeterpreterHelpMeterpreter commandsMigrateHashdumpSearchShellPost-Explotation Challenge Metasploit:…

  • THM – Walking An Application – Part 3

    Last Updated on January 25, 2022 by aghanim This is my notes from the Junior Pentesting course at TryHackMe. This course takes you through the basics and some advanced topics regarding penetration testing. Table Of ContentsIntroductionExploring The WebsiteViewing the Page SourceHow do I view the Page Source?Let’s view some Page Source!Developer Tools – InspectorDeveloper ToolsInspectorDeveloper…

  • THM – File Inclusion – Part 8

    Last Updated on January 25, 2022 by aghanim This is my notes from the Junior Pentesting course at TryHackMe. This course takes you through the basics and some advanced topics regarding penetration testing. Table Of ContentsIntroductionWhat is File inclusion?Why do File inclusion vulnerabilities happen?What is the risk of File inclusion?Path TraversalPath traversalWhat function causes path…

  • THM – Hashing – Part 14

    Last Updated on January 25, 2022 by aghanim This is a continued series where I document my path through different tryhackme courses. I recommend everyone that wants to learn cyber security to subscribe to tryhackme.com and take the courses there. Table Of ContentsKey TermsWhat’s a hash function?Uses for hashingRecognizing password hashesPassword CrackingHashing for integrity checking…

  • TryHackMe – Network Fundementals – Part 1

    Last Updated on January 25, 2022 by aghanim Table Of ContentsForewordsIntroduction NetworkingThe OSI Model: OverviewEncapsulationTCP/IP Forewords In this blog series I will write down my notes from the courses I take from TryHackMe. This series is from the Complete beginner course where I will go through Network security, Web App security, different tools I use…

  • THM – Command Injection – Part 11

    Last Updated on January 25, 2022 by aghanim This is my notes from the Junior Pentesting course at TryHackMe. This course takes you through the basics and some advanced topics regarding penetration testing. Table Of ContentsWhat is Command Injection?Discovering Command InjectionExploiting Command InjectionDetecting Blind Command InjectionLinux WindowsRemediating Command InjectionVulnerable FunctionsInput sanitisationBypassing FiltersPractical: Command InjectionWhat user is…