summaryrefslogtreecommitdiff
path: root/exploits/7350php/common.c
diff options
context:
space:
mode:
authorRoot THC2026-02-24 12:42:47 +0000
committerRoot THC2026-02-24 12:42:47 +0000
commitc9cbeced5b3f2bdd7407e29c0811e65954132540 (patch)
treeaefc355416b561111819de159ccbd86c3004cf88 /exploits/7350php/common.c
parent073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff)
initial
Diffstat (limited to 'exploits/7350php/common.c')
-rw-r--r--exploits/7350php/common.c318
1 files changed, 318 insertions, 0 deletions
diff --git a/exploits/7350php/common.c b/exploits/7350php/common.c
new file mode 100644
index 0000000..9b28d61
--- /dev/null
+++ b/exploits/7350php/common.c
@@ -0,0 +1,318 @@
1
2#include <sys/time.h>
3#include <netinet/in.h>
4#include <time.h>
5#include <stdarg.h>
6#include <stdio.h>
7#include <string.h>
8#include <stdlib.h>
9#include "common.h"
10
11
12#ifdef DEBUG
13void
14debugp (char *filename, const char *str, ...)
15{
16 FILE *fp; /* temporary file pointer */
17 va_list vl;
18
19 fp = fopen (filename, "a");
20 if (fp == NULL)
21 return;
22
23 va_start (vl, str);
24 vfprintf (fp, str, vl);
25 va_end (vl);
26
27 fclose (fp);
28
29 return;
30}
31
32void
33hexdump (char *filename, unsigned char *data, unsigned int amount)
34{
35 FILE *fp; /* temporary file pointer */
36 unsigned int dp, p; /* data pointer */
37 const char trans[] =
38 "................................ !\"#$%&'()*+,-./0123456789"
39 ":;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm"
40 "nopqrstuvwxyz{|}~...................................."
41 "....................................................."
42 "........................................";
43
44 fp = fopen (filename, "a");
45 if (fp == NULL)
46 return;
47
48 fprintf (fp, "\n-packet-\n");
49
50 for (dp = 1; dp <= amount; dp++) {
51 fprintf (fp, "%02x ", data[dp-1]);
52 if ((dp % 8) == 0)
53 fprintf (fp, " ");
54 if ((dp % 16) == 0) {
55 fprintf (fp, "| ");
56 p = dp;
57 for (dp -= 16; dp < p; dp++)
58 fprintf (fp, "%c", trans[data[dp]]);
59 fflush (fp);
60 fprintf (fp, "\n");
61 }
62 fflush (fp);
63 }
64 if ((amount % 16) != 0) {
65 p = dp = 16 - (amount % 16);
66 for (dp = p; dp > 0; dp--) {
67 fprintf (fp, " ");
68 if (((dp % 8) == 0) && (p != 8))
69 fprintf (fp, " ");
70 fflush (fp);
71 }
72 fprintf (fp, " | ");
73 for (dp = (amount - (16 - p)); dp < amount; dp++)
74 fprintf (fp, "%c", trans[data[dp]]);
75 fflush (fp);
76 }
77 fprintf (fp, "\n");
78
79 fclose (fp);
80 return;
81}
82
83#endif
84
85
86/* m_random
87 *
88 * return a random number between `lowmark' and `highmark'
89 */
90
91int
92m_random (int lowmark, int highmark)
93{
94 long int rnd;
95
96 /* flip/swap them in case user messed up
97 */
98 if (lowmark > highmark) {
99 lowmark ^= highmark;
100 highmark ^= lowmark;
101 lowmark ^= highmark;
102 }
103 rnd = lowmark;
104
105 rnd += (random () % (highmark - lowmark));
106
107 /* this is lame, i know :)
108 */
109 return (rnd);
110}
111
112
113/* set_tv
114 *
115 * initializes a struct timeval pointed to by `tv' to a second value of
116 * `seconds'
117 *
118 * return in any case
119 */
120
121void
122set_tv (struct timeval *tv, int seconds)
123{
124 tv->tv_sec = seconds;
125 tv->tv_usec = 0;
126
127 return;
128}
129
130
131/* xstrupper
132 *
133 * uppercase a string `str'
134 *
135 * return in any case
136 */
137
138void
139xstrupper (char *str)
140{
141 for (; *str != '\0'; ++str) {
142 if (*str >= 'a' && *str <= 'z') {
143 *str -= ('a' - 'A');
144 }
145 }
146
147 return;
148}
149
150
151/* concating snprintf
152 *
153 * determines the length of the string pointed to by `os', appending formatted
154 * string to a maximium length of `len'.
155 *
156 */
157
158void
159scnprintf (char *os, size_t len, const char *str, ...)
160{
161 va_list vl;
162 char *ostmp = os + strlen (os);
163
164 va_start (vl, str);
165 vsnprintf (ostmp, len - strlen (os) - 1, str, vl);
166 va_end (vl);
167
168 return;
169}
170
171
172unsigned long int
173tdiff (struct timeval *old, struct timeval *new)
174{
175 unsigned long int time1;
176
177 if (new->tv_sec >= old->tv_sec) {
178 time1 = new->tv_sec - old->tv_sec;
179 if ((new->tv_usec - 500000) >= old->tv_usec)
180 time1++;
181 } else {
182 time1 = old->tv_sec - new->tv_sec;
183 if ((old->tv_usec - 500000) >= new->tv_usec)
184 time1++;
185 }
186
187 return (time1);
188}
189
190
191/* ipv4_print
192 *
193 * padding = 0 -> don't padd
194 * padding = 1 -> padd with zeros
195 * padding = 2 -> padd with spaces
196 */
197
198char *
199ipv4_print (char *dest, struct in_addr in, int padding)
200{
201 unsigned char *ipp;
202
203 ipp = (unsigned char *) &in.s_addr;
204
205 strcpy (dest, "");
206
207 switch (padding) {
208 case (0):
209 sprintf (dest, "%d.%d.%d.%d", ipp[0], ipp[1], ipp[2], ipp[3]);
210 break;
211 case (1):
212 sprintf (dest, "%03d.%03d.%03d.%03d", ipp[0], ipp[1], ipp[2], ipp[3]);
213 break;
214 case (2):
215 sprintf (dest, "%3d.%3d.%3d.%3d", ipp[0], ipp[1], ipp[2], ipp[3]);
216 break;
217 default:
218 break;
219 }
220
221 return (dest);
222}
223
224
225void *
226xrealloc (void *m_ptr, size_t newsize)
227{
228 void *n_ptr;
229
230 n_ptr = realloc (m_ptr, newsize);
231 if (n_ptr == NULL) {
232 fprintf (stderr, "realloc failed\n");
233 exit (EXIT_FAILURE);
234 }
235
236 return (n_ptr);
237}
238
239
240char *
241xstrdup (char *str)
242{
243 char *b;
244
245 b = strdup (str);
246 if (b == NULL) {
247 fprintf (stderr, "strdup failed\n");
248 exit (EXIT_FAILURE);
249 }
250
251 return (b);
252}
253
254
255void *
256xcalloc (int factor, size_t size)
257{
258 void *bla;
259
260 bla = calloc (factor, size);
261
262 if (bla == NULL) {
263 fprintf (stderr, "no memory left\n");
264 exit (EXIT_FAILURE);
265 }
266
267 return (bla);
268}
269
270
271/* source by dk
272 */
273
274char *
275allocncat (char **to, char *from, size_t len)
276{
277 int rlen = strlen (from);
278 int null = *to == NULL;
279
280 len = rlen < len ? rlen : len;
281 *to = realloc (*to, (null ? 0 : strlen (*to)) + len + 1);
282 if (null)
283 **to = '\0';
284
285 if (*to == NULL)
286 perror ("no memory: ");
287
288 return (strncat (*to, from, len));
289}
290
291
292char *
293alloccat (char **to, char *from)
294{
295 return (allocncat (to, from, strlen (from)));
296}
297
298
299char *
300ip_get_random (void)
301{
302 char *ip = xcalloc (1, 17);
303 int i[4];
304
305 for (;;) {
306 i[0] = m_random (1, 239);
307 if (i[0] != 10 && i[0] != 127 && i[0] != 192)
308 break;
309 }
310 i[1] = m_random (1, 254);
311 i[2] = m_random (1, 254);
312 i[3] = m_random (1, 254);
313
314 sprintf (ip, "%d.%d.%d.%d", i[0], i[1], i[2], i[3]);
315
316 return (ip);
317}
318