-
Notifications
You must be signed in to change notification settings - Fork 0
/
len_ext_attack.py
44 lines (31 loc) · 1.1 KB
/
len_ext_attack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python3
# Run me like this:
# $ python3 len_ext_attack.py "https://project1.eecs388.org/uniqname/lengthextension/api?token=...."
# or select "Length Extension" from the VS Code debugger
import sys
from urllib.parse import quote
from pysha256 import sha256, padding
class URL:
def __init__(self, url: str):
# prefix is the slice of the URL from "https://" to "token=", inclusive.
self.prefix = url[:url.find('=') + 1]
self.token = url[url.find('=') + 1:url.find('&')]
# suffix starts at the first "command=" and goes to the end of the URL
self.suffix = url[url.find('&') + 1:]
def __str__(self) -> str:
return f'{self.prefix}{self.token}&{self.suffix}'
def __repr__(self) -> str:
return f'{type(self).__name__}({str(self).__repr__()})'
def main():
if len(sys.argv) < 2:
print(f"usage: {sys.argv[0]} URL_TO_EXTEND", file=sys.stderr)
sys.exit(-1)
url = URL(sys.argv[1])
#
# TODO: Modify the URL
#
url.token = 'TODO'
url.suffix += 'TODO'
print(url)
if __name__ == '__main__':
main()