Script improvements #3

Open
opened 2024-08-01 13:13:32 +00:00 by papey · 4 comments
Member
  1. Make the rotation key a variable/cli flag

String password = Cesar.cesarRotate(user.getString("data"), -4);

  1. Variables should be static final

String LOWER_ALPHABET = "abcdefghijklmnopqrstuvwxyz";

  1. I think this could be simplified, try to use only char numeric value

if (offset < 0) {
LOWER_ALPHABET = new StringBuilder(LOWER_ALPHABET).reverse().toString();
offset = -offset;
}
String UPPER_ALPHABET = LOWER_ALPHABET.toUpperCase();

  1. Could you please try a more functional approach to the following lines, using the Java Stream API ?

for (int i = 0; i < input.length(); i++) {
char newChar = input.charAt(i);
if (!Character.isDigit(input.charAt(i))) {
int pos = LOWER_ALPHABET.indexOf(Character.toLowerCase(input.charAt(i)));
int newPos = (pos + offset) % 26;
if (Character.isUpperCase(input.charAt(i))) {
newChar = UPPER_ALPHABET.charAt(newPos);
} else {
newChar = LOWER_ALPHABET.charAt(newPos);
}
}
output.append(newChar);
}
return output.toString();

  1. Can you find the passwords in parallel ? Is it better in term of performance ? If not why ? Could you find when parallelism is relevant ?
1. Make the rotation key a variable/cli flag https://git.athelas-conseils.fr/Stage/bug-bounty-reports/src/commit/86495716e546ac05730d74d114b1ee130a5a5270/src/fr/motysten/usertwist/exploit/Main.java#L84 2. Variables should be static final https://git.athelas-conseils.fr/Stage/bug-bounty-reports/src/commit/86495716e546ac05730d74d114b1ee130a5a5270/src/fr/motysten/usertwist/exploit/tools/Cesar.java#L7 3. I think this could be simplified, try to use only char numeric value https://git.athelas-conseils.fr/Stage/bug-bounty-reports/src/commit/86495716e546ac05730d74d114b1ee130a5a5270/src/fr/motysten/usertwist/exploit/tools/Cesar.java#L8-L12 4. Could you please try a more [functional](https://en.wikipedia.org/wiki/Functional_programming) approach to the following lines, using the [Java Stream API](https://wary-kick-a3b.notion.site/Streams-329d07bc48c7471bbe028142b9712304) ? https://git.athelas-conseils.fr/Stage/bug-bounty-reports/src/commit/86495716e546ac05730d74d114b1ee130a5a5270/src/fr/motysten/usertwist/exploit/tools/Cesar.java#L17-L31 5. Can you find the passwords in parallel ? Is it better in term of performance ? If not why ? Could you find when parallelism is relevant ?
Mateo was assigned by papey 2024-08-01 13:13:32 +00:00
Member

#4
1 / 2 / 3 done
4 / 5 left

#4 1 / 2 / 3 done 4 / 5 left
Member

I don't understand how it's possible to rewrite the step4 using Java Streams even though I understand what they do. I can't manage to find the different steps of the conversion operation

I don't understand how it's possible to rewrite the step4 using Java Streams even though I understand what they do. I can't manage to find the different steps of the conversion operation
Member

Implemented asynchronous passwords decryption (step 5).
Asynchronous decryption is approximately 2 times faster than synchronous :

1. user1 => zivlwuXiaa1I
...
69. galileoGalilei => iabzwvwugAbiza
Synchronous elapsed time = 10.747904ms
1. user1 => zivlwuXiaa1I
...
69. galileoGalilei => iabzwvwugAbiza
Asynchronous elapsed time = 5.373952ms

So we can consider that asynchronous approach is better. Moreover, it's more stable. In fact, synchronous parsing running time was extremely unstable as it was sometimes as fast as asynchronous.

Asynchronous threads are good to split the tasks on the multiple CPUs but it needs a pretty decent computer. Also, it takes time to create a new process child so it's not interesting to use asynchronous actions on a little set of data. The longer the data set, the more time saved !

Implemented asynchronous passwords decryption (step 5). Asynchronous decryption is approximately 2 times faster than synchronous : ```java 1. user1 => zivlwuXiaa1I ... 69. galileoGalilei => iabzwvwugAbiza Synchronous elapsed time = 10.747904ms ``` ```java 1. user1 => zivlwuXiaa1I ... 69. galileoGalilei => iabzwvwugAbiza Asynchronous elapsed time = 5.373952ms ``` So we can consider that asynchronous approach is better. Moreover, it's more stable. In fact, synchronous parsing running time was extremely unstable as it was sometimes as fast as asynchronous. Asynchronous threads are good to split the tasks on the multiple CPUs but it needs a pretty decent computer. Also, it takes time to create a new process child so it's not interesting to use asynchronous actions on a little set of data. The longer the data set, the more time saved !
Author
Member

👋 @Mateo , starts looking good, left some comments directly in the PR. Let me know if the hints are enough 👍

👋 @Mateo , starts looking good, left some comments directly in the PR. Let me know if the hints are enough 👍
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Stage/bug-bounty-reports#3
No description provided.