Skip to content

Commit

Permalink
added force regex to Decode Operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mattebit committed Oct 20, 2023
1 parent 86620b3 commit c0b1344
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ optional tags:
- `decode operations`
- `checks`
- `edits`
- `force regex` set it to true to enable using regex inside decode param in a recursive decode operation. This is useful when you are decoding the body a JWE when it contains a raw JWT not inside a json element.

#### Body section

Expand Down
24 changes: 17 additions & 7 deletions tool/src/main/java/migt/DecodeOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class DecodeOperation extends Module {
public List<DecodeOperation> decodeOperations; // a list of decode operations to execute them recursevly
public List<EditOperation> editOperations; // a list of edit operations
public boolean check_jwt = false;
boolean force_regex = false; // true if you want to decode by using a regex instead of a path in "decode param"
JWT jwt;
String what;

Expand Down Expand Up @@ -98,6 +99,11 @@ public DecodeOperation(JSONObject decode_op_json) throws ParsingException {
jwt.decrypt = true;
jwt.private_key_pem_enc = decode_op_json.getString("jwe encrypt");
jwt.public_key_pem_enc = decode_op_json.getString("jwe decrypt");
case "force regex":
force_regex = decode_op_json.getBoolean("force regex");
break;
default:
throw new ParsingException("Unsupported key \"" + key + "\" in decode operation");
}
}
}
Expand Down Expand Up @@ -466,13 +472,17 @@ public void execute(List<Var> vars) throws ParsingException {
String j = ((DecodeOperation_API) imported_api).getDecodedContent(from);

String found = "";
// https://github.com/json-path/JsonPath
try {
found = JsonPath.read(j, decode_target); // select what to decode
} catch (com.jayway.jsonpath.PathNotFoundException e) {
applicable = false;
result = false;
return;
if (!force_regex) {
// https://github.com/json-path/JsonPath
try {
found = JsonPath.read(j, decode_target); // select what to decode
} catch (com.jayway.jsonpath.PathNotFoundException e) {
applicable = false;
result = false;
return;
}
} else {
found = j;
}
decoded_content = decode(encodings, found, helpers);
break;
Expand Down

0 comments on commit c0b1344

Please sign in to comment.