bonsaiviking

Some Nmap + critical.io fingerprint matching stuff

Nov 1st, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. :~/nmap$ cat extract.py
  2. #!/usr/bin/env python
  3.  
  4. # Extract just the banner from critical.io's json output
  5.  
  6. import fileinput
  7. import json
  8.  
  9. for l in fileinput.input():
  10. print repr(json.loads(l)["banner"])
  11.  
  12. :~/nmap$ cat matchme.pl
  13. #!/usr/bin/perl
  14.  
  15. # Filter out service banners that Nmap already knows about
  16.  
  17. use strict;
  18. use warnings;
  19. use autodie;
  20. use 5.012;
  21.  
  22. # Read in the service match lines
  23. open my $db, '<', "nmap-src/nmap-service-probes";
  24. my @pats;
  25. while (<$db>) {
  26. # Skip irrelevant lines, but capture patterns
  27. next unless /^match \S+ m(.)(.*?)\1/;
  28. # compile the matches
  29. push @pats, qr/$2/;
  30. }
  31.  
  32. # Read in each banner (Python repr() format)
  33. WORD: while (<>) {
  34. # Handle quoting stuff with a dangerous eval
  35. my $str;
  36. my $do = "str = $_;";
  37. $do =~ s/(["\@\$])/\\$1/g;
  38. $do =~ s/u?'/"/g;
  39. eval "\$$do";
  40. # Bail if there's a problem
  41. exit unless defined $str;
  42. # Try matches until we find one that works, then start over.
  43. for my $pat (@pats) {
  44. next WORD if $str =~ /$pat/;
  45. }
  46. # If it won't match anything, print it.
  47. print $_;
  48. }
  49.  
  50. :~/nmap$ history | grep json
  51. 2152 wget https://scans.io/data/rapid7/sonar.cio/critical_201205_22.json.bz2
  52. 2162 bunzip2 <critical_201205_22.json.bz2 | python extract.py critical_201205_22.json | ../other/JohnTheRipper/run/unique banners
  53.  
  54. ("unique" is equivalent to (but faster than) "sort -u" without the sorting)
Advertisement
Add Comment
Please, Sign In to add comment