Web页面执行shell命令
本文以apache为web服务器为例
- 安装apache服务
yum -y install httpd - 启动apache
systemctl restart httpd - 创建shell脚本
cd /var/www/cgi-bin/
vim shell#!/bin/sh
alias urldecode='sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b"'
echo -e "Content-type: text/plain\n"
decoded_str=`echo $QUERY_STRING | urldecode`
echo -e "`$decoded_str` \n"shell
测试:在浏览器中输入http://127.0.0.1/cgi-bin/shell?pwd,即可列出目录
- 提供web接口
cd /var/www/html
vim index.html<html>
<head>
<script>
function httpGet(url)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url, false); // false: wait respond
xmlHttp.send(null);
return xmlHttp.responseText;
}
function f()
{
var url = "http://127.0.0.1/cgi-bin/shell?"+ document.getElementById('in').value;
document.getElementById('out').innerHTML = httpGet(url);
}
</script>
</head>
<body>
<span>command: </span>
<input id='in'></input>
<button onclick='f()'>send</button>
<br/>
<pre id='out'></pre>
</body>
</html>index.html
注意修改代码中ip,更改为服务器ip或域名
- 效果图如图所示

- cgi-bin目录执行shell脚本格式
#!/bin/sh
printf "Content-Type: text/plain\n\n"
your_commands_here - 安全性优化
限制用户访问cgi-bin目录,修改/etc/httpd/conf/httpd.conf
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
Deny From all
Allow From 127.0.0.1 your-ip-address
</Directory>
配置http页面账号密码访问,也可实现安全性 - 弊端
无法执行复杂的脚本命令,如带有" |等特殊符号的命令无法执行,如yum、top命令执行结果不完整、仅适用于简单带输出脚本命令,脚本运行账号为apache
Web页面执行shell命令的更多相关文章
- 通过web php 执行shell脚本,获取的结果与直接在命令行下获取的结果不同。
公司项目中的一项小功能,统计设备的连接数.其中用到shell脚本来获取已连接设备的统计.使用命令 /bin/netstat -an| grep ESTABLISHED | awk '{print $4 ...
- python中执行shell命令的几个方法小结
原文 http://www.jb51.net/article/55327.htm 最近有个需求就是页面上执行shell命令,第一想到的就是os.system, os.system('cat /proc ...
- python中执行shell命令的几个方法小结(转载)
转载:http://www.jb51.net/article/55327.htm python中执行shell命令的几个方法小结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014- ...
- c++ cgi执行shell命令l发送qq邮件mailx
#include <cstdlib> //随机数 #include <iostream> #include <cstdio> //popen函数调用的需要 #inc ...
- Linux远程执行Shell命令或脚本
## 远程执行shell命令 ssh [user]@[server] '[command]' # eg. ssh root@192.168.1.1 'uptime' ## 远程执行本地shell脚本 ...
- vim中执行shell命令
1):!command 不退出vim,并执行shell命令command,将命令输出显示在vim的命令区域,不会改变当前编辑的文件的内容 例如 :!ls -l 特别的可以运行:!bas ...
- Android Java执行Shell命令
最新内容建议直接访问原文:http://www.trinea.cn/android/android-java-execute-shell-commands/ 主要介绍Android或Java应用中如何 ...
- subprocess模块还提供了很多方便的方法来使得执行 shell 命令
现在你可以看到它正常地处理了转义. 注意 实际上你也可以在shell=False那里直接使用一个单独的字符串作为参数, 但是它必须是命令程序本身,这种做法和在一个列表中定义一个args没什么区别.而如 ...
- nodejs 执行shell 命令
有需要从前端操作服务器执行shell命令的需求 建立一个process.js文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 var process = ...
随机推荐
- Python入门-用户登录程序升级版
编写登陆接口 基础需求: 让用户输入用户名密码 认证成功后显示欢迎信息 输错三次后退出程序 升级需求: 可以支持多个用户登录 (提示,通过列表存多个账户信息) 用户3次认证失败后,退出程序,再次启动程 ...
- Linux awk使用方法~~整理
目录 awk行处理方式 awk命令格式 命令行格式 脚本格式 命令行格式——基本格式 awk内置变量 awk内置函数 测试数据 awk变量和函数使用实例 逻辑判断式 扩展格式 BEGIN 和 END ...
- 监控系统对比 Ganglia vs Open-falcon vs Prometheus vs Zabbix vs Nagios vs PandoraFMS
Zabbix vs Nagios vs PandoraFMS: an in depth comparison - Pandora FMS - The Monitoring Bloghttps://bl ...
- Windows10常用快捷键
1. 打开注册表 ctrl+R ---> regedit 2.打开资源管理器 win + E 3.切换到桌面 win + D 再按一次可以进行还原 4.锁屏 win+ ...
- javascript内置函数:toString()
不同对象有不同的实现方式. 1.Number对象: 语法:numberObject.toString([radix]) 参数:radix,可选/Number类型,指定的基数(进制数),支持[2,36] ...
- Java Hash集合的equals()与hashCode() 方法
Java 集合实现类,无论是HashSet.HashMap等所有的Hash算法实现的集合类(后面简称Hash集合),加入的对象必须实现 hashCode() 与 equals() 方法,稍微不同的地方 ...
- 理解根目录,classpath, getClass().getResourceAsStream和getClass().getClassLoader().getResourceAsStream的区别
一: 理解根目录 <value>classpath*:/application.properties</value> <value>classpath:/appli ...
- [转帖]linux sed命令
linux sed命令就是这么简单 https://www.cnblogs.com/wangqiguo/p/6718512.html 用到的最多的就是一个sed -i 's/nn/mm/' 的命令了. ...
- easyUI 数据表格datagrid的使用
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- Mybatis Dao层注解及XML组合Dao的开发方式
mybatis可以用xml进行数据操作,也可以在dao层用注解的方式,也可以采取xml和dao层接口组合使用的方法.显然 ,后者更加简单. 实体类Student package com.zhao. ...