非常に単純なバッファ オーバーフロー攻撃を実行しようとしています。私はこれにほとんど初心者です。したがって、この質問がばかげている場合は、すみません:-)
コード:
#include<stdio.h>
#include<stdlib.h>
int i, n;
void confused(int i)
{
printf("**Who called me? Why am I here?? *** %x\n ", i);
}
void shell_call(char *c)
{
printf(" ***Now calling \"%s\" shell command *** \n", c);
system(c);
}
void victim_func()
{
int a[4];
printf("Enter n: "); scanf("%d",&n);
printf("~~~~~~~~~~~~~ values and address of n locations ~~~~~~~~~~");
for (i = 0;i <n ;i++)
printf ("\n a[%d] = %x, address = %x", i, a[i], &a[i]);
printf("\nEnter %d HEX Values \n", n);
// Buffer Overflow vulnerability HERE!
for (i=0;i<n;i++) scanf("%x",&a[i]);
printf("Done reading junk numbers\n");
}
int main()
{
victim_func();
printf(“\n done”);
return 0;
}
objdump を使用して関数アドレスを取得すると、次のようになります。
main(): 0x804854d
Address of main() where printf() is called: 0x8048563
victim_func(): 0x8048455
confused(): 0x8048414
今、私が欲しいのは、そこでバッファをオーバーフローさせ、戻りアドレスをconfused()のアドレスに上書きすることにより、victim_func()から関数「confused()」にジャンプすることです。そして、混乱した()からメインのprintf()ステートメントに戻り、正常に終了したいと思います。したがって、次の入力を提供します
Enter n: 7
Enter 7 HEX values:
1
2
3
4
5
8048414 (This is to jump to confused)
8048563 (this is to jump to printf() in main)
ただし、プログラムはその printf ステートメントから "Done" を出力しますが、victim_func() に戻って "Enter n:" を出力します。
私は何を間違っていますか?どんな助けでも大歓迎です!
PS: 質問が正しいかどうかわかりません。さらに情報が必要な場合はお知らせください。