Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.i2p.hack.scripts;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Properties;
- import java.util.Scanner;
- import java.util.StringTokenizer;
- import net.i2p.hack.scripts.util.SystemCommandExecutor;
- import org.apache.commons.lang3.StringUtils;
- /**
- * Test the hosts in public internet to compare the response with the I2P EEPSITES response.
- * @author Adastra
- * */
- public class OutProxyTester implements Runnable{
- /**
- * The path where the file ""
- * */
- private FileInputStream addressNetDB;
- /**
- * The path of the results.
- * */
- private File storeResultsPath;
- /**
- * Main rutine.
- * */
- public static void main(String ... args) {
- OutProxyTester outproxy = new OutProxyTester();
- outproxy.readAddressesInside();
- if(outproxy.addressNetDB == null) {
- System.out.println("Addresses File Not found, I can't continue...");
- System.exit(0);
- }
- outproxy.readScanningDir();
- outproxy.crawlOutsideServers();
- }
- /**
- * Read the file of addresses corresponding the PCAP file generated and I2P NetDB Service
- * */
- private void readAddressesInside() {
- System.out.println("Read the file of Addresses (Addresses correlated between PCAP file and Local I2P NetDb)...");
- Scanner scanner = new Scanner(System.in);
- String addressesFile = scanner.next();
- System.out.println("Addresses File: "+addressesFile);
- try {
- addressNetDB = new FileInputStream(new File(addressesFile));
- } catch(FileNotFoundException file_ex) {
- file_ex.printStackTrace();
- System.out.println("Exception: "+file_ex.getMessage());
- }
- }
- /**
- * Read the Scanning Directory to store all result files.
- * */
- private void readScanningDir() {
- System.out.println("Enter the Directory to Store Files \n");
- Scanner scanner = new Scanner(System.in);
- String dirStore = scanner.next();
- System.out.println("Dir. to store: "+dirStore);
- this.storeResultsPath = new File(dirStore);
- // /media/Adastra/ScanningResultsI2P
- if(!this.storeResultsPath.exists()) {
- this.storeResultsPath.mkdir();
- }
- }
- /**
- * Crawl every site in the list of IP Addresses.
- * */
- public void crawlOutsideServers() {
- try {
- DataInputStream in = new DataInputStream(addressNetDB);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String outproxySite;
- while ((outproxySite = br.readLine()) != null) {
- Thread crawler = new Thread(this);
- crawler.setName(outproxySite);
- crawler.start();
- }
- in.close();
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Overrided method to execute the current Thread.
- * */
- @Override
- public void run() {
- connectOutSiteWebServer(Thread.currentThread().getName());
- }
- /**
- * Method to perform the request to the web server (if there's one).
- * The response is stored to perform the analisys.
- * */
- private void connectOutSiteWebServer(String outproxySite) {
- HttpURLConnection connection = null;
- try {
- String outproxySiteHttp = "http://"+outproxySite;
- URL rutaPeticion = new URL(outproxySiteHttp);
- Properties sysProps = System.getProperties();
- sysProps.put( "http.proxyHost", "127.0.0.1");
- sysProps.put( "http.proxyPort", "81" );
- connection = (HttpURLConnection)rutaPeticion.openConnection();
- connection.setRequestProperty("Content-type", "html/text");
- connection.connect();
- if(Math.round((connection.getResponseCode()/100)) == 2) {
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String content = "";
- while(br.readLine() != null) {
- content = content+"\n"+br.readLine();
- }
- String iframeName = storeResultsPath+System.getProperty("file.separator")+outproxySite+"_outside.html";
- FileWriter iframeFile = new FileWriter(new File(iframeName));
- BufferedWriter iframeWriter = new BufferedWriter(iframeFile);
- iframeWriter.write(content);
- iframeWriter.close();
- List<String> command = new ArrayList<String>();
- command.add("dig");
- command.add("-x");
- command.add(outproxySite);
- SystemCommandExecutor commandExecutor = new SystemCommandExecutor(command);
- commandExecutor.executeCommand();
- String result = commandExecutor.getStandardOutputFromCommand().toString();
- StringTokenizer stResults = new StringTokenizer(result, "\n");
- while(stResults.hasMoreTokens()) {
- String token = stResults.nextToken();
- if(StringUtils.isNotEmpty(token) && StringUtils.startsWith(token, "REVERSE")) {
- storeInformationReverseDNS(outproxySite+","+token+", "+connection.getLastModified()+"\n\n");
- }
- }
- storeInformationOutproxySite(outproxySiteHttp+","+connection.getResponseCode()+","+connection.getResponseMessage()+","+connection.getHeaderField("Server")+","+connection.getHeaderField("Host")+"\n");
- } else {
- storeFailedOutproxySite(outproxySiteHttp+","+connection.getResponseCode()+","+connection.getResponseMessage()+","+connection.getHeaderField("Server")+","+connection.getHeaderField("Host")+"\n");
- }
- }catch(IOException ioException){
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- connection.disconnect();
- }
- }
- /**
- * Store Banned information about EEPSITES scanned in the network.
- * */
- private void storeInformationOutproxySite(String outproxySite) {
- try {
- FileWriter outproxyFile = new FileWriter(new File(storeResultsPath+System.getProperty("file.separator")+"outproxiesSite.txt"), true);
- BufferedWriter csvWriter = new BufferedWriter(outproxyFile);
- csvWriter.write(outproxySite);
- csvWriter.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- private void storeInformationReverseDNS(String resolvedIP) {
- try {
- FileWriter reverseDNS = new FileWriter(new File(storeResultsPath+System.getProperty("file.separator")+"reverseDNSAddresses.txt"), true);
- BufferedWriter reverseDNSWriter = new BufferedWriter(reverseDNS);
- reverseDNSWriter.write(resolvedIP);
- reverseDNSWriter.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * Store the failed addresses to find EEPSITES.
- * */
- private void storeFailedOutproxySite(String failed) {
- try {
- FileWriter outproxyFailed = new FileWriter(new File(storeResultsPath+System.getProperty("file.separator")+"outproxiesFailed.txt"), true);
- BufferedWriter outproxyFailedWriter = new BufferedWriter(outproxyFailed);
- outproxyFailedWriter.write(failed);
- outproxyFailedWriter.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement