예제 #1
0
    def _find_ec2_ami(self, os, os_version):
        """
        Find a suitable AMI from the list of supported AMIs from the given OS
        and OS version. If not a suitable OS is found, raise appropriate
        Exception
        """
        supported_amis = config.supported_amis

        if os == "" or os_version == "":
            raise AMINotFound('No corresponding AMI for the given OS found')

        # sanitize input
        os = os.strip().upper()
        os_version = os_version.strip()

        if os == 'UBUNTU' and os_version == '12':
            os_version = '12.04'

        if os == 'UBUNTU' and os_version == '14':
            os_version = '14.04'

        # filter the supported_amis list by the os and the by the version
        filtered_os = filter(lambda x: x['os'] == os, supported_amis)
        chosen_ami = filter(lambda x: x['version'] == os_version, filtered_os)

        if not chosen_ami or not len(chosen_ami):
            raise AMINotFound('No corresponding AMI for the given OS found')

        # chose the item; there should be only one.
        chosen_ami = chosen_ami[0]

        logger.debug("Choosing AMI: %s; based on input OS: %s, version: %s" %
                     (chosen_ami, os, os_version))

        return chosen_ami['ami_id']
예제 #2
0
def terminate_process(task_id,taskMetaObj, enable_test):
    if enable_test: 
        ongoing_process = CompilationPid.objects.filter(taskid=task_id)
        if ongoing_process == None:
            return False
        else:
            for ele in ongoing_process:
                pid = ele.pid
                os.kill(pid, signal.SIGTERM)
            ongoing_process.delete()
            return True
    else:
        terminateSuccess = False
        os_list = str(taskMetaObj.target_os).split(",")
        compiler_full = str(taskMetaObj.compiler_full).split(",")
        for os, cpl_full in zip(os_list,compiler_full):
            compiler,version = cpl_full.strip().split(" ")
            print(os,compiler,version)
            compiler_info = Compiler_conf.objects.get(target_os=os.strip(),compiler=compiler.strip(),version=version.strip())
            address = compiler_info.ip+":"+compiler_info.port+"/terminate"
            response = requests.post(address, data={"task_id":task_id},timeout=10)
            print(response.content)
            if str(response.content) == "true":
                terminateSuccess = True
        print("task killed: "+task_id)
        return terminateSuccess
예제 #3
0
def os_data_clean(os_lst):
    try:
        if len(os_lst) > 1:
            return [os.strip() for os in os_lst if len(os) > 1]
        else:
            return os_lst
    except Exception as e:
        print("ERROR: os_data_clean", str(e))
예제 #4
0
def getWordFeatures(wordList):
    #createTopicTable()
    #for word in wordList:
    #   cnt[word] += 1
    
    print "\nPopular topics from the event:\n"
    #for word,count in cnt.most_common(500):
    #   if "mwc" in word:
    #       word = ""

    #   if(word != ""):
    #       print '%s\n' % (word.strip('#'))
    #c2.execute("INSERT INTO results VALUES(?)", [word.strip('#')])
    #conn2.commit()

    for topic in c2.execute("SELECT * from results LIMIT 10"):
        print topic

    #l = cnt.items()
    #l.sort(key = lambda item: item[1])

    wordList = nltk.FreqDist(wordList)
    word_features = wordList.keys()
    #createOSBrandTable()
    print("\n\nOperating Systems:")
    for word in OS:
        OS_rank.append((word,wordList[word]))
    for os,count in sorted(OS_rank,key = lambda item: -item[1]):
        c2.execute("INSERT INTO OS VALUES(?,?)",[os.strip('#'),count])

    for os,count in c2.execute("SELECT * from OS"):
        print os+"\t"+str(count)


    #print OS_rank
        #print "OS\tCount"
        #print os.strip('#')+"\t"+str(count)

    print("\n\nBrands:")
    for word in Companies:
        Brand_rank.append((word,wordList[word]))
    for br,count in sorted(Brand_rank,key = lambda item: -item[1]):
        c2.execute("INSERT INTO Brand VALUES(?,?)",[br.strip('#'),count])
    for br,count in c2.execute("SELECT * from Brand"):
        print br+"\t"+str(count)

        #print Brand.strip('#')+"\t"+str(count)
    #print wordList.most_common(550)
    return word_features
예제 #5
0
def find_os_template(os, os_version):
    # What to do when request comes for unavailable OS/version?
    os = OS.upper() if os == "" else os.strip().upper()
    os_version = OS_VERSION if os_version == "" else os_version.strip()
    if os == "UBUNTU":
        if os_version == "12.04" or os_version == "12":
            return "ubuntu-12.04-custom-x86_64"
        elif os_version == "11.10" or os_version == "11":
            return "ubuntu-11.10-x86_64"
    elif os == "CENTOS":
        if os_version == "6.3":
            return "centos-6.3-x86_64"
        elif os_version == "6.2":
            return "centos-6.2-x86_64"
    elif os == "DEBIAN":
        if os_version == "6.0" or os_version == "6":
            return "debian-6.0-x86_64"
    else:
        pass
