{"id":39,"date":"2008-02-03T15:56:28","date_gmt":"2008-02-03T15:56:28","guid":{"rendered":"http:\/\/pentestmonkey.net\/?p=39"},"modified":"2011-08-20T15:51:13","modified_gmt":"2011-08-20T15:51:13","slug":"osvdb-import","status":"publish","type":"post","link":"https:\/\/pentestmonkey.net\/blog\/osvdb-import","title":{"rendered":"Importing OSVDB into a Postgres Database"},"content":{"rendered":"
I was looking at the Open Source Vulnerbility Database<\/a> (OSVDB) recently.\u00a0 If you haven’t come across it before, it’s a source vulnerability information, similar to bugtraq<\/a> or secunia<\/a>.<\/p>\n OSVDB has a good web frontend which is easy to search.\u00a0 I was investigating if the database could be downloaded and searched offline during onsite pentests when no Internet connection is available.<\/p>\n In this post I talk about some of the problems I encountered and how I worked around them.\u00a0 OSVDB is a fantastic resource and I hope this post helps you get some use out of it.<\/p>\n <\/p>\n Once you agree to the license<\/a> it’s possible to download XML dupms of the OSVDB database.\u00a0 At the time of writing these were about 100 MB when uncompressed and contained information on around 40,000 vulnerabilities.\u00a0 This should be a valuable asset when you’re cut off from the Internet.<\/p>\n There are several ways you could go about searching this information.\u00a0 The ones that occurred to me initially were:<\/p>\n Surprisingly, I couldn’t find an existing interface to search OSVDB offline.\u00a0 I’m sure they must exist.\u00a0 Let me know<\/a> if you find one. (Update: see the end of this post).<\/p>\n Grepping the XML file is fast, but making humans read XML is kinda nasty.<\/p>\n I had a brief attempt at writing a command-line tool, but found that PERL’s XML::Simple module took several minutes to read in the 100 MB XML file – even before you attempted to do any searching.\u00a0 I wasn’t willing to wait several minutes for each query, so skipped this option.<\/p>\n The OSVDB website provides database schemas<\/a> for MySQL and PostgreSQL.\u00a0 There’s also a brilliant diagram<\/a> of the schema along with a PERL-based import script<\/a> to read the XML and squirt it into your database.<\/p>\n I ran into some problems importing the XML data into my Postgres database.\u00a0 I’m sure I’ve had it working in the past, but this time round I found that the script took up 500MB of memory, ran for 16 hours or so, then produced an error like:<\/p>\n or:<\/p>\n I also found that incorrect relationships where being created in the “credit” table.<\/p>\n I spent a week or so trying to fix the import script and eventually undertook to write a replacement.<\/p>\n I’m pretty happy that my replcement script, osvdb-xml-to-postgres.pl<\/a> parses the XML properly and creates the correct relationships in the database.\u00a0 However, it’s no faster and uses 2.4GB of RAM.\u00a0 Oops!\u00a0 It’s fairly elegant, but apparently not that efficient.<\/p>\n Here’s an example of how I ran it:<\/p>\n First I made some minor changes to the schema.\u00a0 These are explained in the following section.\u00a0 Download the modified: OSVDB-procedures.sql<\/a> , OSVDB-tables.sql<\/a> and OSVDB-views.sql<\/a>.\u00a0 Also make sure you’ve downloaded the XML file<\/a> (register first).<\/p>\n Next, create a database then run the import script:<\/p>\n If you interrupt the process for some reason, you can resume the import by doing:<\/p>\n Existing entries won’t be overwritten.<\/p>\n Database connection parameters are hard coded at present.\u00a0 You might need to edit these in osvdb-xml-to-postgres.pl<\/a>:<\/p>\n I use PERL’s DBI, so it should be trivial to modify this script to work with MySQL instead of postgres.\u00a0 I haven’t tried this, though.<\/p>\n The table “ext_txt” no longer has an author_id field.\u00a0 I couldn’t see how to parse this information from the XML dump.\u00a0 “vuln”s still have authors, but “external texts” don’t.\u00a0 Views were updated to reflect this change.<\/p>\n I also removed this primary key from the “author” table:<\/p>\n The XML dump seems to violate this uniquness contstraint.<\/p>\n If you don’t want to run the import don’t mind using a potentially out-of-data version of OSVDB here’s a SQL dump (6MB compressed): osvdb-postgres-2008-1-18.sql.bz2<\/a> .<\/p>\n To restore it:<\/p>\n It’s a 41MB SQL file, so the import should take a while.<\/p>\n I haven’t got round to writing a tool yet!\u00a0 I’ll make another post when I get round to this.\u00a0\u00a0 (See update at and of this post for SQLite \/ Ruby on rails tool).<\/p>\n In order to comply with section 5 of the OSVDB Free License<\/a> I’m required to inform you of the following with regard to the SQL schema and SQL dump above:<\/p>\n “This product includes data from the Open Source Vulnerability Database developed by OSVDB (www.osvdb.org) and its contributors.”<\/p>\n It’s also interesting to note that you may need to comply with the license<\/a> depending on what you want to do with the database.\u00a0 Section 8 of the license says it best:<\/p>\n “NON TRANSFERABILITY: This Free License is non-transferable. This means that it applies to you, not to the people you distribute the product to. These people are subject to the same Copyright and MAY OR MAY NOT qualify for their own, free, unregistered license.”<\/p>\n Not long after I made this post, OSVDB release their database in CSV, MySQL dump and SQLite format<\/a> (you need to create an account first).\u00a0 This is great news for pentesters and other professions who need access to OSVDB offline.\u00a0 There’s even an offline tools for browsing the SQLite database called OSVDB Personal Edition<\/a> .<\/p>\n OSVDB Personal Edition is a ruby on rails web server which uses a SQLite backend.\u00a0 It’s VERY easy to install, has a simple search feature and has none of the performance problems associated with slurping a big XML file into memory.\u00a0 It’s meant as a PoC, but it’s still useful.\u00a0 Pentesters beware, though: the web server binds to 0.0.0.0 instead of 127.0.0.1which is probably not what you want. \ud83d\ude42<\/p>\n Great work OSVDB!\u00a0 Keep it up.<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" I was looking at the Open Source Vulnerbility Database (OSVDB) recently.\u00a0 If you haven’t come across it before, it’s a source vulnerability information, similar to bugtraq or secunia. OSVDB has a good web frontend which is easy to search.\u00a0 I was investigating if the database could be downloaded and searched offline during onsite pentests when […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[95,84],"_links":{"self":[{"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/posts\/39"}],"collection":[{"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":2,"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":381,"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/posts\/39\/revisions\/381"}],"wp:attachment":[{"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pentestmonkey.net\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}Downloading OSVDB<\/h3>\n
Searching your Offline OSVDB<\/h3>\n
\n
Importing OSVDB XML file to a SQL database<\/h3>\n
Insert Vuln.DBD::Pg::st execute failed: ERROR:\u00a0 invalid input syntax for type timestamp: \"\"\r\nError: ERROR:\u00a0 invalid input syntax for type timestamp: \"\"<\/pre>\n
Insert Ext Ref Value..........................DBD::Pg::st execute failed: ERROR:\u00a0 duplicate key violates unique constraint \"ext_ref_value_pkey\"<\/pre>\n
Error: ERROR:\u00a0 duplicate key violates unique constraint \"ext_ref_value_pkey\"<\/pre>\n
Alternative Import Script for Postgres<\/h3>\n
$ dropdb -U postgres osvdb; createdb -U postgres osvdb; cat OSVDB-tables.sql OSVDB-views.sql OSVDB-procedures.sql | psql -U postgres osvdb; perl osvdb-xml-to-postgres.pl xmlDumpByID-2008-1-18.xml<\/pre>\n
$ osvdb-xml-to-postgres.pl xmlDumpByID-2008-1-18.xml<\/pre>\n
my $dbname = \"osvdb\";\r\nmy $port = 5432;\r\nmy $host = \"localhost\";\r\nmy $username = \"postgres\";\r\nmy $password = \"\";<\/pre>\n
Modifications to the Database Schema<\/h3>\n
PRIMARY KEY (author_name, author_email)<\/pre>\n
Postgres SQL Dump<\/h3>\n
$ createdb -U postgres osvdb<\/pre>\n
$ psql -U postgres osvdb -c 'create user osvdb'<\/pre>\n
$ bzcat osvdb-postgres-2008-1-18.sql.bz2 | psql -U postgres osvdb<\/pre>\n
Searching the Schema<\/h3>\n
Legal Stuff<\/h3>\n
UPDATE 2007-02-08<\/h3>\n