Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Update block scan
Browse files Browse the repository at this point in the history
  • Loading branch information
minhkhuong2404 committed Oct 27, 2020
1 parent f7db93a commit 1c38a54
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 30 deletions.
Binary file modified .DS_Store
Binary file not shown.
Empty file modified html/index.php
100644 → 100755
Empty file.
Empty file modified html/info.php
100644 → 100755
Empty file.
Empty file modified html/login.php
100644 → 100755
Empty file.
Empty file modified html/logout.php
100644 → 100755
Empty file.
Empty file modified html/register.php
100644 → 100755
Empty file.
Empty file modified html/require_login.php
100644 → 100755
Empty file.
Empty file modified html/special/code01542.php
100644 → 100755
Empty file.
Empty file modified html/welcome.php
100644 → 100755
Empty file.
18 changes: 15 additions & 3 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@
<groupId>com.tvhoang</groupId>
<artifactId>SIEM-Neptune</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>13</source>
<target>13</target>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>15</java.version>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>

<dependencies>
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/CEP/PortScanDetector/BlockPortScan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package CEP.PortScanDetector;

import Utilities.*;
import com.espertech.esper.compiler.client.*;
import com.espertech.esper.runtime.client.*;
import org.pcap4j.packet.namednumber.*;

import java.io.*;
import java.net.*;

public class BlockPortScan {
public BlockPortScan(int alertPeriod, int interval) throws EPCompileException, EPDeployException, IOException, EPCompileException, EPDeployException {

new EPAdapter().execute("add-horizontal-port-scan", "insert into BlockPortScanAlert\n" +
"select hostPort from HorizontalPortScanAlert#expr(oldest_timestamp > newest_timestamp - 1000)");

new EPAdapter().execute("add-vertical-port-scan", "insert into BlockPortScanAlert\n" +
"select hostAddr from VerticalPortScanAlert#expr(oldest_timestamp > newest_timestamp - 1000)");

new EPAdapter().execute("alert-block-port-scan", "select * from BlockPortScanAlert#time( " + alertPeriod + " seconds)#expr(oldest_timestamp > newest_timestamp - 1000)\n" +
"where exists(select * from HorizontalPortScanAlert)\n" +
"and exists(select * from VerticalPortScanAlert)\n"
).addListener((newData, __, ___, ____) -> System.out.println("Alert a block scan:"
+ " is happened!"));
// new EPAdapter().execute("alert-block-port-scan", "on BlockPortScanAlert delete from BlockPortScanAlert\n");
}
}
32 changes: 32 additions & 0 deletions src/main/java/CEP/PortScanDetector/BlockPortScanAlert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package CEP.PortScanDetector;

import org.pcap4j.packet.namednumber.*;

import java.net.*;

public class BlockPortScanAlert {
InetAddress hostAddr;
Port hostPort;
Long timestamp;

public BlockPortScanAlert(InetAddress hostAddr) {
this.hostAddr = hostAddr;
}

public BlockPortScanAlert(Port hostPort) {
this.hostPort = hostPort;
}

public BlockPortScanAlert(Long timestamp) {
this.timestamp = timestamp;
}

public InetAddress getHostAddr() {
return hostAddr;
}
public Port getHostPort() {
return hostPort;
}
public Long getTimestamp() { return timestamp; }

}
Empty file modified src/main/java/CEP/WebserverMonitor/ApacheAccessLogCEP.java
100644 → 100755
Empty file.
Empty file modified src/main/java/CEP/WebserverMonitor/ApacheAccessLogEvent.java
100644 → 100755
Empty file.
51 changes: 24 additions & 27 deletions src/main/java/CEP/WebserverMonitor/Monitor.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.ArrayList;

public class Monitor {
private static String fileErrorlog = "/var/log/apache2/error.log";
private static String fileErrorlog = "/var/log/apache2/error.log";
private static String fileAccesslog = "/var/log/apache2/access.log";
private static ArrayList<String> allLines = new ArrayList<String>();
private static int currentLine = 0;
Expand All @@ -27,6 +27,7 @@ public static void main (String [] args) throws Exception {
// new NeptuneErrorLogCEP(10,3);
new VerticalPortScan(20, 100);
new HorizontalPortScan(60, 2, 10); // set to 2 to test, use 5 or more in production
new BlockPortScan(20,10);

PcapNetworkInterface device = getNetworkDevice();
System.out.println(device.getName() + "(" + device.getDescription() + ")");
Expand All @@ -46,36 +47,32 @@ public static void main (String [] args) throws Exception {
}

// Tell the handle to loop using the listener we created
try {
handle.loop(maxPackets, (PacketListener) packet -> {
try {
IpV4Packet ipV4Packet = packet.get(IpV4Packet.class);
TcpPacket tcpPacket = ipV4Packet.get(TcpPacket.class);
int port = tcpPacket.getHeader().getSrcPort().valueAsInt();
TCPPacket evt = new TCPPacket(
ipV4Packet.getHeader(),
tcpPacket.getHeader()
);
if (port != 443 && port != 80 && port != 62078) {
sendEvent(evt, TCPPacket.class.getSimpleName());
}
} catch (Exception ignored) {

handle.loop(maxPackets, (PacketListener) packet -> {

try {
IpV4Packet ipV4Packet = packet.get(IpV4Packet.class);
TcpPacket tcpPacket = ipV4Packet.get(TcpPacket.class);
int port = tcpPacket.getHeader().getSrcPort().valueAsInt();
TCPPacket evt = new TCPPacket(
ipV4Packet.getHeader(),
tcpPacket.getHeader()
);
if (port != 443 && port != 80 && port != 62078) {
sendEvent(evt, TCPPacket.class.getSimpleName());
}
} catch (Exception ignored) {

ApacheAccessLogEvent aal = null;
try {
aal = ApacheAccessLogEvent.nextEvent();
} catch (IOException e) {
e.printStackTrace();
}
if (aal != null) sendEvent(aal, "AAL_Event");
}

});
ApacheAccessLogEvent aal = null;
try {
aal = ApacheAccessLogEvent.nextEvent();
} catch (IOException e) {
e.printStackTrace();
}
if (aal != null) sendEvent(aal, "AAL_Event");

} catch (InterruptedException e) {
e.printStackTrace();
}
});

// Cleanup when complete
handle.close();
Expand Down
Empty file modified src/main/java/CEP/WebserverMonitor/NeptuneErrorLogCEP.java
100644 → 100755
Empty file.
Empty file modified src/main/java/CEP/WebserverMonitor/NeptuneErrorLogEvent.java
100644 → 100755
Empty file.
Empty file modified src/main/java/Dashboard/CustomOutputStream.java
100644 → 100755
Empty file.
Empty file modified src/main/java/Dashboard/Dashboard.java
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions src/main/java/Utilities/EPAdapter.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static void setup() {
configuration.getCommon().addEventType("TCPPacket", TCPPacket.class);
configuration.getCommon().addEventType("VerticalPortScanAlert",VerticalPortScanAlert.class);
configuration.getCommon().addEventType("HorizontalPortScanAlert",HorizontalPortScanAlert.class);
configuration.getCommon().addEventType("BlockPortScanAlert",BlockPortScanAlert.class);

configuration.getRuntime().getLogging().setEnableExecutionDebug(false);
configuration.getRuntime().getLogging().setEnableTimerDebug(false);
runtime = EPRuntimeProvider.getDefaultRuntime(configuration);
Expand Down
Empty file.
Empty file.

0 comments on commit 1c38a54

Please sign in to comment.