攻防世界Guess the Number

2020.7.21-1
首先这道题 说实话,只是考验的代码能力
这道题的难点在于:拿到java后不知道怎么办
首先对于java程序,要进行反编译,可以利用插件,或者是DJ java discompiler.
将java进行反编译,在反编译之后,我们会得到一个原始代码

import java.io.PrintStream;
import java.math.BigInteger;

public class Gues
{

    public Gues()
    {
    }

    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 = 0x14d8f707;
        int my_number = 0x5c214f6c;
        int flag = 0x149b861a;
                    String str_one = "4b64ca12ace755516c178f72d05d7061";
                    String str_two = "ecd44646cfe5994ebeb35bf922e25dba";
                    my_num += flag;
                    String answer = XOR(str_one, str_two);
                    System.out.println((new StringBuilder("your flag is: ")).append(answer).toString());
                }

将原始代码去掉判断条件,就可以很快的求解出flag了。得到的结果是
your flag is: a7b08c546302cc1fd2a4d48bf2bf2ddb
//再者来说,可以看代码看出我们所要猜想的guess the number 就是0x5c214f6c/5=309137378
所以即使我们不更改程序,也可以直接输出flag

import java.io.PrintStream;
import java.math.BigInteger;

public class Guess
{

    public 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 = 0x14d8f707;
        int my_number = 0x5c214f6c;
        int flag = 0x149b861a;
        if(args.length > 0)
        {
            try
            {
                guess_number = Integer.parseInt(args[0]);
                if(my_number / 5 == guess_number)
                {
                    String str_one = "4b64ca12ace755516c178f72d05d7061";
                    String str_two = "ecd44646cfe5994ebeb35bf922e25dba";
                    my_num += flag;
                    String answer = XOR(str_one, str_two);
                    System.out.println((new StringBuilder("your flag is: ")).append(answer).toString());
                } 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 = 0xf4240;
            num++;
            System.exit(1);
        }
    }
}


```原始代码
或者说,我们可以考虑到代码,我们可以看出answer=one xor two 但是,直接算的话,好像会出一点差错。这个需要再考虑吧。

你可能感兴趣的:(ctf)