-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from DolphFlynn/brute
Brute
- Loading branch information
Showing
17 changed files
with
104,779 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/blackberry/jwteditor/operations/weak/ErrorLoggingRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2025 Dolph Flynn | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.blackberry.jwteditor.operations.weak; | ||
|
||
import burp.api.montoya.logging.Logging; | ||
|
||
class ErrorLoggingRunnable implements Runnable { | ||
interface Task { | ||
void action() throws Exception; | ||
} | ||
|
||
private final Logging logging; | ||
private final Task task; | ||
|
||
ErrorLoggingRunnable(Logging logging, Task task) { | ||
this.logging = logging; | ||
this.task = task; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
task.action(); | ||
} catch (Exception e) { | ||
logging.logToError(e); | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/blackberry/jwteditor/operations/weak/WeakSecretFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2025 Dolph Flynn | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.blackberry.jwteditor.operations.weak; | ||
|
||
import burp.api.montoya.logging.Logging; | ||
import com.blackberry.jwteditor.model.jose.JWS; | ||
|
||
import java.io.Closeable; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
import static com.blackberry.jwteditor.operations.weak.WeakSecretsFinderStatus.*; | ||
import static java.util.concurrent.Executors.newSingleThreadExecutor; | ||
|
||
public class WeakSecretFinder implements Closeable { | ||
private final ExecutorService executorService; | ||
private final WeakSecretsFinderModel model; | ||
private final Logging logging; | ||
|
||
public WeakSecretFinder(WeakSecretsFinderModel model, Logging logging) { | ||
this.model = model; | ||
this.logging = logging; | ||
this.executorService = newSingleThreadExecutor(); | ||
} | ||
|
||
public void bruteForce(JWS jws) { | ||
executorService.submit(new ErrorLoggingRunnable(logging, new Worker(model, jws))); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
executorService.shutdown(); | ||
} | ||
|
||
private static class Worker implements ErrorLoggingRunnable.Task { | ||
private final WeakSecrets weakSecrets; | ||
private final WeakSecretsFinderModel model; | ||
private final WeakSecretTester tester; | ||
|
||
private Worker(WeakSecretsFinderModel model, JWS jws) { | ||
this.model = model; | ||
this.weakSecrets = new WeakSecrets(); | ||
this.tester = new WeakSecretTester(jws); | ||
} | ||
|
||
@Override | ||
public void action() throws Exception { | ||
String secret; | ||
|
||
while (model.status() == RUNNING && (secret = weakSecrets.next()) != null) { | ||
model.setProgress(weakSecrets.progress()); | ||
|
||
if (tester.isSecretCorrect(secret)) { | ||
model.setStatus(SUCCESS); | ||
model.setSecret(secret); | ||
} | ||
} | ||
|
||
if (model.status() == RUNNING) { | ||
model.setStatus(FAILED); | ||
} | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/blackberry/jwteditor/operations/weak/WeakSecretTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2025 Dolph Flynn | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.blackberry.jwteditor.operations.weak; | ||
|
||
import com.blackberry.jwteditor.model.jose.JWS; | ||
import com.blackberry.jwteditor.model.keys.JWKKey; | ||
import com.blackberry.jwteditor.model.keys.JWKKeyFactory; | ||
import com.nimbusds.jose.JWSAlgorithm; | ||
import com.nimbusds.jose.JWSHeader; | ||
import com.nimbusds.jose.jwk.JWK; | ||
import com.nimbusds.jose.jwk.OctetSequenceKey; | ||
import com.nimbusds.jose.util.Base64URL; | ||
|
||
class WeakSecretTester { | ||
private final JWS jws; | ||
private final JWSHeader verificationInfo; | ||
|
||
public WeakSecretTester(JWS jws) { | ||
this.jws = jws; | ||
|
||
JWSAlgorithm algorithm = JWSAlgorithm.parse(jws.header().algorithm()); | ||
this.verificationInfo = new JWSHeader.Builder(algorithm).build(); | ||
} | ||
|
||
boolean isSecretCorrect(String secret) throws Exception { | ||
Base64URL encodedSecret = Base64URL.encode(secret); | ||
|
||
JWK key = new OctetSequenceKey.Builder(encodedSecret).build(); | ||
JWKKey jwkKey = JWKKeyFactory.from(key); | ||
|
||
return jws.verify(jwkKey, verificationInfo); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/blackberry/jwteditor/operations/weak/WeakSecrets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2024 Dolph Flynn | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.blackberry.jwteditor.operations.weak; | ||
|
||
import java.io.*; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
// Secret Source: https://github.com/wallarm/jwt-secrets | ||
class WeakSecrets { | ||
private static final int TOTAL_NUMBER_OF_SECRETS = 103975; | ||
|
||
private final BufferedReader bufferedReader; | ||
private final Object lock; | ||
private final AtomicInteger counter; | ||
|
||
WeakSecrets() { | ||
InputStream inputStream = this.getClass().getResourceAsStream("/jwt.secrets.list.txt"); | ||
|
||
this.bufferedReader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); | ||
this.lock = new Object(); | ||
this.counter = new AtomicInteger(); | ||
} | ||
|
||
String next() { | ||
synchronized (lock) { | ||
counter.incrementAndGet(); | ||
|
||
try { | ||
return bufferedReader.readLine(); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
} | ||
|
||
int progress() { | ||
double progress = (100.0 * counter.get()) / TOTAL_NUMBER_OF_SECRETS; | ||
return (int) progress; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/blackberry/jwteditor/operations/weak/WeakSecretsFinderModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2024 Dolph Flynn | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.blackberry.jwteditor.operations.weak; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static com.blackberry.jwteditor.operations.weak.WeakSecretsFinderStatus.RUNNING; | ||
|
||
public class WeakSecretsFinderModel { | ||
private final AtomicInteger percentageComplete; | ||
private final AtomicReference<WeakSecretsFinderStatus> status; | ||
private final AtomicReference<String> secret; | ||
|
||
public WeakSecretsFinderModel() { | ||
this.percentageComplete = new AtomicInteger(); | ||
this.status = new AtomicReference<>(RUNNING); | ||
this.secret = new AtomicReference<>(); | ||
} | ||
|
||
void setProgress(int percentageComplete) { | ||
this.percentageComplete.set(percentageComplete); | ||
} | ||
|
||
public int progress() { | ||
return percentageComplete.get(); | ||
} | ||
|
||
void setSecret(String secret) { | ||
this.secret.set(secret); | ||
} | ||
|
||
public String secret() { | ||
return secret.get(); | ||
} | ||
|
||
public void setStatus(WeakSecretsFinderStatus status) { | ||
this.status.set(status); | ||
} | ||
|
||
public WeakSecretsFinderStatus status() { | ||
return status.get(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/blackberry/jwteditor/operations/weak/WeakSecretsFinderStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2025 Dolph Flynn | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.blackberry.jwteditor.operations.weak; | ||
|
||
public enum WeakSecretsFinderStatus { | ||
RUNNING, SUCCESS, CANCELLED, FAILED | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.