-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpage-enum.py
More file actions
50 lines (43 loc) · 1.58 KB
/
page-enum.py
File metadata and controls
50 lines (43 loc) · 1.58 KB
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
#!/usr/bin/env python
import requests
from random import randint
from time import sleep
from bs4 import BeautifulSoup
from PIL import Image
from StringIO import StringIO
import mimetypes
import subprocess
USER_AGENT = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0"
INITIAL_URL = "https://www.my-site.com"
add_header = {
'User-Agent': USER_AGENT,
'DNT': '1',
'Upgrade-Insecure-Requests': '1'
}
print("[I] Sending initial request ...")
initial_req = requests.head(INITIAL_URL, headers=add_header, allow_redirects=True)
redir_url = initial_req.url
print("[I] Obtained redirected URL: %s" % (redir_url))
for i in range(1,5):
sleep(randint(2,5))
curr = "%03d" % (i,)
req = requests.get(redir_url + "keyword" + curr, headers=add_header)
resp_parsed = BeautifulSoup(req.text, 'html.parser')
image_element = resp_parsed.find("meta", property="og:image")
if image_element:
image_url = image_element["content"]
print("[I] %s: Found. Saving image %s ..." % (curr, image_url))
try:
image_req = requests.get(image_url)
content_type = image_req.headers['content-type']
extension = mimetypes.guess_extension(content_type)
image_obj = Image.open(StringIO(image_req.content))
image_obj.save("keyword" + curr + extension)
except:
print("[E] %s: Invalid image URL %s. Saving placeholder file ..." % (curr, image_url))
bashCommand = "touch keyword" + curr + ".error.img"
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
else:
print("[E] %s: Not Found" % (curr))
print("[I] Script completed.")