Question: I got stuck in this 2 challenge for ethical hacking course can you help me solve it ? Given the code below for challenges 1

I got stuck in this 2 challenge for ethical hacking course can you help me solve it?
Given the code below for challenges 12 and 9.
This challenge we must solve it in terminal window. What is the secret key for them hint for challenge 12 the username
victor@app.com
password
d6273b77f90d6596e6a874672e5014b2
Challenges 9
package defpackage;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Base64;
import java.util.Random;
import java.util.Scanner;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/* loaded from: EthicalHacking.jar:Challenge9.class */
public class Challenge9{
public static void main(String[] args){
main();
}
public static void main(){
System.out.println("Challenge #9");
Scanner in = new Scanner(System.in);
System.out.print("Enter a secret message :");
String secretMessage = in.nextLine();
if (verify(secretMessage)){
System.out.println("Congratulations! You cracked the code.");
} else {
System.out.println("Invalid. Try again.");
}
}
private static boolean verify(String code){
try {
String cipher = encrypt("AES/CBC/PKCS5Padding", code, getKey(), generateIv());
if (cipher.equals("79fO57SCek07yO3LSAXd9FZpq8DRoV+/ux/zoZntgi0=")){
return true;
}
return false;
} catch (InvalidAlgorithmParameterException e){
throw new RuntimeException(e);
} catch (InvalidKeyException e2){
throw new RuntimeException(e2);
} catch (NoSuchAlgorithmException e3){
throw new RuntimeException(e3);
} catch (InvalidKeySpecException e4){
throw new RuntimeException(e4);
} catch (BadPaddingException e5){
throw new RuntimeException(e5);
} catch (IllegalBlockSizeException e6){
throw new RuntimeException(e6);
} catch (NoSuchPaddingException e7){
throw new RuntimeException(e7);
}
}
public static String encrypt(String algorithm, String input, SecretKey key, IvParameterSpec iv) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(1, key, iv);
byte[] cipherText = cipher.doFinal(input.getBytes());
return Base64.getEncoder().encodeToString(cipherText);
}
public static IvParameterSpec generateIv(){
byte[] iv ={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
return new IvParameterSpec(iv);
}
public static SecretKey getKey() throws NoSuchAlgorithmException, InvalidKeySpecException {
Random r = new Random(89893L);
byte[] randomKey = new byte[16];
for (int i =0; i < randomKey.length; i++){
randomKey[i]=(byte) r.nextInt(256);
}
SecretKey secret = new SecretKeySpec(randomKey, "AES");
return secret;
}
}
Challenge 12
package defpackage;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
/* loaded from: EthicalHacking.jar:Challenge12.class */
public class Challenge12{
public static void main(String[] args){
main();
}
public static void main(){
System.out.println("Challenge #12");
System.out.println("\\ This challenge is based on (database.db) file.");
System.out.println("\\ You can view the database columns but not use values in queries or modify/insert records and the file.");
System.out.println("Note: Login as an admin!");
Scanner in = new Scanner(System.in);
System.out.print("Enter a username :");
String username = in.nextLine();
System.out.print("Enter a password: ");
String password = in.nextLine();
if (verify(username, password)){
System.out.println("Congratulations! You cracked the code.");
} else {
System.out.println("Invalid. Try again.");
}
}
private static boolean verify(String username, String password){
try {
Class.forName("org.sqlite.JDBC");
Connection c = DriverManager.getConnection("jdbc:sqlite:database.db");
Statement stmt = c.createStatement();
String query = "SELECT id,name,role FROM users where username ='"+ username +"' and password =('"+ md5(password)+"')";
if ((username +""+ password).toLowerCase().contains("where")){
System.out.println("Possible injection");
return false;
}
ResultSet rs = stmt.executeQuery(query);
while (rs.next()){
String name = rs.getString("name");
String role = rs.getString("role");
System.out.println("Welcome name: "+ name +", role: "+ role);
if (role.equals("admin")){
return true;
}
}
rs.close();
stmt.close();
return false;
} catch (Exception e){
System.err.println(e.getClass().getName()+": "+ e.getMessage());
System.exit(0);
return false;
}
}
private static String md5(String text){
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(text.getBytes());
byte[] digest = md.digest();
StringBuilder hash = new StringBuilder();
for (byte aByte : digest){
hash.append(String.format("%02x", Byte.valueOf(aByte)));
}
return hash.toString();
} catch (NoSuchAlgorithmException e){
throw new RuntimeException(e);
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!