cross site scripting attack tutorial with examples
क्रॉस साइट स्क्रिप्टिंग (XSS) हमले के लिए एक पूर्ण गाइड, इसे कैसे रोका जाए, और XSS परीक्षण।
क्रॉस साइट स्क्रिप्टिंग (XSS) सबसे लोकप्रिय और कमजोर हमलों में से एक है जो हर उन्नत परीक्षक द्वारा जाना जाता है। यह वेब अनुप्रयोगों के लिए सबसे जोखिम वाले हमलों में से एक माना जाता है और हानिकारक परिणाम भी ला सकता है।
XSS की तुलना अक्सर क्लाइंट-साइड हमलों के साथ की जाती है, क्योंकि क्लाइंट-साइड भाषाओं का उपयोग ज्यादातर इस हमले के दौरान किया जाता है। हालाँकि, XSS हमले को जोखिम भरा माना जाता है, क्योंकि इसकी वजह से कमज़ोर तकनीकों को भी नुकसान पहुँच सकता है।
यह XSS हमला ट्यूटोरियल, हम आपको इसकी आसान समझ के लिए सरल शब्दों में इसके उदाहरणों, औजारों और निवारक उपायों का पूरा अवलोकन देंगे।
आप क्या सीखेंगे:
- XSS हमले का परिचय
- XSS का प्रदर्शन कैसे किया जाता है?
- क्रॉस साइट स्क्रिप्टिंग हमलों के प्रकार
- XSS के खिलाफ टेस्ट कैसे करें?
- XSS परीक्षण उपकरण
- अन्य हमलों के साथ तुलना
- XSS को रोकने के तरीके
- टेक्नोलॉजीज के अनुसार रोकथाम
- XSS धोखा शीट्स
- निष्कर्ष
- अनुशंसित पाठ
XSS हमले का परिचय
क्रॉस साइट स्क्रिप्टिंग हमला एक दुर्भावनापूर्ण कोड इंजेक्शन है, जिसे पीड़ित के ब्राउज़र में निष्पादित किया जाएगा। दुर्भावनापूर्ण स्क्रिप्ट को वेब सर्वर पर सहेजा जा सकता है और हर बार निष्पादित किया जाता है जब उपयोगकर्ता उपयुक्त कार्यक्षमता कहता है। यह अन्य तरीकों के साथ भी किया जा सकता है - वेब सर्वर में किसी भी सहेजी गई स्क्रिप्ट के बिना।
इस हमले का मुख्य उद्देश्य अन्य उपयोगकर्ता के पहचान डेटा को चोरी करना है - कुकीज़, सत्र टोकन और अन्य जानकारी। ज्यादातर मामलों में, इस हमले का उपयोग अन्य व्यक्ति की कुकीज़ चोरी करने के लिए किया जा रहा है। जैसा कि हम जानते हैं, कुकीज़ हमें स्वचालित रूप से लॉग इन करने में मदद करती हैं। इसलिए चुराए गए कुकीज़ के साथ, हम अन्य पहचान के साथ लॉगिन कर सकते हैं। और यह एक कारण है, इस हमले को सबसे जोखिम वाले हमलों में से एक माना जाता है।
XSS अटैक क्लाइंट की तरफ से किया जा रहा है। यह विभिन्न क्लाइंट-साइड प्रोग्रामिंग भाषाओं के साथ किया जा सकता है। हालांकि, सबसे अधिक बार यह हमला जावास्क्रिप्ट और HTML के साथ किया जाता है।
अनुशंसित पढ़ा=> HTML इंजेक्शन ट्यूटोरियल
XSS का प्रदर्शन कैसे किया जाता है?
क्रॉस साइट स्क्रिप्टिंग हमले का मतलब है दुर्भावनापूर्ण कोड या स्क्रिप्ट को भेजना और इंजेक्ट करना। दुर्भावनापूर्ण कोड आमतौर पर क्लाइंट-साइड प्रोग्रामिंग भाषाओं जैसे जावास्क्रिप्ट, HTML, के साथ लिखा जाता है। VBScript है , फ्लैश, आदि। हालांकि, जावास्क्रिप्ट और HTML का उपयोग ज्यादातर इस हमले को करने के लिए किया जाता है।
इस हमले को विभिन्न तरीकों से किया जा सकता है। XSS के हमले के प्रकार के आधार पर, दुर्भावनापूर्ण स्क्रिप्ट पीड़ित के ब्राउज़र पर या डेटाबेस में संग्रहीत और हर बार निष्पादित होने पर परिलक्षित हो सकती है, जब उपयोगकर्ता उपयुक्त फ़ंक्शन को कॉल करता है।
इस हमले का मुख्य कारण अनुचित उपयोगकर्ता का इनपुट सत्यापन है, जहां दुर्भावनापूर्ण इनपुट आउटपुट में मिल सकता है। एक दुर्भावनापूर्ण उपयोगकर्ता एक स्क्रिप्ट दर्ज कर सकता है, जिसे वेबसाइट के कोड में इंजेक्ट किया जाएगा। फिर ब्राउज़र यह पता नहीं कर पा रहा है कि निष्पादित कोड दुर्भावनापूर्ण है या नहीं।
इसलिए दुर्भावनापूर्ण स्क्रिप्ट को पीड़ित के ब्राउज़र पर निष्पादित किया जा रहा है या उपयोगकर्ताओं के लिए कोई भी नकली रूप प्रदर्शित किया जा रहा है। ऐसे कई रूप हैं जिनमें XSS हमला हो सकता है।
क्रॉस साइट स्क्रिप्टिंग के मुख्य रूप इस प्रकार हैं:
- क्रॉस साइट स्क्रिप्टिंग क्लाइंट साइड पर निष्पादित दुर्भावनापूर्ण स्क्रिप्ट पर हो सकती है।
- उपयोगकर्ता को प्रदर्शित नकली पृष्ठ या फ़ॉर्म (जहाँ पीड़ित व्यक्ति क्रेडेंशियल टाइप करता है या दुर्भावनापूर्ण लिंक क्लिक करता है)।
- प्रदर्शित विज्ञापनों वाली वेबसाइटों पर।
- पीड़िता को भेजी गई भद्दी ईमेल
यह हमला तब होता है जब दुर्भावनापूर्ण उपयोगकर्ता वेबसाइट के कमजोर हिस्सों को ढूंढता है और इसे उपयुक्त दुर्भावनापूर्ण इनपुट के रूप में भेजता है। दुर्भावनापूर्ण स्क्रिप्ट को कोड में इंजेक्ट किया जा रहा है और फिर अंतिम उपयोगकर्ता को आउटपुट के रूप में भेजा गया है।
आइए एक सरल उदाहरण का विश्लेषण करें: विचार करें कि हमारे पास खोज क्षेत्र वाली एक वेबसाइट है।
यदि खोज फ़ील्ड असुरक्षित है, जब उपयोगकर्ता किसी भी स्क्रिप्ट में प्रवेश करता है, तो उसे निष्पादित किया जाएगा।
विचार करें, एक उपयोगकर्ता बहुत ही सरल स्क्रिप्ट में प्रवेश करता है जैसा कि नीचे दिखाया गया है:
alert(‘XSS’)
उसके बाद क्लिक करने के बाद 'खोज' बटन, दर्ज की गई स्क्रिप्ट निष्पादित की जाएगी।
जैसा कि हम में देखते हैं उदाहरण ,खोज फ़ील्ड में टाइप की गई स्क्रिप्ट निष्पादित हो जाती है। यह सिर्फ XSS हमले की भेद्यता को दर्शाता है। हालाँकि, अधिक हानिकारक स्क्रिप्ट भी टाइप की जा सकती है।
कई परीक्षकों ने क्रॉस साइट स्क्रिप्टिंग हमले को मिलाया जावास्क्रिप्ट इंजेक्शन , जो क्लाइंट की तरफ से भी किया जा रहा है। दोनों में, दुर्भावनापूर्ण स्क्रिप्ट में इंजेक्शन इंजेक्ट किया जा रहा है। हालांकि, XSS हमले के मामले में स्क्रिप्ट को निष्पादित करने के लिए टैग आवश्यक नहीं हैं।
उदाहरण के लिए :
;
साथ ही, यह दूसरी घटना पर निष्पादित स्क्रिप्ट हो सकती है।
उदाहरण के लिए:माउस होवर पर।
आइए हम एक और उदाहरण का विश्लेषण करें:गौर करें, हमारे पास एक पृष्ठ है, जहां वेबसाइट पर नवीनतम पुस्तक समीक्षा प्रदर्शित की जा रही है।
इस पृष्ठ का कोड नीचे दिखाया गया है:
print '' print '. If this vulnerability is present in the web application, an indicated text will be inserted intags. Trying to pass some code through HTTP request as this is also a method to check if this attack is possible.
Generally, while testing for possible XSS attack, input validation should be checked and the tester should be conscious while checking the website’s output. Also if a code review is being performed, it is important to find how input can get into the output.
XSS Testing Tools
As Cross Site Scripting attack is one of the most popular risky attacks, there are a plenty of tools to test it automatically. We can find various scanners to check for possible XSS attack vulnerabilities – like, Nesus and Nikto. Both of which are considered as quite reliable.
From my software testing career, I would like to mention SOAP UI tool. SOAP UI can be considered as a quite strong tool for checking against the possible XSS attacks. It contains ready templates for checking against this attack. It really simplifies the testing process.
However, in order to test for this vulnerability with SOAP UI tool, API level testing should already be automated with that tool. Another solution to test against XSS can be browser plugins. However, plugins are considered as quite a weak tool to check against this type of attack.
Even while testing automatically, the tester should have good knowledge of this attack type and should be able to analyze the results appropriately.
Good knowledge is also helpful while selecting the testing tool. Also, it is important to know, that while performing scanning for security vulnerabilities with an automatic tool, testing manually is also a good practice and this way the tester will be able to see the results and analyze them.
Recommended Tool:
#1) Kiuwan

