Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/main/java/org/koreops/tauro/cli/TauroMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import org.koreops.tauro.cli.authtrial.threads.FormAuthTrial;
import org.koreops.tauro.cli.dao.UpdaterDao;
import org.koreops.tauro.cli.opts.processor.CliOptsProcessor;
import org.koreops.tauro.core.db.DbConnEngine;
import org.koreops.tauro.core.loggers.Logger;
import org.koreops.tauro.core.process.ProcessManager;
import org.koreops.tauro.core.process.status.reporting.Mailer;

import java.net.UnknownHostException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -153,7 +155,9 @@ public static void main(String[] args) throws Exception {
Logger.info("Starting new batch: ", true);
List<String> hostsList = Arrays.asList(hosts);
mainObject = new TauroMain(hostsList, port);
mainObject.scanAndAttackHosts();
Connection connection = DbConnEngine.getConnection();

mainObject.scanAndAttackHosts(connection);
} else {
Logger.error("No hosts found to scan/attack.", true);
}
Expand All @@ -170,7 +174,7 @@ public static void main(String[] args) throws Exception {
}
}

private void scanAndAttackHosts() throws InterruptedException {
private void scanAndAttackHosts(Connection connection) throws InterruptedException {
List<String> hosts = generateHosts(this.hosts, exclusions);

System.out.println(hosts.size());
Expand All @@ -186,25 +190,27 @@ private void scanAndAttackHosts() throws InterruptedException {
checkedHosts.add(host);
i++;
if (i >= BATCH_SIZE) {
startCracking(futures, checkedHosts);
startCracking(futures, checkedHosts, connection);
futures = new ArrayList<>();
checkedHosts = new ArrayList<>();
i = 0;
}
}

startCracking(futures, checkedHosts);
startCracking(futures, checkedHosts, connection);

Logger.info("All batches done.", true);
}

private void startCracking(List<Future<Host>> futures, List<String> checkedHosts) throws InterruptedException {
private void startCracking(List<Future<Host>> futures, List<String> checkedHosts, Connection connection) throws InterruptedException {
int done = 0;

Thread.sleep(2000);
List<String> doneHosts = new ArrayList<>();
List<Future<?>> attackFutures = new ArrayList<>();

UpdaterDao updaterDao = new UpdaterDao(connection);

while (true) {
if (done == futures.size()) {
break;
Expand All @@ -229,9 +235,9 @@ private void startCracking(List<Future<Host>> futures, List<String> checkedHosts

Thread hostHandler;
if (!host.isFormAuth()) {
hostHandler = new DefaultAuthTrial(host.getIp(), port);
hostHandler = new DefaultAuthTrial(host.getIp(), port, updaterDao);
} else {
hostHandler = new FormAuthTrial(host.getIp(), port);
hostHandler = new FormAuthTrial(host.getIp(), port, updaterDao);
}
attackFutures.add(attackExecutorService.submit(hostHandler));
doneHosts.add(host.getIp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.http.impl.client.HttpClients;
import org.koreops.net.def.beans.AuthCrackParams;
import org.koreops.net.def.beans.Credentials;
import org.koreops.tauro.cli.dao.UpdaterDao;
import org.koreops.tauro.cli.scraper.AbstractScraper;
import org.koreops.tauro.cli.scraper.basicauth.BinatoneScraper;
import org.koreops.tauro.cli.scraper.basicauth.CoshipScraper;
Expand All @@ -47,20 +48,23 @@
*/
public class DefaultAuthTrial extends AbstractAuthTrial {

private final UpdaterDao updaterDao;

/**
* Constructor for the Http Basic Auth Default Login trial.
*
* @param host The host that is being attacked
* @param port The port on which the HTTP server is running
* @param updaterDao The object responsible for Data Layer updates
*/
public DefaultAuthTrial(String host, String port) {
public DefaultAuthTrial(String host, String port, UpdaterDao updaterDao) {
super();
this.host = host;
if (port != null) {
this.port = Integer.valueOf(port);
} else {
this.port = 80;
}
this.updaterDao = updaterDao;
}

@Override
Expand Down Expand Up @@ -132,56 +136,56 @@ protected void logWirelessStation(String hostUrl, AuthCrackParams params) {
boolean success;

System.out.println("Trying Binatone Scraper.");
scraper = new BinatoneScraper(host, hostUrl, params);
scraper = new BinatoneScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
}

System.out.println("Trying DLink Scraper.");
scraper = new DLinkScraper(host, hostUrl, params);
scraper = new DLinkScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
}

System.out.println("Trying New iBall Baton Scraper.");
scraper = new NewIBallBatonScraper(host, hostUrl, params);
scraper = new NewIBallBatonScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
}

System.out.println("Trying Digiflip Scraper.");
scraper = new DigiflipScraper(host, hostUrl, params);
scraper = new DigiflipScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
}

System.out.println("Trying New TPLink Scraper.");
scraper = new NewTpLinkScraper(host, hostUrl, params);
scraper = new NewTpLinkScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
}

System.out.println("Trying Old TPLink Scraper.");
scraper = new TpLinkScraper(host, hostUrl, params);
scraper = new TpLinkScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
}

System.out.println("Trying COSHIP Scraper.");
scraper = new CoshipScraper(host, hostUrl, params);
scraper = new CoshipScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
}

System.out.println("Trying iBall iB-WRX300N Scraper.");
scraper = new IBallWrx300NScraper(host, hostUrl, params);
scraper = new IBallWrx300NScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jsoup.select.Elements;
import org.koreops.net.def.beans.AuthCrackParams;
import org.koreops.net.def.beans.Credentials;
import org.koreops.tauro.cli.dao.UpdaterDao;
import org.koreops.tauro.cli.scraper.AbstractScraper;
import org.koreops.tauro.cli.scraper.formauth.ActBeamScraper;
import org.koreops.tauro.core.loggers.Logger;
Expand All @@ -40,14 +41,15 @@
public class FormAuthTrial extends AbstractAuthTrial {

private final String hostUrl;
private final UpdaterDao updaterDao;

/**
* Constructor for the Form Based Auth Default Login trial.
*
* @param host The host that is being attacked
* @param port The port on which the HTTP server is running
* @param updaterDao The object responsible for Data Layer updates
*/
public FormAuthTrial(String host, String port) {
public FormAuthTrial(String host, String port, UpdaterDao updaterDao) {
super();
this.host = host;
if (port != null) {
Expand All @@ -56,6 +58,7 @@ public FormAuthTrial(String host, String port) {
this.port = 80;
}
hostUrl = this.forgeUrl("http://", this.host, this.port, "/");
this.updaterDao = updaterDao;
}

@Override
Expand Down Expand Up @@ -172,7 +175,7 @@ protected void logWirelessStation(String hostUrl, AuthCrackParams params) {
boolean success;

System.out.println("Trying ActBeam Scraper.");
scraper = new ActBeamScraper(host, hostUrl, params);
scraper = new ActBeamScraper(host, hostUrl, params, updaterDao);
success = scraper.scrape();
if (success) {
return;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/koreops/tauro/cli/dao/UpdaterDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

package org.koreops.tauro.cli.dao;

import org.koreops.tauro.core.db.DbConnEngine;
import org.koreops.tauro.core.exceptions.DbDriverException;
import org.koreops.tauro.core.loggers.Logger;

import java.sql.Connection;
Expand All @@ -32,19 +30,21 @@
*/
public class UpdaterDao {
private static String isp;
private final Connection conn;

public UpdaterDao(Connection conn) {
this.conn = conn;
}

/**
* Saves scraped Wifi station to the database.
*
* @param wifiData A HashMap containing the Wifi Data (BSSID, SSID, Encryption and Key)
* @param host The Host for which the data is being saved (Will be used for logging purposes)
* @throws DbDriverException In case of a JDBC Driver related problem (unlikely to happen).
*/
public static synchronized void saveStation(Map<String, String> wifiData, String host) throws DbDriverException {
public synchronized void saveStation(Map<String, String> wifiData, String host) {
try {
boolean stationExists;
Connection conn;
conn = DbConnEngine.getConnection();
String sql;
sql = "Select * from WirelessStations where lower(BSSID) = lower(?) and SSID = ?";
PreparedStatement stmt = conn.prepareStatement(sql);
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/org/koreops/tauro/cli/scraper/AbstractScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;

import org.koreops.net.def.beans.AuthCrackParams;
import org.koreops.net.utils.ReachabilityUtil;
import org.koreops.tauro.core.exceptions.DbDriverException;
import org.koreops.tauro.core.loggers.Logger;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -90,13 +87,7 @@ public AbstractScraper(String host, String hostUrl, AuthCrackParams params) {
public boolean scrape() {
while (true) {
if (ReachabilityUtil.isReachable()) {
try {
return this.scrapeAndLog();
} catch (DbDriverException ex) {
// Well, we can't go on now, can we?
Logger.error("Database Driver issue. Exiting...");
System.exit(255);
}
return this.scrapeAndLog();
} else {
try {
Thread.sleep(1000);
Expand All @@ -107,5 +98,5 @@ public boolean scrape() {
}
}

public abstract boolean scrapeAndLog() throws DbDriverException;
public abstract boolean scrapeAndLog();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.koreops.tauro.cli.scraper;

import org.koreops.net.def.beans.AuthCrackParams;
import org.koreops.tauro.cli.dao.UpdaterDao;

public abstract class AbstractScrapperAndSaver extends AbstractScraper {
Comment thread
sumitsarkar marked this conversation as resolved.
Outdated

protected final UpdaterDao updaterDao;

/**
* AbstractScraper Constructor.
*
* @param host The host that is to be attacked
* @param hostUrl The complete Url to the host's webpage
* @param params The Authentication Cracking parameters (Credentials and other data)
* @param updaterDao The DAO class that does the job of saving the scraped data
*/
public AbstractScrapperAndSaver(String host, String hostUrl, AuthCrackParams params, UpdaterDao updaterDao) {
super(host, hostUrl, params);
this.updaterDao = updaterDao;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import org.koreops.net.def.beans.AuthCrackParams;
import org.koreops.tauro.cli.authtrial.threads.DefaultAuthTrial;
import org.koreops.tauro.cli.dao.UpdaterDao;
import org.koreops.tauro.cli.scraper.AbstractScraper;
import org.koreops.tauro.cli.scraper.AbstractScrapperAndSaver;
import org.koreops.tauro.cli.scraper.exception.WirelessDisabledException;
import org.koreops.tauro.core.exceptions.DbDriverException;
import org.koreops.tauro.core.loggers.Logger;

import java.io.IOException;
Expand All @@ -39,14 +38,13 @@
* Scraper module for Binatone routers.
* @author Sudipto Sarkar (k0r0pt) (sudiptosarkar@visioplanet.org).
*/
public class BinatoneScraper extends AbstractScraper {

public BinatoneScraper(String host, String hostUrl, AuthCrackParams params) {
super(host, hostUrl, params);
public class BinatoneScraper extends AbstractScrapperAndSaver {
public BinatoneScraper(String host, String hostUrl, AuthCrackParams params, UpdaterDao updaterDao) {
super(host, hostUrl, params, updaterDao);
}

@Override
public boolean scrapeAndLog() throws DbDriverException {
public boolean scrapeAndLog() {
return this.logWirelessStation(hostUrl, base64Login);
}

Expand All @@ -57,7 +55,7 @@ public boolean scrapeAndLog() throws DbDriverException {
* @param hostUrl The complete URL, including the port number, protocol etc
* @param base64Login The base64 login header
*/
private boolean logWirelessStation(String hostUrl, String base64Login) throws DbDriverException {
private boolean logWirelessStation(String hostUrl, String base64Login) {
try {
String macAddr = null;
String devInfoUrl = hostUrl + "status/status_deviceinfo.htm";
Expand Down Expand Up @@ -87,7 +85,7 @@ private boolean logWirelessStation(String hostUrl, String base64Login) throws Db
}

for (Map<String, String> wifiData : wifiDataList) {
UpdaterDao.saveStation(wifiData, host);
updaterDao.saveStation(wifiData, host);
}
} catch (WirelessDisabledException ex) {
Logger.error(host + ex.getMessage());
Expand All @@ -102,8 +100,6 @@ private boolean logWirelessStation(String hostUrl, String base64Login) throws Db
} catch (IOException ex) {
Logger.error(host + ": IOException during logWirelessStation(): " + ex.getMessage() + " ::::::: " + ex.getLocalizedMessage());
java.util.logging.Logger.getLogger(DefaultAuthTrial.class.getName()).log(Level.SEVERE, null, ex);
} catch (DbDriverException ex) {
throw ex;
} catch (Exception ex) {
Logger.error(host + ": Exception during logWirelessStation(): " + ex.getMessage() + " ::::::: " + ex.getLocalizedMessage());
java.util.logging.Logger.getLogger(DefaultAuthTrial.class.getName()).log(Level.SEVERE, null, ex);
Expand Down
Loading