nasl -k implementation & kb loading bugs in nessusd II
Pavel Kankovsky <[email protected]>
| Newsgroups | gmane.comp.security.nessus.devel |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 23 Mar 2004, Pavel Kankovsky wrote: > This patch makes nasl able to load saved KB files. Oops... The patch is here. --Pavel Kankovsky aka Peak [ Boycott Microsoft--http://www.vcnet.com/bms ] "Resistance is futile. Open your source code and prepare for assimilation." _______________________________________________ Nessus-devel mailing list [email protected] http://mail.nessus.org/mailman/listinfo/nessus-devel
nasl-kb.diff
(text/plain, 3.7 KB)
--- nasl.c.orig Thu Jul 17 20:05:36 2003
+++ nasl.c Mon Mar 22 14:25:52 2004
@@ -82,9 +82,10 @@
}
struct arglist *
-init(hostname, ip)
+init(hostname, ip, kb_data)
char * hostname;
struct in_addr ip;
+ struct arglist * kb_data;
{
struct arglist * script_infos = emalloc(sizeof(struct arglist));
struct arglist * prefs = emalloc(sizeof(struct arglist));
@@ -92,7 +93,8 @@
*pip = ip;
arg_add_value(script_infos, "standalone", ARG_INT, sizeof(int), (void*)1);
- arg_add_value(prefs, "checks_read_timeout", ARG_STRING, 4, estrdup("5"));
+ arg_add_value(prefs, "checks_read_timeout", ARG_STRING, 1, estrdup("5"));
+ arg_add_value(prefs, "port_range", ARG_STRING, 7, estrdup("1-65535"));
arg_add_value(script_infos, "preferences", ARG_ARGLIST, -1, prefs);
if(safe_checks_only != 0)
@@ -100,10 +102,98 @@
arg_add_value(script_infos, "HOSTNAME", ARG_ARGLIST, -1,
init_hostinfos(hostname, pip));
-
+
+ if (kb_data)
+ arg_add_value(script_infos, "key", ARG_ARGLIST, -1, kb_data);
+
return script_infos;
}
+struct arglist *
+load_kb(const char *kb_fname)
+{
+ struct arglist *kb_data;
+ FILE *f;
+ char buf[4096];
+
+ kb_data = emalloc(sizeof(struct arglist));
+ f = fopen(kb_fname, "r");
+ if (!f) {
+ perror(kb_fname);
+ efree(&kb_data);
+ return NULL;
+ }
+
+ /* save_kb does an extra fgets()?! */
+
+ while (fgets(buf, sizeof(buf) - 1, f)) {
+ int type, old_type;
+ char *name, *value, *t, *tn;
+ struct arglist *arg;
+
+#define FIELD(sep) \
+ t = tn; tn = strchr(t, sep); \
+ if (!tn) continue; \
+ *tn++ = '\0';
+
+ buf[strlen(buf) - 1]='\0'; /* chomp(buf) */
+ tn = buf;
+ FIELD(' ');
+ /* buf..t is timestamp, ignored here */
+ FIELD(' ');
+ type = atoi(t);
+ FIELD('=');
+ name = t;
+ value = tn;
+
+#undef FIELD
+
+ /* ignore these entries */
+ if (strcmp(name, "Host/dead") == 0 ||
+ strncmp(name, "/tmp/", 4) == 0 ||
+ strcmp(name, "Host/ping_failed") == 0)
+ continue;
+
+ /* convert values to arglists when necessary */
+ arg = kb_data;
+ old_type = arg_get_type(kb_data, name);
+ if (old_type > 0) {
+ /* This is odd...other multivalued kbs seen in the wild
+ * like Transport/SSL */
+ if (!strncmp(name, "Services/", 9)) {
+ if (old_type == ARG_ARGLIST)
+ arg = arg_get_value(kb_data, name);
+ else {
+ arg = emalloc(sizeof(struct arglist));
+ arg_add_value(arg, name, old_type, -1,
+ arg_get_value(kb_data, name));
+ arg_set_value(kb_data, name, -1, arg);
+ arg_set_type(kb_data, name, ARG_ARGLIST);
+ }
+ }
+ else {
+ fprintf(stderr, "%s: warning: unexpected multivalued kb %s\n",
+ kb_fname, name);
+ }
+ }
+
+ if (type == ARG_STRING) {
+ char *tmp = rmslashes(value);
+ arg_add_value(arg, name, ARG_STRING, strlen(tmp), tmp);
+ }
+ else if (type == ARG_INT) {
+ arg_add_value(arg, name, ARG_INT, sizeof(int), (void*) atoi(value));
+ }
+ else {
+ fprintf(stderr, "%s: warning: unsupported type %d\n",
+ kb_fname, type);
+ }
+ }
+
+ fclose(f);
+ return kb_data;
+}
+
void
usage()
{
@@ -126,7 +216,8 @@
int i;
char * target = NULL;
char * default_target = "127.0.0.1";
- char * kb_fname;
+ char * kb_fname = NULL;
+ struct arglist * kb_data = NULL;
void * hg_globals;
struct in_addr ip;
int start, n;
@@ -215,9 +306,13 @@
hg_globals = hg_init(target, 4);
efree(&target);
+ if (kb_fname) {
+ kb_data = load_kb(kb_fname);
+ }
+
while(hg_next_host(hg_globals, &ip, hostname, sizeof(hostname)) >= 0)
{
- script_infos = init(hostname, ip);
+ script_infos = init(hostname, ip, kb_data);
n = start;
while(argv[n])
{