def get_filename2(mode='load', title=None): while True: bancls() if title: fpr('%s' % title) print fpr('Please provide a file name:') fn = raw_input(' []> ') print if fn: if mode == 'save': if os.path.isfile(fn): if get_yesno_input (' File already exist. Overwrite it [y/N]: '): return fn #else: # return None else: return fn if mode == 'load': if os.path.exists(fn): return fn else: fpr.fail('File not found') print if get_yesno_input(' Return to menu [y/N]> '): break
def att_plain_sample(mbody, smtype, sm): #from core.data import smpls,fpr,tc,tr #from core.ui.cmenu import Menu #from core.ui.banner import bancls while True: bancls() if smpls[smtype]['astat'] != 0: fpr('It seems you have already attached this type of sample') if not raw_input(' Do you want to append another one [y/N]:') in [ 'y', 'Y' ]: break if True: smpl_menu = Menu(sm) if smpl_menu.op == '': break #if smpl_menu.op == '1': if smpl_menu.op in ['1', '2', '3', '4', '5', '6', '7']: if smpls[smtype][smpl_menu.op].get('sval', '') == '_': mbody.append(smpls[smtype][smpl_menu.op]['val'].replace( smpls[smtype][smpl_menu.op]['sval'], "")) else: mbody.append(smpls[smtype][smpl_menu.op]['val']) smpls[smtype]['astat'] += 1 fpr.ok('Sample attached (x%d)' % smpls[smtype]['astat']) break
def att_raw_sample(mbody, smtype, sm): #from core.data import smpls,fpr,tc,tr #from core.ui.cmenu import Menu #from core.ui.banner import bancls while True: bancls() if smpls[smtype]['astat'] != 0: fpr('It seems you have already attached this type of sample') if not raw_input(' Do you want to append another one [y/N]:') in [ 'y', 'Y' ]: break if True: smpl_menu = Menu(sm) if smpl_menu.op == '': break #if smpl_menu.op == '1': if smpl_menu.op in ['1', '2', '3', '4']: #FIXME this will not work like that for long tmal # fix sampel types in this shity way, the whole code regarding samples need # to be rewritten and reorginize, this is not flexible/scalable if smpls[smtype][smpl_menu.op].get('type') == 'text': #this overwites type under smpls[smtype]['type'] if smpls[smtype][smpl_menu.op].get('sval', '') == '_': # mbody.append(smpls[smtype][smpl_menu.op]['val'].replace("_","")) smtp['content']['text'].append( smpls[smtype][smpl_menu.op]['val'].replace( smpls[smtype][smpl_menu.op]['sval'], "")) else: #print "wtf: %s - %s" % (smtype,smpls[smtype][smpl_menu.op]['val']) #mbody here is smtp['content']['vof'] - this is dict {} - so overwrite #this with fixed path to 'text' or create a seperate att_plain and add #this as mime plain/text ??? #mbody.append(smpls[smtype][smpl_menu.op]['val']) smtp['content']['text'].append( smpls[smtype][smpl_menu.op]['val']) smpls[smtype]['astat'] += 1 fpr.ok('Sample attached (x%d)' % smpls[smtype]['astat']) break else: if smpls[smtype]['type'] == 'b64': #att_b64(mbody,smtype,'1') att_b64(mbody, smtype, smpl_menu.op) elif smpls[smtype]['type'] == 'file': #att_file_sample(mbody,smtype,'1') att_file_sample(mbody, smtype, smpl_menu.op) break
def mimeuse(): #from core.data import smtp,DEBUG #from core.func import info,waitin if smtp['use_mime']: return 1 else: bancls() info('info','You have alredy defined custom Body Content. ' \ 'First flush it before trying to build a message with other options.') waitin() return 0
def dkim_pktest(privkey): if not (privkey or type(privkey) is str): return False m = re.search("--\n(.*?)\n--", privkey, re.DOTALL) if m is None: return False try: bancls() pkdata = base64.b64decode(m.group(1)) fpr('Private key') info('info', m.group(1), adj='l') return True except TypeError, e: fpr(str(e)) return False
def get_filename(): #import os.path while True: bancls() fpr('Load attachment from file') print fpr('Please provide a full path: ') fn = raw_input(' > ') if fn: #content.att_load_file(smtp['content']['att'],attfn) if os.path.exists(fn): return fn else: fpr.fail('File not found') print if raw_input(' Return to menu [y/N]> ') in ['y','Y']: break
def e_base64(op): # load from file if op == '1': fn = '' while True: bancls() fpr('Diagnostics: Base64 encoder') print fpr('Please provide a file name:') fn = raw_input(' []> ') print inputs = get_file_content(fn) print if inputs: #inputs = f.readlines() # include \n #inputs = f.read().splitlines() # exclude \n dbginfo('debug', inputs) print encb64 = coders.encode_attch(inputs) if isinstance(encb64, dict): fpr.ok('File content was encoded successful') else: fpr.fail('File content was not encoded') waitin() return encb64 elif raw_input(' Return to menu [y/N]> ') in ['y', 'Y']: break waitin() # load from input - paste it if op == '2': bancls() fpr('Diagnostics: Base64 encoder') print if raw_input(' Would you like to encode some content [y/N]> ') in [ 'y', 'Y' ]: print fpr('Please provide some plain content') fpr('Use Ctrl-D with new line to continue.') print fpr.blue('_' * (tc - 4)) print inputs = get_inputs() fpr.blue('_' * (tc - 4)) if inputs: dbglog(inputs) print encb64 = coders.encode_attch('\n'.join(inputs)) if isinstance(encb64, dict): fpr.ok('Input content was encoded successful') else: fpr.fail('Input content was not encoded') waitin() return encb64 #print inputs waitin()
def m2s3_rcptlist(): while True: bancls() m2s3_menu = Menu(menu.m2s3) #menu: return if m2s3_menu.op == '': break #menu: m2s3s1 - Set single recipient if m2s3_menu.op == '1': bancls() a = smtp['addrlist']['rcpt_to'] smtp['addrlist']['rcpt_to'] = get_single_input( 'Please set single RCPT TO (Envelope Recipient):', smtp['addrlist']['rcpt_to'] ) b = smtp['addrlist']['rcpt_to'] if DEBUG: fpr('old: %s\nnew: %s' % (a,b)) def upsingleRecipient(items, a, b): if not b: if a and a in items: #return [b if x == a else x for x in items] # remove a - old items.remove(a) return items if a and a in items: return [b if x == a else x for x in items] else: #print a, 'not in ', items items.insert(0,b) #print items return items if DEBUG: print smtp['addrlist']['rcpts'] smtp['addrlist']['rcpts'] = upsingleRecipient( smtp['addrlist']['rcpts'],a,b) if DEBUG: print smtp['addrlist']['rcpts'] waitin() #menu: m2s3s2 - Build list from headers [To:, Cc:, Bcc:] if m2s3_menu.op == '2': while True: bancls() m2s3s2_menu = Menu(menu.m2s3s2) #menu: return if m2s3s2_menu.op == '': break if m2s3s2_menu.op in ['1','2','3','4']: bancls() # load func from msg.builder builder.rcpt_builder(m2s3s2_menu.op) waitin() #waitin() #menu: m2s3s3 if m2s3_menu.op == '3': pass #menu: m2s3s4 if m2s3_menu.op == '4': pass #menu: m2s3s5 if m2s3_menu.op == '5': pass #menu: m2s3s6 - Get Recipients from STDIN if m2s3_menu.op == '6': bancls() builder.rcpt_builder_f_inputs() waitin() #menu: m2s3s7 if m2s3_menu.op in ['7','v']: bancls() fpr('Envelope Recipients') print viewers.viewMsg('envelope') if smtp['addrlist']['rcpts']: viewers.viewEnvelope() waitin() #menu: m2s3s8 if m2s3_menu.op in ['8','f']: bancls() mutils.flushRecipients() waitin() #menu: m2s3sHELP if m2s3_menu.op == '?': pass
def setSPFvalues(deauth, sh, x): # deauth - dictionary with current SPF values # sh - dictionary with parsed headers # xhv - header number def cldeauth(death=deauth): del deauth['spf'] deauth.setdefault( 'spf', dict({ 'id': { 'mfrom': '', 'helo': '', 'pra': '' }, 'ip': None })) from pprint import pprint from core.func import get_single_input n = 0 for i in sh: #fpr("%s" % i) for j in sh[i]: n += 1 if n == x: # pprint(sh[i][j]) if i == 'Received-SPF': if sh[i][j].get('identity') == 'mailfrom': cldeauth() deauth['spf']['id']['mfrom'] = sh[i][j].get( 'envelope-from') deauth['spf']['ip'] = sh[i][j].get('client-ip') # x-sender - container of helo value (Cisco ESA) if sh[i][j].get('identity') == 'helo': cldeauth() if sh[i][j].get('x'): deauth['spf']['id']['helo'] = sh[i][j]['x'].get( 'x-sender') deauth['spf']['ip'] = sh[i][j].get('client-ip') if i == 'Authentication-Results': if sh[i][j].get('spf'): if sh[i][j]['spf'].get('helo') and sh[i][j]['spf'].get( 'mailfrom'): fpr('The Authentication-Results store more than one SPF identity' ) fpr('Choose identity:') print fpr(' 1) mailfrom') fpr(' 2) helo') fpr.info(' 3) pra') x = get_single_input('', '') if x == '1': cldeauth() deauth['spf']['id']['mfrom'] = sh[i][j]['spf'][ 'mailfrom'].get('value') if x == '2': cldeauth() deauth['spf']['id']['helo'] = sh[i][j]['spf'][ 'helo'].get('value') #from core.msg.viewers import viewers bancls() import core.msg.viewers as viewers viewers.viewSPFvalues(deauth['spf']) fpr.ok('SPF values has been set') if DDDEBUG: pprint(deauth)
def splitHeaders(inputs, crlf=False): #TODO: split headers and parse one header per import email bancls() print fpr.warn('_' * (tc - 4)) print print inputs print fpr.warn('_' * (tc - 4)) print print '\r\n'.join(inputs) print fpr.warn('_' * (tc - 4)) print waitin() bancls() if crlf: # remove empty elements from list # no newlines are allowed between headers inputs = [x for x in inputs if x != ''] msg = email.message_from_string('\r\n'.join(inputs)) AUTHRE = re.compile('Authentication-Results', re.IGNORECASE) RECSPF = re.compile('Received-SPF', re.IGNORECASE) hh = { 'Received-SPF': list(), 'Authentication-Results': list(), } parser = email.parser.HeaderParser() headers = parser.parsestr(msg.as_string()) for hn, hv in headers.items(): if DDDEBUG: fpr.green('Found: %s\n%s' % (hn, hv)) m1 = re.match(AUTHRE, hn) m2 = re.match(RECSPF, hn) if m1: if DDDEBUG: print hn, hv hh['Authentication-Results'].append(hv) if m2: if DDDEBUG: print hn, hv hh['Received-SPF'].append(hv) # print "---------------------------------" # from pprint import pprint # pprint(hh) # print "---------------------------------" # print #build a list # print len(hh['Received-SPF']) # print len(hh['Authentication-Results']) pp = { 'Received-SPF': dict(), 'Authentication-Results': dict(), } for hn in ['Received-SPF', 'Authentication-Results']: x = 0 for h in hh[hn]: p = parse_spfHeaders2('%s: ' % hn + h) if DDDEBUG: pprint(p) pp.setdefault(hn, x) x += 1 pp[hn].setdefault(x, p) print "---------------------------------" pprint(pp) print "---------------------------------" return pp