攻防世界WP-reverse-RC3 CTF 2016-logmein

本文深入解析了RC3安全密码猜解程序的算法逻辑,通过逆向工程揭示了其核心工作原理。文章详细介绍了如何利用字符串比较和特定的XOR操作来破解密码,提供了完整的代码实现,并最终给出了正确的密码,即FLAG RC3-2016-XORISGUD。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接看算法

因为比较简单所以我们直接看F5后的伪代码

void __fastcall __noreturn main(__int64 a1, char **a2, char **a3)
{
  size_t v3; // rsi
  int i; // [rsp+3Ch] [rbp-54h]
  char s[36]; // [rsp+40h] [rbp-50h]
  int v6; // [rsp+64h] [rbp-2Ch]
  __int64 v7; // [rsp+68h] [rbp-28h]
  char v8[8]; // [rsp+70h] [rbp-20h]
  int v9; // [rsp+8Ch] [rbp-4h]

  v9 = 0;
  strcpy(v8, ":\"AL_RT^L*.?+6/46");
  v7 = 28537194573619560LL;
  v6 = 7;
  printf("Welcome to the RC3 secure password guesser.\n", a2, a3);
  printf("To continue, you must enter the correct password.\n");
  printf("Enter your guess: ");
  __isoc99_scanf("%32s", s);//输入字符串
  v3 = strlen(s);
  if ( v3 < strlen(v8) )
    sub_4007C0();
  for ( i = 0; i < strlen(s); ++i )
  {
    if ( i >= strlen(v8) )
      sub_4007C0();
    if ( s[i] != (char)(*((_BYTE *)&v7 + i % v6) ^ v8[i]) )
      sub_4007C0();
  }
  sub_4007F0();
}

代码的逻辑很简单,就是输入一个字符串s,然后检查长度是否为固定长,第一个判断不能小,第二个判断不能大,所以就是相等咯。最后判断字符串是否与给定的字符串相等。解出给定的字符串就可以了。

注意

1.strcpy这个函数,虽然char v8[8],但是strcpy不管这些,是多少就复制多少过去。
2.就是写代码的时候,注意初始化char s[36],因为for循环里面有一个strlen函数,官方文档里面有这么一句话:

The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).
This should not be confused with the size of the array that holds the
string.

所以char s[18]="aaaaaaassaaaaaaaa";这里长度18是因为字符串最后一位留0,而v8的长度为17,不是很清楚这种做法是否为最优的做法。

代码

#include <iostream>
#include <Windows.h>
using namespace std;

int main()
{
	int i; // [rsp+3Ch] [rbp-54h]
	char s[18]="aaaaaaassaaaaaaaa"; // [rsp+40h] [rbp-50h]
	int v6; // [rsp+64h] [rbp-2Ch]
	__int64 v7; // [rsp+68h] [rbp-28h]
	char v8[17]; // [rsp+70h] [rbp-20h]
	strcpy(v8, ":\"AL_RT^L*.?+6/46");
	v7 = 28537194573619560LL;
	v6 = 7;
	for ( i = 0; i < strlen(s); ++i )
	{
		s[i] = (char)(*((BYTE *)&v7 + i % v6) ^ v8[i]);
	}
	cout<<s;
	system("pause");
	return 0;
}

FLAG RC3-2016-XORISGUD

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wallacegen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值