Ejemplo n.º 1
0
 def _process_conf(self, fn):
     c=readconf(fn)
     print ("config=", c)
     self._server_gpg_dir=c['server_gpg_dir']
     if not os.path.isabs(self._server_gpg_dir):
         self._server_gpg_dir=os.path.join(os.path.dirname(sys.argv[0]),self._server_gpg_dir)
     self._server_gpg_dir=os.path.expanduser(self._server_gpg_dir)
     self._ports=[int(i.strip()) for i in c['secret_ports'].split(',')]
     self.filter="tcp and dst portrange %s" % c['sniff_range'].strip()
     self._threads_n=int(c['threads_n'].strip())
     self._open_tcp_port=c['open_tcp_port'].strip()
     self._open_udp_port=c['open_udp_port'].strip()
     self._open_tcp_port_re=re.compile(re.escape(self._open_tcp_port).replace('\\{','{').replace('\\}','}').format(ip=r'(?P<ip>[\d.]+)(?:/\S*)?', dport=r'(?P<dport>\d+)'))
     self._open_udp_port_re=re.compile(re.escape(self._open_udp_port).replace('\\{','{').replace('\\}','}').format(ip=r'(?P<ip>[\d.]+)(?:/\S*)?', dport=r'(?P<dport>\d+)'))
     self._iptables_chain=c['iptables_chain']
     self._iptables_dump_cmd='/sbin/iptables -S '+self._iptables_chain
     if c['just_check_sequence'].strip()=='1':
         self._filter_more()
     self._blobm=int(c['min_random_blob_size'].strip())
     self._blobM=int(c['max_random_blob_size'].strip())
Ejemplo n.º 2
0
def main():
    random.seed(time())
    args_to_c={
      '-p':'secret_ports', '-i':'img_dir',
      '-g': 'client_gpg_dir', '-u':'user'
    }
    try:
        opts, args = getopt(sys.argv[1:], "c:p:i:g:u:", ["help"])
    except (GetoptError, err):
        print (str(err)) # will print something like "option -a not recognized"
        usage()
        sys.exit(1)
    opts=dict([(args_to_c.get(i,i),j) for i,j in opts])
    if opts.has_key('help'):
        usage()
        sys.exit(2)
    fn=opts.get('-c',None)
    if not fn:
      fn='/etc/tariq/client.conf'
    elif fn and not os.path.exists(fn):
        fn='/etc/tariq/client.conf'

    if not os.path.exists(fn):
        fn=os.path.join(os.path.dirname(sys.argv[0]),'client.conf')
    if not os.path.exists(fn):
        fn=os.path.abspath('client.conf')
    if not os.path.exists(fn):
        print (" ** Error: config file not found")
        usage()
        exit(3)
    c=readconf(fn)
    c.update(opts)
    if not all(map(lambda i: i in c,['secret_ports','img_dir', 'client_gpg_dir', 'user'])):
        print (" ** Error: missing required parameters")
        usage()
        exit(4)
    
    
    tariqPorts=map(lambda i: int(i) ,c['secret_ports'].split(','))
    user=c['user']
    img_dir=c['img_dir']
    if not os.path.isdir(img_dir):
      print (" ** Error [%s] not found") % img_dir
      usage()
      exit(5)

    img_ls=glob.glob(os.path.join(img_dir,'*.png'))
    if not img_ls:
      print (" ** Error: no png images found on [%s]") % img_dir
      usage()
      exit(5)
    img=random.choice(img_ls)
    gpg_dir=c['client_gpg_dir']
    if not os.path.isdir(gpg_dir):
      print (" ** Error [%s] not found") % gpg_dir
      print (" ** trying client_gpg_dir=[%s]") % gpg_dir
      gpg_dir=os.path.join(os.path.dirname(sys.argv[0]),'client-gpg')
    if not os.path.isdir(gpg_dir):
        print (" gpg dir not found")
        usage()
        exit(5)
    gpg = gnupg.GPG(gnupghome=gpg_dir)
    if len(args)<3:
        print (" ** missing TARGET CMD ARGS")
        usage()
        exit(6)
    target=args[0]
    cmd=" ".join(args[1:])
    knock(gpg, tariqPorts, user, img , target, cmd)
Ejemplo n.º 3
0
def main():
    random.seed(time())
    args_to_c = {
        '-p': 'secret_ports',
        '-i': 'img_dir',
        '-g': 'client_gpg_dir',
        '-u': 'user'
    }
    try:
        opts, args = getopt(sys.argv[1:], "c:p:i:g:u:", ["help"])
    except (GetoptError, err):
        print(str(err))  # will print something like "option -a not recognized"
        usage()
        sys.exit(1)
    opts = dict([(args_to_c.get(i, i), j) for i, j in opts])
    if opts.has_key('help'):
        usage()
        sys.exit(2)
    fn = opts.get('-c', None)
    if not fn:
        fn = '/etc/tariq/client.conf'
    elif fn and not os.path.exists(fn):
        fn = '/etc/tariq/client.conf'

    if not os.path.exists(fn):
        fn = os.path.join(os.path.dirname(sys.argv[0]), 'client.conf')
    if not os.path.exists(fn):
        fn = os.path.abspath('client.conf')
    if not os.path.exists(fn):
        print(" ** Error: config file not found")
        usage()
        exit(3)
    c = readconf(fn)
    c.update(opts)
    if not all(
            map(lambda i: i in c,
                ['secret_ports', 'img_dir', 'client_gpg_dir', 'user'])):
        print(" ** Error: missing required parameters")
        usage()
        exit(4)

    tariqPorts = map(lambda i: int(i), c['secret_ports'].split(','))
    user = c['user']
    img_dir = c['img_dir']
    if not os.path.isdir(img_dir):
        print(" ** Error [%s] not found") % img_dir
        usage()
        exit(5)

    img_ls = glob.glob(os.path.join(img_dir, '*.png'))
    if not img_ls:
        print(" ** Error: no png images found on [%s]") % img_dir
        usage()
        exit(5)
    img = random.choice(img_ls)
    gpg_dir = c['client_gpg_dir']
    if not os.path.isdir(gpg_dir):
        print(" ** Error [%s] not found") % gpg_dir
        print(" ** trying client_gpg_dir=[%s]") % gpg_dir
        gpg_dir = os.path.join(os.path.dirname(sys.argv[0]), 'client-gpg')
    if not os.path.isdir(gpg_dir):
        print(" gpg dir not found")
        usage()
        exit(5)
    gpg = gnupg.GPG(gnupghome=gpg_dir)
    if len(args) < 3:
        print(" ** missing TARGET CMD ARGS")
        usage()
        exit(6)
    target = args[0]
    cmd = " ".join(args[1:])
    knock(gpg, tariqPorts, user, img, target, cmd)