-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (49 loc) · 1.15 KB
/
main.cpp
File metadata and controls
60 lines (49 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <QApplication>
#include <QTcpServer>
#include <QTcpSocket>
#include <QProcess>
#include <QThread>
#include <iostream>
#include "Client.h"
QString getProgramPath()
{
#ifdef Q_OS_WIN
return "cmd.exe";
#else
const QFileInfo shell("/bin/sh");
if (!shell.exists())
{
const QFileInfo bash("/bin/bash");
if (!bash.exists())
{
qDebug() << "shell not found, please write down the shell path before running this snippet";
return "";
}
return bash.absoluteFilePath();
}
return shell.absoluteFilePath();
#endif
}
int main(int argc, char* argv[])
{
// To connect to this server use the below command( you must have nmap installed)
// ncat -v localhost 3002
const QString program = getProgramPath();
if (program.isEmpty())
return 1;
QApplication a(argc, argv);
QTcpServer* server = new QTcpServer();
if (!server->listen(QHostAddress::LocalHost, 3002))
{
qDebug().noquote() << "Error on listen()";
return 1;
}
QObject::connect(server, &QTcpServer::newConnection, [&]()
{
QTcpSocket* sock = server->nextPendingConnection();
Client* client = new Client(program, sock);
client->interact();
server->close();
});
return a.exec();
}