~ubuntu-branches/ubuntu/precise/xprobe/precise

« back to all changes in this revision

Viewing changes to src/xprobe_module_hdlr.cc

  • Committer: Bazaar Package Importer
  • Author(s): Richard Atterer
  • Date: 2005-02-22 22:54:24 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050222225424-6cqy8rr45pkna819
Tags: 0.2.2-1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: xprobe_module_hdlr.cc,v 1.7 2005/02/09 18:36:45 mederchik Exp $ */
 
2
/*
 
3
** Copyright (C) 2001 Fyodor Yarochkin <fygrave@tigerteam.net>,
 
4
**                    Ofir Arkin       <ofir@sys-security.com>
 
5
**
 
6
** This program is free software; you can redistribute it and/or modify
 
7
** it under the terms of the GNU General Public License as published by
 
8
** the Free Software Foundation; either version 2 of the License, or
 
9
** (at your option) any later version.
 
10
**
 
11
**
 
12
** This program is distributed in the hope that it will be useful,
 
13
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
** GNU General Public License for more details.
 
16
**
 
17
** You should have received a copy of the GNU General Public License
 
18
** along with this program; if not, write to the Free Software
 
19
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
*/
 
21
 
 
22
#include "xprobe.h"
 
23
#include "xprobe_module_hdlr.h"
 
24
#include "interface.h"
 
25
#include "cmd_opts.h"
 
26
#include "xpmodules/static_modules.h"
 
27
#include "log.h"
 
28
 
 
29
extern Interface *ui;
 
30
extern Cmd_Opts *copts;
 
31
extern XML_Log *xml;
 
32
 
 
33
int Xprobe_Module_Hdlr::load(void) {    
 
34
        int cnt=1;
 
35
    xprobe_module_func_t *ptr;
 
36
 
 
37
    ui->msg("[+] Loading modules.\n");
 
38
 
 
39
    ptr = mod_init_funcs;
 
40
    while (ptr !=NULL && ptr->name !=NULL && ptr->func !=NULL) { 
 
41
                if (!copts->mod_is_disabled(cnt++))
 
42
                        add(ptr->func, ptr->name);
 
43
                ptr++;
 
44
        }
 
45
    return 1;
 
46
 
 
47
}
 
48
 
 
49
int Xprobe_Module_Hdlr::init(void) { 
 
50
    map<int, Xprobe_Module *>::iterator m_i;
 
51
 
 
52
    for (m_i = modlist.begin(); m_i != modlist.end(); m_i++) 
 
53
        (*m_i).second->init();
 
54
    return 1;
 
55
}
 
56
 
 
57
int Xprobe_Module_Hdlr::print(void) { 
 
58
    map<int, Xprobe_Module *>::iterator m_i;
 
59
 
 
60
    ui->msg("[+] Following modules are loaded:\n");
 
61
        xml->log(XPROBELOG_MOD_SESS_START, "Loaded modules");
 
62
    for (m_i = modlist.begin(); m_i != modlist.end(); m_i++) {
 
63
        ui->msg("[x] [%d] %s  -  %s\n", (*m_i).first, 
 
64
                        (*m_i).second->get_name(), (*m_i).second->get_desc());
 
65
                xml->log(XPROBELOG_MSG_MODULE, "%t%n%d%s", m_i->second->get_type(), 
 
66
                                m_i->second->get_name(), m_i->first, m_i->second->get_desc());
 
67
        }
 
68
   ui->msg("[+] %i modules registered\n", mod_counter);     
 
69
        xml->log(XPROBELOG_MOD_SESS_END, "End modules");
 
70
   return 1;     
 
71
}
 
72
 
 
73
int Xprobe_Module_Hdlr::exec(int mod_type, Target *tg, OS_Matrix *os) { 
 
74
    map<int, Xprobe_Module *>::iterator m_i;
 
75
 
 
76
    for (m_i = modlist.begin(); m_i != modlist.end(); m_i++)  {
 
77
        if ((*m_i).second->get_type() == mod_type) {
 
78
            xprobe_debug(XPROBE_DEBUG_MODULES, 
 
79
                        "[+] Executing module: %s\n", (*m_i).second->get_name());
 
80
                         (*m_i).second->exec(tg, os);
 
81
        }
 
82
    }
 
83
    return 1;
 
84
}
 
85
 
 
86
int Xprobe_Module_Hdlr::fini(void) { 
 
87
    map<int, Xprobe_Module *>::iterator m_i;
 
88
 
 
89
    //xprobe_debug(XPROBE_DEBUG_MODULES, "[+] Deinitializing modules\n");
 
90
    for (m_i = modlist.begin(); m_i != modlist.end(); m_i++) {
 
91
        xprobe_debug(XPROBE_DEBUG_MODULES, "[+] Deinitializing module: [%i] %s\n", (*m_i).first,
 
92
                (*m_i).second->get_name());
 
93
        (*m_i).second->fini();
 
94
    }
 
95
 
 
96
    for (m_i = modlist.begin(); m_i != modlist.end(); m_i++) 
 
97
        delete (*m_i).second;
 
98
        
 
99
    ui->msg("[+] Modules deinitialized\n");
 
100
    return 1;
 
101
}
 
102
 
 
103
 
 
104
int Xprobe_Module_Hdlr::add(int (*init_func)(Xprobe_Module_Hdlr *, char *), char *nm) {
 
105
 
 
106
    xprobe_debug(XPROBE_DEBUG_MODULES, "[+] adding %s via function: %p\n", nm, init_func);
 
107
    return(init_func(this, nm));
 
108
}
 
109
    
 
110
int Xprobe_Module_Hdlr::register_module(Xprobe_Module *mod) {
 
111
 
 
112
    mod_counter++;
 
113
    mod->set_id(mod_counter);
 
114
    modlist.insert(pair<int, Xprobe_Module *>(mod_counter, mod));
 
115
    
 
116
    return 1;
 
117
}
 
118
 
 
119
void Xprobe_Module_Hdlr::add_keyword(int id, char *str) {
 
120
    string kwd(str);
 
121
 
 
122
    kwdlist.insert(pair<string, int>(kwd, id));
 
123
        keywords++;
 
124
}
 
125
 
 
126
/* XXX: temp plug. Supposed to return module ptr which is registered for
 
127
 * keyword kwd
 
128
 */
 
129
Xprobe_Module *Xprobe_Module_Hdlr::find_mod(string &kwd) {
 
130
    map <string, int>::iterator kw_i;
 
131
    map<int, Xprobe_Module *>::iterator mod_i;
 
132
    
 
133
    kw_i = kwdlist.find(kwd);
 
134
 
 
135
    if (kw_i == kwdlist.end()) {
 
136
        xprobe_debug(XPROBE_DEBUG_CONFIG, "[x] failed to lookup module on %s keyword\n", kwd.c_str());
 
137
        return NULL;
 
138
    }
 
139
    mod_i = modlist.find((* kw_i).second);
 
140
    if (mod_i == modlist.end()) {
 
141
        ui->error("[x] failed to associate moule id!\n");
 
142
        return NULL;
 
143
    }
 
144
    xprobe_debug(XPROBE_DEBUG_CONFIG,"[x] keyword: %s handled by module: %s\n", kwd.c_str(),
 
145
    (*mod_i).second->get_name());
 
146
    return (*mod_i).second;
 
147
}
 
148
 
 
149
int Xprobe_Module_Hdlr::loaded_mods_num(int mod_type) { 
 
150
    map<int, Xprobe_Module *>::iterator m_i;
 
151
    int num = 0;
 
152
 
 
153
    for (m_i = modlist.begin(); m_i != modlist.end(); m_i++) 
 
154
        if ((*m_i).second->get_type() == mod_type) num++;
 
155
 
 
156
    /* sometimes os_test module handles multiple keywords */
 
157
    if (mod_type == XPROBE_MODULE_OSTEST && num < keywords)
 
158
        return keywords;
 
159
 
 
160
    return num;
 
161
}
 
162
 
 
163
int Xprobe_Module_Hdlr::modbyname(char *nm) {
 
164
 
 
165
    xprobe_module_func_t *ptr;
 
166
    int cnt = 0;
 
167
 
 
168
    ptr = mod_init_funcs;
 
169
    while (ptr !=NULL && ptr->name !=NULL && ptr->func != NULL) {
 
170
            cnt++;
 
171
            if (!strcasecmp(ptr->name, nm)) return cnt;
 
172
            ptr++;
 
173
    }
 
174
    return -1;
 
175
 
 
176
}
 
177
 
 
178
void Xprobe_Module_Hdlr::display_mod_names(void) {
 
179
 
 
180
    xprobe_module_func_t *ptr;
 
181
    int cnt = 1;
 
182
 
 
183
    ptr = mod_init_funcs;
 
184
    while (ptr !=NULL && ptr->name !=NULL && ptr->func != NULL) {
 
185
/*
 
186
            ui->msg("%s%c", ptr->name, cnt%4?'\t':'\n');
 
187
            ptr++;
 
188
            cnt++;
 
189
*/
 
190
                ui->msg("[%d] %s\n", cnt++, ptr->name);
 
191
                ptr++;
 
192
 
 
193
        }
 
194
}
 
195
 
 
196
 
 
197
 
 
198
 
 
199
Xprobe_Module_Hdlr::Xprobe_Module_Hdlr(void) {
 
200
    mod_counter = 0;
 
201
    keywords = 0;
 
202
}
 
203
 
 
204
Xprobe_Module_Hdlr::~Xprobe_Module_Hdlr(void) {
 
205
    /* do nothing now */
 
206
}
 
207
 
 
208
int Xprobe_Module_Hdlr::get_module_count() {
 
209
        int modcount=0;
 
210
        xprobe_module_func_t *ptr;
 
211
 
 
212
    ptr = mod_init_funcs;
 
213
    while (ptr !=NULL && ptr->name !=NULL && ptr->func != NULL) {
 
214
                modcount++;
 
215
                ptr++;
 
216
        }
 
217
        return modcount;
 
218
}