1 // Copyright 2021 Code Intelligence GmbH 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package com.example; 16 17 import com.code_intelligence.jazzer.api.FuzzedDataProvider; 18 import com.code_intelligence.jazzer.api.FuzzerSecurityIssueLow; 19 import java.util.Base64; 20 21 public class ExampleValueProfileFuzzer { base64(byte[] input)22 private static String base64(byte[] input) { 23 return Base64.getEncoder().encodeToString(input); 24 } 25 insecureEncrypt(long input)26 private static long insecureEncrypt(long input) { 27 long key = 0xefe4eb93215cb6b0L; 28 return input ^ key; 29 } 30 fuzzerTestOneInput(FuzzedDataProvider data)31 public static void fuzzerTestOneInput(FuzzedDataProvider data) { 32 // Without -use_value_profile=1, the fuzzer gets stuck here as there is no direct correspondence 33 // between the input bytes and the compared string. With value profile, the fuzzer can guess the 34 // expected input byte by byte, which takes linear rather than exponential time. 35 if (((Object) base64(data.consumeBytes(6))).equals("SmF6emVy")) { 36 long[] plaintextBlocks = data.consumeLongs(2); 37 if (plaintextBlocks.length != 2) 38 return; 39 if (insecureEncrypt(plaintextBlocks[0]) == 0x9fc48ee64d3dc090L) { 40 // Without variants of the fuzzer hooks for compares that also take in fake PCs, the fuzzer 41 // would get stuck here as the value profile information for long comparisons would not be 42 // able to distinguish between this comparison and the one above. 43 if (insecureEncrypt(plaintextBlocks[1]) == 0x888a82ff483ad9c2L) { 44 mustNeverBeCalled(); 45 } 46 } 47 } 48 } 49 mustNeverBeCalled()50 private static void mustNeverBeCalled() { 51 throw new FuzzerSecurityIssueLow("mustNeverBeCalled has been called"); 52 } 53 } 54