Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
How to execute JavaScript in HTML environment

For a testing project I want to create a XSS vulnerable site. My basic structure is a forum where people can add forum posts via input fields and a submit button. Currently I render the new post which should be displayed via innerHTML but with this method the malicious (e.g. <script>alert("123")</script>) script which I want to insert as an attacker gets not executed. I searched for other alternatives to innerHTML but none of them worked. How can I achieve JavaScript rendering in my code?

Things I tried

appendChild();
eval();
insertAdjacentElement();

Input fields for creation new post

<form>
  <label for="topic"
    >Topic:
    <br />
    <input id="topic" required
  /></label>
  <br />
  <br />
  <label for="text"
    >Text:
    <br />
    <input id="text" type="text" required
  /></label>
  <br />
  <button type="submit" id="submit">submit</button>
</form>

Input example text field (localStorage is the storage from the input fields)

<div id="post">
  <script>
    if (localStorage.length > 0) {
      post.innerHTML += localStorage.key(0);
    }
  </script>
</div>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Solution

This function gives me actually the desired behaviour.

<div id="post">
  <script>
    if (localStorage.length > 0) {
      post.innerHTML += localStorage.key(0);
      eval(localStorage.getItem(localStorage.key(0)));
    }
  </script>
</div>
about 4 years ago · Juan Pablo Isaza Relatório

0

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <form>
      <label for="topic"
        >Topic:
        <br />
        <input id="topic" required 
      /></label>
      <br />
      <br />
      <label for="text"
        >Text:
        <br />
        <input id="text" type="text" required 
      /></label>
      <br />
      <button id="submit" onclick="test()">submit</button>
    </form>
        <div id="TESTDIV">
        </div>
        <script>
            function test(){
                if(localStorage.length >0){
                  item+=localStorage.setItem(document.getElementById("topic").value,document.getElementById("text").value); 
                }
       else{
var item=localStorage.setItem(document.getElementById("topic").value,document.getElementById("text").value);
                  }
                  document.getElementById("TESTDIV").innerHTML= localStorage.getItem(document.getElementById("topic").value);
            }
        </script>
</body>
</html>



Hi! Hope You are well i think i will works.
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda