Skip to content

Commit f40a96b

Browse files
Merge pull request adeyosemanputra#180 from sumukhchitloor/master
Added XSS Lab and Modified Mitre Attack's Explaination
2 parents cff51c9 + 66c3670 commit f40a96b

12 files changed

Lines changed: 522 additions & 15 deletions

File tree

pygoat/app.log

Lines changed: 386 additions & 0 deletions
Large diffs are not rendered by default.

pygoat/db.sqlite3

0 Bytes
Binary file not shown.

pygoat/introduction/templates/Lab/XSS/xss.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ <h4>DOM XSS</h4>
3838
attacker tries to inject malicious code into a sink , then this type of XSS is called the DOM Xss</p>
3939

4040

41-
41+
<br>
42+
<br>
4243
<button class="coll btn btn-info">Lab Details</button>
4344
<div class="lab">
4445
<p class="bp">
@@ -80,8 +81,28 @@ <h4>Exploiting the Reflection of the search query </h4>
8081
Lab</button></div>
8182

8283
</p>
83-
</div><br>
84+
</div>
85+
86+
<button class="coll btn btn-info">Lab Details</button>
87+
<div class="lab">
88+
<p class="bp">
89+
This lab a demonstration of a stored XSS vulnerability. The challenge is to change the value of flag that is being stored as a cookie on the user's browser. The user input is taken as a POST parameter in the URL and is displayed on the page. The code tries to escape the user input to prevent XSS attacks, but there might still be a way for the attacker to inject malicious code into the page.
90+
</p>
91+
<p class="bp">The goal of this challenge is for the attacker to find a way to execute arbitrary JavaScript code on the page and retrieve the data stored in the cookie. The attacker must be able to bypass the escaping mechanism and find a way to inject their own code into the page.
92+
</p>
93+
<p class="bp">But the problem is <code>&lt;script &gt;</code> tag is sanitised by the server so we have to use another method to bypass this. </p>
94+
<div class="container"> <code> &lt;img src=x onerror=alert(document.cookie) &gt;</code></div>
95+
<p class="bp">Try changing the value of cookie set flag=success</p>
96+
<div class="container"> <code> &lt;img src=x onerror=document.cookie="flag=success"; &gt;</code></div>
97+
<p class="bp">Now when a search query is performed with the above payload you can see that the browser is able to render the script tag and execute the javascript , thus alerting “xss” with a pop up</p>
98+
99+
<br>
100+
<div align="right"> <button class="btn btn-info" type="button" onclick="window.location.href='/xssL2'">Access
101+
Lab</button></div>
102+
</div>
84103
<br>
104+
105+
85106
<h4>Mitigation</h4><br>
86107
<p class="bp"> First let's analyse what part of the code has resulted in this vulnerability.
87108

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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="/xssL2">
9+
{% csrf_token %}
10+
<div class="jumbotron">
11+
<label for="username">Comment:</label>
12+
<input type="text" class="form-control" id="username" name="username" required>
13+
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
14+
</div>
15+
<button class="btn btn-info" type="submit">
16+
Go
17+
</button>
18+
</form>
19+
<br>
20+
<p>Hello, {{ username|safe }}</p>
21+
<script>
22+
function setCookie(name, value) {
23+
document.cookie = name + "=" + value + ";path=/;";
24+
}
25+
26+
function getCookie(name) {
27+
var name = name + "=";
28+
var decodedCookie = decodeURIComponent(document.cookie);
29+
var ca = decodedCookie.split(';');
30+
for (var i = 0; i < ca.length; i++) {
31+
var c = ca[i];
32+
while (c.charAt(0) == ' ') {
33+
c = c.substring(1);
34+
}
35+
if (c.indexOf(name) == 0) {
36+
return c.substring(name.length, c.length);
37+
}
38+
}
39+
return "";
40+
}
41+
</script>
42+
<script>
43+
var flag = getCookie("flag");
44+
if (flag === "success") {
45+
alert("Congratulations! You have solved the XSS Challenge");
46+
}
47+
</script>
48+
<br>
49+
<div align="right">
50+
<button class="btn btn-info" type="button" onclick="window.location.href='/xss'">Back to Lab Details</button>
51+
</div>
52+
{% endblock content %}

pygoat/introduction/templates/introduction/base.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ <h3>PyGoat</h3>
8888
aria-expanded="false"
8989
class="dropdown-toggle"
9090
id="owasp10_2021"
91-
style="padding: 13% 0 0 0"
91+
style="padding: 13% 10% 0 0"
9292
>
9393
<i class="fas fa-flag"></i>
9494
OWASP TOP 10 2021
@@ -351,7 +351,7 @@ <h3>PyGoat</h3>
351351
aria-expanded="false"
352352
class="dropdown-toggle"
353353
id="mitre25"
354-
style="padding: 13% 0 0 0"
354+
style="padding: 13% 10% 0 0"
355355
>
356356
<i class="fas fa-flag"></i>
357357
Mitre top 25 Vulns
@@ -518,7 +518,7 @@ <h3>PyGoat</h3>
518518
aria-expanded="false"
519519
class="dropdown-toggle"
520520
id="owasp10_2017"
521-
style="padding: 13% 0 0 0"
521+
style="padding: 13% 10% 0 0"
522522
>
523523
<i class="fas fa-flag"></i>
524524
OWASP TOP 10 2017

pygoat/introduction/templates/mitre/mitre_top10.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
{% load static %}
33
{% block content %}
44
{% block title %}
5-
<title> Unrestricted Upload of File with Dangerous Type </title>
5+
<title> Predictable Value Range from Previous Values </title>
66
{% endblock %}
77
<div class="container">
8-
<h2 style="font-size:2.7rem">CWE-343: <span>Unrestricted Upload of File with Dangerous Type</span></h2>
8+
<h2 style="font-size:2.7rem">CWE-343: <span>Predictable Value Range from Previous Values</span></h2>
99
</div>
1010

