-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.cpp
More file actions
executable file
·158 lines (128 loc) · 3.4 KB
/
utils.cpp
File metadata and controls
executable file
·158 lines (128 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <stdarg.h>
#include "structs.h"
void put_int32(char **bptr, int32_t a) {
int32_t *b = (int32_t *)*bptr;
*b = a;
*bptr += sizeof(int32_t);
}
int32_t get_int32(char **bptr) {
int32_t *b = (int32_t *)*bptr;
int32_t ret = *b;
*bptr += sizeof(int32_t);
return ret;
}
void put_int64(char **bptr, int64_t a) {
int64_t *b = (int64_t *)*bptr;
*b = a;
*bptr += sizeof(int64_t);
}
int64_t get_int64(char **bptr) {
int64_t *b = (int64_t *)*bptr;
int64_t ret = *b;
*bptr += sizeof(int64_t);
return ret;
}
void put_uint64(char **bptr, uint64_t a) {
uint64_t *b = (uint64_t *)*bptr;
*b = a;
*bptr += sizeof(uint64_t);
}
uint64_t get_uint64(char **bptr) {
uint64_t *b = (uint64_t *)*bptr;
uint64_t ret = *b;
*bptr += sizeof(uint64_t);
return ret;
}
void put_str(char **bptr, char *str, int size) {
char *dst = (char *)*bptr;
memcpy(dst, str, size);
*bptr += size;
}
int stateOK(Connection *cptr) {
return (cptr->state & STATE_OK);
}
/*
Chippy1337 and @packetprophet present:
LizardStresser rekt
is where i found these next functions
*/
unsigned char *fdgets(unsigned char *buffer, int bufferSize, int fd) {
int got = 1, total = 0;
while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
return got == 0 ? NULL : buffer;
}
uint32_t getOurIPv4() {
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if(sock == -1) return 0;
struct sockaddr_in serv;
memset(&serv, 0, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr("8.8.8.8");
serv.sin_port = htons(53);
int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
if(err == -1) return 0;
struct sockaddr_in name;
socklen_t namelen = sizeof(name);
err = getsockname(sock, (struct sockaddr*) &name, &namelen);
if(err == -1) return 0;
//ourIP.s_addr = name.sin_addr.s_addr;
/*
int cmdline = open("/proc/net/route", O_RDONLY);
if (cmdline > 0) {
char linebuf[4096];
while(fdgets((unsigned char *)linebuf, 4096, cmdline) != NULL)
{
if(strstr(linebuf, "\t00000000\t") != NULL)
{
unsigned char *pos = (unsigned char *)linebuf;
while(*pos != '\t') pos++;
*pos = 0;
break;
}
memset(linebuf, 0, 4096);
}
close(cmdline);
}
if(*linebuf)
{
int i;
struct ifreq ifr;
strcpy(ifr.ifr_name, linebuf);
ioctl(sock, SIOCGIFHWADDR, &ifr);
for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i];
}
*/
close(sock);
return name.sin_addr.s_addr;
}
// just a google for 'vsnprintf' example
int sock_printf(Modules *mptr, Connection *cptr, char *fmt, ...) {
va_list va;
char buf[16384];
int ret = 0;
int len = 0;
va_start(va, fmt);
len = vsnprintf(buf, sizeof(buf), fmt, va);
ret = QueueAdd(mptr, cptr, NULL, buf, len);
va_end(va);
return ret;
}
void print_hex(char *buf, int size) {
int i = 0;
for (; i < size; i++) {
printf("%02x", (unsigned char)buf[i]);
}
printf("\n");
}