Skip to content

Commit

Permalink
Add EDR, iplist, banned list
Browse files Browse the repository at this point in the history
  • Loading branch information
slist committed Nov 25, 2020
1 parent 86708e0 commit 219f498
Show file tree
Hide file tree
Showing 97 changed files with 8,362 additions and 280 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019-2020 VMware Carbon Black

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

169 changes: 169 additions & 0 deletions banned.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Copyright 2020 VMware, Inc.
// SPDX-License-Identifier: MIT

#include "banned.h"
#include "ui_banned.h"
#include "droparea.h"

#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <QDropEvent>
#include <QCryptographicHash>

Banned::Banned(QWidget *parent) :
QWidget(parent),
ui(new Ui::Banned)
{
ui->setupUi(this);

auto dropArea = new DropArea(ui->widget_droparea);

ui->widget_droparea->parentWidget()->layout()->replaceWidget(ui->widget_droparea, dropArea);
ui->widget_droparea = dropArea;

QStringList labels;
labels << tr("Format") << tr("Content");
QTableWidget * formatsTable = ui->tableWidget;
formatsTable->setColumnCount(2);
formatsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
formatsTable->setHorizontalHeaderLabels(labels);
formatsTable->horizontalHeader()->setStretchLastSection(true);

formatsTable->setVisible(false); // enable for debug only

connect(dropArea, &DropArea::changed, this, &Banned::updateFormatsTable);
connect(dropArea, &DropArea::dropped, this, &Banned::updateBannedText);
}

Banned::~Banned()
{
delete ui;
}

void Banned::updateFormatsTable(const QMimeData *mimeData)
{
QTableWidget * formatsTable = ui->tableWidget;

formatsTable->setRowCount(0);
if (!mimeData)
return;

for (const QString &format : mimeData->formats()) {
QTableWidgetItem *formatItem = new QTableWidgetItem(format);
formatItem->setFlags(Qt::ItemIsEnabled);
formatItem->setTextAlignment(Qt::AlignTop | Qt::AlignLeft);

QString text;
if (format == QLatin1String("text/plain")) {
text = mimeData->text().simplified();
} else if (format == QLatin1String("text/html")) {
text = mimeData->html().simplified();
} else if (format == QLatin1String("text/uri-list")) {
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < 32; ++i)
text.append(urlList.at(i).toString() + QLatin1Char(' '));
} else {
QByteArray data = mimeData->data(format);
for (int i = 0; i < data.size() && i < 32; ++i)
text.append(QStringLiteral("%1 ").arg(uchar(data[i]), 2, 16, QLatin1Char('0')).toUpper());
}

int row = formatsTable->rowCount();
formatsTable->insertRow(row);
formatsTable->setItem(row, 0, new QTableWidgetItem(format));
formatsTable->setItem(row, 1, new QTableWidgetItem(text));
}

formatsTable->resizeColumnToContents(0);
}

void Banned::updateBannedText(const QMimeData *mimeData)
{
if (!mimeData)
return;

for (const QString &format : mimeData->formats()) {
if (format == QLatin1String("text/uri-list")) {
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < 32; ++i) {
addFile(urlList.at(i).toString());
}
}
}
}

void Banned::addFile(const QString & fileName)
{
bool notascii = false;
QString f;

if (!fileName.startsWith("file://"))
{
qDebug() << "Not a file: " << fileName;
return;
}

if (QSysInfo::prettyProductName().contains("Windows", Qt::CaseInsensitive))
{
f = fileName.mid(sizeof("file:///") - 1); // On Windows file path starts with c: and not /
} else {
f = fileName.mid(sizeof("file://") - 1); // Keep leading / on Unix
}

QFile file(f);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Can Not open file: " << f;
return;
}

while ((!file.atEnd()) && (notascii == false)) {
QByteArray line = file.readLine();
QString s(line);
s = s.simplified(); // remove whitespace and CR/LF...
if (s.startsWith("/") || s.startsWith("#"))
continue;
if (!s.isSimpleText())
{
qDebug() << "Not ASCII ? " << s;
notascii = true;
continue;
}
if (s.size() == 64) {
ui->textEdit_hashlist->append("BLACK_LIST,SHA256," + s + "," + f);
}
}

if (notascii == true) {
QCryptographicHash crypto(QCryptographicHash::Sha256);
QFile file2(f);
file2.open(QFile::ReadOnly);
while(!file2.atEnd()){
crypto.addData(file2.read(8192));
}
QByteArray hash = crypto.result();
ui->textEdit_hashlist->append("BLACK_LIST,SHA256," + hash.toHex() + "," + f);
}
}

void Banned::on_pushButton_save_clicked()
{

QString fileName = QFileDialog::getSaveFileName(this, tr("Save list of hashes"), "", tr("CSV file (*.csv);;All Files (*)"));

if (fileName.isEmpty())
return;

if (!fileName.contains(".")) {
fileName += ".csv";
}

QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
return;
}
file.write(ui->textEdit_hashlist->document()->toPlainText().toLatin1());
file.close();
}
35 changes: 35 additions & 0 deletions banned.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2020 VMware, Inc.
// SPDX-License-Identifier: MIT

#ifndef BANNED_H
#define BANNED_H

#include <QWidget>
#include <QMimeData>

namespace Ui {
class Banned;
}

class Banned : public QWidget
{
Q_OBJECT

public:
explicit Banned(QWidget *parent = nullptr);
~Banned();

private:
Ui::Banned *ui;
void addFile(const QString & fileName);


public slots:
void updateFormatsTable(const QMimeData *mimeData);
void updateBannedText(const QMimeData *mimeData);

private slots:
void on_pushButton_save_clicked();
};

#endif // BANNED_H
53 changes: 53 additions & 0 deletions banned.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Banned</class>
<widget class="QWidget" name="Banned">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>769</width>
<height>785</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_title">
<property name="text">
<string>Drag &amp; Drop files containing SHA256 hashes.
You can Drag &amp; Drop binaries too.
It will create a list of hash to import in VMware Carbon Black Cloud</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_droparea" native="true">
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget"/>
</item>
<item>
<widget class="QTextEdit" name="textEdit_hashlist"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_save">
<property name="text">
<string>Save in txt file</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
76 changes: 65 additions & 11 deletions cb.pro
Original file line number Diff line number Diff line change
@@ -1,37 +1,91 @@
QT = core widgets network
requires(qtConfig(tableview))
CONFIG -= app
QT = core gui widgets network
#requires(qtConfig(tableview))
#CONFIG -= app

lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5")

SOURCES += \
main.cpp \
mainwindow.cpp \
banned.cpp \
droparea.cpp \
edr.cpp \
feed.cpp \
instanceedr.cpp \
ioc.cpp \
ioclist.cpp \
iocs.cpp \
iocsyntaxhighlighter.cpp \
iplist.cpp \
iplistadd.cpp \
main.cpp \
ngav.cpp \
qjsonmodel.cpp \
policy.cpp \
difftool.cpp \
instance.cpp \
instances.cpp \
policies.cpp \
copy.cpp
copy.cpp \
homewindow.cpp \
eraser.cpp \
iocmainwindow.cpp \
report.cpp \
reportobject.cpp \
servers.cpp \
welcome.cpp

FORMS += \
mainwindow.ui \
banned.ui \
edr.ui \
feed.ui \
instanceedr.ui \
ioc.ui \
ioclist.ui \
iocs.ui \
iplist.ui \
iplistadd.ui \
ngav.ui \
policy.ui \
difftool.ui \
instance.ui \
instances.ui \
copy.ui
copy.ui \
homewindow.ui \
eraser.ui \
iocmainwindow.ui \
report.ui \
servers.ui \
welcome.ui

HEADERS += \
mainwindow.h \
banned.h \
droparea.h \
edr.h \
feed.h \
instanceedr.h \
ioc.h \
ioclist.h \
iocs.h \
iocsyntaxhighlighter.h \
iplist.h \
iplistadd.h \
ngav.h \
qjsonmodel.h \
report.h \
reportobject.h \
servers.h \
version.h \
policy.h \
difftool.h \
instance.h \
instances.h \
policies.h \
copy.h
copy.h \
homewindow.h \
eraser.h \
iocmainwindow.h \
welcome.h

RESOURCES += \
cb.qrc

TRANSLATIONS = cb_fr_FR.ts
QMAKE_POST_LINK = lrelease cb.pro
Loading

0 comments on commit 219f498

Please sign in to comment.