def capture(self): """ capture pcap handshake with wifite """ if self.get_cracked(): acracked = util.get_say("already cracked") self.state.queue_add(acracked) LOG.warn("Error, bssid: {} is already cracked".format(self.bssid)) return LOG.info("attempting, handshake capture") os.chdir(self.dest_dir) cmd = ['{wifite}'] if self.channel: cmd.append('-c {channel}') cmd = cmd + [ '-b {bssid}', '-i {mon_adapter}', '--dict {wordlist}', ] cmd_str = " ".join(cmd).format(**self.args) try: exec_cmd(cmd_str, timeout=60 * 3, display=True) except Exception: # @TODO dammit gif # self.state.queue_add("FUUUCK!") self.state.queue_add(get_say("f**k unknown error")) LOG.exception("Error!")
def rename_window(sess_name, win_id, name): """ rename the window in session """ p = (sess_name, win_id, name) cmd = (CMD_RENAME_WINDOW % p).split(config.CMD_SEP) util.exec_cmd(cmd)
def rename_window(sess_name, win_id, name): """ rename the window in session """ p = (sess_name, win_id, name) cmd = (CMD_RENAME_WINDOW % p).split(' ') util.exec_cmd(cmd)
def set_pane_path(pane_idstr, path): """ set pane path by 'send-key' and clear the screen""" cmd = (CMD_SET_PANE_PATH % (pane_idstr,path)).split(' ',3) util.exec_cmd(cmd) #clear history cmd = (CMD_CLEAR_PANE%(pane_idstr)).split(' ') util.exec_cmd(cmd)
def delete(self): for app in self.applications: app.delete() # Unsets all net devices. for name, dev in self.net_devices.iteritems(): dev.delete() exec_cmd("sudo ip netns delete %s" % (self.name,)) self.is_created = False
def test(): cmd = 'dir' ret = '' ret += '\n' + util.convert_newline(util.exec_cmd(cmd), '\n') ret += '\n' ret += '\n' + util.convert_newline( util.exec_cmd(cmd, encoding='shift_jis'), '\n') return ret
def renumber_window(sess_name, win_id_from, win_id_to): """ renumber the window in session """ p = (sess_name + ':' + str(win_id_from), \ sess_name + ':' + str(win_id_to)) cmd = (CMD_MOVE_WINDOW % p).split(config.CMD_SEP) util.exec_cmd(cmd)
def renumber_window(sess_name, win_id_from, win_id_to): """ renumber the window in session """ p = (sess_name + ':' + str(win_id_from), \ sess_name + ':' + str(win_id_to)) cmd = (CMD_MOVE_WINDOW % p).split(' ') util.exec_cmd(cmd)
def create(self): """Creates this node as a netns.""" exec_cmd("sudo ip netns add %s" % (self.name,)) # Sets all net devices. for name, dev in self.net_devices.iteritems(): dev.create() for app in self.applications: app.create() self.is_created = True
def disconnect_vol(name, host): vol_info = vol.list_vols([name])[0] with util.host_db() as db: if host not in db: util.exit_with_msg( 'Error on {}: Host does not exist.'.format(host)) iqn = db[host] lun_number = util.get_lun_number(name) util.exec_cmd('tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 ' '--lun {}'.format(lun_number))
def rename_vol(old_name, new_name): try: util.exec_cmd('lvrename {}/{} {}'.format(VGROUP, old_name, new_name)) except RuntimeError as exc: if 'already exists' in str(exc): util.exit_with_msg( 'Error on {}: Volume already exists.'.format(new_name)) elif 'not found in' in str(exc): util.exit_with_msg( 'Error on {}: Volume does not exist.'.format(old_name)) raise
def checkout_or_update(): # 是否checkout过 code = util.exec_cmd('svn list') if code: cmd = 'svn checkout %s %s --username %s --password %s' % ( constant.SVN_PROJECT_URL, constant.LOCAL_BASE_URL, constant.SVN_USER_NAME, constant.SVN_PASSWD) util.exec_cmd(cmd) else: # svn update util.exec_cmd('svn update')
def create_vol(name, size): try: util.exec_cmd('lvcreate -T -V {} -n {} {}'.format( size, name, FULL_LUN)) except RuntimeError as exc: if 'already exists' in str(exc): util.exit_with_msg( 'Error on {}: Volume already exists'.format(name)) raise if not os.path.exists('/dev/mapper/{}-{}'.format(VGROUP, name)): raise EnvironmentError( 'Could not find path to {} in dev mapper'.format(name))
def list_vols(names): vol_info = [] output = util.exec_cmd('lvs --separator , -o lv_name,lv_time,lv_size,uuid ' '--aligned --noheadings') for vol in output.splitlines(): name, timestamp, size, uuid = [part.strip() for part in vol.split(',')] if name == 'tp1' or name.startswith('.'): continue if names and name not in names: continue size = size.replace('.00', '').upper() timestamp = '{} {}'.format(timestamp.rsplit(' ', 1)[0], util.localtz()) vol_info.append( dict(name=name, size=size, source='-', created=timestamp, serial=uuid)) for name in names: if name not in (v['name'] for v in vol_info): util.exit_with_msg( 'Error on {}: Volume does not exist.'.format(name)) return vol_info
def create_hosts_file(self, node, opts): dirpath = ("/etc/netns/%s" % node.name) filepath = os.path.join(dirpath, 'hosts') if not os.path.exists(dirpath): exec_cmd("sudo mkdir -p %s" % dirpath) exec_cmd("sudo chmod -R 777 %s" % dirpath) if os.path.exists(filepath): exec_cmd("sudo rm -f %s" % filepath) exec_cmd("sudo touch %s" % filepath) exec_cmd("sudo chmod 777 %s" % filepath) lines = ["127.0.0.1\t\tlocalhost\n", "\n"] for host in self.context['hosts']: line = ("%s\t\t%s\n" % (host['ip_addr'], host['hostname'])) lines.append(line) with open(filepath, 'w') as hostsf: hostsf.writelines(lines)
def get_sessions(): """ return a list of tmux session names:size:attached like: sessName:=:(200,300):=:1 """ cmd = CMD_LIST_SESSIONS.split(config.CMD_SEP) s = util.exec_cmd(cmd) return s.split('\n')
def get_panes_from_sess_win(sess_name,win_idx): """return list of result string output format: paneIdx:=:(width,height):=:path:=:active """ p = (sess_name,win_idx) cmd = (CMD_LIST_PANES % p).split(' ') s = util.exec_cmd(cmd) return s.split('\n')
def get_panes_from_sess_win(sess_name, win_idx): """return list of result string output format: paneIdx:=:(width,height):=:path:=:active """ p = (sess_name, win_idx) cmd = (CMD_LIST_PANES % p).split(config.CMD_SEP) s = util.exec_cmd(cmd) return s.split('\n')
def get_sessions(): """ return a list of tmux session names:size:attached like: sessName:=:(200,300):=:1 """ cmd = CMD_LIST_SESSIONS.split(' ') s = util.exec_cmd(cmd) return s.split('\n')
def create(self): exec_cmd("sudo ip link add %s type veth peer name %s" % (self.get_port_name(), self.get_tap_name())) exec_cmd("sudo ip link set %s netns %s" % (self.get_port_name(), self.node.name)) if self.is_connected(): tap_name = self.get_tap_name() exec_cmd("sudo brctl addif %s %s" % (self.channel.name, tap_name)) exec_cmd("sudo ip link set dev %s up" % (tap_name,))
def get_windows_from_session(sess_name): """ return a list of windows by given tmux session name like: 1:=:W-name:=:1 idx:=:name:=:active """ cmd = (CMD_LIST_WINDOWS % sess_name).split(config.CMD_SEP) s = util.exec_cmd(cmd) return s.split('\n')
def get_windows_from_session(sess_name): """ return a list of windows by given tmux session name like: 1:=:W-name:=:1 idx:=:name:=:active """ cmd = (CMD_LIST_WINDOWS % sess_name).split(' ') s = util.exec_cmd(cmd) return s.split('\n')
def __enter__(self): LOG.info("starting monitor mode on {}".format(self.adapter)) cmd = '{airmon} start {adapter}'.format(**self.args) exec_cmd(cmd) time.sleep(2) for iface in pyw.interfaces(): try: c = pyw.getcard(iface) except Exception: LOG.exception("error getting interface: {}".format(iface)) continue if c.phy == self.phy: LOG.info("Found monitor adapter: {}".format(c.dev)) self.mon_adapter = c.dev self.args['mon_adapter'] = self.mon_adapter break if not self.mon_adapter: raise Exception("Error, could not determin monitoring adapter") return self
def delete(self): if self.is_connected(): tap_name = self.get_tap_name() exec_cmd("sudo ip link set dev %s down" % (tap_name,)) exec_cmd("sudo brctl delif %s %s" % (self.channel.name, tap_name)) exec_cmd("sudo ip link delete %s" % (self.get_tap_name(),))
def set_pane_path(pane_idstr, path): """ set pane path by 'send-key' and clear the screen""" #clear history cmdline = (CMD_CLEAR_PANE % (pane_idstr)).split(config.CMD_SEP) util.exec_cmd(cmdline) cmdline = (CMD_SET_PANE_PATH % (pane_idstr, path)).split(config.CMD_SEP) util.exec_cmd(cmdline) #clear history cmdline = (CMD_CLEAR_PANE % (pane_idstr)).split(config.CMD_SEP) util.exec_cmd(cmdline)
def set_pane_path(pane_idstr, path): """ set pane path by 'send-key' and clear the screen""" #clear history cmdline = (CMD_CLEAR_PANE%(pane_idstr)).split(config.CMD_SEP) util.exec_cmd(cmdline) cmdline = (CMD_SET_PANE_PATH % (pane_idstr,path)).split(config.CMD_SEP) util.exec_cmd(cmdline) #clear history cmdline = (CMD_CLEAR_PANE%(pane_idstr)).split(config.CMD_SEP) util.exec_cmd(cmdline)
def connect_vol(name, host): vol_info = vol.list_vols([name])[0] with util.host_db() as db: if host not in db: util.exit_with_msg( 'Error on {}: Host does not exist.'.format(host)) iqn = db[host] vol_path = '/dev/mapper/{}-{}'.format(VGROUP, vol_info['name']) lun_number = util.get_unused_lun() util.exec_cmd('tgtadm --lld iscsi --op new --mode logicalunit --tid 1 ' '--lun {} -b {}'.format(lun_number, vol_path)) util.exec_cmd('tgtadm --lld iscsi --op update --mode logicalunit --tid 1 ' '--lun {} --params scsi_sn={},vendor_id=PURESTORAGE'.format( lun_number, vol_info['serial'])) try: util.exec_cmd( 'tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL') except RuntimeError as exc: if 'rule already exists' not in str(exc): raise
def get_option(option): """ get global option value """ cmd = (CMD_SHOW_OPTION % option).split(config.CMD_SEP) return util.exec_cmd(cmd)
def restore_pane_content(pane_idstr, filename): """restore backuped pane content. """ #put filename in quote, in case there is space, tab etc. filename = '"' + filename + '"' cmd = (CMD_LOAD_CONTENT % (pane_idstr, filename)).split(config.CMD_SEP) util.exec_cmd(cmd)
def __exit__(self, type, value, tb): """ exit loop for enter, make sure airmon stops on the interface """ LOG.info("Shutting down monitor mode on {}".format(self.mon_adapter)) cmd = '{airmon} stop {mon_adapter}'.format(**self.args) exec_cmd(cmd)
def active_window(sess_name, win_id): p = (sess_name,win_id) cmd = (CMD_ACTIVE_WINDOW% p).split(' ') util.exec_cmd(cmd)
def create_empty_window(sess_name, base_index): p = (sess_name, int(base_index)) cmd = (CMD_NEW_EMPTY_WINDOW % p).split(config.CMD_SEP) util.exec_cmd(cmd)
def active_window(sess_name, win_id): p = (sess_name, win_id) cmd = (CMD_ACTIVE_WINDOW % p).split(config.CMD_SEP) util.exec_cmd(cmd)
def create(self): """Creates this channel as a bridge w/o spanning-tree protocol.""" exec_cmd("sudo brctl addbr %s" % (self.name,)) exec_cmd("sudo brctl stp %s off" % (self.name,)) exec_cmd("sudo ip link set dev %s up" % (self.name,))
def restore_pane_content(pane_idstr,filename): """restore backuped pane content. """ #put filename in quote, in case there is space, tab etc. filename = '"' + filename + '"' cmd = (CMD_LOAD_CONTENT % (pane_idstr,filename)).split(config.CMD_SEP) util.exec_cmd(cmd)
def delete(self): """Deletes this channel.""" exec_cmd("sudo ip link set dev %s down" % (self.name,)) exec_cmd("sudo brctl delbr %s" % (self.name,))
def restore_pane_content(pane_idstr,filename): """restore backuped pane content. """ cmd = (CMD_LOAD_CONTENT % (pane_idstr,filename)).split(' ',3) util.exec_cmd(cmd)
def get_option(option): """ get global option value """ cmd = (CMD_SHOW_OPTION % option).split(' ') return util.exec_cmd(cmd)
def create_session(sess_name, size): p = (sess_name, size[0], size[1]) cmd = (CMD_CREATE_SESSION % p).split(config.CMD_SEP) s = util.exec_cmd(cmd)
def exec_node_cmd(node, cmd): exec_cmd("sudo ip netns exec %s %s" % (node.name, cmd))
% (self.channel.name, tap_name)) exec_cmd("sudo ip link delete %s" % (self.get_tap_name(),)) def is_connected(self): return self.channel != None def connect_to(self, channel): if not self.is_connected(): self.channel = channel channel.append_net_device(self) tap_name = self.get_tap_name() def disconnect(self): if self.is_connected(): channel = self.channel self.channel = None channel.remove_net_device(self) if __name__ == '__main__': rc = exec_cmd("ls -la") print rc channel = Channel("vbr-pint") channel.create() exec_cmd("sudo brctl show") channel.delete()
def eradicate_vol(name): util.exec_cmd('lvremove -y {}/.{}'.format(VGROUP, name))
def create_session(sess_name,size): p = (sess_name,size[0],size[1]) cmd = (CMD_CREATE_SESSION % p).split(' ') s = util.exec_cmd(cmd)
def select_layout(sess_name, win_id, layout): p = (sess_name, win_id, layout) cmd = (CMD_SET_LAYOUT % p).split(config.CMD_SEP) util.exec_cmd(cmd)
def create_empty_window(sess_name, base_index): p = (sess_name, int(base_index)) cmd = (CMD_NEW_EMPTY_WINDOW % p).split(' ') util.exec_cmd(cmd)
def split_window(sess_name, win_id, pane_min_id): p = (sess_name, int(win_id), int(pane_min_id)) cmd = (CMD_SPLIT_WINDOW % p).split(config.CMD_SEP) util.exec_cmd(cmd)
def __call__(self): print "accessing your mendeley account..." mendeley_proxy.lazy_init_config() fld = mendeley_proxy.folder(self.folder, ignore_case = True) if fld == None: print "folder '%s' not found, please select from your groups:" % self.folder CONTENT = "%10s|%s" print CONTENT % ("id", "group name") print "-" * 30 flds = mendeley_proxy.folders() for fld in flds: print CONTENT % (fld.id, fld.name) sys.exit() # request content of mendeley-directory print "quering your mendeley papers (in directory '%s')..." % fld.name docs = fld.docs if not self.ima: def foo(doc): #print "DEBUG ", repr(doc), len(doc.abstract) return len(doc.abstract) <= 10 res = filter(foo, docs) if len(res) > 0: print "some papers have no abstract:" for doc in res: print "| %s\n| (%s)" % (doc.title, doc.authorspp) sys.exit(-1) outdir = os.path.abspath(config.output_directory or os.path.curdir) util.trymkdir(outdir) texfilename = os.path.join(outdir, "%s.tex" % self.filename) pdffilename = os.path.join(outdir, "%s.pdf" % self.filename) print "generating files '%s'..." % pdffilename out = codecs.open(texfilename, "w+", "utf-8") out.write(stream_base_begin( foldername = "%s (id %s)" % (fld.name, fld.id), today = datetime.datetime.now().isoformat())) for doc in docs: out.write(stream_entry( title = doc.title, abstract = doc.abstract, authors = doc.authorspp, type = doc.type, published = doc.publisher, year = doc.year, keywords = u", ".join(doc.keywords) )) out.write(stream_base_end()) if os.path.exists(pdffilename): os.unlink(pdffilename) cmd = "%s --output-directory %s -interaction batchmode %s" % (config.pdflatex, outdir, texfilename) try: util.exec_cmd(cmd) util.exec_cmd(cmd) except subprocess.CalledProcessError: pass assert os.access(pdffilename, os.R_OK) cmd = "%s %s" % (config.pdfopen, pdffilename) util.exec_cmd(cmd)
def split_window(sess_name, win_id, pane_min_id): p = (sess_name,int(win_id), int(pane_min_id)) cmd = (CMD_SPLIT_WINDOW % p).split(' ') util.exec_cmd(cmd)
def select_layout(sess_name, win_id, layout): p = (sess_name,win_id,layout) cmd = (CMD_SET_LAYOUT% p).split(' ') util.exec_cmd(cmd)