Re: mySQL database for nessusd (code!)

Javier Fernandez-Sanguino <[email protected]>
Newsgroups gmane.comp.security.nessus.devel
Organization Germinus
Message-ID <[email protected]>
William Heinbockel wrote:
>>	Which ones specifically?
>>
> 
> All of the ID's...
> Currently I'm using the timestamp for the SessionID, but have no
> idea what to do with the UserID, ExecutionID, ProtocolID...

	ExecutionID, ProtocolID and UserID should be autoincrement IDs used by 
the database. You don't have to worry about them, when you insert any 
new item in the table it should get a unique (and distinct ID).
	Say you want to create a new session:

INSERT INTO Session (StartTime, Preferences, Configuration, 
IPAdresses...) VALUES (X, Y, Z, W)

	Say you want to retrieve the SessionID:

SELECT SessionID from Session where StarTime='X';

	You can do this inmediately after inserting so you can be sure that's 
your proper SessionID and pass that info between functions.

	Say you want to add a new service detected by a port scanner, the 
service runs in TCP portnumber 80:

Service = SELECT ServiceID FROM Services, Protocol WHERE 
Services.ProtocolID=Protocol.ProtocolID AND Protocol=6 and PortNumber=80

(Note: TCP is protocol #6 TCP)

INSERT INTO DetectedService (PluginID,HostId,SessionID,ServiceID) VALUES
(X,Y,Z, 'Service')

> This is probably most due to my lack of knowledge with databases.
> And what is UserSessions::Location and User::Hash?

	UserSessions::Location is the place the Nessus client is connected from 
(IP address). User::Hash is the password IIRC. Will have to check.

> 
> It might also end up being a problem to store these ID's and pass
> them in the program.

	There's no need to pass them back. Just retrieve them using an SQL 
statement whenever it's needed. It's also better to pass this (numeric) 
IDs from function to function that to pass a whole lot of other information.

> 
> Right now, I am mainly trying to focus on where the information for the
> database can be best obtained, for some stuff with the plugins, such
> as RevisionNumber, you might have to integrate some code into NASL and
> such.  I don't know for certain though.
>  

	Don't worry about information that should be in the database _before_ 
running a scan. These information should be created based on a SQL 
script that gets loaded (by the user) as part of the database creation 
he needs to (manually) do. After all he needs to create the schema for 
the database before using it. The following tables, IMHO, should be 
created that way (instead of having the nessus server populate them):

- Plugin information: Nessus-plugin, Plugin-CVE, Plugin-BID
- Services information: Services, Protocol

User information should be probably included by the nessus-adduser 
scripts. Whileas UserSession/Session information should be included when 
the session starts/ends.

	Regards

	Javi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.