如果给你一个 shell,你可以干什么?

2017-08-08 16:36:08 +08:00
 rockuw

使用函数计算API 网关做了一个web shell: 随时随地打开一个 shell,用完即走。

欢迎大家来玩,项目地址:

这个项目中我们用到了以下组件:

  1. 使用 nodejs 开发,通过 reactify 生成浏览器代码
  2. 根据用户输入的命令,把请求发送到 API 网关
  3. API 网关把请求发送到后端的函数计算,在函数中执行 shell 命令

函数的代码也非常简单:

'use strict';

var exec = require('child_process');

exports.handler = function(event, context, callback) {
  console.log('event: %s', event.toString());

  var evt = JSON.parse(event.toString());
  var cmd = evt['queryParameters']['cmd'];
  exec.exec(cmd, {}, function(err, stdout, stderr) {
    console.log(stdout, stderr);

    var body = '';
    if (err) {
      body = new Buffer(stderr).toString('base64');
    } else {
      body = new Buffer(stdout).toString('base64');
    }

    var resp = {
      statusCode: 200,
      isBase64Encoded: true,
      body: body,
    };
    callback(null, resp);
  });
};

欢迎大家来体验 serverless 构架的函数计算服务;
也欢迎有兴趣的同学加入一起开发函数计算:

5647 次点击
所在节点    推广
33 条回复
lulinux
2017-08-08 16:43:26 +08:00
这是什么字体这么漂亮?
ynyounuo
2017-08-08 16:45:07 +08:00
@lulinux Inconsolata,如果你喜欢这种细瘦字体也不妨看看 V 友的 Iosevka
minamike
2017-08-08 16:50:59 +08:00
输入 rm -rf /*会怎样
w88975
2017-08-08 16:52:25 +08:00
不支持 tap ctrl vi nano 等快捷键 编辑器也没法用 很鸡肋
这种需求 直接用 Wetty 搭建一个就足够了
rockuw
2017-08-08 16:52:38 +08:00
@minamike 试一下 :)
imnpc
2017-08-08 16:52:55 +08:00
无 root 权限的...
但是还是感觉有风险
hzwjz
2017-08-08 16:55:51 +08:00
我可以这么干

`rm -rf --no-preserve-root /`


```
packages/mercurial/hgweb/hgweb_mod.pyc': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/mercurial/hgweb/__init__.pyc': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/mercurial/hgweb/wsgicgi.py': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/mercurial/context.pyc': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/mercurial/strutil.py': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/mercurial/unionrepo.py': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/mercurial/httppeer.pyc': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/mercurial/ancestor.pyc': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/mercurial/dagparser.pyc': Permission denied
```
hzwjz
2017-08-08 16:56:41 +08:00
@minamike #3
@rockuw #5
亲自实验了一把
timothyye
2017-08-08 16:57:31 +08:00
@hzwjz sudo
hzwjz
2017-08-08 16:59:00 +08:00
@timothyye #9 /bin/sh: 1: sudo: not found
hellove1985
2017-08-08 17:16:52 +08:00
反馈 bug

cat /tmp/test.txt

TypeError: e.data.split is not a function
hellove1985
2017-08-08 17:20:00 +08:00
echo 123 > /tmp/test.txt
cat /tmp/test.txt

TypeError: e.data.split is not a function
rockuw
2017-08-08 17:22:02 +08:00
@hellove1985 已修复
ihainan
2017-08-08 17:28:02 +08:00
快捷键用不了,不开心……
binux
2017-08-08 17:38:26 +08:00
`:(){ :|: & };:` 都运行不了好意思叫 shell ?
hjc4869
2017-08-08 17:39:02 +08:00
当然是上 Fork bomb 了
helica
2017-08-08 18:45:49 +08:00
@binux 我虚拟机怎么卡死了…
rockuw
2017-08-08 18:51:13 +08:00
@hjc4869 防弹的
hjc4869
2017-08-08 19:07:33 +08:00
@rockuw 没屏蔽掉网络访问,可以拿来做很多不好的事情,比如写个 while 循环拿来 DDoS
rockuw
2017-08-08 19:36:52 +08:00
@hjc4869 函数计算有一些限制项,能够有效地防止被拿来做 DDoS: https://help.aliyun.com/document_detail/51907.html

默认情况下一个用户并发执行数是 100,即他最多有 100 个实例在跑。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/381412

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX