現在、作業セキュリティプロジェクト用の単純なポートスキャナー/パスワードチェッカーの作成に関していくつかの大きな問題が発生しています。
私の基本的な目標は、テキストファイルを開き、ポート21、23、80、502、および8080でスキャンし、返されたhttpステータスをファイル(200、404など)に書き込む簡単なツールを作成することです。
これまで、httpclientを使用してこれを実行しようとしてきましたが、結果は非常に悪くなりました。
私のコードは次のようになります
public static void doHosts() throws Exception{
String filename = "C:\\test.txt";
String ip = "";
String port[] = {"21", "23", "80", "502", "8080"};
FileInputStream fstream = new FileInputStream("c:\\scan.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
while ((ip = br.readLine()) != null) {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 3000;
int timeoutSocket = 5000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpHost targetHost = new HttpHost(ip);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("blah", "blah");
httpclient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), creds);
NegotiateSchemeFactory nsf = new NegotiateSchemeFactory();
httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, nsf);
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
httpclient = wrapClient(httpclient);
HttpGet get;
for (int i = 0; i < port.length; i++) {
get = new HttpGet("http://" + ip + ":" + port[i] + "/");
HttpResponse response = httpclient.execute(get);
try {
BufferedWriter out = new BufferedWriter(new FileWriter("filename", true));
out.write("ip: "+ ip + " : "+port+ " - " + response.getStatusLine().getStatusCode()); //HTTP status returned off request );
} catch (IOException e) {
}
}
}
}
これまでの私の問題は、テキストファイルを開き、1つの悪い結果をヒットし、それをシリアル化せず、例外を除いて死ぬことでした。
例外を除いて続行する方法がわかりません(一部のサイトでは「起動していません」と表示されるため、ポートスキャナーです。
どんな助けでも素晴らしいでしょう、そしておそらく明日約6000IPを手動でチェックすることから何人かの貧しいインターンを救うでしょう。