Projects STRLCPY LoggerPlusPlus Commits 3c286a41
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■
    build.gradle
    skipped 12 lines
    13 13  dependencies {
    14 14   compile 'net.portswigger.burp.extender:burp-extender-api:1.7.22'
    15 15   compile 'org.swinglabs:swingx:1.6.1'
    16  - compile 'com.github.CoreyD97:BurpExtenderUtilities:bd824bbd'
     16 + compile 'com.github.CoreyD97:BurpExtenderUtilities:3adaa74c'
    17 17   compile 'com.google.code.gson:gson:2.8.2'
    18 18   compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.5.2'
    19 19   compile 'org.apache.httpcomponents:httpclient:4.5.6'
    skipped 23 lines
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/ElasticExporter.java
    skipped 1 lines
    2 2   
    3 3  import com.coreyd97.BurpExtenderUtilities.Preferences;
    4 4  import com.nccgroup.loggerplusplus.LoggerPlusPlus;
     5 +import com.nccgroup.loggerplusplus.filter.logfilter.LogFilter;
     6 +import com.nccgroup.loggerplusplus.filter.parser.ParseException;
    5 7  import com.nccgroup.loggerplusplus.logentry.LogEntry;
    6 8  import com.nccgroup.loggerplusplus.logentry.LogEntryField;
    7 9  import com.nccgroup.loggerplusplus.logentry.Status;
    8 10  import com.nccgroup.loggerplusplus.util.Globals;
     11 +import org.apache.commons.lang3.StringUtils;
    9 12  import org.apache.http.Header;
    10 13  import org.apache.http.HttpHost;
    11 14  import org.apache.http.message.BasicHeader;
    skipped 17 lines
    29 32  import java.net.ConnectException;
    30 33  import java.net.InetAddress;
    31 34  import java.nio.charset.StandardCharsets;
    32  -import java.util.ArrayList;
    33  -import java.util.Base64;
    34  -import java.util.Date;
    35  -import java.util.List;
     35 +import java.util.*;
    36 36  import java.util.concurrent.Executors;
    37 37  import java.util.concurrent.ScheduledExecutorService;
    38 38  import java.util.concurrent.ScheduledFuture;
    skipped 5 lines
    44 44   
    45 45   RestHighLevelClient httpClient;
    46 46   ArrayList<LogEntry> pendingEntries;
     47 + LogFilter logFilter;
    47 48   private List<LogEntryField> fields;
    48 49   private String indexName;
    49 50   private ScheduledFuture indexTask;
    skipped 11 lines
    61 62   
    62 63   if ((boolean) preferences.getSetting(Globals.PREF_ELASTIC_AUTOSTART_GLOBAL)
    63 64   || (boolean) preferences.getSetting(Globals.PREF_ELASTIC_AUTOSTART_PROJECT)) {
     65 + //Autostart exporter.
    64 66   try {
    65 67   this.exportController.enableExporter(this);
    66 68   } catch (Exception e) {
    skipped 10 lines
    77 79   if (this.fields == null || this.fields.isEmpty())
    78 80   throw new Exception("No fields configured for export.");
    79 81   
     82 + String projectPreviousFilterString = preferences.getSetting(Globals.PREF_ELASTIC_FILTER_PROJECT_PREVIOUS);
     83 + String filterString = preferences.getSetting(Globals.PREF_ELASTIC_FILTER);
     84 + 
     85 + if (!Objects.equals(projectPreviousFilterString, filterString)) {
     86 + //The current filter isn't what we used to export last time.
     87 + int res = JOptionPane.showConfirmDialog(LoggerPlusPlus.instance.getLoggerFrame(),
     88 + "Heads up! Looks like the filter being used to select which logs to export to " +
     89 + "ElasticSearch has changed since you last ran the exporter for this project.\n" +
     90 + "Do you want to continue?", "ElasticSearch Export Log Filter", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
     91 + if (res == JOptionPane.NO_OPTION) {
     92 + throw new Exception("Export cancelled.");
     93 + }
     94 + }
     95 + 
     96 + if (!StringUtils.isBlank(filterString)) {
     97 + try {
     98 + logFilter = new LogFilter(exportController.getLoggerPlusPlus().getLibraryController(), filterString);
     99 + } catch (ParseException ex) {
     100 + logger.error("The log filter configured for the Elastic exporter is invalid!", ex);
     101 + }
     102 + }
     103 + 
    80 104   InetAddress address = InetAddress.getByName(preferences.getSetting(Globals.PREF_ELASTIC_ADDRESS));
    81 105   int port = preferences.getSetting(Globals.PREF_ELASTIC_PORT);
    82 106   indexName = preferences.getSetting(Globals.PREF_ELASTIC_INDEX);
    83 107   String protocol = preferences.getSetting(Globals.PREF_ELASTIC_PROTOCOL).toString();
    84 108   RestClientBuilder builder = RestClient.builder(new HttpHost(address, port, protocol));
     109 + logger.info(String.format("Starting ElasticSearch exporter. %s://%s:%s/%s", protocol, address, port, indexName));
    85 110   
    86 111   Globals.ElasticAuthType authType = preferences.getSetting(Globals.PREF_ELASTIC_AUTH);
    87 112   String user = "", pass = "";
    skipped 12 lines
    100 125   }
    101 126   
    102 127   if (!"".equals(user) && !"".equalsIgnoreCase(pass)) {
     128 + logger.info(String.format("ElasticSearch using %s, Username: %s", authType, user));
    103 129   String authValue = Base64.getEncoder().encodeToString((user + ":" + pass).getBytes(StandardCharsets.UTF_8));
    104 130   builder.setDefaultHeaders(new Header[]{new BasicHeader("Authorization", String.format("%s %s", authType, authValue))});
    105 131   }
    skipped 9 lines
    115 141   @Override
    116 142   public void exportNewEntry(final LogEntry logEntry) {
    117 143   if(logEntry.getStatus() == Status.PROCESSED) {
     144 + if (logFilter != null && !logFilter.matches(logEntry)) return;
    118 145   pendingEntries.add(logEntry);
    119 146   }
    120 147   }
    skipped 1 lines
    122 149   @Override
    123 150   public void exportUpdatedEntry(final LogEntry updatedEntry) {
    124 151   if(updatedEntry.getStatus() == Status.PROCESSED) {
     152 + if (logFilter != null && !logFilter.matches(updatedEntry)) return;
    125 153   pendingEntries.add(updatedEntry);
    126 154   }
    127 155   }
    skipped 119 lines
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/ElasticExporterConfigDialog.java
    1 1  package com.nccgroup.loggerplusplus.exports;
    2 2   
    3 3  import com.coreyd97.BurpExtenderUtilities.Alignment;
     4 +import com.coreyd97.BurpExtenderUtilities.ComponentGroup;
    4 5  import com.coreyd97.BurpExtenderUtilities.PanelBuilder;
    5 6  import com.coreyd97.BurpExtenderUtilities.Preferences;
     7 +import com.nccgroup.loggerplusplus.LoggerPlusPlus;
     8 +import com.nccgroup.loggerplusplus.filter.logfilter.LogFilter;
     9 +import com.nccgroup.loggerplusplus.filter.parser.ParseException;
     10 +import com.nccgroup.loggerplusplus.filterlibrary.FilterLibraryController;
    6 11  import com.nccgroup.loggerplusplus.logentry.LogEntryField;
     12 +import com.nccgroup.loggerplusplus.util.Globals;
    7 13  import com.nccgroup.loggerplusplus.util.MoreHelp;
     14 +import org.apache.commons.lang3.StringUtils;
    8 15   
    9 16  import javax.swing.*;
    10 17  import java.awt.*;
    11 18  import java.awt.event.ActionEvent;
     19 +import java.awt.event.WindowAdapter;
     20 +import java.awt.event.WindowEvent;
    12 21  import java.util.List;
    13 22  import java.util.Objects;
    14 23   
    skipped 36 lines
    51 60   if (ElasticAuthType.ApiKey.equals(authType)) {
    52 61   authUserLabel.setText("Key ID: ");
    53 62   authPassLabel.setText("Key Secret: ");
     63 + userPanel.remove(username);
     64 + passPanel.remove(password);
    54 65   userPanel.add(apiKeyId, BorderLayout.CENTER);
    55 66   passPanel.add(apiKeySecret, BorderLayout.CENTER);
    56 67   } else if (ElasticAuthType.Basic.equals(authType)) {
    57 68   authUserLabel.setText("Username: ");
    58 69   authPassLabel.setText("Password: ");
     70 + userPanel.remove(apiKeyId);
     71 + passPanel.remove(apiKeySecret);
    59 72   userPanel.add(username, BorderLayout.CENTER);
    60 73   passPanel.add(password, BorderLayout.CENTER);
    61 74   }
    skipped 43 lines
    105 118   }
    106 119   });
    107 120   
     121 + 
     122 + String projectPreviousFilterString = preferences.getSetting(Globals.PREF_ELASTIC_FILTER_PROJECT_PREVIOUS);
     123 + String filterString = preferences.getSetting(Globals.PREF_ELASTIC_FILTER);
     124 + if (projectPreviousFilterString != null && !Objects.equals(projectPreviousFilterString, filterString)) {
     125 + int res = JOptionPane.showConfirmDialog(LoggerPlusPlus.instance.getLoggerFrame(),
     126 + "Looks like the log filter has been changed since you last used this Burp project.\n" +
     127 + "Do you want to restore the previous filter used by the project?\n" +
     128 + "\n" +
     129 + "Previously used filter: " + projectPreviousFilterString + "\n" +
     130 + "Current filter: " + filterString, "ElasticSearch Exporter Log Filter",
     131 + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
     132 + if (res == JOptionPane.YES_OPTION) {
     133 + preferences.setSetting(PREF_ELASTIC_FILTER, projectPreviousFilterString);
     134 + }
     135 + }
     136 + 
     137 + JTextField filterField = PanelBuilder.createPreferenceTextField(preferences, PREF_ELASTIC_FILTER);
     138 + filterField.setMinimumSize(new Dimension(600, 0));
     139 + 
    108 140   JCheckBox autostartGlobal = PanelBuilder.createPreferenceCheckBox(preferences, PREF_ELASTIC_AUTOSTART_GLOBAL);
    109 141   JCheckBox autostartProject = PanelBuilder.createPreferenceCheckBox(preferences, PREF_ELASTIC_AUTOSTART_PROJECT);
    110 142   
    skipped 8 lines
    119 151   }
    120 152   });
    121 153   
     154 +// new JComponent[]{new JLabel("Address: "), addressField},
     155 +// new JComponent[]{new JLabel("Port: "), elasticPortSpinner},
     156 +// new JComponent[]{new JLabel("Protocol: "), protocolSelector},
    122 157   
    123  - this.add(PanelBuilder.build(new JComponent[][]{
    124  - new JComponent[]{new JLabel("Address: "), addressField},
    125  - new JComponent[]{new JLabel("Port: "), elasticPortSpinner},
    126  - new JComponent[]{new JLabel("Protocol: "), protocolSelector},
     158 + ComponentGroup connectionGroup = new ComponentGroup(ComponentGroup.Orientation.VERTICAL, "Connection");
     159 + connectionGroup.addComponentWithLabel("Address: ", addressField);
     160 + connectionGroup.addComponentWithLabel("Port: ", elasticPortSpinner);
     161 + connectionGroup.addComponentWithLabel("Protocol: ", protocolSelector);
     162 + connectionGroup.addComponentWithLabel("Index: ", indexNameField);
     163 + 
     164 + ComponentGroup authGroup = new ComponentGroup(ComponentGroup.Orientation.VERTICAL, "Authentication");
     165 + authGroup.add(PanelBuilder.build(new Component[][]{
    127 166   new JComponent[]{new JLabel("Auth: "), elasticAuthType},
    128 167   new JComponent[]{authUserLabel, userPanel},
    129  - new JComponent[]{authPassLabel, passPanel},
    130  - new JComponent[]{new JLabel("Index: "), indexNameField},
     168 + new JComponent[]{authPassLabel, passPanel}
     169 + }, new int[][]{
     170 + new int[]{0, 1},
     171 + new int[]{0, 1},
     172 + new int[]{0, 1}
     173 + }, Alignment.FILL, 1, 1));
     174 + 
     175 + ComponentGroup miscGroup = new ComponentGroup(ComponentGroup.Orientation.VERTICAL, "Misc");
     176 + miscGroup.add(PanelBuilder.build(new Component[][]{
    131 177   new JComponent[]{new JLabel("Upload Frequency (Seconds): "), elasticDelaySpinner},
    132 178   new JComponent[]{new JLabel("Exported Fields: "), configureFieldsButton},
     179 + new JComponent[]{new JLabel("Log Filter: "), filterField},
    133 180   new JComponent[]{new JLabel("Autostart Exporter (All Projects): "), autostartGlobal},
    134 181   new JComponent[]{new JLabel("Autostart Exporter (This Project): "), autostartProject},
    135 182   }, new int[][]{
    skipped 1 lines
    137 184   new int[]{0, 1},
    138 185   new int[]{0, 1},
    139 186   new int[]{0, 1},
    140  - new int[]{0, 1},
    141  - new int[]{0, 1},
     187 + new int[]{0, 1}
     188 + }, Alignment.FILL, 1, 1));
     189 + 
     190 + 
     191 + this.add(PanelBuilder.build(new JComponent[][]{
     192 + new JComponent[]{connectionGroup},
     193 + new JComponent[]{authGroup},
     194 + new JComponent[]{miscGroup}
     195 + }, new int[][]{
     196 + new int[]{1},
     197 + new int[]{1},
     198 + new int[]{1},
    142 199   }, Alignment.CENTER, 1.0, 1.0, 5, 5), BorderLayout.CENTER);
    143 200   
    144 201   setAuthFields.run();
     202 + 
     203 + this.setMinimumSize(new Dimension(600, 200));
    145 204   
    146 205   this.pack();
    147 206   this.setResizable(true);
    148  - this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
     207 + this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
     208 + 
     209 + this.addWindowListener(new WindowAdapter() {
     210 + @Override
     211 + public void windowClosing(WindowEvent e) {
     212 + String logFilter = preferences.getSetting(PREF_ELASTIC_FILTER);
     213 + 
     214 + if (!StringUtils.isBlank(logFilter)) {
     215 + FilterLibraryController libraryController = elasticExporter.getExportController()
     216 + .getLoggerPlusPlus().getLibraryController();
     217 + try {
     218 + new LogFilter(libraryController, logFilter);
     219 + } catch (ParseException ex) {
     220 + JOptionPane.showMessageDialog(ElasticExporterConfigDialog.this,
     221 + "Cannot save Elastic Exporter configuration. The chosen log filter is invalid: \n" +
     222 + ex.getMessage(), "Invalid Elastic Exporter Configuration", JOptionPane.ERROR_MESSAGE);
     223 + return;
     224 + }
     225 + }
     226 + ElasticExporterConfigDialog.this.dispose();
     227 + super.windowClosing(e);
     228 + }
     229 + });
    149 230   }
    150 231  }
    151 232   
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/ElasticExporterControlPanel.java
    skipped 1 lines
    2 2   
    3 3  import com.coreyd97.BurpExtenderUtilities.Alignment;
    4 4  import com.coreyd97.BurpExtenderUtilities.PanelBuilder;
     5 +import com.nccgroup.loggerplusplus.LoggerPlusPlus;
     6 +import com.nccgroup.loggerplusplus.util.Globals;
    5 7  import org.apache.logging.log4j.LogManager;
    6 8  import org.apache.logging.log4j.Logger;
    7 9   
    skipped 19 lines
    27 29   JButton showConfigDialogButton = new JButton(new AbstractAction("Configure Elastic Exporter") {
    28 30   @Override
    29 31   public void actionPerformed(ActionEvent actionEvent) {
    30  - new ElasticExporterConfigDialog(JOptionPane.getFrameForComponent(
    31  - ElasticExporterControlPanel.this), elasticExporter)
     32 + new ElasticExporterConfigDialog(LoggerPlusPlus.instance.getLoggerFrame(), elasticExporter)
    32 33   .setVisible(true);
     34 + 
     35 + //Dialog closed. Update previous project entry filter to current value.
     36 + String newFilter = elasticExporter.getPreferences().getSetting(Globals.PREF_ELASTIC_FILTER);
     37 + elasticExporter.getPreferences().setSetting(Globals.PREF_ELASTIC_FILTER_PROJECT_PREVIOUS, newFilter);
    33 38   }
    34 39   });
    35 40   
    skipped 83 lines
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/preferences/LoggerPreferenceFactory.java
    skipped 83 lines
    84 84   prefs.registerSetting(PREF_ELASTIC_ADDRESS, String.class, "127.0.0.1");
    85 85   prefs.registerSetting(PREF_ELASTIC_PORT, Integer.class, 9200);
    86 86   prefs.registerSetting(PREF_ELASTIC_PROTOCOL, Protocol.class, Protocol.HTTP);
    87  - prefs.registerSetting(PREF_ELASTIC_AUTH, Globals.ElasticAuthType.class, ElasticAuthType.ApiKey);
     87 + prefs.registerSetting(PREF_ELASTIC_AUTH, Globals.ElasticAuthType.class, ElasticAuthType.Basic);
    88 88   prefs.registerSetting(PREF_ELASTIC_CLUSTER_NAME, String.class, "elasticsearch");
    89 89   prefs.registerSetting(PREF_ELASTIC_API_KEY_ID, String.class, "");
    90 90   prefs.registerSetting(PREF_ELASTIC_API_KEY_SECRET, String.class, "");
    skipped 1 lines
    92 92   prefs.registerSetting(PREF_ELASTIC_PASSWORD, String.class, "");
    93 93   prefs.registerSetting(PREF_ELASTIC_INDEX, String.class, "logger");
    94 94   prefs.registerSetting(PREF_ELASTIC_DELAY, Integer.class, 120);
    95  - prefs.registerSetting(PREF_ELASTIC_INCLUDE_REQ_RESP, Boolean.class, false);
     95 + prefs.registerSetting(PREF_ELASTIC_FILTER, String.class, "", Preferences.Visibility.GLOBAL);
     96 + prefs.registerSetting(PREF_ELASTIC_FILTER_PROJECT_PREVIOUS, String.class, null, Preferences.Visibility.PROJECT);
    96 97   prefs.registerSetting(PREF_ELASTIC_AUTOSTART_GLOBAL, Boolean.class, false);
    97 98   prefs.registerSetting(PREF_ELASTIC_AUTOSTART_PROJECT, Boolean.class, false, Preferences.Visibility.PROJECT);
    98 99   prefs.registerSetting(PREF_PREVIOUS_EXPORT_FIELDS, new TypeToken<List<LogEntryField>>() {
    skipped 19 lines
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/util/FieldSelectorDialog.java
    skipped 282 lines
    283 283   
    284 284   public List<LogEntryField> getSelectedFields() {
    285 285   List<LogEntryField> selectedList = new ArrayList<>();
    286  - selectedFields.forEach((field, selected) -> {
    287  - if(selected) selectedList.add(field);
    288  - });
     286 + if (selectedFields != null) {
     287 + selectedFields.forEach((field, selected) -> {
     288 + if (selected) selectedList.add(field);
     289 + });
     290 + }
    289 291   
    290 292   return selectedList;
    291 293   }
    skipped 36 lines
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/util/Globals.java
    skipped 58 lines
    59 59   public static final String PREF_ELASTIC_PASSWORD = "esPassword";
    60 60   public static final String PREF_ELASTIC_INDEX = "esIndex";
    61 61   public static final String PREF_ELASTIC_DELAY = "esDelay";
    62  - public static final String PREF_ELASTIC_INCLUDE_REQ_RESP = "esIncludeReqResp";
     62 + public static final String PREF_ELASTIC_FILTER = "esFilter";
     63 + public static final String PREF_ELASTIC_FILTER_PROJECT_PREVIOUS = "esFilterProjectPrevious";
    63 64   public static final String PREF_ELASTIC_AUTOSTART_GLOBAL = "elasticAutostartGlobal";
    64 65   public static final String PREF_ELASTIC_AUTOSTART_PROJECT = "elasticAutostartProject";
    65 66   public static final String PREF_LOG_OTHER_LIVE = "otherToolLiveLogging";
    skipped 72 lines
Please wait...
Page is in error, reload to recover