use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.
the class PopupMenuExportSelectedURLs method getOutputSet.
private SortedSet<String> getOutputSet(TreePath[] startingPoints) {
JTree siteTree = extension.getView().getSiteTreePanel().getTreeSite();
ArrayList<TreePath> startingPts = new ArrayList<TreePath>();
if (ArrayUtils.isEmpty(startingPoints)) {
startingPts.add(new TreePath(siteTree.getModel().getRoot()));
} else {
startingPts.addAll(Arrays.asList(startingPoints));
}
SortedSet<String> outputSet = new TreeSet<String>();
for (TreePath aPath : startingPts) {
Enumeration<?> en = (((SiteNode) aPath.getLastPathComponent()).preorderEnumeration());
while (en.hasMoreElements()) {
SiteNode node = (SiteNode) en.nextElement();
if (node.isRoot()) {
continue;
}
HistoryReference nodeHR = node.getHistoryReference();
if (nodeHR != null && !HistoryReference.getTemporaryTypes().contains(nodeHR.getHistoryType())) {
outputSet.add(nodeHR.getURI().toString());
}
}
}
return outputSet;
}
use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.
the class SearchThread method search.
private void search() {
Session session = Model.getSingleton().getSession();
Pattern pattern = Pattern.compile(filter, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
Matcher matcher = null;
try {
if (Type.Custom.equals(reqType)) {
if (searchers != null && customSearcherName != null) {
HttpSearcher searcher = searchers.get(customSearcherName);
if (searcher != null) {
List<SearchResult> results;
if (pcc.hasMaximumMatches()) {
results = searcher.search(pattern, inverse, pcc.getMaximumMatches());
} else {
results = searcher.search(pattern, inverse);
}
for (SearchResult sr : results) {
searchListenner.addSearchResult(sr);
}
}
}
return;
}
List<Integer> list = Model.getSingleton().getDb().getTableHistory().getHistoryIdsOfHistType(session.getSessionId(), HistoryReference.TYPE_PROXIED, HistoryReference.TYPE_ZAP_USER, HistoryReference.TYPE_SPIDER, HistoryReference.TYPE_SPIDER_AJAX);
int last = list.size();
int currentRecordId = 0;
for (int index = 0; index < last; index++) {
if (stopSearch) {
break;
}
int historyId = list.get(index).intValue();
try {
currentRecordId = index;
// Create the href to ensure the msg is set up correctly
HistoryReference href = new HistoryReference(historyId);
HttpMessage message = href.getHttpMessage();
if (searchJustInScope && !session.isInScope(message.getRequestHeader().getURI().toString())) {
// Not in scope, so ignore
continue;
}
if (this.baseUrl != null && !message.getRequestHeader().getURI().toString().startsWith(baseUrl)) {
// doesnt start with the specified baseurl
continue;
}
if (Type.URL.equals(reqType)) {
// URL
String url = message.getRequestHeader().getURI().toString();
matcher = pattern.matcher(url);
if (inverse && !pcc.allMatchesProcessed()) {
if (!matcher.find()) {
notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.REQUEST_HEAD);
}
} else {
int urlStartPos = message.getRequestHeader().getPrimeHeader().indexOf(url);
while (matcher.find() && !pcc.allMatchesProcessed()) {
notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.REQUEST_HEAD, urlStartPos + matcher.start(), urlStartPos + matcher.end());
if (!searchAllOccurrences) {
break;
}
}
}
}
if (Type.Header.equals(reqType)) {
// Header
// Request header
matcher = pattern.matcher(message.getRequestHeader().toString());
if (inverse && !pcc.allMatchesProcessed()) {
if (!matcher.find()) {
notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.REQUEST_HEAD);
}
} else {
while (matcher.find() && !pcc.allMatchesProcessed()) {
notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.REQUEST_HEAD, matcher.start(), matcher.end());
if (!searchAllOccurrences) {
break;
}
}
}
// Response header
matcher = pattern.matcher(message.getResponseHeader().toString());
if (inverse && !pcc.allMatchesProcessed()) {
if (!matcher.find()) {
notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.RESPONSE_HEAD);
}
} else {
while (matcher.find() && !pcc.allMatchesProcessed()) {
notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.RESPONSE_HEAD, matcher.start(), matcher.end());
if (!searchAllOccurrences) {
break;
}
}
}
}
if (Type.Request.equals(reqType) || Type.All.equals(reqType)) {
if (inverse && !pcc.allMatchesProcessed()) {
// Check for no matches in either Request Header or Body
if (!pattern.matcher(message.getRequestHeader().toString()).find() && !pattern.matcher(message.getRequestBody().toString()).find()) {
notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.REQUEST_HEAD);
}
} else {
// Request Header
matcher = pattern.matcher(message.getRequestHeader().toString());
while (matcher.find() && !pcc.allMatchesProcessed()) {
notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.REQUEST_HEAD, matcher.start(), matcher.end());
if (!searchAllOccurrences) {
break;
}
}
// Request Body
matcher = pattern.matcher(message.getRequestBody().toString());
while (matcher.find() && !pcc.allMatchesProcessed()) {
notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.REQUEST_BODY, matcher.start(), matcher.end());
if (!searchAllOccurrences) {
break;
}
}
}
}
if (Type.Response.equals(reqType) || Type.All.equals(reqType)) {
if (inverse && !pcc.allMatchesProcessed()) {
// Check for no matches in either Response Header or Body
if (!pattern.matcher(message.getResponseHeader().toString()).find() && !pattern.matcher(message.getResponseBody().toString()).find()) {
notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.RESPONSE_HEAD);
}
} else {
// Response header
matcher = pattern.matcher(message.getResponseHeader().toString());
while (matcher.find() && !pcc.allMatchesProcessed()) {
notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.RESPONSE_HEAD, matcher.start(), matcher.end());
if (!searchAllOccurrences) {
break;
}
}
// Response body
matcher = pattern.matcher(message.getResponseBody().toString());
while (matcher.find() && !pcc.allMatchesProcessed()) {
notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.RESPONSE_BODY, matcher.start(), matcher.end());
if (!searchAllOccurrences) {
break;
}
}
}
}
} catch (HttpMalformedHeaderException e1) {
log.error(e1.getMessage(), e1);
}
if (pcc.hasPageEnded()) {
break;
}
}
} catch (DatabaseException e) {
log.error(e.getMessage(), e);
}
}
use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.
the class ExtensionHistory method purge.
public void purge(SiteMap map, SiteNode node) {
SiteNode child = null;
synchronized (map) {
while (node.getChildCount() > 0) {
try {
child = (SiteNode) node.getChildAt(0);
purge(map, child);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
if (node.isRoot()) {
return;
}
// delete reference in node
removeFromHistoryList(node.getHistoryReference());
ExtensionAlert extAlert = Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.class);
if (node.getHistoryReference() != null) {
deleteAlertsFromExtensionAlert(extAlert, node.getHistoryReference());
node.getHistoryReference().delete();
map.removeHistoryReference(node.getHistoryReference().getHistoryId());
}
// delete past reference in node
while (node.getPastHistoryReference().size() > 0) {
HistoryReference ref = node.getPastHistoryReference().get(0);
deleteAlertsFromExtensionAlert(extAlert, ref);
removeFromHistoryList(ref);
delete(ref);
node.getPastHistoryReference().remove(0);
map.removeHistoryReference(ref.getHistoryId());
}
map.removeNodeFromParent(node);
}
}
use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.
the class PopupMenuHistoryReference method getSelectedHistoryReference.
private HistoryReference getSelectedHistoryReference() {
HistoryReference ref = null;
try {
switch(lastInvoker) {
case sites:
SiteNode sNode = (SiteNode) treeInvoker.getLastSelectedPathComponent();
ref = sNode.getHistoryReference();
break;
case ascan:
case history:
case bruteforce:
case search:
case fuzz:
ref = hrefsTableInvoker.getSelectedHistoryReference();
break;
case alerts:
AlertNode aNode = (AlertNode) treeInvoker.getLastSelectedPathComponent();
if (aNode.getUserObject() != null) {
Alert alert = aNode.getUserObject();
ref = alert.getHistoryRef();
}
break;
case hreftable:
ref = hrefTableInvoker.getSelectedHistoryReference();
break;
}
} catch (Exception e2) {
log.error(e2.getMessage(), e2);
}
return ref;
}
use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.
the class PopupMenuHistoryReference method getSelectedHistoryReferences.
private List<HistoryReference> getSelectedHistoryReferences() {
List<HistoryReference> refs = new ArrayList<>();
TreePath[] treePaths = null;
try {
switch(lastInvoker) {
case sites:
treePaths = treeInvoker.getSelectionPaths();
if (treePaths != null) {
for (TreePath path : treePaths) {
SiteNode node = (SiteNode) path.getLastPathComponent();
refs.add(node.getHistoryReference());
}
}
break;
case ascan:
case history:
case bruteforce:
case fuzz:
case search:
refs = hrefsTableInvoker.getSelectedHistoryReferences();
break;
case alerts:
// Only support single items
AlertNode aNode = (AlertNode) treeInvoker.getLastSelectedPathComponent();
if (aNode.getUserObject() != null) {
Alert alert = aNode.getUserObject();
refs.add(alert.getHistoryRef());
}
break;
case hreftable:
refs = hrefTableInvoker.getSelectedHistoryReferences();
break;
}
} catch (Exception e2) {
log.error(e2.getMessage(), e2);
}
return refs;
}
Aggregations