1
1
#!/usr/env/python3
2
2
import sys
3
3
4
+ from json import loads
4
5
from optparse import OptionParser
5
6
from version import VERSION
6
7
from config import HEADERS
7
- from json import loads
8
8
from urllib .parse import urlparse
9
9
10
10
from lib .tests .info_field_suggestions import field_suggestions
21
21
22
22
parser = OptionParser (usage = '%prog -t http://example.com -o json' )
23
23
parser .add_option ('-t' , '--target' , dest = 'url' , help = 'target url with the path' )
24
- parser .add_option ('-H' , '--header' , dest = 'header' , help = 'Append Header to the request \' {"Authorizathion ": "Bearer eyjt"}\' ' )
24
+ parser .add_option ('-H' , '--header' , dest = 'header' , help = 'Append Header to the request \' {"Authorization ": "Bearer eyjt"}\' ' )
25
25
parser .add_option ('-o' , '--output' , dest = 'output_json' ,
26
26
help = 'Output results to stdout (JSON)' , default = False )
27
27
parser .add_option ('--proxy' , '-x' , dest = 'proxy' , action = 'store_true' , default = False ,
55
55
print ("Cannot cast %s into header dictionary. Ensure the format \' {\" key\" : \" value\" }\' ." % (options .header ))
56
56
57
57
if not urlparse (options .url ).scheme :
58
- print ("Url missing scheme (http:// or https://). Ensure Url contains a scheme." )
58
+ print ("URL missing scheme (http:// or https://). Ensure ULR contains some scheme." )
59
59
sys .exit (1 )
60
60
else :
61
61
url = options .url
64
64
print (url , 'does not seem to be running GraphQL.' )
65
65
sys .exit (1 )
66
66
67
- json_output = {}
68
-
69
- if field_suggestions (url , proxy , HEADERS ):
70
- # Field Suggestions
71
- json_output ['Field Suggestions' ] = {}
72
- json_output ['Field Suggestions' ]['severity' ] = 'LOW'
73
- json_output ['Field Suggestions' ]['impact' ] = 'Information Leakage'
74
- json_output ['Field Suggestions' ]['description' ] = 'Field Suggestions are Enabled'
75
-
76
- if introspection (url , proxy , HEADERS ):
77
- # Introspection
78
- json_output ['Introspection' ] = {}
79
- json_output ['Introspection' ]['severity' ] = 'HIGH'
80
- json_output ['Introspection' ]['impact' ] = 'Information Leakage'
81
- json_output ['Introspection' ]['description' ] = 'Introspection Query Enabled'
82
-
83
- if detect_graphiql (url , proxy , HEADERS ):
84
- # Playground
85
- json_output ['GraphiQL Playground' ] = {}
86
- json_output ['GraphiQL Playground' ]['severity' ] = 'LOW'
87
- json_output ['GraphiQL Playground' ]['impact' ] = 'Information Leakage'
88
- json_output ['GraphiQL Playground' ]['description' ] = 'GraphiQL Explorer Enabled'
89
-
90
- if get_method_support (url , proxy , HEADERS ):
91
- # HTTP GET method support
92
- json_output ['Possible CSRF (GET)' ] = {}
93
- json_output ['Possible CSRF (GET)' ]['severity' ] = 'LOW'
94
- json_output ['Possible CSRF (GET)' ]['impact' ] = 'Possible CSRF'
95
- json_output ['Possible CSRF (GET)' ]['description' ] = 'HTTP GET method supported (maybe CSRF)'
96
-
97
- if alias_overloading (url , proxy , HEADERS ):
98
- # Alias Overloading
99
- json_output ['Alias Overloading' ] = {}
100
- json_output ['Alias Overloading' ]['severity' ] = 'HIGH'
101
- json_output ['Alias Overloading' ]['impact' ] = 'Denial of Service'
102
- json_output ['Alias Overloading' ]['description' ] = 'Alias Overloading with 100+ aliases is allowed'
103
-
104
- if batch_query (url , proxy , HEADERS ):
105
- # Batch Queries
106
- json_output ['Batch Queries' ] = {}
107
- json_output ['Batch Queries' ]['severity' ] = 'HIGH'
108
- json_output ['Batch Queries' ]['impact' ] = 'Denial of Service'
109
- json_output ['Batch Queries' ]['description' ] = 'Batch queries allowed with 10+ simultaneous queries)'
110
-
111
- if field_duplication (url , proxy , HEADERS ):
112
- # Field Duplication
113
- json_output ['Field Duplication' ] = {}
114
- json_output ['Field Duplication' ]['severity' ] = 'HIGH'
115
- json_output ['Field Duplication' ]['impact' ] = 'Denial of Service'
116
- json_output ['Field Duplication' ]['description' ] = 'Queries are allowed with 500 of the same repeated field'
117
-
118
- if trace_mode (url , proxy , HEADERS ):
119
- # Tracing mode
120
- json_output ['Tracing Mode' ] = {}
121
- json_output ['Tracing Mode' ]['severity' ] = 'INFORMATIONAL'
122
- json_output ['Tracing Mode' ]['impact' ] = 'Information Leakage'
123
- json_output ['Tracing Mode' ]['description' ] = 'Tracing is enabled'
67
+ tests = [field_suggestions , introspection , detect_graphiql ,
68
+ get_method_support , alias_overloading , batch_query ,
69
+ field_duplication , trace_mode , directive_overloading ]
124
70
125
- if directive_overloading (url , proxy , HEADERS ):
126
- # Directive Overloading
127
- json_output ['Directive Overloading' ] = {}
128
- json_output ['Directive Overloading' ]['severity' ] = 'HIGH'
129
- json_output ['Directive Overloading' ]['impact' ] = 'Denial of Service'
130
- json_output ['Directive Overloading' ]['description' ] = 'Multiple duplicated directives allowed in a query'
71
+ json_output = []
131
72
73
+ for test in tests :
74
+ json_output .append (test (url , proxy , HEADERS ))
75
+
132
76
if options .output_json == 'json' :
133
- print (json_output )
77
+ from pprint import pprint
78
+ pprint (json_output )
134
79
else :
135
- for k , v in json_output .items ():
136
- print ('[{}] {} - {} ({})' .format (v ['severity' ], k , v ['description' ], v ['impact' ]))
80
+ for i in json_output :
81
+ print ('[{}] {} - {} ({})' .format (i ['severity' ], i ['title' ], i ['description' ], i ['impact' ]))
82
+
0 commit comments