Skip to content

Commit 0340f64

Browse files
add: Reflected XSS
1 parent 624aa04 commit 0340f64

6 files changed

Lines changed: 265 additions & 1 deletion

File tree

Solutions/solution.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ Results page contains the word `TEXT` in Heading as well as Green color hence XS
259259

260260
Now you can go ahead and enter `<script >alert(“xss”) </script >` once XSS is confirmed.
261261

262-
To see results on screen, make sure your browser has JavaScript enabled.
262+
To see results on screen, make sure your browser has JavaScript enabled.
263+
264+
**Lab 3**
265+
- ##### [ step- 1 ] Checking user input is being reflected or not
266+
- Though alphanumeric characters are being escaped we can still write js code with these 6 character `![]()+`
267+
- check [jsfuck](http://www.jsfuck.com/)
263268

264269

265270
## A8:Insecure Deserialization

app.log

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,203 @@ WARNING:django.request:Not Found: /introduction/home.html
615615
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
616616
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/forms.py changed, reloading.
617617
WARNING:django.security.csrf:Forbidden (CSRF token missing or incorrect.): /admin/auth/user/
618+
ERROR:django.request:Internal Server Error: /login/
619+
Traceback (most recent call last):
620+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/backends/django.py", line 61, in render
621+
return self.template.render(context)
622+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 175, in render
623+
return self._render(context)
624+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 167, in _render
625+
return self.nodelist.render(context)
626+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 1005, in render
627+
return SafeString("".join([node.render_annotated(context) for node in self]))
628+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 1005, in <listcomp>
629+
return SafeString("".join([node.render_annotated(context) for node in self]))
630+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 966, in render_annotated
631+
return self.render(context)
632+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/loader_tags.py", line 157, in render
633+
return compiled_parent._render(context)
634+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 167, in _render
635+
return self.nodelist.render(context)
636+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 1005, in render
637+
return SafeString("".join([node.render_annotated(context) for node in self]))
638+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 1005, in <listcomp>
639+
return SafeString("".join([node.render_annotated(context) for node in self]))
640+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 966, in render_annotated
641+
return self.render(context)
642+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/loader_tags.py", line 63, in render
643+
result = block.nodelist.render(context)
644+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 1005, in render
645+
return SafeString("".join([node.render_annotated(context) for node in self]))
646+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 1005, in <listcomp>
647+
return SafeString("".join([node.render_annotated(context) for node in self]))
648+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 966, in render_annotated
649+
return self.render(context)
650+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 1064, in render
651+
output = self.filter_expression.resolve(context)
652+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/base.py", line 742, in resolve
653+
new_obj = func(obj, *arg_vals)
654+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/crispy_forms/templatetags/crispy_forms_filters.py", line 58, in as_crispy_form
655+
template = uni_form_template(template_pack)
656+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/crispy_forms/templatetags/crispy_forms_filters.py", line 21, in uni_form_template
657+
return get_template("%s/uni_form.html" % template_pack)
658+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/loader.py", line 19, in get_template
659+
raise TemplateDoesNotExist(template_name, chain=chain)
660+
django.template.exceptions.TemplateDoesNotExist: bootstrap4/uni_form.html
661+
662+
The above exception was the direct cause of the following exception:
663+
664+
Traceback (most recent call last):
665+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
666+
response = get_response(request)
667+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 220, in _get_response
668+
response = response.render()
669+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/response.py", line 114, in render
670+
self.content = self.rendered_content
671+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/response.py", line 92, in rendered_content
672+
return template.render(context, self._request)
673+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/backends/django.py", line 63, in render
674+
reraise(exc, self.backend)
675+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/template/backends/django.py", line 84, in reraise
676+
raise new from exc
677+
django.template.exceptions.TemplateDoesNotExist: bootstrap4/uni_form.html
678+
WARNING:django.request:Not Found: /favicon.ico
679+
WARNING:django.request:Not Found: /cryptographic_failure/lab3/Admin/admin
680+
WARNING:django.request:Not Found: /cryptographic_failure/lab3/Admin/
681+
WARNING:django.request:Not Found: /cryptographic_failure/lab3/admin
682+
WARNING:django.request:Not Found: /x
683+
WARNING:django.request:Not Found: /x
684+
WARNING:django.request:Not Found: /x
685+
WARNING:django.request:Not Found: /x
686+
WARNING:django.request:Not Found: /x
687+
WARNING:django.request:Not Found: /x
688+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
689+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
690+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/urls.py changed, reloading.
691+
ERROR:django.request:Internal Server Error: /xssL3
692+
Traceback (most recent call last):
693+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
694+
response = get_response(request)
695+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 204, in _get_response
696+
self.check_response(response, callback)
697+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 332, in check_response
698+
raise ValueError(
699+
ValueError: The view introduction.views.xss_lab3 didn't return an HttpResponse object. It returned None instead.
700+
ERROR:django.request:Internal Server Error: /xssL3
701+
Traceback (most recent call last):
702+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
703+
response = get_response(request)
704+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 204, in _get_response
705+
self.check_response(response, callback)
706+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 332, in check_response
707+
raise ValueError(
708+
ValueError: The view introduction.views.xss_lab3 didn't return an HttpResponse object. It returned None instead.
709+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
710+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
711+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
712+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
713+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
714+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
715+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
716+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
717+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
718+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
719+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
720+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
721+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
722+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
723+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
724+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
725+
ERROR:django.request:Internal Server Error: /xssL3
726+
Traceback (most recent call last):
727+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
728+
response = get_response(request)
729+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
730+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
731+
File "/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py", line 124, in xss_lab3
732+
result = re.sub(pattern, '', username)
733+
File "/usr/lib/python3.10/re.py", line 209, in sub
734+
return _compile(pattern, flags).sub(repl, string, count)
735+
TypeError: expected string or bytes-like object
736+
ERROR:django.request:Internal Server Error: /xssL3
737+
Traceback (most recent call last):
738+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
739+
response = get_response(request)
740+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
741+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
742+
File "/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py", line 124, in xss_lab3
743+
result = re.sub(pattern, '', username)
744+
File "/usr/lib/python3.10/re.py", line 209, in sub
745+
return _compile(pattern, flags).sub(repl, string, count)
746+
TypeError: expected string or bytes-like object
747+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
748+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
749+
ERROR:django.request:Internal Server Error: /xssL3
750+
Traceback (most recent call last):
751+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
752+
response = get_response(request)
753+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
754+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
755+
File "/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py", line 124, in xss_lab3
756+
result = re.sub(pattern, '', username)
757+
File "/usr/lib/python3.10/re.py", line 209, in sub
758+
return _compile(pattern, flags).sub(repl, string, count)
759+
TypeError: expected string or bytes-like object
760+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
761+
ERROR:django.request:Internal Server Error: /xssL3
762+
Traceback (most recent call last):
763+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
764+
response = get_response(request)
765+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
766+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
767+
File "/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py", line 125, in xss_lab3
768+
result = re.sub(pattern, '', username)
769+
File "/usr/lib/python3.10/re.py", line 209, in sub
770+
return _compile(pattern, flags).sub(repl, string, count)
771+
TypeError: expected string or bytes-like object
772+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
773+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
774+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
775+
ERROR:django.request:Internal Server Error: /xssL3
776+
Traceback (most recent call last):
777+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
778+
response = get_response(request)
779+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
780+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
781+
File "/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py", line 125, in xss_lab3
782+
result = re.sub(pattern, '', username)
783+
File "/usr/lib/python3.10/re.py", line 209, in sub
784+
return _compile(pattern, flags).sub(repl, string, count)
785+
TypeError: expected string or bytes-like object
786+
ERROR:django.request:Internal Server Error: /xssL3
787+
Traceback (most recent call last):
788+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
789+
response = get_response(request)
790+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
791+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
792+
File "/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py", line 125, in xss_lab3
793+
result = re.sub(pattern, '', username)
794+
File "/usr/lib/python3.10/re.py", line 209, in sub
795+
return _compile(pattern, flags).sub(repl, string, count)
796+
TypeError: expected string or bytes-like object
797+
ERROR:django.request:Internal Server Error: /xssL3
798+
Traceback (most recent call last):
799+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
800+
response = get_response(request)
801+
File "/home/sankalpa/Desktop/gsoc/myenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
802+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
803+
File "/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py", line 125, in xss_lab3
804+
result = re.sub(pattern, '', username)
805+
File "/usr/lib/python3.10/re.py", line 209, in sub
806+
return _compile(pattern, flags).sub(repl, string, count)
807+
TypeError: expected string or bytes-like object
808+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
809+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
810+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
811+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
812+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
813+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
814+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
815+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
816+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.
817+
INFO:django.utils.autoreload:/home/sankalpa/Desktop/gsoc/pygoat/introduction/views.py changed, reloading.

introduction/templates/Lab/XSS/xss.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ <h4>Exploiting the Reflection of the search query </h4>
100100
<div align="right"> <button class="btn btn-info" type="button" onclick="window.location.href='/xssL2'">Access
101101
Lab</button></div>
102102
</div>
103+
104+
<button class="coll btn btn-info">Lab Details</button>
105+
<div class="lab">
106+
<p class="bp">
107+
This lab is a demonstration of a Reflected XSS
108+
</p>
109+
<p class="bp">The goal of this challenge is to trigger an alert, User input is being Reflected on script Tag, but the real challenge lies in the fact that all alphanumeric characters are escaped. Can you find way to pop an alert ?
110+
</p>
111+
112+
113+
<br>
114+
<div align="right"> <button class="btn btn-info" type="button" onclick="window.location.href='/xssL3'">Access
115+
Lab</button></div>
116+
</div>
103117
<br>
104118

105119

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{% extends "introduction/base.html" %}
2+
{% block content %}
3+
{% block title %}
4+
5+
<title>XSS LAB 2</title>
6+
{% endblock %}
7+
<h1>Welcome to XSS Challenge</h1>
8+
<form method="post" action="/xssL3">
9+
{% csrf_token %}
10+
<div class="jumbotron">
11+
<label for="username">Name:</label>
12+
<input type="text" class="form-control" id="username" name="username" required>
13+
</div>
14+
<button class="btn btn-info" type="submit">
15+
Go
16+
</button>
17+
</form>
18+
<br>
19+
<p>{{code}}</p>
20+
<script>
21+
// LAB 3 JS CODE
22+
{{code}}
23+
</script>
24+
<br>
25+
<div align="right">
26+
<button class="btn btn-info" type="button" onclick="window.location.href='/xss'">Back to Lab Details</button>
27+
</div>
28+
{% endblock content %}

introduction/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
path('xss', views.xss,name="xss"),
1010
path('xssL',views.xss_lab,name='xss_lab'),
1111
path('xssL2', views.xss_lab2, name='xss_lab2'),
12+
path('xssL3', views.xss_lab3, name='xss_lab3'),
1213
path('xssL1',views.xss_lab,name='xss_lab'),
1314
path("sql",views.sql,name='sql'),
1415
path("sql_lab",views.sql_lab,name="sql_lab"),

introduction/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from argon2 import PasswordHasher
3939
import logging
4040
import requests
41+
import re
4142
#*****************************************Login and Registration****************************************************#
4243

4344
def register(request):
@@ -115,6 +116,21 @@ def xss_lab2(request):
115116
return render(request, 'Lab/XSS/xss_lab_2.html', context)
116117
else:
117118
return redirect('login')
119+
120+
def xss_lab3(request):
121+
if request.user.is_authenticated:
122+
if request.method == 'POST':
123+
username = request.POST.get('username')
124+
print(type(username))
125+
pattern = r'\w'
126+
result = re.sub(pattern, '', username)
127+
context = {'code':result}
128+
return render(request, 'Lab/XSS/xss_lab_3.html',context)
129+
else:
130+
return render(request, 'Lab/XSS/xss_lab_3.html')
131+
132+
else:
133+
return redirect('login')
118134

119135
#***********************************SQL****************************************************************#
120136

0 commit comments

Comments
 (0)