initial
This commit is contained in:
commit
103011f8f7
7 changed files with 415 additions and 0 deletions
73
.gitignore
vendored
Normal file
73
.gitignore
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
*.user
|
46
CMakeLists.txt
Normal file
46
CMakeLists.txt
Normal file
|
@ -0,0 +1,46 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(littlesnitch LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
|
||||
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
|
||||
# They need to be set before the find_package(Qt5 ...) call.
|
||||
|
||||
#if(ANDROID)
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
|
||||
# set(ANDROID_EXTRA_LIBS
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
|
||||
# endif()
|
||||
#endif()
|
||||
|
||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
find_package(cppzmq REQUIRED)
|
||||
|
||||
if(ANDROID)
|
||||
add_library(littlesnitch SHARED
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
mainwindow.h
|
||||
mainwindow.ui
|
||||
)
|
||||
else()
|
||||
add_executable(littlesnitch
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
mainwindow.h
|
||||
mainwindow.ui
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(littlesnitch PRIVATE Qt5::Widgets cppzmq)
|
11
main.cpp
Normal file
11
main.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
86
mainwindow.cpp
Normal file
86
mainwindow.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "mainwindow.h"
|
||||
#include "./ui_mainwindow.h"
|
||||
#include <QtGui>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
thread = new QThread;
|
||||
Worker* worker = new Worker();
|
||||
worker->moveToThread(thread);
|
||||
//connect(worker, SIGNAL (error(QString)), this, SLOT (errorString(QString)));
|
||||
connect(thread, SIGNAL (started()), worker, SLOT (process()));
|
||||
connect(thread, SIGNAL (httpMessage()), worker, SLOT (httpMessage()));
|
||||
thread->start();
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->historyHTTPTable->setShowGrid(true);
|
||||
ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->historyHTTPTable->setColumnCount(4);
|
||||
ui->historyHTTPTable->setRowCount(1);
|
||||
|
||||
HTTPData data;
|
||||
data.index = 1;
|
||||
data.url = "https://test.com";
|
||||
data.status = 200;
|
||||
data.method = "GET";
|
||||
data.ttl = 44;
|
||||
|
||||
ui->historyHTTPTable->setItem(0,0,new QTableWidgetItem(QString::number(data.index)));
|
||||
ui->historyHTTPTable->setItem(0,1,new QTableWidgetItem(QString::fromStdString(data.method)));
|
||||
ui->historyHTTPTable->setItem(0,2,new QTableWidgetItem(QString::fromStdString(data.url)));
|
||||
ui->historyHTTPTable->setItem(0,3,new QTableWidgetItem(QString::number(data.ttl)));
|
||||
ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::httpMessage(HTTPData data) {
|
||||
qDebug() << data.index;
|
||||
}
|
||||
|
||||
Worker::Worker() { // Constructor
|
||||
}
|
||||
|
||||
Worker::~Worker() { // Destructor
|
||||
}
|
||||
|
||||
void Worker::process() {
|
||||
qDebug("thread started");
|
||||
zmq::context_t ctx(1);
|
||||
zmq::socket_t sock(ctx, zmq::socket_type::pair);
|
||||
try {
|
||||
sock.bind("tcp://127.0.0.1:12345");
|
||||
} catch (zmq::error_t err) {
|
||||
qDebug() << "failed binding socket" << err.what();
|
||||
emit error(err.what());
|
||||
return;
|
||||
};
|
||||
|
||||
qDebug("bound socket");
|
||||
|
||||
while(true) {
|
||||
sock.send(zmq::str_buffer("littlesnitch_init"), zmq::send_flags::dontwait);
|
||||
zmq::message_t msg;
|
||||
const auto ret = sock.recv(msg, zmq::recv_flags::dontwait);
|
||||
if(ret) {
|
||||
qDebug() << "got message: " << msg.to_string().c_str();
|
||||
if(msg.to_string() == "mitmaddon") {
|
||||
qDebug("connected");
|
||||
while(true) {
|
||||
const auto ret = sock.recv(msg, zmq::recv_flags::dontwait);
|
||||
if(ret) {
|
||||
qDebug() << msg.to_string().c_str();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qDebug("not connected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
mainwindow.h
Normal file
51
mainwindow.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <string>
|
||||
#include <zmq.hpp>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class HTTPData {
|
||||
private:
|
||||
public:
|
||||
size_t index;
|
||||
size_t status;
|
||||
size_t ttl;
|
||||
std::string method;
|
||||
std::string url;
|
||||
std::string request_headers;
|
||||
std::string request_content;
|
||||
std::string response_headers;
|
||||
std::string response_content;
|
||||
};
|
||||
|
||||
class Worker : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Worker();
|
||||
~Worker();
|
||||
public slots:
|
||||
void process();
|
||||
signals:
|
||||
void finished();
|
||||
void error(QString err);
|
||||
void httpMessage(HTTPData);
|
||||
private:
|
||||
// add your variables here
|
||||
};
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QThread* thread;
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
void httpMessage(HTTPData data);
|
||||
};
|
97
mainwindow.ui
Normal file
97
mainwindow.ui
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QTreeView" name="treeView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="textEdit"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QTextEdit" name="textEdit_2"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QTextEdit" name="textEdit_3"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QTextEdit" name="textEdit_4"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<widget class="QWidget" name="tabWidgetPage1" native="true">
|
||||
<attribute name="title">
|
||||
<string/>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="historyHTTPTable">
|
||||
<property name="gridStyle">
|
||||
<enum>Qt::SolidLine</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
51
mitmaddon/littlesnitch.py
Normal file
51
mitmaddon/littlesnitch.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python3
|
||||
import pdb
|
||||
from mitmproxy import ctx
|
||||
import threading
|
||||
from queue import Queue
|
||||
import time
|
||||
import zmq
|
||||
|
||||
def networking(q):
|
||||
print("starting thread")
|
||||
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.PAIR)
|
||||
socket.connect("tcp://127.0.0.1:12345")
|
||||
|
||||
while True:
|
||||
print("try recv")
|
||||
message = socket.recv()
|
||||
if message == b"littlesnitch_init":
|
||||
print("connected")
|
||||
socket.send(b"mitmaddon")
|
||||
while True:
|
||||
a = q.get()
|
||||
print(f"got {a}")
|
||||
if a:
|
||||
socket.send(str.encode(a))
|
||||
q.task_done()
|
||||
else:
|
||||
raise ValueError("init failed")
|
||||
|
||||
class Counter:
|
||||
def __init__(self):
|
||||
self.q = Queue()
|
||||
self.thread = threading.Thread(name="NetworkThread", target=networking, args=(self.q,))
|
||||
self.thread.start()
|
||||
self.q.join()
|
||||
|
||||
def request(self, flow):
|
||||
data = flow.request.data
|
||||
self.q.put(f"{flow.id},REQ,{data.method},{data.scheme},{data.host},{data.port},{data.path},{data.http_version},{data.headers}")
|
||||
self.q.join()
|
||||
|
||||
def response(self, flow):
|
||||
data = flow.response.data
|
||||
self.q.put(f"{flow.id},RES,{data.status_code},{data.http_version},{data.reason},{data.headers},{data.content},{data.timestamp_start},{data.timestamp_end}")
|
||||
self.q.join()
|
||||
|
||||
|
||||
addons = [
|
||||
Counter()
|
||||
]
|
Loading…
Reference in a new issue