Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download loot to client #443

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions client/src/Havoc/Demon/CommandOutput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ void DispatchOutput::MessageOutput( QString JsonString, const QString& Date = ""

HavocX::Teamserver.TabSession->LootWidget->AddScreenshot( DemonCommandInstance->DemonID, Name, Date, DecodedData );
}
else if ( Type.compare( "download" ) == 0 )
else if ( Type.compare( "downloadComplete" ) == 0 )
{
auto DecodedData = QByteArray::fromBase64( Data.toLocal8Bit() );
auto MiscDataInfo = JsonDocument[ "MiscData2" ].toString().split( ";" );
auto Name = QByteArray::fromBase64( MiscDataInfo[ 0 ].toLocal8Bit() );
auto Size = ( MiscDataInfo[ 1 ] );

HavocX::Teamserver.TabSession->LootWidget->AddDownload( DemonCommandInstance->DemonID, Name, Size, Date, nullptr );
HavocX::Teamserver.TabSession->LootWidget->AddDownload( DemonCommandInstance->DemonID, Name, Size, Date, DecodedData );
}
else if ( Type.compare( "ProcessUI" ) == 0 )
{
Expand Down
24 changes: 24 additions & 0 deletions client/src/UserInterface/Widgets/LootWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <QScrollBar>
#include <QKeyEvent>
#include <QGraphicsSceneWheelEvent>
#include <QSaveFile>
#include <QFileDialog>

// imagelabel.cpp
ImageLabel::ImageLabel( QWidget* parent ) : QWidget( parent )
Expand Down Expand Up @@ -328,6 +330,28 @@ void LootWidget::onScreenshotTableClick( const QModelIndex &index )

void LootWidget::onDownloadTableClick( const QModelIndex &index )
{
auto DemonID = ComboAgentID->currentText();
auto FileName = DownloadTable->item( index.row(), 0 )->text();

for ( auto& item : LootItems )
{
if ( DemonID.compare( "[ All ]" ) == 0 || DemonID.compare( item.AgentID ) == 0 )
{
if ( item.Type == LOOT_FILE )
{
if ( item.Data.Name.compare( FileName ) == 0 )
{
QFileInfo fi(FileName);
QString saveFileName = QFileDialog::getSaveFileName(this, tr("Save File"),
fi.fileName(), tr("All (*)"));
QSaveFile file(saveFileName);
file.open(QIODevice::WriteOnly);
file.write(item.Data.Data);
file.commit();
}
}
}
}

}

Expand Down
13 changes: 13 additions & 0 deletions teamserver/pkg/agent/demons.go
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,19 @@ func (a *Agent) TaskDispatch(RequestID uint32, CommandID uint32, Parser *parser.
Output["Type"] = "Good"
Output["Message"] = fmt.Sprintf("Finished download of file: %v", FileName)

var err error
var n int
var FileData = make([]byte, download.TotalSize)
n, err = download.File.ReadAt(FileData,0)
logger.Debug(fmt.Sprintf("downloadComplete, %v, %v", n, err))
if err == nil {
Output["MiscType"] = "downloadComplete"
Output["MiscData"] = base64.StdEncoding.EncodeToString([]byte(FileData))
Output["MiscData2"] = base64.StdEncoding.EncodeToString([]byte(download.FilePath)) + ";" + strconv.Itoa(int(download.TotalSize))
} else {
logger.Error(fmt.Sprintf("Could not read file %v after download", download.FilePath))
}

a.DownloadClose(FileID)
} else if Reason == 0x1 {
Output["Type"] = "Info"
Expand Down