forked from vaguileradiaz/tinfoleak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tinfoleak.py
executable file
·5674 lines (4707 loc) · 212 KB
/
tinfoleak.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# License:
# This work is licensed under a Creative Commons Attribution Share-Alike v4.0 License.
# https://creativecommons.org/licenses/by-sa/4.0/
"""
Tinfoleak - The most complete open-source tool for Twitter intelligence analysis
:author: Vicente Aguilera Diaz
:version: 2.3
License:
This work is licensed under a Creative Commons Attribution Share-Alike v4.0 License.
https://creativecommons.org/licenses/by-sa/4.0/
"""
# Classes
# Configuration
# User
# Sources
# Social_Networks
# Geolocation
# Search_GeoTweets
# Hashtags
# Mentions
# User_Tweets
# User_Images
# User_Conversations
# Parameters
# Followers
# Friends
# Lists
# Collections
# Favorites
import argparse
import tweepy
import sys
import ConfigParser
import datetime
import errno
import os
import urllib2
from PIL import Image, ExifTags, ImageCms
import exifread
import struct
import time
from datetime import date, timedelta
import pyexiv2
from collections import OrderedDict
from operator import itemgetter
from OpenSSL import SSL
from jinja2 import Template, Environment, FileSystemLoader
from urlparse import urlparse
import re
import csv
import json
import oauth2 as oauth
import operator
import random
from PyQt4 import QtGui, QtCore
import main_window
import users_window
import relations_window
import lists_window
import collections_window
import followers_window
import friends_window
reload(sys)
sys.setdefaultencoding('utf8')
# ==========================================================================
class Configuration():
"""Configuration information"""
# ----------------------------------------------------------------------
def __init__(self):
try:
# Read tinfoleak configuration file ("tinfoleak.conf")
config = ConfigParser.RawConfigParser()
config_path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/tinfoleak.conf'
config.read(config_path)
CONSUMER_KEY = config.get('Twitter OAuth', 'CONSUMER_KEY')
CONSUMER_SECRET = config.get('Twitter OAuth', 'CONSUMER_SECRET')
ACCESS_TOKEN = config.get('Twitter OAuth', 'ACCESS_TOKEN')
ACCESS_TOKEN_SECRET = config.get('Twitter OAuth', 'ACCESS_TOKEN_SECRET')
# User authentication
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# Tweepy (a Python library for accessing the Twitter API)
self.api = tweepy.API(auth)
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
access_token = oauth.Token(key=ACCESS_TOKEN, secret=ACCESS_TOKEN_SECRET)
# Twitter API
self.client = oauth.Client(consumer, access_token)
except Exception, e:
show_error(e)
sys.exit(1)
# ==========================================================================
class User:
"""Information about a Twitter user"""
# ----------------------------------------------------------------------
def __init__(self):
try:
self.screen_name = ""
self.name = ""
self.id = ""
self.created_at = ""
self.followers_count = ""
self.statuses_count = ""
self.location = ""
self.geo_enabled = ""
self.description = ""
self.expanded_description = ""
self.url = ""
self.expanded_url = ""
self.profile_image_url = ""
self.profile_banner_url = ""
self.tweets_average = ""
self.likes_average = ""
self.meta = ""
self.protected = ""
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ----------------------------------------------------------------------
def set_user_information(self, api):
try:
self.screen_name = api.screen_name
self.name = api.name
self.id = api.id
self.created_at = api.created_at
self.followers_count = api.followers_count
self.friends_count = api.friends_count
self.statuses_count = api.statuses_count
self.location = api.location
self.geo_enabled = api.geo_enabled
self.time_zone = api.time_zone
self.favourites_count = str(api.favourites_count)
self.protected = api.protected
td = datetime.datetime.today() - self.created_at
if td.days > 0:
self.tweets_average = round(float(self.statuses_count / (td.days * 1.0)),2)
self.likes_average = round(float(api.favourites_count / (td.days * 1.0)),2)
else:
self.tweets_average = self.statuses_count
self.likes_average = self.favourites_count
self.url = api.url
if len(api.entities) > 1:
if api.entities['url']['urls']:
self.expanded_url = api.entities['url']['urls'][0]['expanded_url']
else:
self.expanded_url = ""
else:
self.expanded_url = ""
try:
self.description = api.description
if api.entities['description']['urls']:
tmp_expanded_description = api.description
url = api.entities['description']['urls'][0]['url']
expanded_url = api.entities['description']['urls'][0]['expanded_url']
self.expanded_description = tmp_expanded_description.replace(url, expanded_url)
else:
self.expanded_description= ""
except:
self.expanded_description= ""
self.profile_image_url = str(api.profile_image_url).replace("_normal","")
try:
if api.profile_banner_url:
self.profile_banner_url = str(api.profile_banner_url).replace("_normal","")
else:
self.profile_banner_url = ""
except:
self.profile_banner_url = ""
self.verified = str(api.verified)
self.listed_count = str(api.listed_count)
self.lang = str(api.lang)
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ==========================================================================
class Sources:
"""Get apps used to publish tweets"""
# ----------------------------------------------------------------------
def __init__(self):
try:
# source = [source1, source2, ... ]
# sources_firstdate = {source1: first_date1, source2: first_date2, ... ]
# sources_lastdate = {source1: last_date1, source2: last_date2, ... ]
# sources_count = {source1: tweets_number1, source2: tweets_number2, ... ]
# sources_lasttweet = {source1: tweet_id1, source2: tweet_id2, ...}
self.sources = []
self.sources_firstdate = {}
self.sources_lastdate = {}
self.sources_count = {}
self.sources_total_count = 0
self.sources_percent = {}
self.sources_firsttweet = {}
self.sources_lasttweet = {}
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ----------------------------------------------------------------------
def set_sources_information(self, tweet):
try:
add = 1
for index, item in enumerate(self.sources):
if tweet.source == item[0]:
add = 0
self.sources_count[tweet.source] += 1
self.sources_total_count += 1
if tweet.created_at < self.sources_firstdate[tweet.source]:
self.sources_firstdate[tweet.source] = tweet.created_at
if tweet.created_at > self.sources_lastdate[tweet.source]:
self.sources_lastdate[tweet.source] = tweet.created_at
self.sources_firsttweet[tweet.source] = tweet.id
if add:
self.sources.append([tweet.source])
self.sources_count[tweet.source] = 1
self.sources_firstdate[tweet.source] = tweet.created_at
self.sources_lastdate[tweet.source] = tweet.created_at
self.sources_total_count += 1
self.sources_lasttweet[tweet.source] = tweet.id
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ----------------------------------------------------------------------
def set_global_information(self):
try:
for s in self.sources:
self.sources_percent[s[0]] = round((self.sources_count[s[0]] * 100.0) / self.sources_total_count, 1)
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ==========================================================================
class Lists:
"""Get info about the lists the authenticated user has been added to or is owner"""
# ----------------------------------------------------------------------
def get_memberships(self, client, listed_count, screen_name):
try:
memberships_file = screen_name + "_memberships.txt"
username_directory = os.path.dirname(os.path.abspath(__file__)) + "/" + screen_name
if not os.path.isdir(username_directory):
os.mkdir(username_directory)
csvFile = open(username_directory + "/" + memberships_file, "wb")
csvWriter = csv.writer(csvFile)
csvWriter.writerow(["", "TINFOLEAK Report"])
csvWriter.writerow(["", "Vicente Aguilera Díaz"])
csvWriter.writerow(["", "@VAguileraDiaz"])
csvWriter.writerow(["", "www.isecauditors.com"])
csvWriter.writerow([""])
csvWriter.writerow(["", ">>> Date:", datetime.datetime.now().strftime('%Y-%m-%d')])
csvWriter.writerow(["", ">>> Time:", datetime.datetime.now().strftime('%H:%M')])
csvWriter.writerow(["", ">>> Analyzed user:", screen_name])
csvWriter.writerow(["", ">>> Information:", "Membership Lists"])
csvWriter.writerow([""])
csvWriter.writerow(["#", "ID", "LIST NAME", "LIST DESCRIPTION", "LIST MEMBER COUNT", "LIST SUBSCRIBER COUNT", "LIST URI", "USER SCREEN NAME", "USER CREATED AT", "USER NAME", "USER DESCRIPTION", "USER FOLLOWERS", "USER FRIENDS"])
cursor = -1
api_path = "https://api.twitter.com/1.1/lists/memberships.json?screen_name=" + screen_name
public_lists = 0
while cursor != 0:
try:
url_with_cursor = api_path + "&cursor=" + str(cursor)
response, data = client.request(url_with_cursor)
if response['status'] != "404":
response_dictionary = json.loads(data)
if "Rate limit exceeded" in str(response_dictionary):
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
else:
for public_list in response_dictionary['lists']:
if public_lists < int(str(ui.tb_lists_number.text())):
public_lists += 1
show_ui_message(str(public_lists) + " public lists analyzed", "INFO", br=0)
cursor = ui.tb_messages.textCursor()
cursor.movePosition(QtGui.QTextCursor.StartOfLine, 0)
cursor.movePosition(QtGui.QTextCursor.EndOfLine, QtGui.QTextCursor.KeepAnchor)
cursor.removeSelectedText()
csvWriter.writerow([public_lists, public_list['id_str'], public_list['name'], public_list['description'], public_list['member_count'], public_list['subscriber_count'], public_list['uri'], public_list['user']['screen_name'], public_list['user']['created_at'], public_list['user']['name'], public_list['user']['description'], public_list['user']['followers_count'], public_list['user']['friends_count']])
csvFile.flush()
else:
cursor = 0
break
if cursor != 0:
cursor = response_dictionary['next_cursor']
else:
cursor = 0
except Exception, e:
rate_limit = show_error(e)
if rate_limit:
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
private_lists = listed_count - public_lists
show_ui_message("The user has been added to " + str(listed_count) + " lists (private: " + str(private_lists) + ", public: " + str(public_lists) + ")", "INFO", br=1)
show_ui_message("Output file: " + username_directory + "/" + memberships_file, "INFO", br=1)
csvFile.close()
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ----------------------------------------------------------------------
def get_ownerships(self, client, screen_name):
try:
ownerships_file = screen_name + "_ownerships.txt"
username_directory = os.path.dirname(os.path.abspath(__file__)) + "/" + screen_name
if not os.path.isdir(username_directory):
os.mkdir(username_directory)
csvFile = open(username_directory + "/" + ownerships_file, "wb")
csvWriter = csv.writer(csvFile)
csvWriter.writerow(["", "TINFOLEAK Report"])
csvWriter.writerow(["", "Vicente Aguilera Díaz"])
csvWriter.writerow(["", "@VAguileraDiaz"])
csvWriter.writerow(["", "www.isecauditors.com"])
csvWriter.writerow([""])
csvWriter.writerow(["", ">>> Date:", datetime.datetime.now().strftime('%Y-%m-%d')])
csvWriter.writerow(["", ">>> Time:", datetime.datetime.now().strftime('%H:%M')])
csvWriter.writerow(["", ">>> Analyzed user:", screen_name])
csvWriter.writerow(["", ">>> Information:", "Ownership Lists"])
csvWriter.writerow([""])
csvWriter.writerow(["#", "ID", "LIST NAME", "LIST DESCRIPTION", "LIST MEMBER COUNT", "LIST SUBSCRIBER COUNT", "LIST URI", "USER SCREEN NAME", "USER CREATED AT", "USER NAME", "USER DESCRIPTION", "USER FOLLOWERS", "USER FRIENDS"])
cursor = -1
api_path = "https://api.twitter.com/1.1/lists/ownerships.json?screen_name=" + screen_name
owner_lists = 0
while cursor != 0:
try:
url_with_cursor = api_path + "&cursor=" + str(cursor)
response, data = client.request(url_with_cursor)
if response['status'] != "404":
response_dictionary = json.loads(data)
if "Rate limit exceeded" in str(response_dictionary):
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
else:
for owner_list in response_dictionary['lists']:
owner_lists += 1
csvWriter.writerow([owner_lists, owner_list['id_str'], owner_list['name'], owner_list['description'], owner_list['member_count'], owner_list['subscriber_count'], owner_list['uri'], owner_list['user']['screen_name'], owner_list['user']['created_at'], owner_list['user']['name'], owner_list['user']['description'], owner_list['user']['followers_count'], owner_list['user']['friends_count']])
csvFile.flush()
cursor = response_dictionary['next_cursor']
else:
cursor = 0
except Exception, e:
rate_limit = show_error(e)
if rate_limit:
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
show_ui_message(str(owner_lists) + " public lists owned by the user", "INFO", br=1)
show_ui_message("Output file: " + username_directory + "/" + ownerships_file, "INFO", br=1)
csvFile.close()
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ----------------------------------------------------------------------
def get_lists(self, client, screen_name):
try:
lists_file = screen_name + "_lists.txt"
username_directory = os.path.dirname(os.path.abspath(__file__)) + "/" + screen_name
if not os.path.isdir(username_directory):
os.mkdir(username_directory)
csvFile = open(username_directory + "/" + lists_file, "wb")
csvWriter = csv.writer(csvFile)
csvWriter.writerow(["", "TINFOLEAK Report"])
csvWriter.writerow(["", "Vicente Aguilera Díaz"])
csvWriter.writerow(["", "@VAguileraDiaz"])
csvWriter.writerow(["", "www.isecauditors.com"])
csvWriter.writerow([""])
csvWriter.writerow(["", ">>> Date:", datetime.datetime.now().strftime('%Y-%m-%d')])
csvWriter.writerow(["", ">>> Time:", datetime.datetime.now().strftime('%H:%M')])
csvWriter.writerow(["", ">>> Analyzed user:", screen_name])
csvWriter.writerow(["", ">>> Information:", "Subscribed to Lists"])
csvWriter.writerow([""])
csvWriter.writerow(["#", "ID", "LIST NAME", "LIST DESCRIPTION", "LIST MEMBER COUNT", "LIST SUBSCRIBER COUNT", "LIST URI", "USER SCREEN NAME", "USER CREATED AT", "USER NAME", "USER DESCRIPTION", "USER FOLLOWERS", "USER FRIENDS"])
cursor = -1
api_path = "https://api.twitter.com/1.1/lists/list.json?screen_name=" + screen_name
user_lists = 0
url_with_cursor = api_path + "&cursor=" + str(cursor)
response, data = client.request(url_with_cursor)
if response['status'] != "404":
rate_limit = 0
while not rate_limit:
response_dictionary = json.loads(data)
if "Rate limit exceeded" in str(response_dictionary):
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
else:
rate_limit = 1
for user_list in response_dictionary:
try:
user_lists += 1
csvWriter.writerow([user_lists, user_list['id_str'], user_list['name'], user_list['description'], user_list['member_count'], user_list['subscriber_count'], user_list['uri'], user_list['user']['screen_name'], user_list['user']['created_at'], user_list['user']['name'], user_list['user']['description'], user_list['user']['followers_count'], user_list['user']['friends_count']])
csvFile.flush()
except Exception, e:
rate_limit = show_error(e)
if rate_limit:
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
show_ui_message("User subscribed to " + str(user_lists) + " lists", "INFO", br=1)
show_ui_message("Output file: " + username_directory + "/" + lists_file, "INFO", br=1)
csvFile.close()
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ==========================================================================
class Collections:
"""Get info about the colletions created by the specified user"""
# ----------------------------------------------------------------------
def get_collections(self, client, screen_name):
try:
collections_file = screen_name + "_collections.txt"
username_directory = os.path.dirname(os.path.abspath(__file__)) + "/" + screen_name
if not os.path.isdir(username_directory):
os.mkdir(username_directory)
csvFile = open(username_directory + "/" + collections_file, "wb")
csvWriter = csv.writer(csvFile)
csvWriter.writerow(["", "TINFOLEAK Report"])
csvWriter.writerow(["", "Vicente Aguilera Díaz"])
csvWriter.writerow(["", "@VAguileraDiaz"])
csvWriter.writerow(["", "www.isecauditors.com"])
csvWriter.writerow([""])
csvWriter.writerow(["", ">>> Date:", datetime.datetime.now().strftime('%Y-%m-%d')])
csvWriter.writerow(["", ">>> Time:", datetime.datetime.now().strftime('%H:%M')])
csvWriter.writerow(["", ">>> Analyzed user:", screen_name])
csvWriter.writerow(["", ">>> Information:", "Collections"])
csvWriter.writerow([""])
csvWriter.writerow(["#", "ID", "COLLECTION NAME", "COLLECTION DESCRIPTION", "COLLECTION URL"])
cursor = -1
api_path = "https://api.twitter.com/1.1/collections/list.json?screen_name=" + screen_name
collections = 0
while cursor != 0:
try:
url_with_cursor = api_path + "&cursor=" + str(cursor)
response, data = client.request(url_with_cursor)
response_dictionary = json.loads(data)
if "Rate limit exceeded" in str(response_dictionary):
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
else:
if response_dictionary['objects']:
for timeline in response_dictionary['objects']['timelines']:
collections += 1
name = response_dictionary['objects']['timelines'][str(timeline)]['name']
try:
description = response_dictionary['objects']['timelines'][str(timeline)]['description']
except Exception, e:
description = ""
url = response_dictionary['objects']['timelines'][str(timeline)]['collection_url']
csvWriter.writerow([collections, timeline, name, description, url])
csvFile.flush()
if len(response_dictionary['objects']) > 0:
cursor = response_dictionary['response']['cursors']['next_cursor']
else:
cursor = 0
except Exception, e:
rate_limit = show_error(e)
if rate_limit:
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
show_ui_message(str(collections) + " public collections owned by the user", "INFO", br=1)
show_ui_message("Output file: " + username_directory + "/" + collections_file, "INFO", br=1)
csvFile.close()
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ==========================================================================
class Activity:
"""Get statistics about the timeline activity"""
# ----------------------------------------------------------------------
def __init__(self):
try:
self.activity_count = 0
self.activity_tweet = 0
self.activity_tweet_retweets = 0
self.activity_tweet_likes = 0
self.activity_retweet = 0
self.activity_reply = 0
self.activity_url = 0
self.activity_expanded_url = []
self.activity_media = 0
self.activity_tweet_percent = 0
self.activity_retweet_percent = 0
self.activity_reply_percent = 0
self.activity_url_percent = 0
self.activity_media_percent = 0
self.activity_hours = {}
self.activity_hours["00"] = 0
self.activity_hours["01"] = 0
self.activity_hours["02"] = 0
self.activity_hours["03"] = 0
self.activity_hours["04"] = 0
self.activity_hours["05"] = 0
self.activity_hours["06"] = 0
self.activity_hours["07"] = 0
self.activity_hours["08"] = 0
self.activity_hours["09"] = 0
self.activity_hours["10"] = 0
self.activity_hours["11"] = 0
self.activity_hours["12"] = 0
self.activity_hours["13"] = 0
self.activity_hours["14"] = 0
self.activity_hours["15"] = 0
self.activity_hours["16"] = 0
self.activity_hours["17"] = 0
self.activity_hours["18"] = 0
self.activity_hours["19"] = 0
self.activity_hours["20"] = 0
self.activity_hours["21"] = 0
self.activity_hours["22"] = 0
self.activity_hours["23"] = 0
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ----------------------------------------------------------------------
def set_activity(self, tweet):
try:
self.activity_count += 1
if hasattr(tweet, 'retweeted_status'):
self.activity_retweet += 1
else:
self.activity_tweet += 1
self.activity_tweet_retweets += tweet.retweet_count
self.activity_tweet_likes += tweet.favorite_count
if hasattr(tweet, 'in_reply_to_screen_name'):
self.activity_reply += 1
if tweet.entities['urls']:
medias = tweet.entities['urls']
for m in medias:
try:
url = m['expanded_url']
if url:
expanded_url = urllib2.urlopen(url)
if "https://twitter.com/i/web/status/" not in expanded_url.url:
self.activity_expanded_url.append(expanded_url.url)
if "instagram" in url:
self.activity_media += 1
else:
self.activity_url += 1
except Exception as e:
pass
if tweet.entities.has_key('media') :
self.activity_media += 1
self.activity_hours[str(tweet.created_at.time().strftime('%H'))] += 1
except Exception as e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ----------------------------------------------------------------------
def set_global_information(self):
try:
self.activity_tweet_percent = round((self.activity_tweet * 100.0) / self.activity_count, 1)
self.activity_retweet_percent = round((self.activity_retweet * 100.0) / self.activity_count, 1)
self.activity_url_percent = round((self.activity_url * 100.0) / self.activity_count, 1)
self.activity_media_percent = round((self.activity_media * 100.0) / self.activity_count, 1)
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ==========================================================================
class Followers:
"""Get followers for the specified user"""
users = []
# ----------------------------------------------------------------------
def get_followers(self, username, api, limit):
try:
followers_file = username + "_followers.txt"
username_directory = os.path.dirname(os.path.abspath(__file__)) + "/" + username
if not os.path.isdir(username_directory):
os.mkdir(username_directory)
pics_directory = username_directory + "/followers-" + datetime.datetime.now().strftime('%Y%m%d')
if not os.path.isdir(pics_directory):
os.mkdir(pics_directory)
csvFile = open(pics_directory + "/" + followers_file, "wb")
csvWriter = csv.writer(csvFile)
csvWriter.writerow(["", "TINFOLEAK Report"])
csvWriter.writerow(["", "Vicente Aguilera Díaz"])
csvWriter.writerow(["", "@VAguileraDiaz"])
csvWriter.writerow(["", "www.isecauditors.com"])
csvWriter.writerow([""])
csvWriter.writerow(["", ">>> Date:", datetime.datetime.now().strftime('%Y-%m-%d')])
csvWriter.writerow(["", ">>> Time:", datetime.datetime.now().strftime('%H:%M')])
csvWriter.writerow(["", ">>> Analyzed user:", username])
csvWriter.writerow(["", ">>> Information:", "Followers"])
csvWriter.writerow([""])
csvWriter.writerow(["#", "ID", "USERNAME", "SCREEN NAME", "DESCRIPTION", "PROFILE IMAGE URL", "PROFILE BANNER URL", "CREATED AT", "LOCATION", "TIME_ZONE", "GEO ENABLED", "FOLLOWERS COUNT", "FRIENDS COUNT", "STATUSES COUNT", "LISTED COUNT", "FAVOURITES COUNT", "USER VERIFIED", "USER LANG"])
analyzed_user = 0
for userid in tweepy.Cursor(api.followers_ids, screen_name=username).items():
try:
if int(analyzed_user) < int(limit):
user = api.get_user(userid)
self.users.append(user)
analyzed_user += 1
csvWriter.writerow([analyzed_user, user.id, user.name.encode('utf-8'), user.screen_name, user.description.encode('utf-8'), user.profile_image_url, user.profile_background_image_url, user.created_at, user.location, user.time_zone, user.geo_enabled, user.followers_count, user.friends_count, user.statuses_count, user.listed_count, user.favourites_count, user.verified, user.lang])
csvFile.flush()
show_ui_message(str(analyzed_user) +"/" + str(limit) + " users analyzed", "INFO", br=0)
cursor = ui.tb_messages.textCursor()
cursor.movePosition(QtGui.QTextCursor.StartOfLine, 0)
cursor.movePosition(QtGui.QTextCursor.EndOfLine, QtGui.QTextCursor.KeepAnchor)
cursor.removeSelectedText()
try:
img = urllib2.urlopen(user.profile_image_url.replace("_normal.", ".")).read()
filename = str(user.id) + ".jpg"
image = pics_directory + "/" +filename
if not os.path.exists(image):
f = open(image, 'wb')
f.write(img)
f.close()
except Exception, e:
pass
else:
break
except Exception, e:
rate_limit = show_error(e)
if rate_limit:
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
show_ui_message("Output file: " + pics_directory + "/" + followers_file, "INFO", br=1)
csvFile.close()
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ==========================================================================
class Friends:
"""Get friends for the specified user"""
# ----------------------------------------------------------------------
def get_friends(self, username, api, limit):
try:
friends_file = username + "_friends.txt"
username_directory = os.path.dirname(os.path.abspath(__file__)) + "/" + username
if not os.path.isdir(username_directory):
os.mkdir(username_directory)
pics_directory = username_directory + "/friends-" + datetime.datetime.now().strftime('%Y%m%d')
if not os.path.isdir(pics_directory):
os.mkdir(pics_directory)
csvFile = open(pics_directory + "/" + friends_file, "wb")
csvWriter = csv.writer(csvFile)
csvWriter.writerow(["", "TINFOLEAK Report"])
csvWriter.writerow(["", "Vicente Aguilera Díaz"])
csvWriter.writerow(["", "@VAguileraDiaz"])
csvWriter.writerow(["", "www.isecauditors.com"])
csvWriter.writerow([""])
csvWriter.writerow(["", ">>> Date:", datetime.datetime.now().strftime('%Y-%m-%d')])
csvWriter.writerow(["", ">>> Time:", datetime.datetime.now().strftime('%H:%M')])
csvWriter.writerow(["", ">>> Analyzed user:", username])
csvWriter.writerow(["", ">>> Information:", "Friends"])
csvWriter.writerow([""])
csvWriter.writerow(["#", "ID", "USERNAME", "SCREEN NAME", "DESCRIPTION", "PROFILE IMAGE URL", "PROFILE BANNER URL", "CREATED AT", "LOCATION", "TIME_ZONE", "GEO ENABLED", "FOLLOWERS COUNT", "FRIENDS COUNT", "STATUSES COUNT", "LISTED COUNT", "FAVOURITES COUNT", "USER VERIFIED", "USER LANG"])
analyzed_user = 0
for userid in tweepy.Cursor(api.friends_ids, screen_name=username).items():
try:
if int(analyzed_user) < int(limit):
user = api.get_user(userid)
analyzed_user += 1
csvWriter.writerow([analyzed_user, user.id, user.name.encode('utf-8'), user.screen_name, user.description.encode('utf-8'), user.profile_image_url, user.profile_background_image_url, user.created_at, user.location, user.time_zone, user.geo_enabled, user.followers_count, user.friends_count, user.statuses_count, user.listed_count, user.favourites_count, user.verified, user.lang])
csvFile.flush()
try:
img = urllib2.urlopen(user.profile_image_url.replace("_normal.", ".")).read()
filename = str(user.id) + ".jpg"
image = pics_directory + "/" +filename
if not os.path.exists(image):
f = open(image, 'wb')
f.write(img)
f.close()
except Exception, e:
pass
else:
break
except Exception, e:
rate_limit = show_error(e)
if rate_limit:
show_ui_message("Waiting...", "INFO", br=1)
time.sleep(60)
continue
show_ui_message("Output file: " + pics_directory + "/" + friends_file, "INFO", br=1)
csvFile.close()
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ==========================================================================
class Social_Networks:
"""Identify social networks identities for a user"""
#: social networks used by a Twitter user:
#: {'twitteruser': [[Instagram_user, Instagram_profile],
#: [Foursquare_user, Foursquare_profile],
#: [Facebook_user, Facebook_profile],
#: [LinkedIn_user, LinkedIn_profile],
#: [Runkeeper_user, Runkeeper_profile],
#: [Flickr_user, Flickr_profile],
#: [Vine_user, Vine_profile],
#: [Periscope_user, Periscope_profile],
#: [Kindle_user, Kindle_profile],
#: [Youtube_user, Youtube_profile],
#: [Google+_user, Google+_profile],
#: [Frontback_user, Frontback_profile]
#: ]}
# ----------------------------------------------------------------------
def __init__(self):
try:
self.user_sn = {}
self.see_again = 1
except Exception, e:
show_ui_message(str(e) + "<br>", "ERROR", 1)
# ----------------------------------------------------------------------
def get_socialnetwork_userinfo(self, status, socialnetwork):
try:
#: username used in the social network
username = ""
#: link to the user profile in the social network
link = ""
#: user picture in the social network
pic = "?"
#: real user name
name = ""
#: additional info
info = ""
#: html page
html = ""
medias = status.entities['urls']
for m in medias:
url = m['expanded_url']
try:
response = urllib2.urlopen(url)
html = response.read()
except Exception as e:
pass
if socialnetwork.lower().find("instagram") >= 0:
#: Instagram
#: ----------------------------------------------
urls = re.search('"viewer_has_saved_to_collection":(.*)"profile_pic_url":"(.*)","username":"(.*)","blocked_by_viewer"', html)
if urls:
username = urls.group(3)
pic = urls.group(2)
urls = re.search('<meta property="og:title" content="(.*) on Instagram:(.*)', html)
if urls:
name = urls.group(1)
if username:
link = "https://instagram.com/" + username
# Stop after the first result
break
else:
if socialnetwork.lower().find("foursquare") >= 0:
#: Foursquare
#: ----------------------------------------------
urls = re.search('https://www.swarmapp.com/(.*)/checkin/', html)
if urls:
username = urls.group(1)
link = "https://foursquare.com/" + username
else:
urls = re.search('canonicalPath":"..(\w*)","canonicalUrl"', html)
if urls:
username = urls.group(1)
link = "https://foursquare.com/" + username
tmp = re.search('<div class="venue push"><h1><strong>(.*)</strong> at ', html)
if tmp:
name = tmp.group(1).decode('utf-8')
tmp = re.search('<div id="mapContainer"><img src="(.*)" alt="(.*)" class="avatar mainUser"width="86"', html)
if tmp:
pic = tmp.group(1).decode('unicode-escape')
if username:
# Stop after the first result
break
else:
if socialnetwork.lower().find("facebook") >= 0:
#: Facebook
#: ----------------------------------------------
if status.source.lower().find("facebook") >= 0:
# Identify Faceboook acount from Facebook page
if not html:
# Identify Faceboook acount from 404 not found facebook page
try:
response = urllib2.urlopen(url)
html = response.read()
except Exception as e:
pass
urls = re.search(';id=(.*)">', html)
if urls:
try:
response = urllib2.urlopen("https://facebook.com/profile.php?id=" + urls.group(1))
html = response.read()
except Exception as e:
pass
urls = re.search('0; URL=/(.*)\/\?_fb_noscript=1', html)
if urls:
username = urls.group(1)
link = "https://facebook.com/" + username
try:
response = urllib2.urlopen(link)
html = response.read()
except Exception as e:
pass
tmp = re.search('<img class="profilePic img" alt="(.*)" src="(.*)" /></a></div></div><div class="_58gk">', html)
if tmp:
pic = tmp.group(2).replace("&", "&")
tmp = re.search('<span itemprop="name">(.*)</span><span class="_5rqt">', html)
if tmp:
info = tmp.group(1).decode('utf-8')
else:
urls = re.search('autocomplete="off" name="next" value="https://www.facebook.com/(.*)/posts/[0-9]*"', html)
if urls:
if str(urls.group(1)).find("profile.php") < 0:
username = urls.group(1)
link = "https://facebook.com/" + username
else:
try:
response = urllib2.urlopen("http://longurl.org/expand?url="+url)
html2 = response.read()
urls = re.search('<a href="https://www.facebook.com/(.*)/posts/[0-9]*">https://', html2)
except Exception as e:
pass
if urls:
username = urls.group(1)
link = "https://facebook.com/" + username
try:
response = urllib2.urlopen(link)
html = response.read()
except Exception as e:
pass
tmp = re.search('<img class="profilePic img" alt="(.*)" src="(.*)" /></a></div></div><div class="_58gk">', html)
if tmp:
pic = tmp.group(2).replace("&", "&")
tmp = re.search('<span itemprop="name">(.*)</span><span class="_5rqt">', html)
if tmp:
info = tmp.group(1).decode('utf-8')
else:
if self.see_again == 0:
username = ""
if (self.user_sn[status.user.screen_name][1][0] and self.user_sn[status.user.screen_name][1][0].find("Unknown") < 0 and self.see_again > 0):
# Identify Faceboook acount from Fourquare page
self.see_again = 0
username = ""
try:
response = urllib2.urlopen("https://foursquare.com/"+self.user_sn[status.user.screen_name][1][0])
html = response.read()
except Exception as e:
pass
urls = re.search('<ul class="social"><li><a href="http://www.facebook.com/profile.php\?id=(.*)" rel="nofollow" target="_blank" class="fbLink"', html)
if urls:
username = urls.group(1)
link = "http://www.facebook.com/profile.php?id=" + username
try:
response = urllib2.urlopen(link)
html = response.read()
except Exception as e:
pass
tmp = re.search('<img class="profilePic img" alt="(.*)" src="(.*)" /></div></div><meta itemprop="image"', html)
if tmp:
pic = tmp.group(2).replace("&", "&")
tmp = re.search('autocomplete="off" name="next" value="https://www.facebook.com/(.*)" /></form>', html)
if tmp:
username = tmp.group(1)
link = "https://facebook.com/" + username
tmp = re.search('<span id="fb-timeline-cover-name">(.*)</span></a><span class="_1xim">', html)
if tmp:
name = tmp.group(1)
try:
response = urllib2.urlopen(link)
html = response.read()
except Exception as e: