Browse code

First draft of CheckURL

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@733 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/08/09 06:32:39
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Sun Aug  8 22:31:12 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav/mbox:	Started code (not yet enabled by default) to scan URLs
4
+  				embedded in emails for viruses.
5
+
1 6
 Sun Aug  8 20:14:04 BST 2004 (njh)
2 7
 ----------------------------------
3 8
   * libclamav:		Improved the efficiency of scanning of emails for
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.93  2004/08/08 21:30:47  nigelhorne
21
+ * First draft of CheckURL
22
+ *
20 23
  * Revision 1.92  2004/08/08 19:13:14  nigelhorne
21 24
  * Better handling of bounces
22 25
  *
... ...
@@ -264,7 +267,7 @@
264 264
  * Compilable under SCO; removed duplicate code with message.c
265 265
  *
266 266
  */
267
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.92 2004/08/08 19:13:14 nigelhorne Exp $";
267
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.93 2004/08/08 21:30:47 nigelhorne Exp $";
268 268
 
269 269
 #if HAVE_CONFIG_H
270 270
 #include "clamav-config.h"
... ...
@@ -351,6 +354,7 @@ static	bool	continuationMarker(const char *line);
351 351
 static	int	parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const char *arg);
352 352
 static	void	saveTextPart(message *m, const char *dir);
353 353
 static	bool	saveFile(const blob *b, const char *dir);
354
+static	void	checkURLs(message *m, const char *dir);
354 355
 
355 356
 /* Maximum number of attachments that we accept */
356 357
 #define	MAX_ATTACHMENTS	10
... ...
@@ -1258,6 +1262,7 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1258 1258
 									addAttachment = TRUE;
1259 1259
 								}
1260 1260
 							} else {
1261
+								checkURLs(aMessage, dir);
1261 1262
 								messageAddArgument(aMessage, "filename=textportion");
1262 1263
 								addAttachment = TRUE;
1263 1264
 							}
... ...
@@ -2192,6 +2197,67 @@ saveFile(const blob *b, const char *dir)
2192 2192
 	return (close(fd) >= 0);
2193 2193
 }
2194 2194
 
2195
+#if	0
2196
+static void
2197
+checkURLs(message *m, const char *dir)
2198
+{
2199
+	blob *b = messageToBlob(m);
2200
+	char *ptr;
2201
+	size_t len;
2202
+
2203
+	if(b == NULL)
2204
+		return;
2205
+
2206
+	ptr = blobGetData(b);
2207
+	len = blobGetDataSize(b);
2208
+
2209
+	while(len >= 8) {
2210
+		/* FIXME: allow any number of white space */
2211
+		if(strncasecmp(ptr, "<a href=", 8) == 0) {
2212
+			char *p2 = &ptr[8];
2213
+			char *p3;
2214
+			char cmd[512];
2215
+			char name[512];
2216
+
2217
+			len -= 8;
2218
+			while((len > 0) && ((*p2 == '\"') || isspace(*p2))) {
2219
+				len--;
2220
+				p2++;
2221
+			}
2222
+			if(len == 0)
2223
+				break;
2224
+			ptr = p2;
2225
+			while((len > 0) && (isalnum(*ptr) || strchr("?/:.", *ptr))) {
2226
+				ptr++;
2227
+				len--;
2228
+			}
2229
+			if(len == 0)
2230
+				break;
2231
+			*ptr = '\0';
2232
+			cli_dbgmsg("Downloading URL %s to be scanned", p2);
2233
+			strncpy(name, p2, sizeof(name));
2234
+			for(p3 = name; *p3; p3++)
2235
+				if(*p3 == '/')
2236
+					*p3 = '_';
2237
+
2238
+			snprintf(cmd, sizeof(cmd), "GET %s > %s/%s", p2, dir, name);
2239
+			cli_dbgmsg("%s\n", cmd);
2240
+			system(cmd);
2241
+		} else {
2242
+			ptr++;
2243
+			len--;
2244
+		}
2245
+	}
2246
+	blobDestroy(b);
2247
+}
2248
+#else
2249
+static void
2250
+checkURLs(message *m, const char *dir)
2251
+{
2252
+}
2253
+#endif
2254
+
2255
+
2195 2256
 #ifdef HAVE_BACKTRACE
2196 2257
 static void
2197 2258
 sigsegv(int sig)