📄 lisyshttpserver.java
字号:
/*================= * Copyright (C) 2001 Hajime Inoue * * Lisys is a program that monitors TCP SYN packets to detect network * traffic anomalies. * * Licensed under the GNU General Public License (GPL), version 2 or * higher. Please see the COPYING and PATENT files included with the * Lisys distribution, which can be found at: * * http://www.cs.unm.edu/~judd/lisys/ * * Also, the current text of the GPL can be found at: * * http://www.gnu.org/copyleft/gpl.html * * Note that Lisys has NO WARRANTY! *=================*/package edu.unm.cs.lisys.net;import edu.unm.cs.lisys.detection.bip.*;import java.io.*;import java.net.Socket;/**========== * HttpServer * A very simple single-threaded http server used with lisys that * * will NOT serve files, only accept posts. This server has just * * enough to make it work. * * Format for POST messages is as follows: * * <machine>?<packet> * * machine is in the traditional form. * packet is in the ugly URL encoded form. * * For example: * * umwert.cs.unm.edu?destination%3d198%2e59%2e151%2e21%2e25%3a+S+ * 1178336325%3a1178336325%280%29+win+32120+%3cmss+1460 * %2csackOK%2ctimestamp+69622901%5b%7ctcp%5d%26source * %3d198%2e59%2e151+14%3a24%3a03%2e900180+198%2e59%2e151 * %2e54%2e3588 * * The above would work if it were all on one line. * * Here are the people who have worked on this code in the order they * have worked on it: * @author Hajime Inoue <hinoue@cs.unm.edu> * @author Justin Balthrop <judd@cs.unm.edu> *==========*/public class LisysHttpServer extends SimpleServer{ public LisysHttpServer() { this(8080); } public LisysHttpServer(int port) { this.port = port; } public void serveConnection (InputStream ins, OutputStream outs) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(ins)); PrintWriter out = new PrintWriter(outs); String request = in.readLine(); // Break into pieces: // This should consist of a GET/POST followed by a very long // string of file information, followed by (possibly) HTTP/1.x. // Strip off GET/POST, since they are equivalent here request = request.substring(request.indexOf(' ')+1); // See if HTTP is there int index = request.indexOf(' '); if ( index != -1 ) request = request.substring(0, index); out.println("<HTML><H4>Result of costimulation request:<P>"); out.println(doCostimulation(request)); out.println("</HTML>"); out.flush(); } public String doCostimulation(String request) throws Exception { // Get host information String host = request.substring(1, request.indexOf('?')).trim(); String hostname = host.substring(0, host.indexOf(':')).trim(); String port = host.substring(host.indexOf(':')+1).trim(); int portnum = Integer.parseInt(port); // Get bip information String bip = URLDecoder.decode(request.substring(request.indexOf('?')+1)); return costimulateDetectionNode(hostname, portnum, bip); } public String costimulateDetectionNode(String host, int port, String bipstring) { try { Socket s = new Socket(host, port); s.setSoTimeout(1000); BufferedReader in = new BufferedReader (new InputStreamReader(s.getInputStream())); PrintWriter out = new PrintWriter(s.getOutputStream()); out.println("COSTIMULATE"); out.println(bipstring); out.flush(); String response = in.readLine(); System.out.println(response); return response; } catch(Exception e) { System.err.println("ERROR IN COSTIMULATION:"); System.err.println(e); return new String("An error occured in contacting the detection node\n" + host + " for the costimulation of " + bipstring + "\n"); } } public static void main(String[] args) { LisysHttpServer server = new LisysHttpServer(); server.start(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -