-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgraphme.py
More file actions
178 lines (156 loc) · 4.6 KB
/
Copy pathgraphme.py
File metadata and controls
178 lines (156 loc) · 4.6 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import sys
import argparse
import requests as rq
import json
builtin_keywords =["Int","String","Boolean","__Schema","__Type","__TypeKind","__Field","__InputValue","__EnumValue","__Directive","__DirectiveLocation"]
def send_request(url,query):
#proxy = {"http":"http://127.0.0.1:8080"}
headers = {
"Authorization":"Bearer xxx",
"X-CSRF-Token":"xxx",
"Cookie":"xx"
}
payload = {'query': query}
req = rq.post(url,json=payload,headers=headers)#proxies=proxy
if req.status_code == 200:
return json.loads(req.content)
else:
print "\033[93mStatus Code is not 200\033[0m"
exit()
def Graph_schema(url):
print "\033[95mFetching GraphQL Schema\033[0m"
print
query = '''\n{\n __schema {\n types {\n name\n }\n }\n}'''
temp = send_request(url,query)
r = temp["data"]["__schema"]["types"]
for i in r:
if i["name"] not in builtin_keywords:
print "\033[1;31m" + "Type: " + i["name"] + "\033[0m"
Get_fileds(url,i["name"])
def Get_fileds(url,typename):
query = '''{__type(name: "''' + typename + '''") {
name
fields {
name
type {
name
kind
ofType {
name
kind
ofType {
name
kind
ofType {
name
kind
}
}
}
}
args {
name
type {
name
kind
ofType {
name
kind
ofType {
name
kind
ofType {
name
kind
}
}
}
}
}
}
}
}'''
temp = send_request(url,query)
r = temp["data"]["__type"]["fields"]
if r == None:
print "Fields: Null"
return
for i in r:
Field_parser(i)
def Field_parser(fields):
name = fields["name"]
if fields["args"] == []:
print name + ": " + Ret_type_parser(fields["type"])
else:
print name + "("+Args_parser(fields["args"]) + "): " + Ret_type_parser(fields["type"])
def Ret_type_parser(ret_type): #Support: [Obj], Obj, Obj!, [Obj!], [Obj]!, [Obj!]!
r = ""
if ret_type["ofType"] == None and ret_type["kind"] != "LIST" and ret_type["kind"] != "NON_NULL":
r = ret_type["name"]
else:
if ret_type["kind"] == "NON_NULL" and ret_type["ofType"]["ofType"] == None:
r = ret_type["ofType"]["name"] + "!"
elif ret_type["kind"] == "NON_NULL" and ret_type["ofType"]["ofType"] != None:
if ret_type["ofType"]["ofType"]["ofType"] == None:
r = "[" + ret_type["ofType"]["ofType"]["name"] + "]!"
else:
r = "[" + ret_type["ofType"]["ofType"]["ofType"]["name"] + "!]!"
elif ret_type["kind"] == "LIST" and ret_type["ofType"]["ofType"] == None:
r = "[" + ret_type["ofType"]["name"] + "]"
else:
r = "[" + ret_type["ofType"]["ofType"]["name"] + "!]"
return r
def Args_parser(args):
r = ""
tmp = len(args)
if len(args) > 1:
for i in args:
tmp = tmp - 1
if i["type"]["ofType"] == None:
sw = i["name"] + ": " + i["type"]["name"]
if tmp !=0:
sw = sw + ", "
else:
if i["type"]["kind"] == "LIST" and i["type"]["kind"] != "NON_NULL":
if i["type"]["ofType"]["ofType"] == None:
sw = i["name"] + ": " + "[" + i["type"]["ofType"]["name"] + "]"
if tmp !=0:
sw = sw + ", "
else:
sw = i["name"] + ": " + "[" + i["type"]["ofType"]["ofType"]["name"] + "!]"
if tmp !=0:
sw = sw + ", "
else:
if i["type"]["ofType"]["ofType"] == None:
sw = i["name"] + ": " + i["type"]["ofType"]["name"] + "!"
if tmp !=0:
sw = sw + ", "
else:
sw = i["name"] + ": " + "[" + i["type"]["ofType"]["ofType"]["ofType"]["name"] + "!]!"
if tmp !=0:
sw = sw + ", "
r = r + sw
else:
if args[0]["type"]["ofType"] == None:
sw = args[0]["name"] + ": " + args[0]["type"]["name"]
else:
if args[0]["type"]["kind"] == "LIST" and args[0]["type"]["kind"] != "NON_NULL":
if args[0]["type"]["ofType"]["ofType"] == None:
sw = args[0]["name"] + ": " + "[" + args[0]["type"]["ofType"]["name"] + "]"
else:
sw = args[0]["name"] + ": " + "[" + args[0]["type"]["ofType"]["ofType"]["name"] + "!]"
else:
if args[0]["type"]["ofType"]["ofType"] == None:
sw = args[0]["name"] + ": " + args[0]["type"]["ofType"]["name"] + "!"
else:
sw = args[0]["name"] + ": " + "[" + args[0]["type"]["ofType"]["ofType"]["ofType"]["name"] + "!]!"
r = r + sw
return r
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-u', help='URL target. Ex: http://target.com/ , Note: config Custom Headers in send_request()',metavar='')
args = parser.parse_args()
if(len(sys.argv) <= 1):
print parser.print_help()
else:
Graph_schema(args.u)