1
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?

毎日write up 4日目 caas

Posted at

問題

Description
Now presenting cowsay as a service

コンテナではなく牛だそうです
スクリーンショット 2025-05-09 18.33.36.png

スクリーンショット 2025-05-09 18.33.51.png

解答

パスに指定したものが直接表示されているので、そこの制御不備を突くのだろうなと思いながら、添付されているindex.jsを見ます。

const express = require('express');
const app = express();
const { exec } = require('child_process');

app.use(express.static('public'));

app.get('/cowsay/:message', (req, res) => {
  exec(`/usr/games/cowsay ${req.params.message}`, {timeout: 5000}, (error, stdout) => {
    if (error) return res.status(500).end();
    res.type('txt').send(stdout).end();
  });
});

app.listen(3000, () => {
  console.log('listening');
});

expressで書かれたサーバサイドのコードのようです。
app.getで/cowsay/リクエストパラメータの制御を行っています。
どうやらなんのサニタイズもされず、直接execに使われていることがわかります。
execはnode.jsの組み込みのシェルコマンドを実行する関数です。もう明らかにヤバいですね
現在では、/usr/games/cowsay にparamsのmessageを引数として実行しています。
message引数を与えた後にパイプ | でつないで任意のコマンドを実行できます。
試しに/cowsay/a | lsとurlに入れて見ます。
するとフォルダ一覧が見えました。
スクリーンショット 2025-05-09 18.52.38.png
なぜかflagではなくfalg.txtとなっているのに気を付けて、cat等で出力します
/cowsay/a | cat falg.txt
するとflagが出力されます

1
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
1
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?