Advertisement
Ollie920049

load_db.q

May 3rd, 2012
2,425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
q/kdb+ 3.00 KB | None | 0 0
  1. / =====================================================================================
  2. /      Filename:  load_db.q
  3. /   Description:  Loads three files (main.ndb, main.hdb and ftsigs). The script
  4. /                 proccesses each file converting it into a format that QScanner
  5.  
  6. /       Version:  1.0
  7. /       Created:  23/02/12 15:42:19
  8.  
  9. /        Author:  Oliver Fletcher, ttolf@lboro.ac.uk
  10. /    University:  Loughborough University
  11. / =====================================================================================
  12.  
  13. virus_sigs:("SISS";":") 0: `:main.ndb                    / Load main.ndb, convert to
  14. virus_sigs:virus_sigs _2;                                / string and flip to a table
  15. virus_sigs[2]:string virus_sigs[2];
  16. virus_sigs:flip `MalwareName`TargetType`HexSig!(virus_sigs)
  17.  
  18. md5_sigs: ("SIS";":") 0: `:main.hdb                      / Load main.hdb, convert to
  19. md5_sigs[0]:string md5_sigs[0];                          / string and flip to a table
  20. md5_sigs: flip `MD5`Size`MalwareName!(md5_sigs)
  21.  
  22. virus_sigs[`HexSig]:{[xx]                                / ClamAV contains ? as wild
  23.   ssr[xx;"?";"."]                                        / cards. Use ssr to replace
  24.   }peach virus_sigs[`HexSig];                            / them with . for regex
  25.  
  26. virus_sigs[`HexSig]:{[xx]                                / Convert * to .*
  27.   ssr[xx;"*";".*"]
  28.   }peach virus_sigs[`HexSig];
  29.  
  30. virus_sigs[`HexSig]:{[xx]                                / Convert {n+}.. to a regex
  31.   xx:"{" vs xx;xx:"}" vs/: xx;xx                          / format.
  32.   }peach virus_sigs[`HexSig];                            
  33.  
  34. adjust:{[c]$[c like "-*";t:"(..){0",c,"}";                / Adjust replaces:
  35.     $[c like "*-";t:"(..){",c,"}";                        / -* with "(..){0",c,"}"
  36.       $[c like "*?-?*";t:"(..){",c,"}";                  / *- with "(..){",c,"}"
  37.         t:"(..){",c,"}"]]];t};                            / *?-?* with "(..){",c,"}"
  38.                                                          / else "(..){",c,"}"
  39.                                                          
  40. virus_sigs[`HexSig]:{[zz]                                / Apply to the list of lists
  41.   {[xx]
  42.     $[(count xx)~2;adjust[xx[0]],xx[1];xx]
  43.     }each zz
  44.   }each virus_sigs[`HexSig];
  45.  
  46.                                                          / Raze then replace - with ,
  47. virus_sigs[`HexSig]:raze each raze each virus_sigs[`HexSig];
  48. virus_sigs[`HexSig]:{[ex]ssr[ex;"-";","]}each virus_sigs[`HexSig];
  49.  
  50. filetype_sigs:("ISS";",") 0: `:ftsigs.db                  / Load file type sigs
  51. filetype_sigs[1]:string filetype_sigs[1];
  52. filetype_sigs:flip `fileType`Sig`Ext!(filetype_sigs);
  53.  
  54.                                                          / Add a table of file types
  55. filetype_iden:([]Id:(0;1;2;3;4;5;6;7;8;9;10);Name:("Any file type";"Windows PE";"OLE";"Normalized HTML";"E-mail file";"Images";"ELF";"Normalized ASCII file";"Unused";"Mach-O binaries";"Unknown"));
  56.  
  57. save `:filetype_iden
  58. save `:filetype_sigs
  59. save `:md5_sigs
  60. save `:virus_sigs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement