Changeset 1680

Show
Ignore:
Timestamp:
08/13/08 15:44:06 (3 months ago)
Author:
jose
Message:

[phoneyc] save files even if clam isn't running (bug); dump links (for w); one shot (for w, d)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • phoneyc/trunk/honeywalk.py

    r1485 r1680  
    1717    -d          output a Graphviz directed graph 
    1818                of URLs walked 
     19    -D          dump alist of URLs on the page 
     20    -1          only analyze the one URL 
    1921""" % progname 
    2022    print usagestr 
     
    2830    m = md5.md5(body).hexdigest() 
    2931    if len(body) == 0: return '-' 
    30     try: 
    31         os.stat('/tmp/clamd') 
    32     except OSError: return m, '!!!' 
    3332    f = open('/tmp/hc-walk-scan-%s' % m, 'wb') 
    3433    f.write(body) 
    3534    f.close() 
     35    try: os.stat('/tmp/clamd') 
     36    except OSError: return m, '!!!' 
    3637    o, i, e = popen2.popen3('/usr/local/bin/clamdscan /tmp/hc-walk-scan-%s' % m) 
    3738    try: r = o.read().split('\n')[0].split(':')[1].strip() 
     
    4243    return m, r 
    4344 
    44 def walk(hc, URL, referrer, visited, depth): 
     45def walk(hc, URL, referrer, visited, depth, options): 
    4546    if referrer and not depth.has_key(URL):  
    4647        depth[URL] = depth[referrer] + 1 
     
    7374    print js,  
    7475    print scan(js[0]) 
     76    if options['do_list']: 
     77        print URL 
     78        for l in hc.pages[URL].links: 
     79            print ' --> %s' % l 
    7580    #print hc.vbs_eval(url=URL, html=page.contents) 
    7681    #vbs = hc.vbs_eval(URL) 
     82    if options['do_one']: return 
    7783    for url in hc.pages[URL].links: 
    7884        if url not in visited and url.startswith('http'): 
    7985            host = url.split('/')[2] 
    8086            if not hc.ignored(host): 
    81                 walk(hc, url, URL, visited, depth
     87                walk(hc, url, URL, visited, depth, options
    8288 
    8389def main(argv): 
    84     try: opts, args = getopt.getopt(argv[1:], 'dh') 
     90    try: opts, args = getopt.getopt(argv[1:], 'dD1h') 
    8591    except: usage(sys.argv[0]) 
    8692 
    87     do_dot = False 
     93    options = {} 
     94    options['do_dot'] = False 
     95    options['do_one'] = False 
     96    options['do_list'] = False 
    8897    for o, a in opts: 
    89         if o == '-d': do_dot = True 
     98        if o == '-d': options['do_dot'] = True 
     99        elif o == '-D': options['do_list'] = True 
     100        elif o == '-1': options['do_one'] = True 
    90101        else: usage(sys.argv[0]) 
    91102    url = args[0] 
     
    93104    start = time.time() 
    94105    print 'HoneyWalk started at %s UTC' % time.asctime(time.gmtime()) 
    95     try: walk(hc, url, False, [], {url: 0}
     106    try: walk(hc, url, False, [], {url: 0}, options
    96107    except KeyboardInterrupt: print '' 
    97108    end = time.time() 
    98109 
    99     if do_dot
     110    if options['do_dot']
    100111        print 'walked %d URLs in %f seconds' % (hc.cnt, end-start) 
    101112        print '\n\ndigraph "%s" {' % url