-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmf_nb.py
93 lines (74 loc) · 3.19 KB
/
gmf_nb.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
# GMF [File Downloader] for NAVER Blog
import re
import sys
import json
from http import client
from urllib import request
def print_logo():
print("#------------------------------------------#")
print("# [GMF] Give Me a File!! [File Downloader] #")
print("#------------------------------------------#")
print("# for NAVER Blog\n")
def get_url_source(url):
try:
while url.find("PostView.naver") == -1 and url.find("PostList.naver") == -1:
f = request.urlopen(url)
url_info = f.info()
url_charset = client.HTTPMessage.get_charsets(url_info)[0]
url_source = f.read().decode(url_charset)
# find 'NBlogWlwLayout.nhn'
if url_source.find("NBlogWlwLayout.naver") == -1:
print("\n[-] It is not a NAVER Blog")
sys.exit(0)
# get frame src
p_frame = re.compile(r"\s*.*?<iframe.*?mainFrame.*?(.*)", re.IGNORECASE | re.DOTALL)
p_src_url = re.compile(r"\s*.*?src=[\'\"](.+?)[\'\"]", re.IGNORECASE | re.DOTALL)
src_url = p_src_url.match(p_frame.match(url_source).group(1)).group(1)
url = src_url
if url.find("http://blog.naver.com") == -1:
last_url = "http://blog.naver.com" + url
else:
last_url = url
print(" => Last URL : %s\n" % last_url)
f = request.urlopen(last_url)
url_info = f.info()
url_charset = client.HTTPMessage.get_charsets(url_info)[0]
url_source = f.read().decode(url_charset)
return url_source
except Exception as e:
print("[-] Error : %s" % e)
sys.exit(-1)
def main():
print_logo()
if len(sys.argv) != 2:
print("[*] Usage : gmf_nb.py [NAVER Blog URL]")
else:
url = sys.argv[1]
print("[*] Target URL : %s" % url)
url_source = get_url_source(url)
# find 't.static.blog.naver.net'
if url_source.find("t.static.blog/mylog") == -1:
print("\n[-] It is not a NAVER Blog")
sys.exit(0)
try:
# find 'aPostFiles'
#p_attached_file = re.compile(r"\s*.*aPostFiles\[1\] = \[(.*?)\]", re.IGNORECASE | re.DOTALL)
p_attached_file = re.compile(r"\s*.*aPostFiles\[1\] = JSON.parse\(\'\[(.*?)\]", re.IGNORECASE | re.DOTALL)
result = p_attached_file.match(url_source).group(1)
if result:
# convert to JSON style
data = "[" + result.replace('\\\'', '\"') + "]"
json_data = json.loads(data)
for each_file in json_data:
print("* File : %s, Size : %s Bytes" % (each_file["encodedAttachFileName"], each_file["attachFileSize"]))
print(" Link : %s" % each_file["encodedAttachFileUrl"])
# File Download
request.urlretrieve(each_file["encodedAttachFileUrl"], each_file["encodedAttachFileName"])
print(" => Done!!\n")
else:
print("[-] Attached File not found !!")
except Exception as e:
print("[-] Error : %s" % e)
sys.exit(-1)
if __name__ == "__main__":
sys.exit(main())