re学习笔记(35)BUUCTF-re-[GXYCTF2019]luck_guy

新手一枚,如有错误(不足)请指正,谢谢!!
个人博客:点击进入
题目链接:[GXYCTF2019]luck_guy
题目下载:点击下载

IDA64载入,main()函数F5
re学习笔记(35)BUUCTF-re-[GXYCTF2019]luck_guy_第1张图片
将用户输入的字符串存到v4中,然后作为patch_me()函数的参数
re学习笔记(35)BUUCTF-re-[GXYCTF2019]luck_guy_第2张图片
进入get_flag()函数查看

unsigned __int64 get_flag()
{
  unsigned int v0; // eax
  char v1; // al
  signed int i; // [rsp+4h] [rbp-3Ch]
  signed int j; // [rsp+8h] [rbp-38h]
  __int64 s; // [rsp+10h] [rbp-30h]
  char v6; // [rsp+18h] [rbp-28h]
  unsigned __int64 v7; // [rsp+38h] [rbp-8h]

  v7 = __readfsqword(0x28u);
  v0 = time(0LL);                               // 获取时间
  srand(v0);                                    // 用时间作为种子来生成随机数
  for ( i = 0; i <= 4; ++i )
  {
    switch ( rand() % 200 )                     // 生成随机数0~199
    {
      case 1:
        puts("OK, it's flag:");
        memset(&s, 0, 0x28uLL);
        strcat((char *)&s, f1);                 // f1='GXY{do_not_'
        strcat((char *)&s, &f2);                // f2初始为空
        printf("%s", &s);
        break;
      case 2:
        printf("Solar not like you");
        break;
      case 3:
        printf("Solar want a girlfriend");
        break;
      case 4:
        v6 = 0;
        s = 0x7F666F6067756369LL;
        strcat(&f2, (const char *)&s);
        break;
      case 5:
        for ( j = 0; j <= 7; ++j )
        {
          if ( j % 2 == 1 )
            v1 = *(&f2 + j) - 2;
          else
            v1 = *(&f2 + j) - 1;
          *(&f2 + j) = v1;
        }
        break;
      default:
        puts("emmm,you can't find flag 23333");
        break;
    }
  }
  return __readfsqword(0x28u) ^ v7;
}

取了0~199的随机数,然后case1 case4 case5才是有效路径,还要找准顺序,怪不得题目为luck_guy了
根据判断顺序应该为case4 case5 case1
写脚本

#include 
#include 
int main()
{
	char f2[] = { 0x69,0x63,0x75,0x67,0x60,0x6f,0x66,0x7f,0 };
	for (int i = 0; i < 8; i++)
	{
		if (i % 2 == 1)
			f2[i] -= 2;
		else
			f2[i] -= 1;
	}
	char f1[] = "GXY{do_not_";
	char flag[20];
	memset(flag, 0,20);
	strcat(flag, f1);
	strcat(flag, f2);
	puts(flag);
	return 0;
}

re学习笔记(35)BUUCTF-re-[GXYCTF2019]luck_guy_第3张图片
得出flag为GXY{do_not_hate_me}

你可能感兴趣的:(ctf小白成长ing,#,reverse)