def rcpt_builder_f_inputs(): #from core.data import smtp,fpr,tc,tr #from core.func import append_uniq,get_inputs,dbglog #from core.msg.utils import get_addresses fpr('Load recipients list using input. Press Ctrl+D to proceed.') print fpr('Paste your recipients in one or multiplea lines seperate by comma or newline' ) fpr('Use Ctrl-D with new line to continue.') fpr.info('_' * (tc - 4)) print inputs = get_inputs() fpr.info('_' * (tc - 4)) if inputs != '': #print inputs r = get_addresses(inputs) append_uniq(smtp['addrlist']['rcpts'], r) #print get_addresses(", ".join(inputs)) dbglog(smtp['addrlist']['rcpts']) print fpr('Processing recipients ..') print fpr(' Addresses found with input : %d' % len(r)) fpr(' Total number of recipients : %d' % len(smtp['addrlist']['rcpts']))
def get_spfHeaders(): fpr('Please provide your input') fpr('Use Ctrl-D with new line to continue.') print fpr.info('_' * (tc - 4)) print inputs = get_inputs(nl=True) fpr.info('_' * (tc - 4)) if inputs: #dbglog(inputs) #inputs = [x.lstrip() for x in inputs] return splitHeaders(inputs, crlf=True)
def d_headers(): fpr('Diagnostics: Header decoder') print if raw_input(' Would you like to decode some headers [y/N]> ') in [ 'y', 'Y' ]: print fpr('Please provide an encoded part of the header:') #ehead = raw_input(' ') fpr('Use Ctrl-D with new line to continue.') fpr.blue('_' * (tc - 4)) print inputs = get_inputs(nl=True) fpr.info('_' * (tc - 4)) # decode multiline email headers ehead = coders.decode_mheaders(inputs) waitin() if ehead.keys(): fpr('Decoded Headers') fpr.info('_' * (tc - 4)) #print for k in ehead.keys(): print dhead, enc = decode_header(''.join(ehead[k]).replace( '?==?', '?= =?'))[0] if re.match('-no-hn-', k): fpr('Header-name: <None>') else: fpr('Header-Name: %s' % k) fpr('Header: %s' % dhead) ##print dhead fpr('Encoding: %s' % enc) print fpr.blue('_' * (tc - 4)) waitin() # _end_of_decode_multiline_headers else: fpr('Sorry! No header to decode') waitin() ehead.clear() else: waitin()
def att_cont_as_string(content=''): #from core.data import smtp,fpr,tc,tr,DEBUG #from core.func import waitin,get_inputs,dbglog,dbginfo if content: fpr('Body content has been created') smtp['content']['string'] = content dbginfo('debug', smtp['content']['string']) smtp['use_mime'] = False else: while True: #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 fpr.info('_' * (tc - 4)) print inputs = get_inputs(nl=True) fpr.info('_' * (tc - 4)) if inputs: dbglog(inputs) smtp['content']['string'] = '\r\n'.join(inputs) dbginfo('debug', smtp['content']['string']) # change the way how msg_builder build the message # even if you paste a proparly formatted mime message do not # treat this as MIME because you are not anymore responsible for building # a mime parts, you only need to attach this content as it is smtp['use_mime'] = False # TODO # Since now all other function should be aware when usemime() is FALSE and # than not be able to attach any of predefined sample break else: fpr('Leaving ..') break
def att_custom_header(): #import re print if raw_input(' Would you like to include your own headers [y/N]> ') in [ 'y', 'Y' ]: while True: print fpr('Please provide a header in format: >> Header-name: header-value <<' ) fpr('Use Ctrl-D with new line to save it and continue.') fpr.blue('_' * (tc - 4)) print # inputs = [] # while True: # try: # line = raw_input("") # except EOFError: # break # inputs.append(line) # to preserve new line pass nl=True with get_inputs() inputs = get_inputs() if inputs != '': thead = {} ####### TODO: move this to def encode_mheaders() for (i, hline) in enumerate(inputs): #print hline m1 = re.match(r'(.*):(.*)', hline) # it is a header m2 = re.match(r'^(\s+)(.*)', hline) # it is a continuation of prev header if hline == '\n': key = '' elif m1: if m1.group(1): key = m1.group(1) thead.setdefault(key, []).append(m1.group(2)) elif m2: if key == '' and inputs[i - 1] != '\n': key = '-no-hn-' while key in thead.keys(): key += '-' thead.setdefault(key, []).append(m2.group(1) + m2.group(2)) ############# fpr.blue('_' * (tc - 4)) for k in thead.keys(): fpr.info('_' * (tc - 4)) print if re.match('-no-hn-', k): fpr('Header-name: <None>') else: fpr('Header-Name: %s' % k) fpr('Header: %s' % thead[k]) #fpr('Encoding: %s' % enc) fpr.info('_' * (tc - 4)) fpr.blue('_' * (tc - 4)) print #print theadi if thead.keys(): if raw_input(' Are your headers parsed correctly [Y/n]:> ' ) in ['n', 'N']: if raw_input( ' Would you like to add them one more time [Y/n]:> ' ) in ['n', 'N']: break else: waitin() else: # if RFC: format header-name, format header length, # rfcline = 1 # if raw_input(' Should lines follow the RFC or leave it as you put it [Y/n]> ') in ['n', 'N']: # rfcline = 0 #### for k in thead.keys(): smtp['headers']["h_%s" % k] = thead[k] #### dbglog(smtp['headers']) waitin() break else: fpr('No header was specified') waitin() break
def att_zip_input(mbody, smtype, sn): #mbody = mbody #sn = '1' #smtype = 'img' #import os #from core.data import smpls,fpr,tc,tr,smtp #from core.func import waitin,get_zipfile,get_inputs,get_sample,dbginfo smtype = 'zip-input' while True: if smpls['zip'].get(smtype) and smpls['zip'][smtype]['astat'] != 0: fpr('It seems you have already attached one of USER input sample') if not raw_input(' Do you want to append another one [y/N]:') in [ 'y', 'Y' ]: break else: smpls['zip'].setdefault(smtype, {})['astat'] = 0 fpr.info('Zip your own text content') fpr.info('Use Ctrl-D with new line to continue.') print fpr.info('_' * (tc - 4)) print inputs = get_inputs(nl=True) fpr.info('_' * (tc - 4)) if inputs != '': print if raw_input(' Zip it [Y/n]:> ') in ['N', 'n']: break print # zipit zipinputs = get_zipfile({'val': '\n'.join(inputs)}, fn='user-input.txt') n = 1 if mbody.keys(): n = max(mbody.keys()) n += 1 #print max(mbody.keys()) mbody.setdefault(n, {})['raw'] = zipinputs mbody[n]['h_Content-Type'] = \ raw_input(' Content-Type: [%s]> ' % 'application/zip') \ or 'application/zip' mbody[n]['h_Content-Disposition'] = \ raw_input(' Content-Disposition: [%s]> ' % 'attachments; filename=%s' % 'uin-test.zip' ) \ or 'attachments; filename=%s' % 'test.zip' mbody[n]['h_Content-Transfer-Encoding'] = \ raw_input(' Content-transfer-encoding: [%s]> ' % 'base64') \ or 'base64' # if no cid - client like Mail.app does not # show the attachment mbody[n]['h_Content-ID'] = \ raw_input(' Content-ID: [%s]> ' % '') \ or '' mbody[n]['h_Content-Description'] = \ raw_input(' Content-Description: [%s]> ' % '') \ or '' smpls['zip']['astat'] += 1 smpls['zip'].setdefault(smtype, {})['astat'] += 1 print fpr('Zipped %s attached (x%d)' % ('INPUT', smpls['zip'][smtype]['astat'])) break waitin()
def att_load_base64(mbody): # attachment: paste base64 encoded part #from core.data import smtp,fpr,tc,tr,DEBUG #from core.func import waitin,get_inputs,dbglog,dbginfo #from core.msg.coders import isBase64 while True: fpr.info('_' * (tc - 4)) print inputs = get_inputs() fpr.info('_' * (tc - 4)) if inputs != '': dbglog(inputs) b64result = 1 for i in inputs: if not isBase64(i): dbginfo('error', 'Err: Line is not a proper base64 line', i) b64result = 0 break if b64result and inputs: print fpr('Message seems to have proper base64 lines') print fpr('Please define MIME headers for this attachment') print n = 1 if mbody.keys(): #global n n = max(mbody.keys()) n += 1 #print max(mbody.keys()) fpr('Attachment no: %d' % n, adj='c') print mbody.setdefault(n, {})['b64'] = inputs #mbody['0']['b64'] = inputs mbody[n]['h_Content-Type'] = \ raw_input(' Content-Type: [%s]> ' % '') \ or '' mbody[n]['h_Content-Disposition'] = \ raw_input(' Content-Disposition: [%s]> ' % '') \ or '' mbody[n]['h_Content-transfer-encoding'] = \ raw_input(' Content-transfer-encoding: [%s]> ' % 'base64') \ or 'base64' mbody[n]['h_Content-ID'] = \ raw_input(' Content-ID: [%s]> ' % '') \ or '' mbody[n]['h_Content-Description'] = \ raw_input(' Content-Description: [%s]> ' % '') \ or '' waitin() break
def e_headers(): fpr('Diagnostics: Header encoder') print if raw_input(' Would you like to encode some headers [y/N]> ') in [ 'y', 'Y' ]: if True: print fpr('Please provide a header in format: >> Header-name: header-value <<' ) fpr('Use Ctrl-D to continue.') fpr.blue('_' * (tc - 4)) print # to preserve new line pass nl=True with get_inputs() inputs = get_inputs() if inputs != '': thead = {} ####### TODO: move this to def encode_mheaders() for (i, hline) in enumerate(inputs): #print hline m1 = re.match(r'(.*):(.*)', hline) # it is a header m2 = re.match(r'^(\s+)(.*)', hline) # it is a continuation of prev header if hline == '\n': key = '' elif m1: if m1.group(1): key = m1.group(1) thead.setdefault(key, []).append(m1.group(2)) elif m2: if key == '' and inputs[i - 1] != '\n': key = '-no-hn-' while key in thead.keys(): key += '-' thead.setdefault(key, []).append(m2.group(1) + m2.group(2)) ############# fpr.blue('_' * (tc - 4)) print fpr('Found headers') print for k in thead.keys(): fpr.info('_' * (tc - 4)) print if re.match('-no-hn-', k): fpr('Header-name: <None>') else: fpr('Header-Name: %s' % k) fpr('Header: %s' % thead[k]) #fpr('Encoding: %s' % enc) fpr.info('_' * (tc - 4)) if thead.keys(): print chset = raw_input( ' Define headers encoding or leave empty to use a default one\n [us-ascii]: ' ) or 'us-ascii' fpr.blue('_' * (tc - 4)) print #print if chset: #from email.message import Message #from email.header import Header for hn in thead.keys(): try: h = Header(''.join(thead[hn]), charset=chset, maxlinelen=76, header_name=hn) #print h.encode() print msg = Message() msg[hn] = h print msg.as_string() except UnicodeDecodeError, e: print fpr.err('UnicodeDecodeError: %s' % e) print fpr('Try to set proper encoder! ') print fpr.blue('_' * (tc - 4)) waitin() """
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()