Example #1
0
def create_dir_hook(spawner):
    username = spawner.user.name  # get the username
    #volume_path = os.path.join('/volumes/jupyterhub', username)
    nfs = libnfs.NFS('nfs://koben-tsvm/nfs4_ostack')
    volume_path = os.path.join('/users/', username)
    if not nfs.isdir(volume_path):
        # create a directory with umask 0755
        # hub and container user must have the same UID to be writeable
        # still readable by other users on the system
        nfs.mkdir(volume_path)  #, 0o755)
Example #2
0
def ls(dir):
    import libnfs

    nfs = libnfs.NFS(dir)
    print 'nfs', nfs
    for ent in nfs.listdir("."):
        if ent in ['.', '..']:
            continue
        st = nfs.lstat(ent)
        print ent, st
Example #3
0
def worker_init(use_libnfs):
    if use_libnfs:
        nfs = libnfs.NFS(NFS_ROOT)
        def reader(path):
            fh = nfs.open(path, "rb")
            fh.read()
            fh.close()
    else:
        def reader(path):
            with open(path, "rb") as f:
                f.read()

    WORKER_CTX[get_name()] = reader
Example #4
0
def run(server_ip, mount_point):
    if server_ip == '127.0.0.1' and mount_point == '/mnt/':  # credentials not provided, use api
        print("Getting NFS MOUNT info from MITM API...")
        mount_url = get_mount_point()
    else:  # credentials provided
        if mount_point[0] != '/':
            mount_point = '/' + mount_point
        mount_url = 'nfs://' + server_ip + mount_point

    print("\t- " + str(mount_url) + "\n")
    nfs = libnfs.NFS(mount_url)
    menu(nfs)

    while True:
        print("Choose option")
        choice = input(">> ")
        func = case_statement(choice)
        func(nfs)
Example #5
0
# You do NOT have to convert the new number to the existing format used on the page.
# Bonus points for a solution that is implemented as a single pipeline of Linux commands.

import csv
import re
import pprint
import argparse
import ipaddress
from collections import OrderedDict

# NFS Python Library example:
# https://pypi.org/project/libnfs/
#
import libnfs

nfs = libnfs.NFS('nfs://127.0.0.1/var/www')
a = nfs.open('/test.html', mode='w+')
a.write('Test string')
a.close()

# print(nfs.open('/foo-test', mode='r').read())

# parser = argparse.ArgumentParser(
# 	description="Determine if IPv4 address is in the given CIDR subnet")
# parser.add_argument('-i', dest='ipAddress',
# 	help='IP address ex: -i 0xc0a80101')
# parser.add_argument('-c', dest='cidrSubnet',
# 	help='CIDR Subnet ex: -c 192.168.1.0/24')
# parser.add_argument('-s', dest='srcCSV',
# 	help='Source CSV ex: -s ~/Desktop/fileName.csv')
# parser.add_argument('-d', dest='dstCSV',
Example #6
0
def check(target, language, scan_id, scan_cmd, log_in_file):
    import platform
    if platform.system() == "Windows":
        error(messages(language, "windows_error"))
        sys.exit(0)
    try:
        Popen(["showmount"], stdout=PIPE, stderr=PIPE)
    except OSError as e:
        if e.errno == os.errno.ENOENT:
            error(messages(language, "showmount_error"))
            sys.exit(0)

    shares = []
    response = []
    raw = Popen(["showmount", "-e", target], stdout=PIPE, stderr=PIPE)
    output, error = raw.communicate()
    if raw.returncode == 0:
        tmp = output.split("\n")[1:-1]
        for i in tmp:
            shares.append(i[:i.index(" ")])

        response.append("[*] IP: " + target)
        response.append("\tShared Resources: ")
        for share in shares:
            response.append("\t    " + share)

        for path in shares:
            nfs_addr = "nfs://" + target + path
            response.append("\tFiles on: " + nfs_addr)
            nfs = libnfs.NFS(nfs_addr)
            files = nfs.listdir('')
            for f in files:
                response.append("\t\t" + f)
        for resp in response:
            info(messages(language, "show_nfs_results").format(resp))
        data = json.dumps({
            'HOST': target,
            'USERNAME': '',
            'PASSWORD': '',
            'PORT': '',
            'TYPE': 'nfs_scan',
            'DESCRIPTION': str(response),
            'TIME': now(),
            'CATEGORY': "scan",
            'SCAN_ID': scan_id,
            'SCAN_CMD': scan_cmd
        }) + "\n"
    else:
        warn(messages(language, "nfs_not_found").format(target, error))
        data = json.dumps({
            'HOST':
            target,
            'USERNAME':
            '',
            'PASSWORD':
            '',
            'PORT':
            '',
            'TYPE':
            'nfs_scan',
            'DESCRIPTION':
            "no network share found on ip: " + target + " .. " + error,
            'TIME':
            now(),
            'CATEGORY':
            "scan",
            'SCAN_ID':
            scan_id,
            'SCAN_CMD':
            scan_cmd
        }) + "\n"

    __log_into_file(log_in_file, 'a', data, language)
Example #7
0
import libnfs

nfs = libnfs.NFS('nfs://127.0.0.1/data/tmp/')
a = nfs.open('/foo-test', mode='w+')
a.write("Test string")
a.close()
print (nfs.open('/foo-test', mode='r').read())
'''
a=nfs.listdir('/')
for i in a:
    print(a)
'''