this is based on calsyslab project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
9.4 KiB

  1. __author__ = 'DarkWeb'
  2. # Here, we are importing the auxiliary functions to clean or convert data
  3. from MarketPlaces.Utilities.utilities import *
  4. # Here, we are importing BeautifulSoup to search through the HTML tree
  5. from bs4 import BeautifulSoup
  6. import re
  7. # parses description pages, so takes html pages of description pages using soup object, and parses it for info it needs
  8. # stores info it needs in different lists, these lists are returned after being organized
  9. # @param: soup object looking at html page of description page
  10. # return: 'row' that contains a variety of lists that each hold info on the description page
  11. def zeroday_description_parser(soup):
  12. # Fields to be parsed
  13. vendor = "-1" # 0 *Vendor_Name y
  14. success = "-1" # 1 Vendor_Successful_Transactions n
  15. rating_vendor = "-1" # 2 Vendor_Rating y
  16. name = "-1" # 3 *Product_Name y
  17. describe = "-1" # 4 Product_Description y
  18. CVE = "-1" # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures)
  19. MS = "-1" # 6 Product_MS_Classification (Microsoft Security)
  20. category = "-1" # 7 Product_Category y
  21. views = "-1" # 8 Product_Number_Of_Views y
  22. reviews = "-1" # 9 Product_Number_Of_Reviews n
  23. rating_item = "-1" # 10 Product_Rating n
  24. addDate = "-1" # 11 Product_AddedDate y
  25. BTC = "-1" # 12 Product_BTC_SellingPrice y
  26. USD = "-1" # 13 Product_USD_SellingPrice y
  27. EURO = "-1" # 14 Product_EURO_SellingPrice n
  28. sold = "-1" # 15 Product_QuantitySold n
  29. left = "-1" # 16 Product_QuantityLeft n
  30. shipFrom = "-1" # 17 Product_ShippedFrom n
  31. shipTo = "-1" # 18 Product_ShippedTo n
  32. image = "-1" # 19 Product_Image n
  33. vendor_image = "-1" # 20 Vendor_Image n
  34. # Finding Vendor
  35. div_vendor = soup.find('div', {'class': "exploit_view_table_user_content"})
  36. vendor = div_vendor.find('a').text.strip()
  37. # Finding Vendor Rating (bug in their system shows standard rating)
  38. div_rating = div_vendor.find_next_sibling('div')
  39. rating_vendor = div_rating.find_all('div', {'class': "td"})[1].text
  40. # Finding Product Name
  41. div_name = soup.find('div', {'class': "exploit_title"})
  42. name = div_name.find('h1', {'class': "YellowText"}).text
  43. name = name.strip()
  44. # Finding Product description
  45. describe = soup.find('meta', attrs={'name': "description"}).get("content")
  46. # Searching for CVE and MS categories
  47. cve = soup.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  48. if cve:
  49. CVE = " "
  50. for idx in cve:
  51. CVE += (idx)
  52. CVE += " "
  53. CVE = CVE.replace(',', ' ')
  54. CVE = CVE.replace('\n', '')
  55. ms = soup.findAll(text=re.compile('MS\d{2}-\d{3}'))
  56. if ms:
  57. MS = " "
  58. for im in ms:
  59. MS += (im)
  60. MS += " "
  61. MS = MS.replace(',', ' ')
  62. MS = MS.replace('\n', '')
  63. # Finding category
  64. div_category = soup.find('div', {'class': "td"}, text="Category").find_next_sibling('div', {'class': "td"})
  65. category = div_category.text.strip()
  66. # Finding views
  67. div_views = soup.find('div', {'class': "td"}, text="Views").find_next_sibling('div', {'class': "td"})
  68. views = div_views.text.replace(' ', '').strip()
  69. # Finding added date
  70. div_date = soup.find('div', {'class': 'td'}, text='Date add').find_next_sibling('div', {'class': "td"})
  71. addDate = div_date.text.strip()
  72. # Finding BTC and USD/GOLD
  73. div_price = soup.find('div', {'class': "td"}, text="Price")
  74. price = div_price.find_next_sibling('div', {'class': "td"}).text.strip()
  75. if "free" in price.lower():
  76. BTC = 0
  77. USD = 0
  78. else:
  79. price = ''.join(price.split())
  80. index = price.index('BTC')
  81. BTC = price[:index]
  82. USD = price[index + 3:].replace('USD', '')
  83. # Populating the final variable (this should be a list with all fields scraped)
  84. row = (vendor, rating_vendor, success, name, describe, CVE, MS, category, views, reviews, rating_item, addDate,
  85. BTC, USD, EURO, sold, left, shipFrom, shipTo, image, vendor_image)
  86. # Sending the results
  87. return row
  88. # parses listing pages, so takes html pages of listing pages using soup object, and parses it for info it needs
  89. # stores info it needs in different lists, these lists are returned after being organized
  90. # @param: soup object looking at html page of listing page
  91. # return: 'row' that contains a variety of lists that each hold info on the listing page
  92. def zeroday_listing_parser(soup):
  93. # Fields to be parsed
  94. nm = 0 # *Total_Products (Should be Integer)
  95. mktName = "0Days" # 0 *Marketplace_Name y
  96. vendor = [] # 1 *Vendor y
  97. rating_vendor = [] # 2 Vendor_Rating y
  98. success = [] # 3 Vendor_Successful_Transactions n
  99. name = [] # 4 *Product_Name y
  100. CVE = [] # 5 Product_CVE_Classification (Common Vulnerabilities and Exposures) dont worry about this
  101. MS = [] # 6 Product_MS_Classification (Microsoft Security) dont worry about this
  102. category = [] # 7 Product_Category y
  103. describe = [] # 8 Product_Description n
  104. views = [] # 9 Product_Number_Of_Views y
  105. reviews = [] # 10 Product_Number_Of_Reviews n
  106. rating_item = [] # 11 Product_Rating n
  107. addDate = [] # 12 Product_AddDate y
  108. BTC = [] # 13 Product_BTC_SellingPrice y
  109. USD = [] # 14 Product_USD_SellingPrice y
  110. EURO = [] # 15 Product_EURO_SellingPrice n
  111. sold = [] # 16 Product_QuantitySold n
  112. qLeft = [] # 17 Product_QuantityLeft n
  113. shipFrom = [] # 18 Product_ShippedFrom n
  114. shipTo = [] # 19 Product_ShippedTo n
  115. image = [] # 20 Product_Image n
  116. image_vendor = [] # 21 Vendor_Image n
  117. href = [] # 22 Product_Links y
  118. listings = soup.findAll('div', {"class": "ExploitTableContent"})
  119. # Populating the Number of Products
  120. nm = len(listings)
  121. for listing in listings:
  122. # Finding the vendor name
  123. vendor_name = listing.find('a', href=lambda href: href and '/author/' in href).text.strip()
  124. vendor.append(vendor_name)
  125. # Finding the vendor rating
  126. vendor_level_div = listing.find('div', {'class': "tips_bl"})
  127. vendor_level = vendor_level_div.find('div', {'class': "tips_value_big"}).text
  128. rating_vendor.append(vendor_level)
  129. # Finding the product name
  130. product_name = listing.find('h3').text.strip()
  131. name.append(product_name)
  132. # Searching for CVE and MS categories
  133. cve = listing.findAll(text=re.compile('CVE-\d{4}-\d{4}'))
  134. if not cve:
  135. cveValue = "-1"
  136. else:
  137. cee = " "
  138. for idx in cve:
  139. cee += (idx)
  140. cee += " "
  141. cee = cee.replace(',', ' ')
  142. cee = cee.replace('\n', '')
  143. cveValue = cee
  144. CVE.append(cveValue)
  145. ms = listing.findAll(text=re.compile('MS\d{2}-\d{3}'))
  146. if not ms:
  147. MSValue = "-1"
  148. else:
  149. me = " "
  150. for im in ms:
  151. me += (im)
  152. me += " "
  153. me = me.replace(',', ' ')
  154. me = me.replace('\n', '')
  155. MSValue = me
  156. MS.append(MSValue)
  157. # Finding the category
  158. category_text = listing.find_all('div', {'class': "td"})[2].text.strip()
  159. category.append(category_text)
  160. # Finding the hrefs
  161. description_link = listing.find('h3').find('a')['href']
  162. href.append(description_link)
  163. # Finding the views
  164. views_text = listing.find_all('div', {'class': "td"})[3].text.strip()
  165. views.append(views_text)
  166. # Finding the date added
  167. date = listing.find('div', {'class': "td"}).find('a').text.strip()
  168. addDate.append(date)
  169. # Finding the BTC and USD/GOLD
  170. btc_listing = listing.find('div', {"class": 'tips_price_btc'})
  171. if btc_listing:
  172. btc_price = btc_listing.text.strip().replace('Open this exploit for ', '').replace(' BTC', '')
  173. crossed = btc_listing.find('span', {'class': "crossed"})
  174. if crossed:
  175. btc_price = crossed.next_sibling.strip().replace(' BTC', '')
  176. else:
  177. btc_price = 0
  178. BTC.append(btc_price)
  179. usd_listing = listing.find('div', {"class": 'tips_price_1'})
  180. if usd_listing:
  181. usd_price = usd_listing.text.strip().replace('Open this exploit for ', '').replace(' GOLD', '')
  182. crossed = usd_listing.find('span', {'class': "crossed"})
  183. if crossed:
  184. usd_price = crossed.next_sibling.strip().replace(' GOLD', '')
  185. usd_price = ''.join(usd_price.replace(' ', ''))
  186. else:
  187. usd_price = 0
  188. USD.append(usd_price)
  189. # Populate the final variable (this should be a list with all fields scraped)
  190. return organizeProducts(mktName, nm, vendor, rating_vendor, success, name, CVE, MS, category, describe, views,
  191. reviews, rating_item, addDate, BTC, USD, EURO, sold, qLeft, shipFrom, shipTo, href, image,
  192. image_vendor)
  193. # called by the crawler to get description links on a listing page
  194. # @param: beautifulsoup object that is using the correct html page (listing page)
  195. # return: list of description links from a listing page
  196. def zeroday_links_parser(soup):
  197. # Returning all links that should be visited by the Crawler
  198. href = []
  199. listings = soup.findAll('div', {"class": "ExploitTableContent"})
  200. for listing in listings:
  201. # Adding the url to the list of urls
  202. description_link = listing.find('h3').find('a')['href']
  203. href.append(description_link)
  204. return href