Advertisement
Neonprimetime

2018-11-29 old python script

Nov 30th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. from urllib.request import urlopen
  2.  
  3. from urllib.request import urlretrieve
  4.  
  5. import re
  6.  
  7. import sys
  8.  
  9. import os
  10.  
  11. filepath = 'urls.txt'
  12.  
  13. with open(filepath) as fp:
  14.  
  15. theurl = fp.readline()
  16.  
  17. while theurl:
  18.  
  19. if(not theurl.startswith('http')):
  20.  
  21. if(":443" in theurl):
  22.  
  23. theurl = 'https://' + theurl.strip()
  24.  
  25. else:
  26.  
  27. theurl = 'http://' + theurl.strip()
  28.  
  29. theurl = theurl.strip()
  30.  
  31. if(theurl.endswith("/") or theurl.endswith("\\")):
  32.  
  33. theurl = theurl[:-1]
  34.  
  35. stopnow = 0
  36.  
  37. while stopnow == 0:
  38.  
  39. try:
  40.  
  41. html = urlopen(theurl, timeout=3)
  42.  
  43. val = html.read()
  44.  
  45. titles = re.findall(r'(?i)<title>(.*?)</title>',str(val))
  46.  
  47. if len(titles) > 0:
  48.  
  49. if titles[0].startswith('Index of'):
  50.  
  51. print("opendir," + theurl + "(" + titles[0] + ")")
  52.  
  53. zipfiles = re.findall(r'(?i)href\=\"[^\"]+\.zip\"\>',str(val))
  54.  
  55. if len(zipfiles) > 0:
  56.  
  57. for zipfile in zipfiles:
  58.  
  59. zipfile = zipfile.replace('\"', '').replace('href=', '').replace('>','').replace("&amp;", "&")
  60.  
  61. if theurl.endswith('/'):
  62.  
  63. phishkit = theurl + zipfile
  64.  
  65. else:
  66.  
  67. phishkit = theurl + "/" + zipfile
  68.  
  69. try:
  70.  
  71. urlretrieve(phishkit, zipfile)
  72.  
  73. print("phishkit," + phishkit)
  74.  
  75. except Exception as e:
  76.  
  77. print("failedphishkit," + phishkit + "(" + str(e) + ")")
  78.  
  79. exefiles = re.findall(r'(?i)href\=\"[^\"]+\.exe\"\>',str(val))
  80.  
  81. if len(exefiles) > 0:
  82.  
  83. for exefile in exefiles:
  84.  
  85. exefile = exefile.replace('\"', '').replace('href=', '').replace('>','').replace("&amp;", "&")
  86.  
  87. if theurl.endswith('/'):
  88.  
  89. malware = theurl + exefile
  90.  
  91. else:
  92.  
  93. malware = theurl + "/" + exefile
  94.  
  95. try:
  96.  
  97. urlretrieve(malware, exefile)
  98.  
  99. print("malware," + malware)
  100.  
  101. except Exception as e:
  102.  
  103. print("failedmalware," + malware + "(" + str(e) + ")")
  104.  
  105. panels = re.findall(r'(?i)href\=\"(panel|webpanel|fre\.php)\"\>',str(val))
  106.  
  107. if len(panels) > 0:
  108.  
  109. for panel in panels:
  110.  
  111. panel = panel.replace('\"', '').replace('href=' ,'').replace('>', '').replace("&amp;", "&")
  112.  
  113. if theurl.endswith('/'):
  114.  
  115. panelurl = theurl + panel
  116.  
  117. else:
  118.  
  119. panelurl = theurl + "/" + panel
  120.  
  121. print("panel," + panelurl)
  122.  
  123. else:
  124.  
  125. print("webpage," + theurl + "(" + titles[0] + ")")
  126.  
  127. theurl = re.sub(r'\/[^\/]*$', '', theurl)
  128.  
  129. if theurl.endswith('http:/') or theurl.endswith('https:/'):
  130.  
  131. stopnow = 1
  132.  
  133. except Exception as e:
  134.  
  135. if "no host given" in str(e):
  136.  
  137. stopnow = 1
  138.  
  139. else:
  140.  
  141. print("failedurl," + theurl + "(" + str(e) + ")")
  142.  
  143. theurl = re.sub(r'\/[^\/]*$', '', theurl)
  144.  
  145. theurl = fp.readline()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement