-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
951 additions
and
766 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2019 Jason Gillam | ||
* | ||
* 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.professionallyevil.bc; | ||
|
||
import burp.IHttpRequestResponse; | ||
|
||
public class JSONParamInstance extends ParamInstance { | ||
|
||
private String paramName; | ||
private String paramValue; | ||
private ParamInstance parent; | ||
static final byte TYPE = 64; | ||
|
||
public JSONParamInstance(String name, String value, ParamInstance parent) { | ||
super(null, parent.getMessage()); | ||
this.paramName = name; | ||
String[] parts = value.split("\n\r"); | ||
this.paramValue = String.join(" ", parts); | ||
this.parent = parent; | ||
} | ||
|
||
@Override | ||
public byte getType() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return paramName; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return paramValue; | ||
} | ||
|
||
@Override | ||
public int getNameStart() { | ||
return parent.getNameStart(); | ||
} | ||
|
||
@Override | ||
public int getNameEnd() { | ||
return parent.getNameEnd(); | ||
} | ||
|
||
@Override | ||
public int getValueStart() { | ||
return parent.getValueStart(); | ||
} | ||
|
||
@Override | ||
public int getValueEnd() { | ||
return parent.getValueEnd(); | ||
} | ||
|
||
@Override | ||
public IHttpRequestResponse getMessage() { | ||
return parent.getMessage(); | ||
} | ||
|
||
} |
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,108 @@ | ||
/* | ||
* Copyright (c) 2019 Jason Gillam | ||
* | ||
* 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.professionallyevil.bc; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
class JSONParamParser { | ||
|
||
enum JSONValue { | ||
OBJECT("^\\{(\\s*\"([^\\\"^\\\\^\\p{Cntrl}]+)\"\\s*:(\\s*((-?\\d+)|(\"[^\\\"^\\\\^\\p{Cntrl}]*\")|true|false|null|\\[.*\\]|\\{.*\\})\\s*))(,\\s*\"([^\\\"^\\\\^\\p{Cntrl}]*)\"\\s*:(\\s*((\\-?d+)|(\"[^\\\"^\\\\^\\p{Cntrl}]*\")|true|false|null|\\[.*\\]|\\{.*\\})\\s*))*\\}$"); | ||
|
||
|
||
private String regex; | ||
private Pattern pattern; | ||
|
||
JSONValue(String regex) { | ||
this.regex = regex; | ||
this.pattern = Pattern.compile(regex); | ||
} | ||
|
||
String getRegex(){ | ||
return regex; | ||
} | ||
|
||
Pattern getPattern() { | ||
return pattern; | ||
} | ||
} | ||
|
||
private static void parseValue(List<JSONParamInstance> paramList, ParamInstance parent, String key, Object value) { | ||
if (value instanceof JSONObject) { | ||
parseObject((JSONObject)value, paramList, parent); | ||
paramList.add(new JSONParamInstance(key, value.toString(), parent)); | ||
} else if (value instanceof JSONArray) { | ||
parseArray((JSONArray)value, key, paramList, parent); | ||
paramList.add(new JSONParamInstance(key, value.toString(), parent)); | ||
} else if (value instanceof String) { | ||
paramList.add(new JSONParamInstance(key, (String)value, parent)); | ||
} else if (value instanceof Integer) { | ||
try { | ||
paramList.add(new JSONParamInstance(key, Integer.toString((Integer)value), parent)); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} else if (value instanceof Boolean) { | ||
paramList.add(new JSONParamInstance(key, Boolean.toString((Boolean)value), parent)); | ||
} | ||
} | ||
|
||
private static void parseObject(JSONObject jsonObject, List<JSONParamInstance> paramList, ParamInstance parent) { | ||
for(String key: jsonObject.keySet()) { | ||
Object value = jsonObject.get(key); | ||
parseValue(paramList, parent, key, value); | ||
} | ||
} | ||
|
||
private static void parseArray(JSONArray array, String key, List<JSONParamInstance> paramList, ParamInstance parent) { | ||
for(Object value: array) { | ||
parseValue(paramList, parent, key, value); | ||
} | ||
} | ||
|
||
static List<JSONParamInstance> parseObjectString(String jsonString, ParamInstance parent){ | ||
List<JSONParamInstance> paramList = new ArrayList<>(); | ||
|
||
try { | ||
JSONObject jo = new JSONObject(jsonString); | ||
parseObject(jo, paramList, parent); | ||
} catch (JSONException e) { | ||
// skip | ||
} | ||
|
||
return paramList; | ||
|
||
} | ||
|
||
// public static void main(String[] args) { | ||
// parseObjectString("{\"foo\":\"bar\"}"); | ||
// parseObjectString("{\"foo\":-42}"); | ||
// parseObjectString("{\"foo\":[\"foo bar\", -42]}"); | ||
// parseObjectString("{\"foo\": true}"); | ||
// parseObjectString("{\"foo\": null}"); | ||
// parseObjectString("{\"foo\": {\"bar\": \"foo2\"}}"); | ||
// parseObjectString("{\"foo\":\"bar\" ,\"foo2\":\"bar2\",\"foo3\":\"bar3\",\"foo4\":\"bar4\"}"); | ||
// parseObjectString("not a json object"); | ||
// } | ||
|
||
} |
Oops, something went wrong.