forked from soxoj/socid-extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocid_extractor.py
executable file
·322 lines (293 loc) · 13.2 KB
/
socid_extractor.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/env python3
import argparse
import json
import logging
import sys
import re
from http.cookies import SimpleCookie
import requests
schemes = {
'Yandex Disk file': {
'flags': ['@yandexdisk', 'yastatic.net'],
'regex': r'"users":{.*?"uid":"(?P<uid>\d+)","displayName":"(?P<name>.+?)"',
},
'Yandex Disk photoalbum': {
'flags': ['yastatic.net/disk/album', 'isAvailableToAlbum'],
'regex': r'"display_name":"(?P<name>.*?)","uid":"(?P<uid>\d+)","locale":"\w+","login":"(?P<username>.*?)"',
},
'Yandex Music user profile': {
'flags': ['musicCspLogger'],
'regex': r'{"uid":"(?P<uid>\d+)","login":"(?P<username>.+?)","name":"(?P<name>.+?)"}',
# TODO: fix random order, add lastName and firstName
},
'Yandex Znatoki user profile': {
'flags': ['Ya.Znatoki'],
'regex': r'displayName":"(?P<name>[^&]+?)","uuid":(?P<yandex_uid>\d+),".+?login":"(?P<username>[^&]+?)".+?"id":"(?P<uid>[\w-]+)"'
},
'Yandex Realty offer': {
'flags': ['realty.yandex.ru/offer'],
'regex': r'({"routing":{"locationBeforeTransitions.+?});',
'extract_json': True,
'fields': {
'your_yuid': lambda x: x['user']['yuid'],
'your_uid': lambda x: x['user']['uid'],
'your_wallet_balance': lambda x: x['user']['walletInfo'].get('balance'),
'your_emails': lambda x: ', '.join(x['user']['emails']),
'your_name': lambda x: x['user'].get('displayName'),
'your_username': lambda x: x['user'].get('defaultEmail'),
'your_phone': lambda x: x['user'].get('defaultPhone'),
'uid': lambda x: x['cards']['offers']['author']['id'],
'name': lambda x: decode_ya_str(x['cards']['offers']['author']['agentName'])
}
},
'VK user profile': {
'flags': ['var vk =', 'change_current_info'],
'regex': r'Profile\.init\({"user_id":(?P<uid>\d+).*?(,"loc":"(?P<username>.*?)")?,"back":"(?P<name>.*?)"'
},
'Instagram': {
'flags': ['instagram://user?username'],
'regex': r'{"id":"(?P<uid>\d+)","username":"(?P<username>.*?)"}',
},
'Medium': {
'flags': ['https://medium.com', 'com.medium.reader'],
'regex': r'"User:.*?{"id":"(?P<uid>.*?)",.*?,"username":"(?P<username>.*?)",.*?,"name":"(?P<name>.*?)",.*?,"twitterScreenName":"(?P<twitter_username>.*?)","facebookAccountId":"(?P<facebook_uid>.*?)"',
},
'Odnoklassniki': {
'flags': ['OK.startupData'],
'regex': r'path:"/profile/(?P<uid>\d+)",state:',
},
'Habrahabr': {
'flags': ['habracdn.net'],
'regex': r'<div class="page-header page-header_full js-user_(?P<uid>\d+)">[\s\S]*?/users/(?P<username>.*?)/',
},
'Twitter': {
'flags': ['abs.twimg.com', 'moreCSSBundles'],
'regex': r'{"id":(?P<uid>\d+),"id_str":"\d+","name":"(?P<username>.*?)","screen_name":"(?P<name>.*?)"'
},
'Reddit': {
'flags': ['www.redditstatic.com', 'displayNamePrefixed'],
'regex': r'"displayText":"(?P<username>[^\"]+)","hasUserProfile":\w+,"hideFromRobots":\w+,"id":"(?P<uid>.+?)"',
},
'Facebook user profile': {
'flags': ['com.facebook.katana', 'scribe_endpoint'],
'regex': r'"uri":"[^\"]+\/(?P<username>[^\"\\\/]+?)","entity_id":"(?P<uid>\d+)"',
},
'Facebook group': {
'flags': ['com.facebook.katana', 'XPagesProfileHomeController'],
'regex': r'"uri":"[^\"]+\/(?P<username>[^\"\\\/]+?)[\\\/]+","entity_id":"(?P<uid>\d+)"',
},
'GitHub': {
'flags': ['github.githubassets.com'],
'regex': r'data-scope-id="(?P<uid>\d+)" data-scoped-search-url="/search\?user=(?P<username>.+?)"'
},
'My Mail.ru': {
'flags': ['my.mail.ru', 'models/user/journal'],
'regex': r'"name": "(?P<name>[^"]+)",\s+"id": "(?P<uid>\d+)",[\s\S]+?"email": "(?P<username>[^@]+)@mail.ru"',
},
'Behance': {
'flags': ['behance.net', 'beconfig-store_state'],
'message': 'Cookies required, ensure you added --cookies "ilo0=1"',
'regex': r'{"id":(?P<uid>\d+),"first_name":"(?P<first_name>[^"]+)","last_name":"(?P<last_name>[^"]+)","username":"(?P<username>[^"]+)"',
},
'Blogger': {
'flags': ['www.blogger.com/static', 'blogspot.com/feeds/posts'],
'regex': r'www.blogger.com\/feeds\/(?P<blog_id>\d+)\/posts\/default" \/>\n<link rel="me" href="https:\/\/www.blogger.com\/profile/(?P<uid>\d+)" \/>',
},
'D3.ru': {
'flags': ['feedSettingsHandler.subscribe(this', 'd3.ru/static'],
'regex': r"feedSettingsHandler.subscribe\(this, 'users', '(?P<uid>\d+)'",
},
'Gitlab': {
'flags': ['gitlab-static.net'],
'regex': r'abuse_reports.+?user_id=(?P<uid>\d+)"',
},
'500px': {
'flags': ['//assetcdn.500px.org'],
'regex': r'({"userdata":{"id":.+?"groups":\[\]}})',
'extract_json': True,
'fields': {
'uid': lambda x: x['userdata']['id'],
'username': lambda x: x['userdata']['username'],
'name': lambda x: x['userdata']['fullname'],
'qq_username': lambda x: x['userdata']['contacts']['qq'],
'website': lambda x: x['userdata']['contacts']['website'],
'blog': lambda x: x['userdata']['contacts']['blog'],
'lastfm_username': lambda x: x['userdata']['contacts']['lastfm'],
'facebook_uid': lambda x: x['userdata']['contacts']['facebook'],
'msn_username': lambda x: x['userdata']['contacts']['MSN'],
'facebook_page': lambda x: x['userdata']['contacts']['facebookpage'],
'livejournal_username': lambda x: x['userdata']['contacts']['livejournal'],
'instagram_username': lambda x: x['userdata']['contacts']['instagram'],
'twitter_username': lambda x: x['userdata']['contacts']['twitter'],
'skype_username': lambda x: x['userdata']['contacts']['skype'],
'thumblr_username': lambda x: x['userdata']['contacts']['thumblr'],
'gtalk_username': lambda x: x['userdata']['contacts']['gtalk'],
'icq_uid': lambda x: x['userdata']['contacts']['icq'],
'flickr_username': lambda x: x['userdata']['contacts']['flickr'],
'lookatme_username': lambda x: x['userdata']['contacts']['LOOKATME'],
'googleplus_uid': lambda x: x['userdata']['contacts']['googleplus'],
}
},
'Google document': {
'flags': ['_docs_flag_initialData'],
'regex': r'({"docs-ails":"docs_\w+".+?"docs-(comp|fsd|dcr)":\w+})',
'extract_json': True,
'message': 'Auth cookies requires, add through --cookies in format "a=1;b=2"n\nTry to run twice to get result.',
'fields': {
'your_ls_uid': lambda x: x.get('docs-offline-lsuid'),
'your_cpf': lambda x: x.get('docs-cpf'),
'your_username': lambda x: x.get('docs-offline-ue') or x.get('docs-hue'),
'your_uid': lambda x: x['docs-pid'],
'org_name': lambda x: x['docs-doddn'],
'org_domain': lambda x: x['docs-dodn'],
}
},
'Bitbucket': {
'flags': ['bitbucket.org/account'],
'regex': r'({"section": {"profile.+?"whats_new_feed":.+?}})',
'extract_json': True,
'fields': {
'uid': lambda x: x['global']['targetUser']['uuid'].strip('{}'),
'username': lambda x: x['global']['targetUser']['nickname'],
'created_at': lambda x: x['global']['targetUser']['created_on'],
'is_service': lambda x: x['global']['targetUser']['is_staff'],
}
},
'Steam': {
'flags': ['store.steampowered.com'],
'regex': r'({"url":".+?});',
'extract_json': True,
'fields': {
'uid': lambda x: x['steamid'],
'name': lambda x: x['personaname'],
'username': lambda x: [y for y in x['url'].split('/') if y][-1],
}
},
'Stack Overflow & similar': {
'flags': ['StackExchange.user.init'],
'regex': r'StackExchange.user.init\({ userId: (?P<uid>\d+), accountId: (?P<stack_exchange_uid>\d+) }\);',
},
'SoundCloud': {
'flags': ['eventlogger.soundcloud.com'],
'regex': r'catch\(t\){}}\)},(\[{"id":.+?)\);',
'extract_json': True,
'message': 'Run with auth cookies to get your ids.',
'fields': {
'your_uid': lambda x: x[-2]['data'][0].get('id'),
'your_name': lambda x: x[-2]['data'][0].get('full_name'),
'your_username': lambda x: x[-2]['data'][0].get('username'),
'uid': lambda x: x[-1]['data'][0]['id'],
'name': lambda x: x[-1]['data'][0]['full_name'],
'username': lambda x: x[-1]['data'][0]['username'],
}
},
'VC.ru': {
'flags': ['property="og:site_name" content="vc.ru"'],
'regex': r'({"module.page":{.+});',
'extract_json': True,
'fields': {
'uid': lambda x: x['module.page']['subsite']['id'],
'name': lambda x: x['module.page']['subsite']['name'],
'username': lambda x: x['module.page']['subsite']['url'].split('/')[-1],
}
},
'LiveJournal': {
'flags': ['Site.journal'],
'regex': r'Site.journal = ({".+?"});',
'extract_json': True,
'fields': {
'uid': lambda x: x['id'],
'is_paid': lambda x: x['is_paid'],
'is_news': lambda x: x['is_news'],
'is_identity': lambda x: x['is_identity'],
'is_medius': lambda x: x['is_medius'],
'is_permanent': lambda x: x['is_permanent'],
'is_community': lambda x: x['is_community'],
'is_personal': lambda x: x['is_personal'],
'is_suspended': lambda x: x['is_suspended'],
'is_bad_content': lambda x: x['is_bad_content'],
'username': lambda x: x['username'],
'name': lambda x: x['display_username'],
}
},
'MySpace': {
'flags': ['myspacecdn.com'],
'regex': r'context = ({.+?});',
'extract_json': True,
'fields': {
'uid': lambda x: x['displayProfileId'],
'username': lambda x: x['filterStreamUrl'].split('/')[2],
}
},
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
}
def decode_ya_str(val):
try:
return val.encode('iso-8859-1').decode('utf-8')
except:
return val
def parse_cookies(cookies_str):
cookies = SimpleCookie()
cookies.load(cookies_str)
logging.debug(cookies)
return {key: morsel.value for key, morsel in cookies.items()}
def parse(url, cookies_str=''):
cookies = parse_cookies(cookies_str)
page = requests.get(url,headers=headers, cookies=cookies, allow_redirects=True)
logging.debug(page.text)
logging.debug(page.status_code)
return page.text, page.status_code
def extract(page):
for scheme_name, scheme_data in schemes.items():
flags = scheme_data['flags']
found = all([flag in page for flag in flags])
if found:
logging.info('%s has been detected' % scheme_name)
if 'message' in scheme_data:
print(scheme_data['message'])
else:
continue
info = re.search(scheme_data['regex'], page)
if info:
if scheme_data.get('extract_json', False):
values = {}
logging.debug(info.group(1))
json_data = json.loads(info.group(1))
loaded_json = json.dumps(json_data, indent=4, sort_keys=True)
logging.debug(loaded_json)
if logging.root.level == logging.DEBUG:
with open('debug_extracted.json', 'w') as f:
f.write(loaded_json)
for name, get_field in scheme_data['fields'].items():
value = get_field(json_data)
values[name] = str(value) if value != None else ''
else:
values = info.groupdict()
return {a: b for a, b in values.items() if b}
else:
print('Could not extract!')
return {}
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Extract accounts\' identifiers from pages.')
parser.add_argument('url', help='url to parse')
parser.add_argument('--cookies', default='', help='cookies to make http requests with auth')
parser.add_argument('--debug', action='store_true', help='log debug information')
parser.add_argument('--file', action='store_true', help='load from file instead of URL')
args = parser.parse_args()
log_level = logging.INFO if not args.debug else logging.DEBUG
logging.basicConfig(level=log_level, format='-'*40 + '\n%(levelname)s: %(message)s')
if not args.file:
url = args.url
page, status = parse(url, args.cookies)
if status != 200:
logging.info('Answer code {}, something went wrong'.format(status))
else:
page = open(args.url).read()
info = extract(page)
if not info:
sys.exit()
logging.info('Result\n' + '-'*40)
for key, value in info.items():
print('%s: %s' % (key, value))