Skip to content

Commit

Permalink
fix Linklocal
Browse files Browse the repository at this point in the history
  • Loading branch information
isayan committed Apr 19, 2020
1 parent 6a59e7d commit ef2ab0b
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 55 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<version>1.7</version>
<packaging>jar</packaging>
<properties>
<releaseVersion>${project.version}.0.0</releaseVersion>
<releaseVersion>${project.version}.1.0</releaseVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down Expand Up @@ -98,12 +98,12 @@
<dependency>
<groupId>burp</groupId>
<artifactId>BurpExtlib</artifactId>
<version>2.0.2</version>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
78 changes: 63 additions & 15 deletions src/main/java/extend/util/external/JsonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
Expand All @@ -25,14 +25,23 @@
*/
public class JsonUtil {

public static boolean validJson(String jsonElementString) {
try {
JsonParser.parseString(jsonElementString);
return true;
}
catch (JsonSyntaxException ex) {
return false;
}
}

public static String stringify(JsonElement jsonElement) {
return prettyJson(jsonElement, false);
}

public static JsonElement parse(String jsonElementString) throws JsonSyntaxException {
JsonParser jp = new JsonParser();
return jp.parse(jsonElementString);
}
return JsonParser.parseString(jsonElementString);
}

public static String prettyJson(String jsonString) throws IOException {
return prettyJson(jsonString, true);
Expand Down Expand Up @@ -99,21 +108,29 @@ private static void toJsonTreeNode(JsonElement jsonElement, DefaultMutableTreeNo

public static boolean isJson(String jsonString) {
Matcher m = JSON_TYPE.matcher(jsonString);
try {
if (m.lookingAt()) {
JsonUtil.prettyJson(jsonString, false);
return true;
} else {
return false;
}
} catch (JsonSyntaxException ex) {
if (m.lookingAt()) {
return JsonUtil.validJson(jsonString);
} else {
return false;
}
}
}

private static final Map<Class<?>, Object> typeAdapterMap = new HashMap<>();

public static void registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
typeAdapterMap.put(baseType, typeAdapter);
}

public static void removeTypeHierarchyAdapter(Class<?> baseType) {
typeAdapterMap.remove(baseType);
}

public static void saveToJson(File fo, Object bean, boolean exludeFields) throws IOException {
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
if (exludeFields) {
for (Map.Entry<Class<?>, Object> set : typeAdapterMap.entrySet()) {
gsonBuilder.registerTypeHierarchyAdapter(set.getKey(), set.getValue());
}
if (exludeFields) {
gsonBuilder = gsonBuilder.excludeFieldsWithoutExposeAnnotation();
}
Gson gson = gsonBuilder.create();
Expand All @@ -122,9 +139,40 @@ public static void saveToJson(File fo, Object bean, boolean exludeFields) throws
}

public static <T> T loadFromJson(File fi, Class<T> classOfT, boolean exludeFields) throws IOException {
Gson gson = new GsonBuilder().serializeNulls().excludeFieldsWithoutExposeAnnotation().create();
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
for (Map.Entry<Class<?>, Object> set : typeAdapterMap.entrySet()) {
gsonBuilder.registerTypeHierarchyAdapter(set.getKey(), set.getValue());
}
if (exludeFields) {
gsonBuilder = gsonBuilder.excludeFieldsWithoutExposeAnnotation();
}
Gson gson = gsonBuilder.create();
String jsonString = Util.decodeMessage(Util.bytesFromFile(fi), StandardCharsets.UTF_8);
return gson.fromJson(jsonString, classOfT);
}

public static String jsonToString(Object bean, boolean exludeFields) {
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
for (Map.Entry<Class<?>, Object> set : typeAdapterMap.entrySet()) {
gsonBuilder.registerTypeHierarchyAdapter(set.getKey(), set.getValue());
}
if (exludeFields) {
gsonBuilder = gsonBuilder.excludeFieldsWithoutExposeAnnotation();
}
Gson gson = gsonBuilder.create();
return gson.toJson(bean);
}

public static <T> T jsonFromString(String jsonString, Class<T> classOfT, boolean exludeFields) {
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
for (Map.Entry<Class<?>, Object> set : typeAdapterMap.entrySet()) {
gsonBuilder.registerTypeHierarchyAdapter(set.getKey(), set.getValue());
}
if (exludeFields) {
gsonBuilder = gsonBuilder.excludeFieldsWithoutExposeAnnotation();
}
Gson gson = gsonBuilder.create();
return gson.fromJson(jsonString, classOfT);
}

}
3 changes: 3 additions & 0 deletions src/main/java/passive/signature/BigIPCookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ protected static List<BigIPIssueItem> parseDecryptList(boolean messageIsRequest,
if (cookieIP.isPrivateIP()) {
cookieIP.setServerity(MatchItem.Severity.LOW);
cookieIP.setConfidence(MatchItem.Confidence.CERTAIN);
} else if (cookieIP.isLinkLocalIP()) {
cookieIP.setServerity(MatchItem.Severity.LOW);
cookieIP.setConfidence(MatchItem.Confidence.CERTAIN);
} else {
cookieIP.setServerity(MatchItem.Severity.INFORMATION);
cookieIP.setConfidence(MatchItem.Confidence.FIRM);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/passive/signature/BigIPCookieTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class BigIPCookieTab extends javax.swing.JPanel implements ITab {

private final String PRIVATE_IP_INFO = "<html><ul><li>PrivateIP: %s</li></ul></html>";
private final String PRIVATE_IP_INFO = "<html><ul><li>PrivateIP: %s</li><li>LinkLocalIP: %s</li></ul></html>";

/**
* Creates new form BigIpDecryptTab
Expand Down Expand Up @@ -349,7 +349,7 @@ private void btnDecryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
String value = BigIPCookie.decrypt(this.txtEncrypt.getText());
if (value != null) {
try {
this.lblDecryptInfo.setText(String.format(PRIVATE_IP_INFO, IpUtil.isPrivateIP(value)));
this.lblDecryptInfo.setText(String.format(PRIVATE_IP_INFO, IpUtil.isPrivateIP(value), IpUtil.isLinkLocalIP(value)));
this.txtDecrypt.setText(value);
} catch (ParseException ex) {
}
Expand Down
Loading

0 comments on commit ef2ab0b

Please sign in to comment.