1111
<div class="box">
12-
The software allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment.
12+
The product's random number generator produces a series of values which, when observed, can be used to infer a relatively small range of possibilities for the next value that could be generated.
1313
<br>
14-
In vulnerability databases and other places, the term "unrestricted file upload" is used, however it is not specific enough. The statement could be taken to mean that there are no limitations on the amount or size of uploaded files, which is a problem with resource use.
14+
The output of a random number generator should not be predictable based on observations of previous values. In some cases, an attacker cannot predict the exact value that will be produced next, but can narrow down the possibilities significantly. This reduces the amount of effort to perform a brute force attack. For example, suppose the product generates random numbers between 1 and 100, but it always produces a larger value until it reaches 100. If the generator produces an 80, then the attacker knows that the next value will be somewhere between 81 and 100. Instead of 100 possibilities, the attacker only needs to consider 20.
1515
</div>
1616

1717
{% endblock %}

pygoat/introduction/templates/mitre/mitre_top11.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@
88
<h2 style="font-size:2.7rem">CWE-476: <span> NULL Pointer Dereference</span></h2>
99
</div>
1010
<div class="box">
11-
When an application dereferences a pointer that it anticipates to be valid but is NULL,
12-
it results in a crash or programme exit. Issues with NULL pointer dereference can arise
13-
from a variety of bugs, such as race situations and straightforward programming errors.
11+
The program can potentially dereference a null pointer, thereby raising a NullPointerException. Null pointer errors are usually the result of one or more programmer assumptions being violated. Most null pointer issues result in general software reliability problems, but if an attacker can intentionally trigger a null pointer dereference, the attacker might be able to use the resulting exception to bypass security logic or to cause the application to reveal debugging information that will be valuable in planning subsequent attacks.
12+
<br>
13+
<br>
14+
A null-pointer dereference takes place when a pointer with a value of NULL is used as though it pointed to a valid memory area.
15+
<br>
16+
<br>
17+
Null-pointer dereferences, while common, can generally be found and corrected in a simple way. They will always result in the crash of the process, unless exception handling (on some platforms) is invoked, and even then, little can be done to salvage the process.
18+
<br>
19+
<br>
20+
<h4 id="example-1">Example 1</h4>
21+
22+
In the following code, the programmer assumes that the system always has
23+
a property named “cmd” defined. If an attacker can control the program’s
24+
environment so that “cmd” is not defined, the program throws a null
25+
pointer exception when it attempts to call the trim() method.
26+
27+
<p><code class="language-plaintext highlighter-rouge"> String cmd = System.getProperty("cmd");</code>
1428
</div>
1529
{% endblock %}

pygoat/introduction/templates/mitre/mitre_top13.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ <h2 style="font-size:2.7rem">CWE-190: <span>Integer Overflow or Wraparound</span
1111
The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.
1212
<br>
1313
When an integer value is increased to a value that is too large to be stored in the associated representation, an integer overflow or wraparound occurs. If this takes place, the value can wrap, turning into a very small or negative integer. Even while this might be the intended course of action in situations when wrapping is necessary, it might have security repercussions if the wrapping is unanticipated. This is especially true if human inputs can cause the integer overflow to occur. When the outcome is used to manage looping, make a security choice, or choose the offset or size for operations like memory allocation, copying, concatenation, etc., this turns into a security-critical situation.
14-
14+
<br>
15+
"Integer overflow" is sometimes used to cover several types of errors, including signedness errors, or buffer overflows that involve manipulation of integer data types instead of characters. Part of the confusion results from the fact that 0xffffffff is -1 in a signed context. Other confusion also arises because of the role that integer overflows have in chains
1516
</div>
1617

1718
{% endblock %}

pygoat/introduction/templates/mitre/mitre_top20.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
<div class="container">
88
<h2 style="font-size:2.7rem">CWE-276: <span>Incorrect Default Permissions</span></h2>
99
</div>
10-
<div class="box">During installation, installed file permissions are set to allow anyone to modify those files.</div>
10+
<div class="box">During installation, installed file permissions are set to allow anyone to modify those files.
11+
<br>
12+
<br>
13+
Usually this weakness is locally exploitable. A malicious user might be able to gain access to sensitive information, tamper with sensitive data or compromise the vulnerable system entirely. If a setuid/setgid executable has world writable permissions any local user can inject malicious content into it and execute arbitrary code with privileges of the file's owner.
14+
<br>
15+
Basically, any application writable by an unintended actor poses a threat to system security and might be used to elevate privileges on the system, e.g. if such application was modified by a malicious and unprivileged user before being executed by a privileged one.
16+
</div>
1117

1218
{% endblock %}

pygoat/introduction/templates/mitre/mitre_top7.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,13 @@ <h2 style="font-size: 2.7rem">CWE-416: <span>User after free</span></h2>
2727
has a potential to contain a class. The execution of arbitrary code is
2828
possible if one of these function pointers is overwritten with an address to
2929
legitimate shellcode.
30+
<br>
31+
<br>
32+
To prevent Use After Free vulnerabilities, software developers should carefully
33+
manage memory allocation and deallocation, validate user input to ensure that it
34+
does not trigger a double-free condition, and use safe programming practices that
35+
automatically detect and prevent the use of freed memory. Tools like memory-safe
36+
programming languages and memory-management libraries can also help prevent this
37+
type of vulnerability.
3038
</div>
3139
{% endblock %}

0 commit comments

Comments
 (0)