def find_os_template(os, os_version):
    # What to do when request comes for unavailable OS/version?
    os = OS.upper() if os == "" else os.strip().upper()
    os_version = OS_VERSION if os_version == "" else os_version.strip()
    if os == "UBUNTU":
        if os_version == "12.04" or os_version == "12":
            return "ubuntu-12.04-custom-x86_64"
        elif os_version == "11.10" or os_version == "11":
            return "ubuntu-11.10-x86_64"
    elif os == "CENTOS":
        if os_version == "6.3":
            return "centos-6.3-x86_64"
        elif os_version == "6.2":
            return "centos-6.2-x86_64"
    elif os == "DEBIAN":
        if os_version == "6.0" or os_version == "6":
            return "debian-6.0-x86_64"
    else:
        pass
예제 #7
0
파일: iops.py 프로젝트: hero0906/jiaoben
 def get_system(self):
     cmd = 'uname -r'
     kernel = self.execute('get kernel', cmd)
     kernel = kernel.strip('\n')
     #        print 'kernel: ',kernel
     cmd = 'cat /etc/redhat-release'
     os = self.execute('get os', cmd)
     os = os.strip('\n')
     #        print 'os: ',os
     cmd = "cat /proc/cpuinfo |grep processor |awk 'END{print $3}'"
     cpu_core = self.execute('get cpu core number', cmd)
     cpu_core = int(cpu_core.strip('\n')) + 1
     #        print 'cpu core number =',cpu_core
     cmd = "cat /proc/cpuinfo |grep 'physical id' |awk 'END{print $4}'"
     cpu_num = self.execute('get cpu number', cmd)
     cpu_num = int(cpu_num.strip('\n')) + 1
     #        print 'cpu number =',cpu_num
     cmd = "cat /proc/cpuinfo |grep 'model name' |awk 'END{print}'"
     cpu_model = self.execute('get cpu model', cmd)
     cpu_model = cpu_model.strip('\n')
     cpu_model = cpu_model[13:]
     #        print 'cpu model =',cpu_model
     cmd = "cat /proc/meminfo |grep MemTotal |awk '{print $2 $3}'"
     memory_total = self.execute('get memory total', cmd)
     memory_total = memory_total.strip('\n')
     #        print 'memory total =',memory_total
     cmd = "cat /proc/meminfo |grep MemFree |awk '{print $2 $3}'"
     memory_free = self.execute('get memory free', cmd)
     memory_free = memory_free.strip('\n')
     #        print 'memory free =',memory_free
     system = 'Kernel: ' + kernel + '\n' + 'OS: ' + os + '\n' + 'CPU: ' + cpu_model + '  ' + str(
         cpu_num
     ) + '*' + str(
         cpu_core / cpu_num
     ) + 'core \n' + 'Memory total: ' + memory_total + '\n' + 'Memory free: ' + memory_free
     return system
예제 #8
0
import re
import shlex
from dateutil import parser
from IPy import IP
import datetime
import subprocess
import time

mac_os_ua = {}
win_os_ua = {}


with open("mac_os_agents.txt") as f:
    for line in f:
        cfn, os = line.strip().split(",")
        mac_os_ua[cfn] = os.strip()


with open("win_os_agents.txt") as f:
    for line in f:
        nt, os = line.strip().split(",")
        win_os_ua[nt] = os.strip()

def follow(thefile):
    thefile.seek(0,2) # Go to the end of the file
    while True:
        line = thefile.readline()
        if not line:
            continue
        yield line
