xctf攻防世界Guess-the-Number writeup

下载附件,是一个java,用jd-gui打开:

发现就是需要输入一个数字参数:

import java.math.BigInteger;

public class guess {
  static String XOR(String _str_one, String _str_two) {
    BigInteger i1 = new BigInteger(_str_one, 16);
    BigInteger i2 = new BigInteger(_str_two, 16);
    BigInteger res = i1.xor(i2);
    String result = res.toString(16);
    return result;
  }
  
  public static void main(String[] args) {
    int guess_number = 0;
    int my_num = 349763335;
    int my_number = 1545686892;
    int flag = 345736730;
    if (args.length > 0) {
      try {
        guess_number = Integer.parseInt(args[0]); //输入参数赋给guess
        if (my_number / 5 == guess_number) { //guess应该等于1545686892/5=309137378
          String str_one = "4b64ca12ace755516c178f72d05d7061";
          String str_two = "ecd44646cfe5994ebeb35bf922e25dba";
          my_num += flag; //mynum=695500065
          String answer = XOR(str_one, str_two);//两个字符串异或
          System.out.println("your flag is: " + answer); //输出答案
        } else {
          System.err.println("wrong guess!");
          System.exit(1);
        } 
      } catch (NumberFormatException e) {
        System.err.println("please enter an integer \nexample: java -jar guess 12");
        System.exit(1);
      } 
    } else {
      System.err.println("wrong guess!");
      int num = 1000000;
      num++;
      System.exit(1);
    } 
  }
}

cmd里面运行这个java程序:

PS C:\Users\Administrator\Desktop> java -jar guessthenumber.jar 309137378
your flag is: a7b08c546302cc1fd2a4d48bf2bf2ddb

参考脚本python3:

str_one = "4b64ca12ace755516c178f72d05d7061"
str_two = "ecd44646cfe5994ebeb35bf922e25dba"
flag = [8]*16

newstr_o = bytes.fromhex(str_one)
newstr_t = bytes.fromhex(str_two)
for i in range(len(newstr_o)):
	flag[i] = newstr_o[i]^newstr_t[i]
	flag[i] = hex(flag[i])
print(flag)
	
PS C:\Users\Administrator\Desktop> python3 C:\Users\Administrator\Desktop\guessthenumber.py
['0xa7', '0xb0', '0x8c', '0x54', '0x63', '0x2', '0xcc', '0x1f', '0xd2', '0xa4', '0xd4', '0x8b', '0xf2', '0xbf', '0x2d', '0xdb']

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值