How to detect snort alerts with Java? - java

Is there any Java API or Class that can be used in a Java code allowing to detect in real time Snort alerts without using Snort log files ? In other words, does Snort can send alerts which can be recieved by a server process rather than recording them in a log file ?

You can configure the syslog forwarding options.

On Unix
If you are on Unix you can use unix-sockets to send the snort alert to. Then you can either use the Java Native Interface (JNI) to create your own api for unix sockets in java. Or use a preexisting one like junixsocket.
Of course you also need to read the data snort sent to you. This would efficiently also be done with the JNI.
But in the end the whole process of sending data from c-structs in a c program to a java client is never really trivial.

Related

How to capture Network traffic using Java and get file type without using Proxy?

I need to capture network traffic using Java and get the File type.
eg: IF it is xmlHTTPrequest the File type is XHR.
Depends on what you actually want to do. But if you want a whole machine network sniffer (something like what whireshark is doing), libpcap or winpcap is probably what you're searching for. There is also a java library which handles the low level stuff: pcap4j

How to capture all Network traffics(http\https) of a Web Application using Java in Eclipse IDE?

I want to record a Web Application traffic using Java code in the back-end and replay it after recording.
Is there any way to record Web Application traffic like we do in Load-runner using Java code?
Although it doesn't automate everything or is not specific to Java, you can use Wireshark to retrieve HTTP/HTTPS requests and export them ( https://www.wireshark.org/docs/wsug_html_chunked/ChIOExportSection.html ). Some other tools such as PlayCap allow to directly playback the wireshark capture.
Or you can write some Java code that mimics the requests and even load the wireshark capture file to send logged requests with any HTTP-able library.
You can also use directly pcap to retrieve packages (or the jpcap variant, written in Java, that may have some reusable code for your use-case), and try the similar approach to playback the capture.

NPAPI alternative for live file editing

I currently have a web app, which allows users to download files to their computers, edit them with their own editors and automatically sends them back to server upon saving and sends some extra data when closing the file. It utilises a Java applet to handle the client side processing which includes
file download,
sending request to lock the file,
opening the file in default desktop app,
watching for changes,
file upload back to server,
sending request to unlock the file upon closing.
Since chrome will stop supporting NPAPI in September, I need to create an alternative while maintaining the funcionality. I wasn't able to find many alternatives. The only thing I found that would be able to achieve at least something is Native Messaging, but still I can't imagine how could I use it to emulate the behavior of the java applet.
So the question is - what are possible alternatives I can use to replace the applet?
Looking at your comments, I'm going to break down your question into 2 basic questions:
How does native messaging work?
How do I download a file and launch it in an application, etc, in a windows application?
Native messaging essentially allows you to launch an application (which must be registered when installed to allow it to work this way) which can communicate with your extension. You can then talk back and forth with your native messaging application from your extension (or from the web page proxying requests through your extension); your messages have to be essentially json formatted (on the javascript side you provide json encodable values and on the executable side you have to read that from stdin and parse it, then write to stdout the result; there are also 2 byte integers preceding each message indicating the length of the message).
basically once you have communications, you just have to make your application be able to respond to a message that tells it to download the file by doing so, etc. This is something you'll have to figure out how to do -- you could do it with a python script, a windows exe, a .net app, or whatever you want that can be executed, but each has advantages and disadvantages.
Hope that helps

How can Java Applications communicate with MATLAB

I have some mex files that urgently need to be called via MATLAB, there is currently no way around. However, I really despise MATLAB's GUI (in)possibilities and would like to create some e.g. JavaFX Apps.
My question: how can a Java app's communicate with a running MATLAB instance?
I know that you can include Java objects into MATLAB, however I would prefere to have a standalone Java app.
Java can execute commands via command line for example:
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
So it is possible to execute a MATLAB script via command line in Java.
In MATLAB it is possible to write files with any data needed. I don't remember the exact way you may do this. http://www.mathworks.com/help/matlab/ref/fprintf.html gives an example:
x = 0:.1:1;
A = [x; exp(x)];
fileID = fopen('exp.txt','w');
fprintf(fileID,'%6s %12s\n','x','exp(x)');
fprintf(fileID,'%6.2f %12.8f\n',A);
fclose(fileID);
It is some kind of a workaround but it should work and it is not really hard to implement.
Update.
If Matlab is already running and you want to communicate with it in another application (Java), it may be done using a network connection through the localhost. Matlab may listen to some predefined port (for code example see http://www.mathworks.com/matlabcentral/fileexchange/11802-matlab-tcp-ip-code-example ) and do some action when a "start" trigger is sent via Java (or even some data along with the trigger). In Java you may use the Socket class (some code example may be found here http://www.javaworld.com/article/2077322/core-java/core-java-sockets-programming-in-java-a-tutorial.html ).
Also it may be done writing data into files. For example, Java adds some command to some file with predefined name (command.txt). Matlab scans this file in a loop and when something is found there it starts calculation (and Java application waits for results in some results.txt file).
I would suggest to start a server in Matlab that listens on a specific port to send/receive data to/from a Java client. By using the eval Matlab command you could even invoke scripts/command/etc. remotely controlled by a Java client.
You might want to have a look at this code example.

How can I utilize a Java program from PHP?

Say I have a php application that reads JSON stock data and stores it in MySQL.
Somewhere nearby on the server, I have a compiled Java (or Python, C, etc) executable that can take a set of numbers and return a set of analytics. Is there a way to call and receive data from that program from PHP without using an intermediary text file (or something similar?)
I see theres http://php-java-bridge.sourceforge.net/pjb/, but would it be necessary to run a Java server like Tomcat as well?
Technically you could use the exec function of PHP to call "java -jar YourExecutableJar.jar" and process the return value.
http://php.net/manual/en/function.exec.php
One "general" way is to connect them through sockets -> i.e have a listener at a port in Java that takes the set of numbers and returns the set of analytics back to the socket. The big advantage is that this is universal and can be done between any languages and between remote servers/clients as well.
Technically, any program runninng in background and accepting connections is server. Tomcat is only an example, used in numerous tutorial because it is relatively-light-and-easy-to-learn.
You can use Jetty: Shortest code to start embedded Jetty server
You can use JSON format as communication protocol (GSON library on Java side, on PHP side you already use JSON).

Categories

Resources