예제 #9
0
    def findHostnames(self, int_ip, CIDR, timestamp):

        print(bcolors.OKGREEN + "      [ HOSTNAMES ENUMERATION MODULE ]\n" +
              bcolors.ENDC)
        hostname = socket.gethostname()

        res_table = PrettyTable([
            bcolors.OKGREEN + '[IP]' + bcolors.ENDC,
            bcolors.OKGREEN + '[Hostname]' + bcolors.ENDC,
            bcolors.OKGREEN + '[Domain]' + bcolors.ENDC,
            bcolors.OKGREEN + '[Operating System]' + bcolors.ENDC
        ],
                                border=False,
                                header=True)
        res_table.align = "l"
        print("Searching for hostnames in %s...\n" % CIDR)
        print("Current Hostname:" + bcolors.TITLE + " %s" % hostname +
              bcolors.ENDC)
        print(" ")

        try:
            #Discover live hosts
            nm = nmap.PortScanner()
            nm_arp = nm.scan(hosts=CIDR, arguments="-sn")
            for x in nm_arp.items()[1][1]:
                self.live_ips.append(x)

            self.live_ips.remove(int_ip)  # we dont need to scan ourself

            for live_ip in self.live_ips:
                subprocess.call(
                    'cme -t 1 --timeout 2 smb %s  >> Results/hostnames_%s' %
                    (live_ip, timestamp),
                    shell=True)

            subprocess.call(
                "strings Results/hostnames | grep '445' | awk '{print $2}' > Results/ips_gathered",
                shell=True)
            subprocess.call(
                "strings Results/hostnames | grep '445' | awk '{print $4}' > Results/hostnames_gathered",
                shell=True)
            subprocess.call(
                'strings Results/hostnames | grep ":" | cut -d ":" -f 3 | cut -d ")" -f 1 > Results/domains_gathered',
                shell=True)
            subprocess.call(
                'strings Results/hostnames | grep ":" | cut -d "(" -f 1  > Results/operating_systems',
                shell=True)

            ips_gathered = []
            hostnames_gathered = []
            domains_gathered = []
            os_gathered = []

            # Read files into the lists
            with open("Results/ips_gathered", "r") as ips:
                ips_gathered = ips.readlines()
            with open("Results/hostnames_gathered", "r") as hostnames:
                hostnames_gathered = hostnames.readlines()
            with open("Results/domains_gathered", "r") as domains:
                domains_gathered = domains.readlines()
            with open("Results/operating_systems", "r") as oper:
                os_gathered = oper.readlines()

            #subprocess.call("rm Results/ips_gathered", shell=True)
            #subprocess.call("rm Results/hostnames_gathered", shell=True)
            #subprocess.call("rm Results/domains_gathered", shell=True)
            #subprocess.call("rm Results/operating_systems", shell=True)
            #subprocess.call("rm Results/hostnames", shell=True)

            # Get the array length for the loop
            length = len(ips_gathered)

            for i in range(0, length):
                self.ips_gathered.append(ips_gathered[i].strip())
                self.hostnames_gathered.append(hostnames_gathered[i].strip())
                self.domains_gathered.append(domains_gathered[i].strip())
                os = os_gathered[i].replace("[0m", " ")
                self.os_gathered.append(os.strip())

            # Write the results on stdout and DB
            for i in range(0, length):
                if self.ips_gathered[i].strip() != int_ip.strip():
                    res_table.add_row([
                        self.ips_gathered[i].strip(),
                        self.hostnames_gathered[i].strip(),
                        self.domains_gathered[i].strip(),
                        self.os_gathered[i].strip()
                    ])
            print(res_table)
        except:
            print(bcolors.FAIL + "No Hostnames Found\n" + bcolors.ENDC)
        length = len(self.live_ips)
        if length != 0:
            print(bcolors.OKGREEN + "\n      [  SCOPE DEFINITION MODULE ]\n" +
                  bcolors.ENDC)
            for ip in self.live_ips:
                if ip.strip() != int_ip.strip():
                    print(bcolors.TITLE + "[+] " + bcolors.ENDC +
                          "%s " % ip.strip() + "added to scope!")
        else:
            print(
                bcolors.WARNING +
                "NO LIVE IPS FOUND! THERE IS NO NEED TO CONTINUE! WARBERRY WILL NOW EXIT!"
                + bcolors.ENDC)
            sys.exit(1)
