トップ «前の日記(2024-09-12) 最新 次の日記(2024-09-28)» 編集

はじめてのにき

ここの位置付け

2004|11|
2005|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|04|05|06|07|08|09|10|

ToDo:


2024-09-23

_ gnalang

https://ierae-ctf.com/ の gnalang

制約は

  • The polyglot must be executable in `sh` and `node` both.
  • `sh` and `node` must exit normally when executing the polyglot.
  • `sh` and `node` must return the same output when executing the polyglot.
  • `sh` must never cause error for each executed command.
  • The polyglot must output "Yes\n" when the string given from stdin is a palindrome. "No\n" otherwise.
  • The polyglot must be a palindrome.
  • The polyglot must not contain the following tokens: '$', '#', "//", "<!--", "-->", '\n', ' '.
  • The polyglot must not write anything to file as a shell script (because it fails and causes error)

マジで?てなったけど、考えいくと割と普通にというか、新奇な道具が出ることなく解けてしまった

  • 空白不在はタブで無問題
  • sh は exit 以降無視できるので一行コメントがあるようなもの (と思っていた)
  • /* が封じられてないので、 sh と js の分離は /*/true とかで開幕でできる
  • POSIX shell なんて知らんしめんどいよーと思ったけど、 sed があったのでそれで OK (地味に $ が封じられてたので少しハマったけど)
  • JS 側は "fs" を require するやつが、 sandbox 中だと動かなかったので、適当にぐぐって process.stdin というのを使うやつを拾った
  • palindrome は1行コメントがなくても、 "n"" でおおむね無力化できる、てのがかなり一般的に広い言語で使える

くらいか。最後のは作問者が知らなかったらしい。前から読むと文字列だけど、後ろから読むと " があまるので、これを二つ使うと好きな区間をコメントアウトできる

一番ハマったのは polyglot や palindrome と直接関係がない、 backquote の挙動で、煎じ詰めると

exit;echo `\``

が /bin/sh だとエラーになる、ってことだった。 bash だったら OK だし

exit
echo `\``

も OK 。改行あったら読み込まないのは、よくある実行中に編集しちゃって困る経験的にもそうなんだけど、なんで実行しないスクリプトの `` の中身の backqoute がそろってるかを気にしるの?てなっていた

今思えば単に、 backquote の中で backquote を escape することはできない、ってこと?いや、うーんそれだと

echo `echo \`

が通らないのも説明がつかないので、単に /bin/sh はマトモな処理系ではないから、な気がする……

まあなんかよくわからないので、 backquote のかわりに double quote を使って解決した

最終的なコード

/*/true	"n\"";/usr/bin/cat	-|/usr/bin/sed	's@.*@&_@;:l;/^.\?_/s@.*@Yes@;/^Yes\b/q;s@^\(.\)\(.*\)\1_@\2_@;tl;s@.*@No\n@';/bin/true	'*/;m=this;m/"/;";(async()=>{const	buffers	=	[];for	await	(const	chunk	of	process.stdin)	buffers.push(chunk);const	buffer	=	Buffer.concat(buffers);const	text	=	buffer.toString();e=text.substring(9999);console.log(text.split(e).reverse().join(e)==text?String.fromCharCode(89,101,115):String.fromCharCode(78,111))})();exit=1;/*';/bin/true	*/;exit;"\n";"n\";tixe;/*	eurt/nib/;'*/;1=tixe;)()}))111,87(edoCrahCmorf.gnirtS:)511,101,98(edoCrahCmorf.gnirtS?txet==)e(nioj.)(esrever.)e(tilps.txet(gol.elosnoc;)9999(gnirtsbus.txet=e;)(gnirtSot.reffub	=	txet	tsnoc;)sreffub(tacnoc.reffuB	=	reffub	tsnoc;)knuhc(hsup.sreffub	)nidts.ssecorp	fo	knuhc	tsnoc(	tiawa	rof;][	=	sreffub	tsnoc{>=)(cnysa(;";/"/m;siht=m;/*'	eurt/nib/;'@n\oN@*.@s;lt;@_2\@_1\)\*.(\)\.(\^@s;q/b\seY^/;@seY@*.@s/_?\.^/;l:;@_&@*.@s'	des/nib/rsu/|-	tac/nib/rsu/;""\n"	eurt/*/

(10:34)

お名前:
E-mail:
コメント:
人生、宇宙、すべての答え
本日のリンク元

2024年
9月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

search / home / index

全てリンクフリーです。 コード片は自由に使用していただいて構いません。 その他のものはGPL扱いであればあらゆる使用に関して文句は言いません。 なにかあれば下記メールアドレスへ。

shinichiro.hamaji _at_ gmail.com / shinichiro.h