-
Notifications
You must be signed in to change notification settings - Fork 23
/
payload.py
137 lines (106 loc) · 4.53 KB
/
payload.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"""
xira payload module :
for payload cheatsheet checkout: "https://github.com/xadhrit/xss-hacker"
"""
import json
import requests
class PayloadInformation( ):
def __init__(self, key ,payload_name):
""" Create Payload Information Object
self --- This Object
key --- Key for payload
payload_name --- Code of payload
Return value:
Nothing.
"""
self.key = key
self.payload_name = payload_name
for payload in payload_name.values():
payload
return
def __str__(self):
""" Convert Object to String
Keywords Arguments:
self -- This Oject
Return Value:
Nicely fomatted string to get information about this payload
"""
return f"{self.key} ({self.payload_name}) "
class PayloadsInfo():
def __init__(self,payload_file_path=None):
"""Create Other information Object for printing and accessing payloads
Keywords Arguments:
self --- This Object
payload_file_path ------ String which indicates path to data file.
The file name must end in ".json".
"""
if payload_file_path is None:
payload_file_path = "https://raw.githubusercontent.com/xadhrit/xira/main/payload.json"
if not payload_file_path.lower().endswith(".json"):
raise FileNotFoundError(f"Incorrect Json file extension for payloads")
if "http://" == payload_file_path[:7].lower() or "https://" == payload_file_path[:8].lower():
# refrence is to URl
try:
response = requests.get(url=payload_file_path)
except:
raise FileNotFoundError(f"Problem While attempting to access"
f"payload file URL '{payload_file_path}': "
)
if response.status_code == 200:
try:
payload_data = response.json()
except Exception as error:
raise ValueError(f"Problem parsing json content at"
f" '{payload_file_path}': {str(error)}."
)
else:
raise FileNotFoundError(f"Bad response while accessing"
f" data file URL '{payload_file_path}'"
)
else:
try:
with open(payload_file_path, "r", encoding="utf-8") as file:
try:
payload_data = json.load(file)
except Exception as error:
raise ValueError (f"Problem parsing json contents at"
f"'{payload_file_path}' : {str(error)}."
)
except FileNotFoundError as error:
raise FileNotFoundError (f"Problem while attempting to access"
f"payload file '{payload_file_path}'."
)
f =open('payload.json', 'r', encoding="utf-8")
payload_data = json.load(f)
self.payloads = {}
for payload_name in payload_data:
try:
self.payloads[payload_name] = \
PayloadInformation(payload_name,
payload_data[payload_name]
)
except KeyError as error:
raise ValueError(f"Problem parsing json contents at "
f"'{payload_file_path}' : "
f"Missing attribute {str(error)}."
)
return
def __iter__(self):
"""Iterator for Object.
Keyword Arguments:
self --- This Object
Return Value:
Iterator for payload object.
"""
for payload_name in self.payloads:
yield self.payloads[payload_name]
def __len__(self):
"""Length for Object
Keywords Arguments:
self -- This Object
Return Value:
Length of paylaod objects.
"""
return len(self.payloads)
if __name__ == '__main__':
PayloadsInfo('payload.json')