2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Functions Linux 従量課金プランでの疑似リモートシェル

Last updated at Posted at 2022-12-28

はじめに

この記事で紹介する内容は OSコマンドインジェクション につながるため、あくまでも検証目的です。

きっかけ

Azure Functions Linux Consumption Plan(従量課金プラン) では Kuduによる、WebSSH(アプリケーションコンテナへの接続) や Bash 接続(Kudu への接続)が利用できません。
そのため、アプリケーションが動作する環境の詳細を手軽に確認することができません。

そこで、アプリケーションコード内からコマンドを実行することで実行環境の情報を探ってみます。

コード例

index.js
const util = require("util");
const {exec} = require("child_process");
const execAsync = util.promisify(exec);

module.exports = async function (context, req) {
    const cmd = req.query.cmd || "date"
    const output = {
        cmd,
    }
    context.log(`${cmd}`)
    try {
        const result = await execAsync(`${cmd}`);
        output.stdout = result.stdout;
        context.log(output.stdout)
    } catch (e){
        output.error = e
        context.log(e.stderr)
    }

    if (req.query.type === 'json') {
        context.res = {
            body: output
        };
    } else {
        context.res = {
            body: `${output.cmd}

${output.error ? output.error.stderr : output.stdout}`
        };
    }
}

実行例

  • echo とか

image.png

  • df -h

image.png

  • cat

image.png

image.png

image.png

  • ps

image.png

いろんなことがわかりますね。やったぜ。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?