#!/usr/bin/env python

import sys
import subprocess

def banner():
  print '''
  |-----------------------------------------------|
  |[+] Metasploit wrapper for BOFs exploitaion    |
  |[+] Home: http://lnxg33k.wordpress.com         |
  |[+] Written by: Ahmed el-3ntry aka lnxg33k     |
  |[+] Email me @: ahmed [at] isecur1ty.org       |
  |-----------------------------------------------|
  '''

def usage():
  if len(sys.argv) <4:
    banner()
    print '\nUsage:'
    print '\t%s --basic [buffer] [size] [file.m3u]' % sys.argv[0]
    print '\t%s --msfcreat [size] [file.m3u]'       % sys.argv[0]
    print '\t%s --msfoffset [address] [size]'       % sys.argv[0]
    print '\t%s --badchars [creat] [size]'          % sys.argv[0]
    sys.exit(1)
usage()

option  = sys.argv[1]

banner()
if option == '--basic':
  buff    = sys.argv[2]
  size    = int(sys.argv[3])
  m3ufile = sys.argv[4]

  f = open(m3ufile, 'w')
  data = buff * size
  f.write(data)
  f.close()
  print 'File created successfully in [%s] with [%s bytes] of [%s] inside\n' % (m3ufile, size, buff)

elif option == '--msfcreat':
  size    = int(sys.argv[2])
  m3ufile = sys.argv[3]
  
  subprocess.Popen('ruby /opt/metasploit3/msf3/tools/pattern_create.rb %d > %s' % (size,m3ufile), shell= True).wait()
  print 'File created successfully in [%s] with [%s bytes]\n' % (m3ufile, size)

elif option == '--msfoffset':
  address = sys.argv[2]
  size    = int(sys.argv[3])

  subprocess.Popen('ruby /opt/metasploit3/msf3/tools/pattern_offset.rb %s %s' % (address, size), shell= True).wait()

elif option == '--badchars':
  creat = sys.argv[2]
  size  = int(sys.argv[3])
  
  for i in range(size):  sys.stdout.write('\\x%02x' % i)
  print "\n\n[%d bytes] of Decimal converted to hex\n" % size

