2013-10-20 80 views
0

我來到這裏2個簡單的代碼:在java服務器中的安全風險?

服務器:

package myserver; 

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

class MyServer { 

public static void main(String argv[]) throws Exception { 
    String clientSentence; 
    String capitalizedSentence; 
    ServerSocket welcomeSocket = new ServerSocket(6789); 
    while (true) { 
     Socket connectionSocket = welcomeSocket.accept(); 
     BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); 
     DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); 
     clientSentence = inFromClient.readLine(); 
     System.out.println("Received: " + clientSentence); 
     capitalizedSentence = clientSentence.toUpperCase() + '\n'; 
     outToClient.writeBytes(capitalizedSentence); 
    } 
    } 
} 

客戶:

package myclient; 

import java.lang.*; 
import java.io.*; 
import java.net.*; 
import java.util.Scanner; 

class MyClient { 

public static void main(String argv[]) throws Exception { 
    String sentence; 
    String modifiedSentence; 
    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); 
    Socket clientSocket = new Socket("localhost", 6789); 
    DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); 
    BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); 
    sentence = inFromUser.readLine(); 
    outToServer.writeBytes(sentence + '\n'); 
    modifiedSentence = inFromServer.readLine(); 
    System.out.println("FROM SERVER: " + modifiedSentence); 
    clientSocket.close(); 
} 
} 

現在....如果我開這臺服務器公衆,是否有任何安全隱患發送修改後的軟件包並進入系統? (Server使用一些Linux DIST) 或者僅是可以發送簡單的字符串?

回答

0

這段代碼將只讀取的字節序列,並且將其打印出來(和發送響應)。據我所知,這完全沒有風險。

0

有人可以通過不換行它發送大量數據崩潰的Java進程。取決於你有多少內存給JVM,這可能會影響到正在運行的程序的服務器。