示例#1
0
func init() {
	var blockSize int
	pad := Commands.Add("pad", "[input]")
	pad.Flags.IntVar(&blockSize, "blockSize", 20, "block size")
	pad.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Ascii)
		input := encoding.In.Decode(cmd.GetInput(args, 0))
		fmt.Print(encoding.Out.Encode(Pkcs7_pad(blockSize, input)))
	}

	unpad := Commands.Add("unpad", "[input]")
	unpad.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Ascii)
		input := encoding.In.Decode(cmd.GetInput(args, 0))
		fmt.Print(encoding.Out.Encode(Pkcs7_unpad(input)))
	}

	encrypt := Commands.Add("encrypt", "[key] [iv] [input]")
	encrypt.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Base64)
		key := encoding.Key.Decode(cmd.GetInput(args, 0))
		iv := make([]byte, aes.BlockSize)
		nextArg := 1

		if len(args) == 3 {
			iv = encoding.Key.Decode(cmd.GetInput(args, nextArg))
			nextArg += 1
		}

		input := encoding.In.Decode(cmd.GetInput(args, nextArg))

		fmt.Print(encoding.Out.Encode(AesCBCEncrypt(key, iv, input)))
	}

	decrypt := Commands.Add("decrypt", "[key] (iv) [input]")
	decrypt.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Ascii, encoding.Ascii)
		key := encoding.Key.Decode(cmd.GetInput(args, 0))
		iv := make([]byte, aes.BlockSize)
		nextArg := 1

		if len(args) == 3 {
			iv = encoding.Key.Decode(cmd.GetInput(args, nextArg))
			nextArg += 1
		}

		input := encoding.In.Decode(cmd.GetInput(args, nextArg))

		fmt.Print(encoding.Out.Encode(AesCBCDecrypt(key, iv, input)))
	}

	randomKey := Commands.Add("randomKey", "")
	randomKey.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Base64)
		key := RandomAESKey()

		fmt.Print(encoding.Out.Encode(key))
	}

	randomEncrypt := Commands.Add("randomEncrypt", "[input]")
	randomEncrypt.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Base64)

		input := encoding.In.Decode(cmd.GetInput(args, 0))

		result, _ := AesRandomEncrypt(input)

		fmt.Print(encoding.Out.Encode(result))
	}

	blockMode := Commands.Add("blockMode", "[input]")
	blockMode.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Ascii, encoding.Ascii)

		input := encoding.In.Decode(cmd.GetInput(args, 0))

		isEcb, _, _ := package1.DetectAesEcb(input)

		if isEcb {
			fmt.Print("Detected: ECB")
		} else {
			fmt.Print("Assuming: CBC")
		}
	}

	ecbEncrypt := Commands.Add("ecbEncrypt", "[key] [input]")
	ecbEncrypt.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Hex)

		key := encoding.Key.Decode(cmd.GetInput(args, 0))

		input := encoding.In.Decode(cmd.GetInput(args, 1))

		fmt.Print(encoding.Out.Encode(AesECBEncrypt(key, input)))
	}

	blockSizeCmd := Commands.Add("blockSize", "[key] [input]")
	blockSizeCmd.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Base64, encoding.Ascii)

		input := encoding.In.Decode(cmd.GetInput(args, 0))

		oracle := CreateOracle(input)

		fmt.Print(DetectBlockSize(oracle))
	}

	crackAesEcb := Commands.Add("crackAesEcb", "[input]")
	crackAesEcb.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Base64, encoding.Ascii)

		input := encoding.In.Decode(cmd.GetInput(args, 0))

		oracle := CreateOracle(input)

		fmt.Print(encoding.Out.Encode(CrackAesEcb(oracle)))
	}

	profileFor := Commands.Add("profileFor", "{email]")
	profileFor.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Ascii)

		fmt.Print(ProfileFor(cmd.GetInput(args, 0)).Encode())
	}

	profileEncrypt := Commands.Add("profileEncrypt", "[key] {email]")
	profileEncrypt.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Base64, encoding.Base64)

		key := encoding.Key.Decode(cmd.GetInput(args, 0))

		pe, _ := CreateProfileOracle(key)

		fmt.Print(encoding.Out.Encode(pe(cmd.GetInput(args, 1))))
	}

	profileDecrypt := Commands.Add("profileDecrypt", "[key] {data]")
	profileDecrypt.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Base64, encoding.Ascii)

		key := encoding.Key.Decode(cmd.GetInput(args, 0))
		input := encoding.In.Decode(cmd.GetInput(args, 1))

		_, pd := CreateProfileOracle(key)

		fmt.Printf("%#v", pd(input))
	}

	profileCrack := Commands.Add("profileCrack", "[key] [role]")
	profileCrack.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Base64, encoding.Base64)

		key := encoding.Key.Decode(cmd.GetInput(args, 0))
		input := encoding.In.Decode(cmd.GetInput(args, 1))

		pe, _ := CreateProfileOracle(key)

		fmt.Print(encoding.Out.Encode(CrackProfile(pe, string(input))))
	}

	var prefixLength int
	crackAesEcbPrefix := Commands.Add("crackAesEcbPrefix", "[input]")
	crackAesEcbPrefix.Flags.IntVar(&prefixLength, "prefixLength", 32, "random prefix length")
	crackAesEcbPrefix.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Base64, encoding.Ascii)

		input := encoding.In.Decode(cmd.GetInput(args, 0))

		oracle := CreateOracleWithPrefix(prefixLength, nil, input)

		fmt.Print(encoding.Out.Encode(CrackAesEcbWithPrefix(oracle)))
	}
}
示例#2
0
func init() {
	translate := func(decode func(string) []byte, encode func([]byte) string) func([]string) {
		return func(args []string) {
			data := decode(cmd.GetInput(args, 0))
			fmt.Print(encode(data))
		}
	}

	for inputName, inputEncoding := range encoding.Encodings {
		translateCommand := Commands.Add(inputName, "Translate from "+inputName)
		for outputName, outputEncoding := range encoding.Encodings {
			if outputName == inputName {
				continue
			}
			translateCommand.Add(outputName, "to "+outputName).Command = translate(inputEncoding.Decode, outputEncoding.Encode)
		}
	}

	xor := Commands.Add("xor", "[key] [input]")
	xor.Command = func(args []string) {
		encoding.SetDefault(encoding.Ascii, encoding.Ascii, encoding.Hex)
		key := encoding.Key.Decode(cmd.GetInput(args, 0))
		input := encoding.In.Decode(cmd.GetInput(args, 1))
		fmt.Print(encoding.Out.Encode(RepeatXor(key, input)))
	}

	decryptXor := Commands.Add("decryptXor", "[encryptedInput]")
	coverage := decryptXor.Flags.Float64("c", 0.05, "percentage coverage")
	decryptXor.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Hex, encoding.Ascii)
		input := encoding.In.Decode(cmd.GetInput(args, 0))
		result, key := DecryptXor(input, *coverage)
		fmt.Fprintln(os.Stderr, "Key:", encoding.Out.Encode(key))
		fmt.Print(encoding.Out.Encode(result))
	}

	fixedXor := Commands.Add("fixedXor", "[inputA] [inputB]")
	fixedXor.Command = func(args []string) {
		encoding.SetDefault(encoding.Hex, encoding.Hex, encoding.Hex)
		key := encoding.Key.Decode(cmd.GetInput(args, 0))
		input := encoding.In.Decode(cmd.GetInput(args, 1))
		fmt.Print(encoding.Out.Encode(FixedXor(key, input)))
	}

	decryptSingleXor := Commands.Add("decryptSingleXor", "[encryptedInput]")
	decryptSingleXor.Command = func(args []string) {
		encoding.SetDefault(encoding.Hex, encoding.Hex, encoding.Ascii)
		input := encoding.In.Decode(cmd.GetInput(args, 0))
		result, key, _ := DecryptSingleXor(input)

		fmt.Fprintln(os.Stderr, "Key:", key)

		fmt.Print(encoding.Out.Encode(result))
	}

	detectSingleXorLine := Commands.Add("detectSingleXorLine", "[inputLines]")
	detectSingleXorLine.Command = func(args []string) {
		encoding.SetDefault(encoding.Hex, encoding.Hex, encoding.Ascii)
		result, key, line := DetectSingleXorLine(cmd.GetInput(args, 0), encoding.In.Decode)

		fmt.Fprintln(os.Stderr, "Key:", key, "Line:", line)

		fmt.Print(encoding.Out.Encode(result))
	}

	decryptAes := Commands.Add("decryptAes", "[decryptKey] [encryptedInput]")
	decryptAes.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Ascii, encoding.Ascii)
		key := encoding.Key.Decode(cmd.GetInput(args, 0))
		input := encoding.In.Decode(cmd.GetInput(args, 1))

		result := DecryptAes(input, key)

		fmt.Print(encoding.Out.Encode(result))
	}

	detectAesLine := Commands.Add("detectAesLine", "[inputLines]")
	detectAesLine.Command = func(args []string) {
		encoding.SetDefault(encoding.Base64, encoding.Hex, encoding.Hex)
		line, block1Start, block2Start := DetectAesEcbLine(cmd.GetInput(args, 0), encoding.In.Decode)

		if block1Start == block2Start {
			fmt.Println("No line detected")
		} else {
			fmt.Printf("Found Line %v, [%v:%v] matches [%v:%v]", line, block1Start, block1Start+16, block2Start, block2Start+16)
		}
	}
}