1

I'm making a script that uploads a script, or "payload" to a site with these steps:

1. User enters URL with * in place of query
2. User selects payload, which is simply a file with a pre-written JS script.
3. The * is replaced with the contents of the payload.
4. The URL with a script replacing the query is opened in an iframe.

How would I do this? My main problem is the file-uploading-into-variable part. Here's my code so far:

<!DOCTYPE html>

<html>

  <head>

    <title>Slingshot.XSS</title>

  </head>

  <body style="font-family:monospace;" align="center">

    <h2>Slingshot.XSS</h2>
    <h3>Slingshot.XSS is a script that launches pre-loaded XSS payloads at a target to test its vulnerabilities.</h3>
    <h4>Please report all issues to <a href="https://github.com/keeganjk/slingshot.xss/issues"></a> or contact me at [email protected].</h4>
    <a href="github.com/keeganjk/slingshot.xss" style="font-family:monospace" align="center">Source Code / Learn More</a>
    <br />

    <h4>Enter a URL with <b>*</b> in the place of query.</h4>
    <h5>Example: https://www.google.com/#q=*</h5>
    <input type="text" id="myText" placeholder="Enter a URL"> <button onclick="myFunction()">Submit</button>
    <p id="demo">No Submitted URL</p>

    <h4>Select a payload:</h4>
    <input type="text" id="myPayload" placeholder="Enter payload path"> <button onclick="selectPayload()">Submit</button>


    <script>

      function myFunction() {

        var errors = [];
        var x = document.getElementById("myText").value;

        if ( !x.includes("http://") && !x.includes("https://") ) {

          errors.push('missing HTTP or HTTPS in URL');

        }

        if (!x.includes("*")) {

          errors.push('missing * in place of query')

        }

        // Renders errors
        if (errors.length) {

           x = 'Error: ' + errors.join(', ') + '!'; 

        }

        document.getElementById("demo").innerHTML = x;

        }

      function selectPayload() {



      }

    </script>

  </body>

</html>

How would I let the user browse through files and then select one and upload it to a variable?

1
  • 1
    Which files are you referencing? What is being uploaded? Commented Apr 28, 2017 at 0:22

1 Answer 1

2

First, change the type attribute of your input tag to be "file", e.g.:

<input type="file" id="file">

Then create a filereader:

var fr = new FileReader();

Since the file will be read asynchronously, you should add a callback to proceed further, e.g. something like:

fr.onload = function(){... do something ...};

To read the file call readAsText (for example, add this to an onclick event):

fr.readAsText(document.getElementById('file').files[0]);

Once the file has been loaded the content will be a string in fr.result.

MDN has more documentation and examples.

Sign up to request clarification or add additional context in comments.

3 Comments

This is kind of vague... Could you go into more detail?
Which parts are vague/where do you want more detail?
Maybe just add a full block of code putting all the parts together.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.