예제 #1
0
 def email_detail_template(self, email_id=''):
     title='SHIVA honeypot: view email'
     
     emails = backend_operations.retrieve_by_ids([email_id])
     
     # display error message and terminate
     if not emails:
         template = Template('<%include file="view_email.html"/>', lookup=self.template_lookup, output_encoding='utf-8', encoding_errors='replace')
         return template.render(title=title)
     
     mailFields = emails[0]
     
     
     
     if mailFields:        
         # store html content to static file if it doesn't exist
         staticHtmlFile = self.rawHtmlPath + '/' + email_id 
 
         if not os.path.exists(staticHtmlFile):
             f = open(staticHtmlFile, 'w')
             if f:
                 f.write(mailFields['html'].encode('utf8'))
                 f.close()
             else:
                 staticHtmlFile = ''
     
     email_result = backend_operations.get_results_of_email(mailFields['s_id'])
     template = Template('<%include file="view_email.html"/>', lookup=self.template_lookup, output_encoding='utf-8', encoding_errors='replace')
     return template.render(title=title, email_result=email_result, mailFields=mailFields, attachmentsPath=self.attachmentsPath,staticHtmlFile=staticHtmlFile)
예제 #2
0
def prepare_matrix():
    """     
    reads results of learning into database and returns them as a matrix
    suitable for further processing
    
    Method should be called  when database is in consistent state.
    
    Produced matrix has format [M + 1, N + 1]
    
    M is count of emails in database, first two rows contains rule codes.
    Firs column of each of M rows contains derived status (1 for phishing, 0 for spam)
    
    
    Entries [0][0], [1][0] are constant with no practical meaning
    
    Matrix format:
    
    
    [ '_code'         , code1          , code2           ... codeN           ]
    [ derived_status1 , rule_1_1_result, rule_1_2_result ... rule_1_N_result ]
    [ derived_status2 , rule_2_1_result, rule_2_2_result ... rule_2_N_result ]
    .                   .                .                   .
    .                   .                .                   .
    .                   .                .                   .
    [ derived_statusM , rule_M_1_result, rule_M_2_result ... rule_M_N_result ] 
    """
    matrix = []

    # indicator of walkthrough
    first_loop = True

    for email_id in backend_operations.get_email_ids():

        email_result = backend_operations.get_results_of_email(email_id)
        if "rules" in email_result:

            # sort rules to ensure same order in all rows of matrix
            sorted_rules = sorted(email_result["rules"], key=lambda a: a["code"])

            # add first row into matrix (codes) during first walkthrough
            if first_loop:
                first_row = ["_derived_result"]
                first_row.extend(map(lambda a: a["code"], sorted_rules))

                matrix.append(first_row)
                first_loop = False

            # append row of matrix
            sorted_resuls_vector = [1] if email_result["derivedStatus"] else [0]
            sorted_resuls_vector.extend(map(lambda a: a["result"], sorted_rules))
            matrix.append(sorted_resuls_vector)

    # write matrix to file
    out_file = open("../../../web/learning_output.csv", "w")
    if out_file:
        for row in matrix:
            out_file.write(",".join(map(lambda a: str(a), row)))
            out_file.write("\n")
        out_file.close()

    return matrix
예제 #3
0
def prepare_matrix():
    """     
    reads results of learning into database and returns them as a matrix
    suitable for further processing
    
    Method should be called  when database is in consistent state.
    
    Produced matrix has format [M + 1, N + 1]
    
    M is count of emails in database, first two rows contains rule codes.
    Firs column of each of M rows contains derived status (1 for phishing, 0 for spam)
    
    
    Entries [0][0], [1][0] are constant with no practical meaning
    
    Matrix format:
    
    
    [ '_code'         , code1          , code2           ... codeN           ]
    [ derived_status1 , rule_1_1_result, rule_1_2_result ... rule_1_N_result ]
    [ derived_status2 , rule_2_1_result, rule_2_2_result ... rule_2_N_result ]
    .                   .                .                   .
    .                   .                .                   .
    .                   .                .                   .
    [ derived_statusM , rule_M_1_result, rule_M_2_result ... rule_M_N_result ] 
    """     
    matrix = []
    
    # indicator of walkthrough 
    first_loop = True;
    
    for email_id in backend_operations.get_email_ids():
        
        email_result = backend_operations.get_results_of_email(email_id)
        if 'rules' in email_result:
            
            #sort rules to ensure same order in all rows of matrix
            sorted_rules = sorted(email_result['rules'],key=lambda a: a['code'])
            
            #add first row into matrix (codes) during first walkthrough
            if first_loop:
                first_row = ['_derived_result']
                first_row.extend(map(lambda a: a['code'], sorted_rules))
                
                matrix.append(first_row)
                first_loop = False
            
            
            # append row of matrix
            sorted_resuls_vector = [1] if email_result['derivedStatus'] else [0]
            sorted_resuls_vector.extend(map(lambda a: a['result'], sorted_rules))
            matrix.append(sorted_resuls_vector)
         
    # write matrix to file   
    out_file = open('../../../web/learning_output.csv','w')
    if out_file:
        for row in matrix:
            out_file.write(','.join(map(lambda a: str(a), row)))
            out_file.write('\n')
        out_file.close()
            
    return matrix