All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.owasp.jbrofuzz.db.DBAdaptor Maven / Gradle / Ivy

Go to download

JBroFuzz is a stateless web application fuzzer for requests being made over HTTP and/or HTTPS. Its purpose is to provide a single, portable application that offers stable web protocol fuzzing capabilities. As a tool, it emerged from the needs of penetration testing.

There is a newer version: 2.5.1
Show newest version
package org.owasp.jbrofuzz.db;

import java.sql.Connection;
import java.util.Vector;

import org.json.JSONObject;
import org.owasp.jbrofuzz.JBroFuzz;
import org.owasp.jbrofuzz.fuzz.MessageContainer;
import org.owasp.jbrofuzz.graph.GraphingPanel;
import org.owasp.jbrofuzz.graph.utils.DBWalker;
import org.owasp.jbrofuzz.graph.utils.Walker;
import org.owasp.jbrofuzz.system.Logger;
import org.owasp.jbrofuzz.ui.JBroFuzzWindow;
import org.owasp.jbrofuzz.version.JBroFuzzPrefs;


public class DBAdaptor{
	private Object dbHandler;
	
	public DBAdaptor(Object dbHandler){
		this.dbHandler = dbHandler;
	}
	
	/**
	 * @author [email protected]
	 * @param session SessionDTO - containing sessionData to be stored
	 * @return returnCode int - 0 == OK | 1 == failed.
	 */
	public int store(MessageContainer outputMessage, String sessionName){
		String dbName = JBroFuzz.PREFS.get(JBroFuzzPrefs.DBSETTINGS[12].getId(), "");
		int returnCode = 0;
		
		if (dbHandler.getClass().getName().equals(CouchDBHandler.class)){
			Logger.log("Storing to CouchDB", 0);
			CouchDBMapper couchMapper = new CouchDBMapper();	
			JSONObject document = couchMapper.toCouch2(outputMessage);
			returnCode = ((CouchDBHandler) dbHandler).store(dbName, "", document);
		}

		else{
				SQLiteHandler sqlH = (SQLiteHandler) dbHandler;
				try {
					Connection conn = sqlH.getConnection(dbName);
					if (conn == null) Logger.log("Connection = null", 0);
					returnCode = sqlH.store(outputMessage, conn, sessionName);
				} catch (Exception e) {
					e.printStackTrace();
				}
		}
		
		return returnCode;
	}
	
	/**
	 * @author [email protected]
	 * @since version 2.5
	 * @param fileName
	 * @return MessageContainer - content read from db
	 */
	public Vector read(String fileName, String sessionId, JBroFuzzWindow mWindow){
		Vector mcv = new Vector();
		
		if (dbHandler.getClass().getName().equals(CouchDBHandler.class)){
			Logger.log("TODO: reading from CouchDB", 0);
		}
		else{
			SQLiteHandler sqlH = (SQLiteHandler) dbHandler;
			 String dbName = JBroFuzz.PREFS.get(JBroFuzzPrefs.DBSETTINGS[12].getId(), "");
			Connection conn = sqlH.getConnection(dbName);
			
			mcv = sqlH.read(conn, sessionId, fileName, mWindow.getPanelFuzzing());
		}
		return mcv;
	}
	
	public String[] executeQuery(String sql){
		if (dbHandler.getClass().getName().equals(CouchDBHandler.class)){
			Logger.log("TODO: reading form CouchDB", 3);
		}
		else{
			SQLiteHandler sqlH = (SQLiteHandler) dbHandler;
			Connection conn = sqlH.getConnection(JBroFuzz.PREFS.get(JBroFuzzPrefs.DBSETTINGS[12].getId(), ""));
			return sqlH.executeQuery(conn, sql);
		}
		return null;
	}
	
	public DBWalker getWalker(GraphingPanel gPanel){
		//TODO: Distinction between Couch and SQLite missing - only SQLite here and now.
		return new DBWalker(gPanel);
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy