-
Notifications
You must be signed in to change notification settings - Fork 2
/
strapi_exploit.py
executable file
·82 lines (81 loc) · 3.34 KB
/
strapi_exploit.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
'''Strapi Exploit Interface'''
from json import JSONDecodeError
from random import choices
from string import ascii_lowercase
import requests
from rich.prompt import Prompt
from logger import logger
class StrapiExploitInterface:
''''Interface for Strapi Exploit'''
def __init__(self, name: str, description: str):
self.name = name
self.description = description
self.logger = logger
def run(self) -> bool:
'''Run the plugin. Returns True if successful, False if not.'''
def get_name(self) -> str:
'''Get the name of the plugin.'''
return self.name
def get_description(self) -> str:
'''Get the description of the plugin.'''
return self.description
def is_valid(self) -> bool:
'''Check if the plugin is valid.'''
if self.name != "" and self.description != "":
return True
else:
return False
def get_strapi_version(self, url: str) -> str:
'''Get the version of Strapi.'''
try:
version = requests.get(f"{url}/admin/init", timeout=10).json()["data"]["strapiVersion"]
return version
except JSONDecodeError:
try:
version = requests.get(f"{url}/admin/strapiVersion", timeout=10).json()["strapiVersion"]
return version
except JSONDecodeError:
return ""
def input(self, prompt: str) -> str:
'''Get input from the user.'''
return Prompt.ask(f"[bold cyan][>] {prompt} [/bold cyan]")
def input_default(self, prompt: str, default: str) -> str:
'''Get input from the user with a default value.'''
return Prompt.ask(f"[bold cyan][>] {prompt} [/bold cyan]", default=default)
def display(self, text: str) -> None:
'''Display text to the user.'''
self.logger.display(f"[{self.name}] {text}")
def success(self, text: str) -> None:
'''Display success message to the user.'''
self.logger.success(f"[{self.name}] {text}")
def error(self, text: str) -> None:
'''Display error message to the user.'''
self.logger.error(f"[{self.name}] {text}")
def warning(self, text: str) -> None:
'''Display warning message to the user.'''
self.logger.warning(f"[{self.name}] {text}")
def info(self, text: str) -> None:
'''Display info message to the user.'''
self.logger.info(f"[{self.name}] {text}")
def get_random_email(self) -> str:
'''Get a random email.'''
return "".join(choices(ascii_lowercase, k=10)) + "@strapwn.dev"
def get_random_password(self) -> str:
'''Get a random password.'''
return "".join(choices(ascii_lowercase, k=10)) + "?A#"
def get_random_username(self) -> str:
'''Get a random username.'''
return "".join(choices(ascii_lowercase, k=10))
def get_admin_token(self, url: str, email: str, password: str) -> str:
'''Get the admin token.'''
try:
r = requests.post(f"{url}/admin/login",
data={"email": email, "password": password},
timeout=10
)
if r.status_code == 200:
return r.json()['data']['token']
else:
return ""
except JSONDecodeError:
return ""