Find and fix vulnerabilities in your code at every stage of the SDLC.
Kiuwan is compliant with the most stringent security standards including OWASP, CWE, SANS 25, HIPPA, and more. Integrate Kiuwan in your IDE for instant feedback during development.
Kiuwan supports all major programming languages and integrates with leading DevOps tools.
=> Scan your code for free
Comparison with Other Attacks
XSS is considered to be one of the riskiest attacks, as its main purpose is to steal the website’s or system’s user identities. Also, XSS attack can be performed with different client-side languages like Javascript, HTML, VBScript, Flash, etc. And this makes it more harmful and widespread than the other possible attacks.
Testing for XSS attack is quite similar to testing for the other possible client-side attacks. However, it is important to remember what additional cases should be checked while testing for XSS.
Another thing, that makes this attack riskier is the possibility to be stored in the web service – this way it can affect many users for a longer period of time. XSS sometimes can be performed to even less vulnerable systems and its vulnerabilities are sometimes difficult to be found.
Also, while comparing with the other attacks, XSS has many ways to be performed and affect the website as well.
Ways to Prevent XSS
Though this type of attack is considered to be one of the most dangerous and risky one, still a preventing plan should be prepared. Because of the popularity of this attack, there are quite many ways to prevent it.
Commonly used main prevention methods include:
- Data validation
- Filtering
- Escaping
The first step in the prevention of this attack is Input validation . Everything, that is entered by the user should be precisely validated, because the user’s input may find its way to the output. Data validation can be named as the basis for ensuring the system’s security. I would remind, that the idea of validation is not to allow inappropriate input.
Therefore it just helps to reduce the risks, but may not be enough to prevent the possible XSS vulnerability.
Another good prevention method is user’s input filtering. The idea of the filtering is to search for risky keywords in the user’s input and remove them or replace them by empty strings.
Those keywords may be:
- tags
- Javascript commands
- HTML markup
Input filtering is quite easy to practice. It can be performed in different ways too.
Like:
- By developers who have written server-side code.
- Appropriate programming language’s library is being used.
In this case, some developers write their own code to search for appropriate keywords and remove them. However, the easier way would be to select appropriate programming languages library to filter the user’s input. I would like to comment, that using libraries is a more reliable way, as those libraries were used and tested by many developers.
Another possible prevention method is characters escaping . In this practice, appropriate characters are being changed by special codes. For Example, Meanwhile, good testing should not be forgotten as well. It should be invested in good software testers knowledge and reliable software testing tools. This way good software quality will be better assured.
Prevention According to Technologies
As already discussed, filtering and characters escaping are the main prevention methods. However, it can be performed differently in different programming languages. Some programming languages have appropriate filtering libraries and some do not.
It should be mentioned, that filtering can be performed quite easily in Java and PHP programming languages, as they have appropriate libraries for it.
Java technology is quite widely used, therefore there are many solutions to it. If you are using Spring technology and if you would like to escape HTML for the whole application, then you have to write the appropriate code in the project’s web.xml file.
defaultHtmlEscape true
यह कोड संपूर्ण अनुप्रयोग के लिए HTML से बच जाएगा।
यदि आप उपयुक्त पृष्ठ के रूपों के लिए HTML से बचना चाहते हैं, तो कोड निम्नानुसार लिखा जाना चाहिए:
.Jar फ़ाइल के रूप में कई तैयार XSS फ़िल्टर हैं। मैं याद दिलाता हूं, कि .jar फ़ाइल को आपके प्रोजेक्ट में जोड़ा जाना है और उसके बाद ही इसके पुस्तकालयों का उपयोग किया जा सकता है। ऐसा ही एक XSS फ़िल्टर है xssflt.jar, जो एक सर्वलेट फ़िल्टर है। इस .jar फ़ाइल को इंटरनेट से आसानी से डाउनलोड किया जा सकता है और इसे आपके प्रोजेक्ट में जोड़ा जा सकता है।
यह फ़िल्टर हर उस अनुरोध की जाँच करता है जो अनुप्रयोग को भेजा जाता है और एक संभावित इंजेक्शन से इसे साफ करता है।
मर्ज सॉर्ट c ++ एल्गोरिथ्म
जब प्रोजेक्ट में एक बाहरी.जर फ़ाइल जोड़ी जाती है, तो उसे web.xml फ़ाइल में भी वर्णित किया जाना चाहिए:
XSSFilter com.cj.xss.XSSFilter
एक अन्य संभावित समाधान ईएसएपीआई पुस्तकालय है। ESAPI पुस्तकालय कई प्रोग्रामिंग भाषाओं के साथ संगत है। आप जावा और PHP प्रोग्रामिंग भाषाओं के लिए ESAPI पुस्तकालय पा सकते हैं। यह एक खुला स्रोत और मुफ्त पुस्तकालय है, जो एप्लिकेशन की सुरक्षा को नियंत्रित करने में मदद करता है।
XSS धोखा शीट्स
XSS चीट शीट्स क्रॉस साइट स्क्रिप्टिंग की रोकथाम के लिए बहुत मददगार हो सकती हैं। यह डेवलपर्स के लिए एक दिशानिर्देश है कि XSS हमलों को कैसे रोका जाए। नियम बहुत सहायक होते हैं और विकसित होते समय इसे नहीं भूलना चाहिए। XSS चीट शीट्स को इंटरनेट समुदायों जैसे OWASP (द ओपन वेब एप्लीकेशन सिक्योरिटी प्रोजेक्ट) में पाया जा सकता है।
विभिन्न प्रकार की धोखा शीट्स:
- एक्सएसएस रोकथाम धोखा शीट
- डोम XSS धोखा शीट
- XSS फ़िल्टर एविज़न चीट शीट
मुख्य दिशानिर्देश XSS प्रिवेंशन चीट शीट होगा, क्योंकि यह XSS हमले की रोकथाम के लिए सामान्य नियम प्रदान करता है। यदि आप DOM XSS चीट शीट और XSS फ़िल्टर एविएशन चीट शीट नियमों का पालन करेंगे, तो भी आपको XSS प्रिवेंशन चीट शीट का पालन करना होगा।
जैसा कि कहा गया है, XSS रोकथाम धोखा शीट OWASP समुदाय में पाई जा सकती है। यह चीट शीट हमें नियमों की एक सूची प्रदान करती है, जो हमें संभावित XSS हमलों के जोखिम को कम करने में मदद करेगी। यह न केवल कोडिंग नियम है, बल्कि रोकथाम के आधार पर सुरक्षा कमजोरियां भी हैं।
कुछ नियमों में शामिल हैं:
- अविश्वसनीय डेटा नहीं डाला जाना चाहिए।
- HTML को किसी भी अविश्वसनीय डेटा को डालने से पहले बच जाना चाहिए।
- अविश्वसनीय डेटा, आदि डालने से पहले विशेषता से बच जाना चाहिए।
इसलिए, इस प्रकार के हमलों को रोकने में धोखा शीट बहुत मददगार हो सकती है।
निष्कर्ष
परीक्षण करते समय, XSS हमलों को संभव बनाने वाले जोखिमों का मूल्यांकन करने के लिए अत्यधिक अनुशंसा की जाती है। XSS अटैक वेब एप्लिकेशन को प्रभावित कर सकता है, जो सुरक्षित भी लगता है।
इसे सबसे हानिकारक और जोखिम भरे हमलों में से एक माना जाता है। इसलिए, हमें इस प्रकार के परीक्षण को नहीं भूलना चाहिए। एक्सएसएस के खिलाफ परीक्षण करते समय, इस हमले के बारे में अच्छी जानकारी होना जरूरी है। और यह परीक्षण के परिणामों का सही विश्लेषण करने और उचित परीक्षण उपकरण चुनने का आधार है।
क्या आप एक परीक्षक हैं, जिन्होंने क्रॉस साइट स्क्रिप्टिंग एक्सएसएस हमलों से निपटा है? क्या आपके पास एक्सएसएस हमलों के बारे में कोई रोचक तथ्य है जो हमारे पाठकों को भी मदद करेगा? नीचे टिप्पणी अनुभाग में हमारे साथ अपने अनुभव साझा करने के लिए स्वतंत्र महसूस करें !!
अनुशंसित पाठ
- शुरुआती के लिए गहराई से ग्रहण ट्यूटोरियल
- HTML इंजेक्शन ट्यूटोरियल: उदाहरण और उदाहरण के साथ रोकथाम
- SQL इंजेक्शन परीक्षण ट्यूटोरियल (उदाहरण और SQL इंजेक्शन हमले की रोकथाम)
- DDoS Attack क्या है और DDoS कैसे करें?
- सेलेनियम ग्रिड ट्यूटोरियल: सेटअप और क्रॉस ब्राउज़र परीक्षण का उदाहरण
- उदाहरणों के साथ जावा परावर्तन ट्यूटोरियल
- एसवीएन ट्यूटोरियल: स्रोत कोड प्रबंधन तोड़फोड़ का उपयोग करना
- उदाहरणों के साथ पायथन डेटटाइम ट्यूटोरियल