-
Notifications
You must be signed in to change notification settings - Fork 0
/
cylma.py
172 lines (118 loc) · 6.11 KB
/
cylma.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
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
#!/usr/bin/env python3
from urllib.request import Request, urlopen
from urllib.parse import urlencode
from sys import argv, exit
from getopt import getopt
from json import dumps, loads
__author__ = 'nigella'
__version__ = '0.0.4-dev'
SHODAN_API_KEY = ''
UA_API_KEY = ''
# Useless functions
def flag(): print('\n\t\t\t\t\t ▄▄· ▄· ▄▌▄▄▌ • ▌ ▄ ·. ▄▄▄·\n\t\t\t\t\t ▐█ ▌▪▐█▪██▌██• ·██ ▐███▪▐█ ▀█\n\t\t\t\t\t ██ ▄▄▐█▌▐█▪██▪ ▐█ ▌▐▌▐█·▄█▀▀█\n\t\t\t\t\t ▐███▌ ▐█▀·.▐█▌▐▌██ ██▌▐█▌▐█ ▪▐▌\n\t\t\t\t\t ·▀▀▀ ▀ • .▀▀▀ ▀▀ █▪▀▀▀ ▀ ▀\n\n\t\t\t\t\t nigella. twttr: @_ngll gh: @nig\n')
def usage(): print('\n\n\n\t\t\t\t\t\t\t USAGE \n\t\t\t\t\t\t\t =====\n\n\t\t\t\t\t\t FLAG -i, --ip-address\n\t\t\t\t\t\t FLAG -u, --user-agent\n\n\t\t\t\t\t P.S. python(3) cylma.py <flags>\n\n'); exit()
def create_json(ip_data=None, shodan_data='None', ua_data=None):
' Create JSON data from given variables '
# IP API ERROR HANDLING
if ip_data == None: ip_data, ip_api_status = 'None', 'None'
elif ip_data != None:
if ip_data['status'] == 'fail': ip_data, ip_api_status = ip_data['message'], 'error'
else: ip_api_status = 'success'
# USER-AGENT API ERROR HANDLING
if ua_data == None: ua_data, ua_api_status = 'None', 'None'
elif ua_data != None:
if 'error' in ua_data: ua_data, ua_api_status = ua_data['error']['message'], 'error'
else: ua_api_status = 'success'
# SHODAN API ERROR HANDLING
if shodan_data == 'None': shodan_api_status, shodan_data = 'None', 'None'
elif shodan_data != None:
if 'error' in shodan_data: shodan_data, shodan_api_status = shodan_data['error'], 'error'
else: shodan_api_status = 'success'
else: shodan_api_status, shodan_data = 'error', 'error_occured'
data = {
"ip_api": ip_api_status,
"ip_data": [ip_data],
"ua_api": ua_api_status,
"ua_data": [ua_data],
"shodan_api": shodan_api_status,
"shodan_data": [shodan_data],
"author": "nigella",
"author_data": [{"twitter": "@_ngll", "github": "@nig"}],
"last_words": [
"An old friend once told me something that gave me great comfort.",
"Something he read. He said Mozart, Beethoven and Chopin never died.",
"They simply became music."
]
}
with open('data.json', 'w') as datas: datas.writelines(dumps(data, indent=4 * ' '))
def create_request(URL, values=None, hds='Cylma - nigella is watching'):
' Create new request '
request = Request(
URL, # Use HTTP, maybe user doesn't have up-to-date SSL certificate.
data = values, # Default is none, if you want to change it, be sure you know what are you doing.
headers = { # Default is just User-Agent, but you can use other headers too.
'User-Agent': hds
}
)
return request
def open_request(request):
' Open given request '
try: return loads(urlopen(request).read())
except: pass
def ip_analysis(ip, shodan=True, ip_api=True):
' Shodan API & IP-API '
global ip_data, shodan_data
if shodan:
shodan_data = open_request(
create_request('https://api.shodan.io/shodan/host/{0}?key={1}'.format(ip, SHODAN_API_KEY))
)
if ip_api:
ip_data = open_request(
create_request('http://ip-api.com/json/{0}?fields=254233'.format(ip))
)
def ua_analysis(ua):
' User-Agent API '
global ua_data
ua_data = open_request(
create_request('https://useragentapi.com/api/v4/json/{0}/{1}'.format(UA_API_KEY, ua))
)
def friendly_output():
' Print friendly output '
if ip_data:
try:
print('\n\t\t\t\t\t\t\t IP DATA\n\t\t\t\t\t\t\t =======\n\n\t\t\t\t\t\t CITY {0}\n\t\t\t\t\t\t COUNTRY {1}\n\t\t\t\t\t\t MOBILE {2}\n\t\t\t\t\t\t PROXY {3}\n\t\t\t\t\t\t REGION {4}\n\t\t\t\t\t\t TIMEZONE {5}\n'.format(
ip_data['city'], ip_data['country'], ip_data['mobile'], ip_data['proxy'], ip_data['regionName'], ip_data['timezone']
))
except: pass
if shodan_data != 'None':
try:
print('\n\t\t\t\t\t\t SHODAN DATA\n\t\t\t\t\t\t ===========\n\n\t\t\t\t\t\t OS {0}\n\t\t\t\t\t\t ISP {1}\n\t\t\t\t\t\t POSTAL {2}\n\t\t\t\t\t\t COORDINATES {3}, {4}\n\t\t\t\t\t\t PORTS {5}\n'.format(
shodan_data['os'], shodan_data['isp'], shodan_data['postal_code'], shodan_data['longitude'], shodan_data['latitude'], "i am a port"
))
except: pass
if ua_data:
try:
print('\n\t\t\t\t\t\t\t UA DATA\n\t\t\t\t\t\t\t =======\n\n\t\t\t\t\t\t TYPE {0}\n\t\t\t\t\t\t OS {1}, {2}\n\t\t\t\t\t\t BRWSR {3}\n\t\t\t\t\t\t VER {4}\n'.format(
ua_data['data']['ua_type'], ua_data['data']['os_name'], ua_data['data']['os_version'], ua_data['data']['browser_name'], ua_data['data']['browser_version']
))
except: pass
if __name__ == '__main__':
' When script is started mainly (directly) '
flag()
try: opts, args = getopt(argv[1:], 'hi:u:', ['ip-address=', 'user-agent='])
except: usage() # When bad argument typed
for opt, arg in opts:
if opt == '-h': usage()
elif opt in ('-i', '--ip-address'): ip = arg
elif opt in ('-u', '--user-agent'): ua = urlencode({"Agent": arg}).split('Agent=')[1]
try:
if opt: ''
except: usage() # When there is no arguments
# UN-USED ARGUMENTS ERROR HANDLING
try: ip_analysis(ip)
except: ip_data, shodan_data = None, 'None'
try: ua_analysis(ua)
except: ua_data = None
create_json(ip_data=ip_data, shodan_data=shodan_data, ua_data=ua_data) # Create final JSON data
friendly_output() # Friendly output ^^
else: print('Well.. You can use this script in yours but, you\'ll be suffer.') # When script is started from another one