python通过接口执行shell命令

需求:通过网站url方式直接执行服务器的shell命令

 

 实现:

1、安装依赖
pip3 install falsk

2、python脚本

[root@localhost tmp]# more falsh-index.py 
from flask import Flask,render_template  #Flask 、jinja2、pillow
import sqlite3
import subprocess



app = Flask(__name__)
@app.route('/user/<name>')
def name(name):
    print(name)
    a = subprocess.getoutput(name)   #执行shell命令
    print(a)
    return a

# web 服务器
if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=8888)
3、启动脚本
[root@localhost tmp]# python3 falsh-index.py 
 * Serving Flask app 'falsh-index' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on http://100.98.100.186:8888/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 123-927-491

  

  

  

 
posted @ 2022-10-21 13:58  苍茫宇宙  阅读(215)  评论(0编辑  收藏  举报