예제 #10
0
    def findHostnames(self, int_ip, CIDR):

        print(bcolors.OKGREEN + "      [ HOSTNAMES ENUMERATION MODULE ]\n" + bcolors.ENDC)
        hostname = socket.gethostname()

        res_table = PrettyTable([bcolors.OKGREEN + '[IP]' + bcolors.ENDC, bcolors.OKGREEN + '[Hostname]' + bcolors.ENDC,
                                 bcolors.OKGREEN + '[Domain]' + bcolors.ENDC,
                                 bcolors.OKGREEN + '[Operating System]' + bcolors.ENDC], border=False, header=True)
        res_table.align = "l"
        print("Searching for hostnames in %s...\n" % CIDR)
        print("Current Hostname:" + bcolors.TITLE + " %s" % hostname + bcolors.ENDC)
        print(" ")
        
        try:
            subprocess.call('cme -t 50 --timeout 2 smb %s  > Results/hostnames' % CIDR, shell=True)
            #Discover live hosts
            nm=nmap.PortScanner()
            nm_arp=nm.scan(hosts=CIDR,arguments="-sn")
            for x in nm_arp.items()[1][1]:
                self.live_ips.append(x)
            
            self.live_ips.remove(int_ip)

            subprocess.call("strings Results/hostnames | grep '445' | awk '{print $2}' > Results/ips_gathered",shell=True)
            subprocess.call("strings Results/hostnames | grep '445' | awk '{print $4}' > Results/hostnames_gathered",shell=True)
            subprocess.call('strings Results/hostnames | grep ":" | cut -d ":" -f 3 | cut -d ")" -f 1 > Results/domains_gathered', shell=True)
            subprocess.call('strings Results/hostnames | grep ":" | cut -d "(" -f 1  > Results/operating_systems', shell=True)

            ips_gathered=[]
	    hostnames_gathered=[]
            domains_gathered=[]
            os_gathered=[]
   
	 # Read files into the lists
            with open("Results/ips_gathered", "r") as ips:
                ips_gathered = ips.readlines()
            with open("Results/hostnames_gathered", "r") as hostnames:
                hostnames_gathered = hostnames.readlines()
            with open("Results/domains_gathered", "r") as domains:
                domains_gathered = domains.readlines()
            with open("Results/operating_systems", "r") as oper:
                os_gathered = oper.readlines()

            subprocess.call("rm Results/ips_gathered", shell=True)
            subprocess.call("rm Results/hostnames_gathered", shell=True)
            subprocess.call("rm Results/domains_gathered", shell=True)
            subprocess.call("rm Results/operating_systems", shell=True)
  	    subprocess.call("rm Results/hostnames", shell=True)  

            # Get the array length for the loop
            length = len(ips_gathered)
	    
    	    for i in range(0, length):
        		self.ips_gathered.append(ips_gathered[i].strip())
        		self.hostnames_gathered.append(hostnames_gathered[i].strip())
        		self.domains_gathered.append(domains_gathered[i].strip())
                	os=os_gathered[i].replace("[0m"," ")
                	self.os_gathered.append(os.strip())
        	
            # Write the results on stdout and DB
            for i in range(0, length):
                if self.ips_gathered[i].strip() != int_ip.strip():
                    res_table.add_row([self.ips_gathered[i].strip(), self.hostnames_gathered[i].strip(),
                                       self.domains_gathered[i].strip(), self.os_gathered[i].strip()])
            print(res_table)
        except:
            print(bcolors.FAIL + "No Hostnames Found\n" + bcolors.ENDC)
        length = len(self.live_ips)
        if length != 0:
            print(bcolors.OKGREEN + "\n      [  SCOPE DEFINITION MODULE ]\n" + bcolors.ENDC)
            for ip in self.live_ips:
                if ip.strip() != int_ip.strip():
                    print(bcolors.TITLE + "[+] " + bcolors.ENDC + "%s " % ip.strip() + "added to scope!")
        else:
            print(
                    bcolors.WARNING + "NO LIVE IPS FOUND! THERE IS NO NEED TO CONTINUE! WARBERRY WILL NOW EXIT!" + bcolors.ENDC)
            sys.exit(1)
예제 #11
0
# Get operating system and version
os = subprocess.check_output('cat /etc/redhat-release', shell=True).decode('utf-8')

# Get system memory and hdd/ssd info
mem_cmd = "free -h | sed -n 2p | awk '{ print $2 }'"
memory = subprocess.check_output(mem_cmd, shell=True).decode('utf-8')
hdd_cmd = "lsblk | grep disk | cut -d' ' -f1"
hdd = subprocess.check_output(hdd_cmd, shell=True).decode('utf-8')
hdd_name = hdd.strip('\n')
hdd_capacity_cmd = "lsblk | grep disk | awk '{ print $4 }'"
hdd_capacity = subprocess.check_output(hdd_capacity_cmd, shell=True).decode('utf-8')
hdd_model_cmd = "udevadm info --query=all --name=/dev/" + hdd_name + "| grep -i SCSI_MODEL | sed -n 1p | cut -d'=' -f2"
hdd_model = subprocess.check_output(hdd_model_cmd, shell=True).decode('utf-8')
hdd_serial_cmd = "udevadm info --query=all --name=/dev/" + hdd_name + "| grep -i serial_short | cut -d'=' -f2"
hdd_serial = subprocess.check_output(hdd_serial_cmd, shell=True).decode('utf-8')

df = pd.DataFrame({
    'Hostname': [hostname.strip('\n')],
    'SerialNumber': [serial.strip('\n')],
    'Manufacturer': [manufacturer.strip('\n')],
    'Model': [model.strip('\n')],
    'OS': [os.strip('\n')],
    'Memory': [memory.strip('\n')],
    'HDD_Capacity': [hdd_capacity.strip('\n')],
    'HDD_Model': [hdd_model.strip('\n')],
    'HDD_Serial': [hdd_serial.strip('\n')]
    })

df.to_csv('demo.csv', index=False)