Advertisement
Mayk0

#; Whatsapp Metadata Extractor [Python]!~

May 13th, 2013
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. #; Whatsapp Metadata Extractor!~
  2.  
  3. ยท WhatsApp Metadata Extractor :
  4. - main_manage.py (main de consola en forma de cliente)
  5. - DB_Extractor.py (extrae los metadatos de la BD)
  6. - metaimg_extractor.py (extrae los metadatos de los .jpg encontrados)
  7.  
  8. ------------------------------------------------------------------
  9.  
  10. main_manage.py :
  11.  
  12. # -*- coding: utf-8 *-*
  13. import DB_Extractor, metaimg_extractor
  14.  
  15. class WhatsApp_Extractor():
  16.  
  17. def __init__(self):
  18. self.__opt()
  19.  
  20. def __opt(self):
  21. #Uncomment the OPTION that you want to use
  22.  
  23. #self.__opt1() #-> DB METADATA EXTRACTOR
  24. self.__opt2() #-> IMG METADATA EXTRACTOR
  25. #self.__opt3() #-> BOTH, OPT1 AND OPT2
  26.  
  27. def __opt1(self):
  28. print "DB METADATA"
  29. print "------------"
  30. DB_Extractor.DB_Extractor()
  31. print "------------"
  32.  
  33. def __opt2(self):
  34. print "IMG META"
  35. print "------------"
  36. metaimg_extractor.IMG_Meta()
  37. print "------------"
  38.  
  39. def __opt3(self):
  40. print "DB METADATA"
  41. print "------------"
  42. DB_Extractor.DB_Extractor()
  43. print "------------"
  44. print "\nIMG META"
  45. print "------------"
  46. metaimg_extractor.IMG_Meta()
  47. print "------------"
  48.  
  49. WhatsApp_Extractor()
  50. ------------------------------------------------------------------
  51.  
  52. DB_Extractor.py :
  53.  
  54. # -*- coding: utf-8 *-*
  55. #Script to extract the metadata from the WhatsApp crypted DB
  56.  
  57. import sqlite3
  58. from Crypto.Cipher import AES
  59.  
  60. class DB_Extractor():
  61.  
  62. def __init__(self):
  63. self._manage_do()
  64.  
  65. def _manage_do(self):
  66. try:
  67. self.__DB_Breaker('msgstore.db.crypt')
  68. self.__DB_conn()
  69. self.__SQL_Consulter()
  70. #Log exporter
  71. except:
  72. print "Error starting the script"
  73.  
  74. def __DB_Breaker(self, DBPath):
  75. self.DBPath = DBPath
  76. #breaking the hash
  77. f = open(self.DBPath, 'rb')
  78. key = "346a23652a46392b4d73257c67317e352e3372482177652c"
  79. #triying to break the hash
  80. try:
  81. key = key.decode('hex')
  82. cipher = AES.new(key, 1)
  83. decoded = cipher.decrypt(f.read())
  84. #Saving into a new db file
  85. try:
  86. decoded_DB = open('metadb.db', 'wb')
  87. decoded_DB.write(decoded)
  88. decoded_DB.close()
  89. print "metadb.db has been created in the same directory"
  90. except:
  91. print "An error has ocurred creating the decoded DB"
  92. except:
  93. print "Error decoding the hash"
  94.  
  95.  
  96. def __DB_conn(self):
  97. #triying to connect with the sqlite database
  98. try:
  99. self.conn = sqlite3.connect('metadb.db')
  100. self.consult = self.conn.cursor()
  101. except:
  102. print "An error has ocurred connecting with the SQLite DB"
  103.  
  104.  
  105. def __SQL_Consulter(self):
  106. #Divided in :
  107. # Messages
  108. # Chat_list
  109.  
  110. def __Messages():
  111. #SQLConsult
  112. try:
  113. self.consult.execute("SELECT key_remote_jid, key_from_me, \
  114. remote_resource, status, datetime(timestamp), data, media_url, media_mime_type, \
  115. media_size, latitude, longitude FROM messages;")
  116.  
  117. except:
  118. print "An error has ocurred doing the SQL Consult"
  119.  
  120. def __Shower():
  121. #Message details
  122. #nota : parsear status, comprobar si yo envio o recivo
  123.  
  124. for data in self.consult:
  125. try:
  126. print "\nMessages Details:"
  127. print "----------------------"
  128.  
  129. if str(data[2]):
  130. if str(data[1]) == '1':
  131. print "From: me"
  132. print "To: %s(group), integrant: %s"%(str(data[0]), str(data[2]))
  133. else:
  134. print "From: %s(group), integrant: %s"%(str(data[0]), str(data[2]))
  135. print "To: me"
  136. else:
  137. if str(data[1]) == '1':
  138. print "From: me"
  139. print "To: " + str(data[0])
  140. else:
  141. print "From: " + str(data[0])
  142. print "To: me"
  143.  
  144. print "Status: " + str(data[3])
  145. print "Timestamp: " + str(data[4])
  146. print "Message: " + str(data[5])
  147. print "Media content: %s, type: %s, size: %s"%(str(data[6]), str(data[7]), str(data[8]))
  148. print "Location(Lat: %s, Long: %s)"%(str(data[9]), str(data[10]))
  149. print "----------------------"
  150.  
  151. except:
  152. continue
  153. print "ERROR showing message details"
  154.  
  155. __Shower()
  156.  
  157.  
  158. def __Chat_list():
  159. #SQLConsult
  160. try:
  161. self.consult.execute("SELECT id, \
  162. key_remote_jid FROM chat_list;")
  163.  
  164. except:
  165. print "An error has ocurred doing the SQL Consult"
  166.  
  167. def __Shower():
  168. #Chat list details
  169. for data in self.consult:
  170. try:
  171. print "\nChat_list"
  172. print "ID: " + str(data[0])
  173. print "Number: " + str(data[1])
  174. print "----------------------"
  175. except:
  176. continue
  177. print "ERROR showing chat list details"
  178.  
  179. __Shower()
  180.  
  181. #Initializing
  182. __Messages()
  183. __Chat_list()
  184. ------------------------------------------------------------------
  185.  
  186. metaimg_extractor.py :
  187.  
  188. # -*- coding: utf-8 *-*
  189. import os, exif
  190.  
  191. class IMG_Meta():
  192.  
  193. def __init__(self):
  194. try:
  195. self.__Media_extractor()
  196. print "------------------------------------------------------\n"
  197. self.__Profile_extractor()
  198. except:
  199. print "An error has ocurred starting the script"
  200. def __Media_extractor(self):
  201. try:
  202. images = os.listdir('Media/WhatsApp Images/')
  203. except:
  204. print "An error has ocurred listing the files into the directory"
  205.  
  206. def __Shower():
  207. for i in images:
  208. print "-------------"
  209. print i
  210. obj = exif.extract_EXIF('Media/WhatsApp Images/%s' % i)
  211. print "-------------"
  212.  
  213. __Shower()
  214.  
  215. def __Profile_extractor(self):
  216. try:
  217. images = os.listdir('Profile Pictures/')
  218. except:
  219. print "An error has ocurred listing the files into the directory"
  220.  
  221. def __Shower():
  222. for i in images:
  223. print "-------------"
  224. print i
  225. obj = exif.extract_EXIF('Profile Pictures/%s' % i)
  226. print "-------------"
  227.  
  228. __Shower()
  229. ------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement