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 challenge for ethical hacking course can you help me solve it
Given the code below for challenges and
This challenge we must solve it in terminal window. What is the secret key for them hint for challenge the username
victor@app.com
password
dbfdeaeb
Challenges
package defpackage;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Base;
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:Challengeclass
public class Challenge
public static void mainString args
main;
public static void main
System.out.printlnChallenge #;
Scanner in new ScannerSystemin;
System.out.printEnter a secret message :;
String secretMessage innextLine;
if verifysecretMessage
System.out.printlnCongratulations You cracked the code.";
else
System.out.printlnInvalid Try again.";
private static boolean verifyString code
try
String cipher encryptAESCBCPKCSPadding", code, getKey generateIv;
if cipherequalsfOSCekyOLSAXdFZpqDRoVuxzoZntgi
return true;
return false;
catch InvalidAlgorithmParameterException e
throw new RuntimeExceptione;
catch InvalidKeyException e
throw new RuntimeExceptione;
catch NoSuchAlgorithmException e
throw new RuntimeExceptione;
catch InvalidKeySpecException e
throw new RuntimeExceptione;
catch BadPaddingException e
throw new RuntimeExceptione;
catch IllegalBlockSizeException e
throw new RuntimeExceptione;
catch NoSuchPaddingException e
throw new RuntimeExceptione;
public static String encryptString algorithm, String input, SecretKey key, IvParameterSpec iv throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException
Cipher cipher Cipher.getInstancealgorithm;
cipher.init key, iv;
byte cipherText cipher.doFinalinputgetBytes;
return BasegetEncoderencodeToStringcipherText;
public static IvParameterSpec generateIv
byte iv ;
return new IvParameterSpeciv;
public static SecretKey getKey throws NoSuchAlgorithmException, InvalidKeySpecException
Random r new RandomL;
byte randomKey new byte;
for int i ; i randomKey.length; i
randomKeyibyte rnextInt;
SecretKey secret new SecretKeySpecrandomKey "AES";
return secret;
Challenge
package defpackage;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sqlConnection;
import java.sqlDriverManager;
import java.sqlResultSet;
import java.sqlStatement;
import java.util.Scanner;
loaded from: EthicalHacking.jar:Challengeclass
public class Challenge
public static void mainString args
main;
public static void main
System.out.printlnChallenge #;
System.out.println This challenge is based on databasedb file.";
System.out.println You can view the database columns but not use values in queries or modifyinsert records and the file.";
System.out.printlnNote: Login as an admin!";
Scanner in new ScannerSystemin;
System.out.printEnter a username :;
String username innextLine;
System.out.printEnter a password: ;
String password innextLine;
if verifyusername password
System.out.printlnCongratulations You cracked the code.";
else
System.out.printlnInvalid Try again.";
private static boolean verifyString username, String password
try
Class.forNameorgsqlite.JDBC;
Connection c DriverManager.getConnectionjdbc:sqlite:database.db;
Statement stmt ccreateStatement;
String query "SELECT idname,role FROM users where username username and password mdpassword;
if username passwordtoLowerCasecontainswhere
System.out.printlnPossible injection";
return false;
ResultSet rs stmtexecuteQueryquery;
while rsnext
String name rsgetStringname;
String role rsgetStringrole;
System.out.printlnWelcome name: name role: role;
if roleequalsadmin
return true;
rsclose;
stmtclose;
return false;
catch Exception e
System.err.printlnegetClassgetName: egetMessage;
System.exit;
return false;
private static String mdString text
try
MessageDigest md MessageDigest.getInstanceMD;
mdupdatetextgetBytes;
byte digest mddigest;
StringBuilder hash new StringBuilder;
for byte aByte : digest
hash.appendStringformatx Byte.valueOfaByte;
return hash.toString;
catch NoSuchAlgorithmException e
throw new RuntimeExceptione;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
