forked from hydrogen18/kojoney
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coret_std_unix.py
93 lines (63 loc) · 2.18 KB
/
coret_std_unix.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
import sys
import urllib
import random
from coret_config import DOWNLOAD_REAL_FILE, DOWNLOAD_REAL_DIR
def getGoodFilename(filename):
buf = ""
for c in filename:
if c.isalnum():
buf += c
else:
buf += "_"
return(buf + str(random.randint(0, 999)))
def downloadFileTo(url, directory):
try:
if url.find("://") == -1:
url = "http://" + url
# Fix for a security bug found by Nicob <nicob[at]nicob[dot]net>
if url.find("ftp://") == 0 or url.find("http://") == 0 or url.find("https://") == 0:
data = urllib.urlopen(url)
data = data.read()
filename = getGoodFilename(url)
f = open(directory + filename, "wb")
f.write(data)
f.close()
print "Saved the file",directory + filename,"requested by the attacker."
except:
print "Error downloading file",url,"request by attacker.",sys.exc_info()[1]
def wget(params):
i = 0
data = ""
if len(params) == 1:
data = "wget: You need to specify the URL\r\n"
data +="\r\n"
data +="Usage: wget [OPTIONS] [URL]\r\n"
data +="\r\n"
data +="Use wget --help to read the complete option list.\r\n"
return data
for param in params:
if i == 0:
i += 1
continue
if not param.startswith("-"):
if DOWNLOAD_REAL_FILE:
downloadFileTo(param, DOWNLOAD_REAL_DIR)
data = "Downloading URL ", str(param)
return "wget: Unknown error"
return data
def curl(params):
i = 0
data = ""
if len(params) == 1:
data = "curl: try 'curl --help' or 'curl --manual' for more information\r\n"
return data
for param in params:
if i == 0:
i += 1
continue
if not param.startswith("-"):
if DOWNLOAD_REAL_FILE:
downloadFileTo(param, DOWNLOAD_REAL_DIR)
data = "Downloading URL ", str(param)
return "curl: Unknown error"
return data